From c237cd46e5765eaa1db3b50aa2f2cf4bb5be7964 Mon Sep 17 00:00:00 2001 From: MirceaKitsune Date: Wed, 2 Mar 2011 23:52:21 +0200 Subject: [PATCH] Move code in an already existing function, as that is better --- data/qcsrc/server/cl_weaponsystem.qc | 88 +++++++++++++--------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/data/qcsrc/server/cl_weaponsystem.qc b/data/qcsrc/server/cl_weaponsystem.qc index 004442c9..8b06407c 100644 --- a/data/qcsrc/server/cl_weaponsystem.qc +++ b/data/qcsrc/server/cl_weaponsystem.qc @@ -1567,8 +1567,42 @@ void W_DecreaseAmmo(.float ammo_type, float ammo_use, float ammo_reload) .float reload_complain; .string reload_sound; -float W_ReloadCheck() +void W_ReloadedAndReady() { + // finish the reloading process, and do the ammo transfer + + self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading + + // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load + if(!self.reload_ammo_min) + self.clip_load = self.reload_ammo_amount; + else + { + while(self.clip_load < self.reload_ammo_amount && self.(self.current_ammo)) // make sure we don't add more ammo than we have + { + self.clip_load += 1; + self.(self.current_ammo) -= 1; + } + } + self.weapon_load[self.weapon] = self.clip_load; + + // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon, + // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there, + // so your weapon is disabled for a few seconds without reason + + //ATTACK_FINISHED(self) -= self.reload_time - 1; + + w_ready(); +} + +void W_Reload(float sent_ammo_min, float sent_ammo_amount, float sent_time, string sent_sound) +{ + // set global values to work with + self.reload_ammo_min = sent_ammo_min; + self.reload_ammo_amount = sent_ammo_amount; + self.reload_time = sent_time; + self.reload_sound = sent_sound; + // check if we meet the necessary conditions to reload entity e; @@ -1578,16 +1612,16 @@ float W_ReloadCheck() if not(e.spawnflags & WEP_FLAG_RELOADABLE) { dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n"); - return FALSE; + return; } // return if reloading is disabled for this weapon if(!self.reload_ammo_amount) - return FALSE; + return; // our weapon is fully loaded, no need to reload if (self.clip_load >= self.reload_ammo_amount) - return FALSE; + return; // no ammo, so nothing to load if(!self.(self.current_ammo) && self.reload_ammo_min) @@ -1604,60 +1638,18 @@ float W_ReloadCheck() self.clip_load = -1; // reload later W_SwitchToOtherWeapon(self); } - return FALSE; + return; } if (self.weaponentity) { if (self.weaponentity.wframe == WFRAME_RELOAD) - return FALSE; + return; // allow switching away while reloading, but this will cause a new reload! self.weaponentity.state = WS_READY; } - return TRUE; -} - -void W_ReloadedAndReady() -{ - // finish the reloading process, and do the ammo transfer - - self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading - - // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load - if(!self.reload_ammo_min) - self.clip_load = self.reload_ammo_amount; - else - { - while(self.clip_load < self.reload_ammo_amount && self.(self.current_ammo)) // make sure we don't add more ammo than we have - { - self.clip_load += 1; - self.(self.current_ammo) -= 1; - } - } - self.weapon_load[self.weapon] = self.clip_load; - - // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon, - // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there, - // so your weapon is disabled for a few seconds without reason - - //ATTACK_FINISHED(self) -= self.reload_time - 1; - - w_ready(); -} - -void W_Reload(float sent_ammo_min, float sent_ammo_amount, float sent_time, string sent_sound) -{ - // set global values to work with - self.reload_ammo_min = sent_ammo_min; - self.reload_ammo_amount = sent_ammo_amount; - self.reload_time = sent_time; - self.reload_sound = sent_sound; - - if(!W_ReloadCheck()) - return; - // now begin the reloading process sound (self, CHAN_WEAPON2, self.reload_sound, VOL_BASE, ATTN_NORM); -- 2.39.2