SERVER: Move weapon utilities to their own file

This commit is contained in:
Steam Deck User 2023-03-22 10:23:15 -04:00
parent 2da62518c0
commit 316aba63e7
7 changed files with 138 additions and 109 deletions

View file

@ -10,6 +10,7 @@
../source/server/rounds.qc ../source/server/rounds.qc
../source/server/nzdparser.qc ../source/server/nzdparser.qc
../source/server/main.qc ../source/server/main.qc
../source/server/utilities/weapon_utilities.qc
../source/server/utilities/game_restart.qc ../source/server/utilities/game_restart.qc
../source/server/utilities/command_parser.qc ../source/server/utilities/command_parser.qc
../source/server/utilities/math.qc ../source/server/utilities/math.qc

View file

@ -14,6 +14,7 @@
../source/server/rounds.qc ../source/server/rounds.qc
../source/server/nzdparser.qc ../source/server/nzdparser.qc
../source/server/main.qc ../source/server/main.qc
../source/server/utilities/weapon_utilities.qc
../source/server/utilities/game_restart.qc ../source/server/utilities/game_restart.qc
../source/server/utilities/command_parser.qc ../source/server/utilities/command_parser.qc
../source/server/utilities/math.qc ../source/server/utilities/math.qc

View file

@ -615,99 +615,3 @@ void(entity person, float expamt, float doublepoint) addmoney =
UpdatePlayerPoints(person.playernum, person.points, expamt, person.kills, person.netname, person); 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;
}

View file

@ -244,16 +244,16 @@ void() GetDown =
// Reset Juggernog health // Reset Juggernog health
self.max_health = self.health = PLAYER_START_HEALTH; self.max_health = self.health = PLAYER_START_HEALTH;
if(Util_PlayerHasWeapon(self, W_BIATCH, false) || if(Weapon_PlayerHasWeapon(self, W_BIATCH, false) ||
Util_PlayerHasWeapon(self, W_RAY, true) || Weapon_PlayerHasWeapon(self, W_RAY, true) ||
Util_PlayerHasWeapon(self, W_357, true)) { Weapon_PlayerHasWeapon(self, W_357, true)) {
float weapon_slot; float weapon_slot;
float total_ammo; float total_ammo;
total_ammo = 0; total_ammo = 0;
weapon_slot = Util_PlayerHasWeapon(self, W_RAY, true); weapon_slot = Weapon_PlayerHasWeapon(self, W_RAY, true);
if (weapon_slot == 0) weapon_slot = Util_PlayerHasWeapon(self, W_BIATCH, false); if (weapon_slot == 0) weapon_slot = Weapon_PlayerHasWeapon(self, W_BIATCH, false);
if (weapon_slot == 0) weapon_slot = Util_PlayerHasWeapon(self, W_357, true); if (weapon_slot == 0) weapon_slot = Weapon_PlayerHasWeapon(self, W_357, true);
switch(weapon_slot) { switch(weapon_slot) {
case 1: case 1:

View file

@ -149,12 +149,12 @@ void () WallWeapon_TouchTrigger =
float slot; float slot;
// Player has this weapon in any of their slots, PaP'd or not. // 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; float is_pap = true;
// But the utility function returns the same value if we are NOT PaP'd // 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; is_pap = false;
// Set the cost and weapon value (for useprint). // Set the cost and weapon value (for useprint).
@ -168,7 +168,7 @@ void () WallWeapon_TouchTrigger =
} }
// Store current Ammo value. // Store current Ammo value.
float ammo = Util_GetPlayerAmmoInSlot(other, slot); float ammo = Weapon_GetPlayerAmmoInSlot(other, slot);
// Max carrying capacity of the wall weapon // Max carrying capacity of the wall weapon
float wall_ammo = (is_pap) ? getWeaponAmmo(EqualPapWeapon(self.weapon)) : getWeaponAmmo(self.weapon); float wall_ammo = (is_pap) ? getWeaponAmmo(EqualPapWeapon(self.weapon)) : getWeaponAmmo(self.weapon);
@ -188,7 +188,7 @@ void () WallWeapon_TouchTrigger =
other.ach_tracker_coll++; other.ach_tracker_coll++;
// Set the weapon's ammo to the max capacity. // 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); sound(other, 0, "sounds/misc/ching.wav", 1, 1);
other.reload_delay = 0; other.reload_delay = 0;

View file

@ -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;
}

View file

@ -1473,7 +1473,7 @@ void(float side) W_Fire =
playdownfire(); playdownfire();
// Check if weapon is semi-automatic and if it is, if it's ready to be fired. // 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 (side == S_RIGHT) {
if (self.semi) return; if (self.semi) return;
self.semi = true; self.semi = true;
@ -1484,7 +1484,7 @@ void(float side) W_Fire =
} }
// Weapon Projectile/Trace Logic. // Weapon Projectile/Trace Logic.
if (Util_WeaponFiresTraceshot(self.weapon)) { if (Weapon_FiresTraceshot(self.weapon)) {
#ifdef FTE #ifdef FTE