From 1f64c0239a76b2e14031777d8a8bbd71e58dae0d Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 17 Nov 2022 21:49:50 -0500 Subject: [PATCH] Server: Streamline weapon projectile determination Use new #defines for firetypes and a new utility function Util_WeaponIsSemiAutomatic to make W_Fire far more legible in the section where firing a projectile or trace is done. --- source/server/clientfuncs.qc | 19 +++++++++++- source/server/weapons/weapon_core.qc | 46 ++++++++++++++-------------- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/source/server/clientfuncs.qc b/source/server/clientfuncs.qc index ae520b0..52c2705 100644 --- a/source/server/clientfuncs.qc +++ b/source/server/clientfuncs.qc @@ -646,6 +646,23 @@ float(entity person, float comparison, float include_pap) Util_PlayerHasWeapon = 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_RAYBEAM || firetype == FIRETYPE_TESLA) + return true; + + return false; +} + // // Util_WeaponFiresTraceshot(weapon) // Simply returns true if given weapon's firetype requires a @@ -656,7 +673,7 @@ float(float weapon) Util_WeaponFiresTraceshot = float firetype = GetFiretype(weapon); // Valid firetypes - if (firetype == 0 || firetype == 1) + 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 87f0f41..867ce08 100644 --- a/source/server/weapons/weapon_core.qc +++ b/source/server/weapons/weapon_core.qc @@ -1507,38 +1507,38 @@ void(float side) W_Fire = if (self.downed) playdownfire(); - // MOTO - should probably reorganize this whole firetype chunk in the future.. - - //Fire weapons - if (firetype == 1 || firetype == 3) - { + // Check if weapon is semi-automatic and if it is, if it's ready to be fired. + if (Util_WeaponIsSemiAutomatic(self.weapon)) { if (side == S_RIGHT) { - if (self.semi) { - return; - } - self.semi = TRUE; + if (self.semi) return; + self.semi = true; } else if (side == S_LEFT) { - if (self.semi2) { - return; - } - self.semi2 = TRUE; + if (self.semi2) return; + self.semi2 == true; } - - if (firetype == 3) { - W_FireGrenade(side); - } - } else if (firetype == 4) { - W_FireRay(); - } else if (firetype == 5) { - W_FireTesla(); - } else if (firetype == 6) { - W_FireM2(); } + // Weapon Projectile/Trace Logic. if (Util_WeaponFiresTraceshot(self.weapon)) { FireTrace(shotcount, spread, damage, side); } + switch(firetype) { + case FIRETYPE_GRENADE: + W_FireGrenade(side); + break; + case FIRETYPE_RAYBEAM: + W_FireRay(); + break; + case FIRETYPE_TESLA: + W_FireTesla(); + break; + case FIRETYPE_FLAME: + W_FireM2(); + break; + default: break; + } + //Play weapon animation and sound startframe = GetFrame(self.weapon,FIRE_START); endframe = GetFrame(self.weapon,FIRE_END);