diff --git a/progs/fte-server.src b/progs/fte-server.src index baed883..5023726 100644 --- a/progs/fte-server.src +++ b/progs/fte-server.src @@ -10,6 +10,7 @@ ../source/server/rounds.qc ../source/server/nzdparser.qc ../source/server/main.qc +../source/server/utilities/weapon_utilities.qc ../source/server/utilities/game_restart.qc ../source/server/utilities/command_parser.qc ../source/server/utilities/math.qc diff --git a/progs/standard.src b/progs/standard.src index 67ee4e8..34be927 100644 --- a/progs/standard.src +++ b/progs/standard.src @@ -14,6 +14,7 @@ ../source/server/rounds.qc ../source/server/nzdparser.qc ../source/server/main.qc +../source/server/utilities/weapon_utilities.qc ../source/server/utilities/game_restart.qc ../source/server/utilities/command_parser.qc ../source/server/utilities/math.qc diff --git a/source/server/clientfuncs.qc b/source/server/clientfuncs.qc index a51ca7b..cb9dbb7 100644 --- a/source/server/clientfuncs.qc +++ b/source/server/clientfuncs.qc @@ -614,100 +614,4 @@ void(entity person, float expamt, float doublepoint) addmoney = person.points += expamt; UpdatePlayerPoints(person.playernum, person.points, expamt, person.kills, person.netname, person); -}; - -// -// Util_GetPlayerAmmoInSlot(person, slot) -// Returns the reserve ammo the player has in a weapon slot. -// -float(entity person, float slot) Util_GetPlayerAmmoInSlot = -{ - switch(slot) { - case 1: return person.currentammo; break; - case 2: return person.secondaryammo; break; - case 3: return person.thirdammo; break; - default: return 0; break; - } -} - -// -// Util_SetPlayerAmmoInSlot(person, slot, ammo) -// Sets the player's reserve ammo in a slot to param3. -// -void(entity person, float slot, float ammo) Util_SetPlayerAmmoInSlot = -{ - switch(slot) { - case 1: person.currentammo = ammo; break; - case 2: person.secondaryammo = ammo; break; - case 3: person.thirdammo = ammo; break; - default: return; break; - } -}; - -// -// Util_PlayerHasWeapon(peron, comparison, include_pap) -// Checks to see if the Player is holding a weapon in any -// of their three slots. `include_pap` dictates whether to -// consider Pack-A-Punch'd varients. Returns 1, 2, 3 depending -// on the slot the weapon is contained in. -// -float(entity person, float comparison, float include_pap) Util_PlayerHasWeapon = -{ - // Storage. - float first, second, third; - - // If we're including pap'd weapons, just convert the weapon set to the base - // ones to save on comparison checks. - if (include_pap == true) { - first = EqualNonPapWeapon(person.weapon); - second = EqualNonPapWeapon(person.secondaryweapon); - third = EqualNonPapWeapon(person.thirdweapon); - } else { - first = person.weapon; - second = person.secondaryweapon; - third = person.thirdweapon; - } - - // Now do the comparisons - if (first == comparison) - return 1; - if (second == comparison) - return 2; - if (third == comparison) - return 3; - - return 0; -}; - -// -// Util_WeaponIsSemiAutomatic(float weapon) -// Checks weapon firetypes and returns true if intended -// to be semi-automatic. -// -float(float weapon) Util_WeaponIsSemiAutomatic = -{ - float firetype = GetFiretype(weapon); - - // Valid firetypes - if (firetype == FIRETYPE_SEMIAUTO || firetype == FIRETYPE_GRENADE || - firetype == FIRETYPE_TESLA) - return true; - - return false; -} - -// -// Util_WeaponFiresTraceshot(weapon) -// Simply returns true if given weapon's firetype requires a -// firetrace to be used properly. -// -float(float weapon) Util_WeaponFiresTraceshot = -{ - float firetype = GetFiretype(weapon); - - // Valid firetypes - if (firetype == FIRETYPE_FULLAUTO || firetype == FIRETYPE_SEMIAUTO) - return true; - - return false; -} +}; \ No newline at end of file diff --git a/source/server/damage.qc b/source/server/damage.qc index 803349e..8894710 100644 --- a/source/server/damage.qc +++ b/source/server/damage.qc @@ -244,16 +244,16 @@ void() GetDown = // Reset Juggernog health self.max_health = self.health = PLAYER_START_HEALTH; - if(Util_PlayerHasWeapon(self, W_BIATCH, false) || - Util_PlayerHasWeapon(self, W_RAY, true) || - Util_PlayerHasWeapon(self, W_357, true)) { + if(Weapon_PlayerHasWeapon(self, W_BIATCH, false) || + Weapon_PlayerHasWeapon(self, W_RAY, true) || + Weapon_PlayerHasWeapon(self, W_357, true)) { float weapon_slot; float total_ammo; total_ammo = 0; - weapon_slot = Util_PlayerHasWeapon(self, W_RAY, true); - if (weapon_slot == 0) weapon_slot = Util_PlayerHasWeapon(self, W_BIATCH, false); - if (weapon_slot == 0) weapon_slot = Util_PlayerHasWeapon(self, W_357, true); + weapon_slot = Weapon_PlayerHasWeapon(self, W_RAY, true); + if (weapon_slot == 0) weapon_slot = Weapon_PlayerHasWeapon(self, W_BIATCH, false); + if (weapon_slot == 0) weapon_slot = Weapon_PlayerHasWeapon(self, W_357, true); switch(weapon_slot) { case 1: diff --git a/source/server/entities/wall_weapon.qc b/source/server/entities/wall_weapon.qc index 0e4495e..5816b8c 100644 --- a/source/server/entities/wall_weapon.qc +++ b/source/server/entities/wall_weapon.qc @@ -149,12 +149,12 @@ void () WallWeapon_TouchTrigger = float slot; // Player has this weapon in any of their slots, PaP'd or not. - if ((slot = Util_PlayerHasWeapon(other, self.weapon, true)) != 0) { + if ((slot = Weapon_PlayerHasWeapon(other, self.weapon, true)) != 0) { float is_pap = true; // But the utility function returns the same value if we are NOT PaP'd - if (Util_PlayerHasWeapon(other, self.weapon, false) == slot) + if (Weapon_PlayerHasWeapon(other, self.weapon, false) == slot) is_pap = false; // Set the cost and weapon value (for useprint). @@ -168,7 +168,7 @@ void () WallWeapon_TouchTrigger = } // Store current Ammo value. - float ammo = Util_GetPlayerAmmoInSlot(other, slot); + float ammo = Weapon_GetPlayerAmmoInSlot(other, slot); // Max carrying capacity of the wall weapon float wall_ammo = (is_pap) ? getWeaponAmmo(EqualPapWeapon(self.weapon)) : getWeaponAmmo(self.weapon); @@ -188,7 +188,7 @@ void () WallWeapon_TouchTrigger = other.ach_tracker_coll++; // Set the weapon's ammo to the max capacity. - Util_SetPlayerAmmoInSlot(other, slot, wall_ammo); + Weapon_SetPlayerAmmoInSlot(other, slot, wall_ammo); sound(other, 0, "sounds/misc/ching.wav", 1, 1); other.reload_delay = 0; diff --git a/source/server/utilities/weapon_utilities.qc b/source/server/utilities/weapon_utilities.qc new file mode 100644 index 0000000..b9a3690 --- /dev/null +++ b/source/server/utilities/weapon_utilities.qc @@ -0,0 +1,123 @@ +/* + server/utilities/weapon_utilities.qc + + Contains some wrapped or easy access functions to streamline weapon + behaviors a bit. + + Copyright (C) 2021-2023 NZ:P Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ + +// +// Weapon_GetPlayerAmmoInSlot(person, slot) +// Returns the reserve ammo the player has in a weapon slot. +// +float(entity person, float slot) Weapon_GetPlayerAmmoInSlot = +{ + switch(slot) { + case 1: return person.currentammo; break; + case 2: return person.secondaryammo; break; + case 3: return person.thirdammo; break; + default: return 0; break; + } +} + +// +// Weapon_SetPlayerAmmoInSlot(person, slot, ammo) +// Sets the player's reserve ammo in a slot to param3. +// +void(entity person, float slot, float ammo) Weapon_SetPlayerAmmoInSlot = +{ + switch(slot) { + case 1: person.currentammo = ammo; break; + case 2: person.secondaryammo = ammo; break; + case 3: person.thirdammo = ammo; break; + default: return; break; + } +}; + +// +// Weapon_PlayerHasWeapon(peron, comparison, include_pap) +// Checks to see if the Player is holding a weapon in any +// of their three slots. `include_pap` dictates whether to +// consider Pack-A-Punch'd varients. Returns 1, 2, 3 depending +// on the slot the weapon is contained in. +// +float(entity person, float comparison, float include_pap) Weapon_PlayerHasWeapon = +{ + // Storage. + float first, second, third; + + // If we're including pap'd weapons, just convert the weapon set to the base + // ones to save on comparison checks. + if (include_pap == true) { + first = EqualNonPapWeapon(person.weapon); + second = EqualNonPapWeapon(person.secondaryweapon); + third = EqualNonPapWeapon(person.thirdweapon); + } else { + first = person.weapon; + second = person.secondaryweapon; + third = person.thirdweapon; + } + + // Now do the comparisons + if (first == comparison) + return 1; + if (second == comparison) + return 2; + if (third == comparison) + return 3; + + return 0; +}; + +// +// Weapon_IsSemiAutomatic(float weapon) +// Checks weapon firetypes and returns true if intended +// to be semi-automatic. +// +float(float weapon) Weapon_IsSemiAutomatic = +{ + float firetype = GetFiretype(weapon); + + // Valid firetypes + if (firetype == FIRETYPE_SEMIAUTO || firetype == FIRETYPE_GRENADE || + firetype == FIRETYPE_TESLA) + return true; + + return false; +} + +// +// Weapon_FiresTraceshot(weapon) +// Simply returns true if given weapon's firetype requires a +// firetrace to be used properly. +// +float(float weapon) Weapon_FiresTraceshot = +{ + float firetype = GetFiretype(weapon); + + // Valid firetypes + if (firetype == FIRETYPE_FULLAUTO || firetype == FIRETYPE_SEMIAUTO) + return true; + + return false; +} diff --git a/source/server/weapons/weapon_core.qc b/source/server/weapons/weapon_core.qc index 9132318..f6ab579 100644 --- a/source/server/weapons/weapon_core.qc +++ b/source/server/weapons/weapon_core.qc @@ -1473,7 +1473,7 @@ void(float side) W_Fire = playdownfire(); // Check if weapon is semi-automatic and if it is, if it's ready to be fired. - if (Util_WeaponIsSemiAutomatic(self.weapon)) { + if (Weapon_IsSemiAutomatic(self.weapon)) { if (side == S_RIGHT) { if (self.semi) return; self.semi = true; @@ -1484,7 +1484,7 @@ void(float side) W_Fire = } // Weapon Projectile/Trace Logic. - if (Util_WeaponFiresTraceshot(self.weapon)) { + if (Weapon_FiresTraceshot(self.weapon)) { #ifdef FTE