From: Mircea Kitsune Date: Thu, 20 Jan 2011 21:54:07 +0000 (+0200) Subject: First step in a common reload system for all weapons. Move the campingrifle reload... X-Git-Tag: xonotic-v0.5.0~309^2~7^2~184 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d1003fe9a755eab10021b974f285c35d5df11847;p=xonotic%2Fxonotic-data.pk3dir.git First step in a common reload system for all weapons. Move the campingrifle reload code to cl_weaponsystem.qc. --- diff --git a/qcsrc/server/cl_weaponsystem.qc b/qcsrc/server/cl_weaponsystem.qc index 057c5cb1d..bd1612536 100644 --- a/qcsrc/server/cl_weaponsystem.qc +++ b/qcsrc/server/cl_weaponsystem.qc @@ -1611,3 +1611,81 @@ void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread) #define W_SETUPPROJECTILEVELOCITY_UP(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), cvar(#s "_speed_up"), cvar(#s "_speed_z"), cvar(#s "_spread"), FALSE) #define W_SETUPPROJECTILEVELOCITY(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), 0, 0, cvar(#s "_spread"), FALSE) + +// ---------------------------------------------------------------- +// weapon reload code +// ---------------------------------------------------------------- + +float W_SniperRifle_CheckMaxBullets(float checkammo) +{ + float maxbulls; + maxbulls = autocvar_g_balance_sniperrifle_magazinecapacity; + if(!maxbulls) + maxbulls = 8; // match HUD + if(checkammo) + if not(self.items & IT_UNLIMITED_WEAPON_AMMO) + maxbulls = min(maxbulls, floor(self.ammo_nails / min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo))); + if(self.sniperrifle_bulletcounter > maxbulls || !autocvar_g_balance_sniperrifle_magazinecapacity) + self.sniperrifle_bulletcounter = maxbulls; + return (self.sniperrifle_bulletcounter == maxbulls); +} + +void W_SniperRifle_ReloadedAndReady() +{ + float t; + self.sniperrifle_bulletcounter = autocvar_g_balance_sniperrifle_magazinecapacity; + W_SniperRifle_CheckMaxBullets(TRUE); + t = ATTACK_FINISHED(self) - autocvar_g_balance_sniperrifle_reloadtime - 1; + ATTACK_FINISHED(self) = t; + w_ready(); +} + +float W_SniperRifle_Reload() +{ + float t; + + W_SniperRifle_CheckMaxBullets(TRUE); + + if(self.ammo_nails < min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo)) // when we get here, bulletcounter must be 0 or -1 + { + print("cannot reload... not enough bullets\n"); + self.sniperrifle_bulletcounter = -1; // reload later + W_SwitchToOtherWeapon(self); + return 0; + } + + if (self.sniperrifle_bulletcounter >= autocvar_g_balance_sniperrifle_magazinecapacity) + return 0; + + if (self.weaponentity) + { + if (self.weaponentity.wframe == WFRAME_RELOAD) + return 0; + + // allow to switch away while reloading, but this will cause a new reload! + self.weaponentity.state = WS_READY; + } + + sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM); + + t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_sniperrifle_reloadtime + 1; + ATTACK_FINISHED(self) = t; + + weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_sniperrifle_reloadtime, W_SniperRifle_ReloadedAndReady); + + self.sniperrifle_bulletcounter = -1; + + return 1; +} + +void W_SniperRifle_CheckReloadAndReady() +{ + w_ready(); + if(self.sniperrifle_bulletcounter <= 0) + if(W_SniperRifle_Reload()) + return; +} + +// ---------------------------------------------------------------- +// end of weapon reload code +// ---------------------------------------------------------------- \ No newline at end of file diff --git a/qcsrc/server/cl_weaponsystem.qh b/qcsrc/server/cl_weaponsystem.qh new file mode 100644 index 000000000..6ba450aeb --- /dev/null +++ b/qcsrc/server/cl_weaponsystem.qh @@ -0,0 +1 @@ +void W_SniperRifle_CheckReloadAndReady(); \ No newline at end of file diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index c76395fdb..ad13a4f18 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -38,6 +38,7 @@ campaign.qh accuracy.qh csqcprojectile.qh csqceffects.qc +cl_weaponsystem.qh anticheat.qh cheats.qh diff --git a/qcsrc/server/w_sniperrifle.qc b/qcsrc/server/w_sniperrifle.qc index 68dec352d..102769aa5 100644 --- a/qcsrc/server/w_sniperrifle.qc +++ b/qcsrc/server/w_sniperrifle.qc @@ -8,76 +8,6 @@ REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_T .float sniperrifle_accumulator; -float W_SniperRifle_CheckMaxBullets(float checkammo) -{ - float maxbulls; - maxbulls = autocvar_g_balance_sniperrifle_magazinecapacity; - if(!maxbulls) - maxbulls = 8; // match HUD - if(checkammo) - if not(self.items & IT_UNLIMITED_WEAPON_AMMO) - maxbulls = min(maxbulls, floor(self.ammo_nails / min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo))); - if(self.sniperrifle_bulletcounter > maxbulls || !autocvar_g_balance_sniperrifle_magazinecapacity) - self.sniperrifle_bulletcounter = maxbulls; - return (self.sniperrifle_bulletcounter == maxbulls); -} - -void W_SniperRifle_ReloadedAndReady() -{ - float t; - self.sniperrifle_bulletcounter = autocvar_g_balance_sniperrifle_magazinecapacity; - W_SniperRifle_CheckMaxBullets(TRUE); - t = ATTACK_FINISHED(self) - autocvar_g_balance_sniperrifle_reloadtime - 1; - ATTACK_FINISHED(self) = t; - w_ready(); -} - -float W_SniperRifle_Reload() -{ - float t; - - W_SniperRifle_CheckMaxBullets(TRUE); - - if(self.ammo_nails < min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo)) // when we get here, bulletcounter must be 0 or -1 - { - print("cannot reload... not enough bullets\n"); - self.sniperrifle_bulletcounter = -1; // reload later - W_SwitchToOtherWeapon(self); - return 0; - } - - if (self.sniperrifle_bulletcounter >= autocvar_g_balance_sniperrifle_magazinecapacity) - return 0; - - if (self.weaponentity) - { - if (self.weaponentity.wframe == WFRAME_RELOAD) - return 0; - - // allow to switch away while reloading, but this will cause a new reload! - self.weaponentity.state = WS_READY; - } - - sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM); - - t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_sniperrifle_reloadtime + 1; - ATTACK_FINISHED(self) = t; - - weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_sniperrifle_reloadtime, W_SniperRifle_ReloadedAndReady); - - self.sniperrifle_bulletcounter = -1; - - return 1; -} - -void W_SniperRifle_CheckReloadAndReady() -{ - w_ready(); - if(self.sniperrifle_bulletcounter <= 0) - if(W_SniperRifle_Reload()) - return; -} - void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAddedDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant) { if not(self.items & IT_UNLIMITED_WEAPON_AMMO) @@ -106,7 +36,6 @@ void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAdded SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self); self.sniperrifle_bulletcounter = self.sniperrifle_bulletcounter - 1; - W_SniperRifle_CheckMaxBullets(TRUE); } void W_SniperRifle_Attack()