From: Mircea Kitsune Date: Fri, 21 Jan 2011 16:33:11 +0000 (+0200) Subject: Tidy up code and comments X-Git-Tag: xonotic-v0.5.0~309^2~7^2~155 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d4141455575f8af54dded126ec888aa61373bbda;p=xonotic%2Fxonotic-data.pk3dir.git Tidy up code and comments --- diff --git a/qcsrc/server/cl_weaponsystem.qc b/qcsrc/server/cl_weaponsystem.qc index faf18b8da..cb8ff3d59 100644 --- a/qcsrc/server/cl_weaponsystem.qc +++ b/qcsrc/server/cl_weaponsystem.qc @@ -928,8 +928,8 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain) f = weapon_action(wpn, WR_CHECKAMMO1); f = f + weapon_action(wpn, WR_CHECKAMMO2); - // don't switch away from reloadable weapons, even if we're out of ammo, since the - // weapon itself might still be loaded. The reload code takes care of the switching + // allow switching to reloadable weapons, even if we're out of ammo, since the weapon itself + // might still be loaded. The reload code takes care of complaining and forced switching entity e; e = get_weaponinfo(self.weapon); if(cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) @@ -1054,8 +1054,8 @@ float weapon_prepareattack_checkammo(float secondary) if not(self.items & IT_UNLIMITED_WEAPON_AMMO) if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary)) { - // don't switch away from reloadable weapons, even if we're out of ammo, since the - // weapon itself might still be loaded. The reload code takes care of the switching + // allow switching to reloadable weapons, even if we're out of ammo, since the weapon itself + // might still be loaded. The reload code takes care of complaining and forced switching entity e; e = get_weaponinfo(self.weapon); if(cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) @@ -1626,20 +1626,20 @@ 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 -// ---------------------------------------------------------------- - +// shared weapon reload code float W_ReloadCheck(float ammo_amount) { entity e; e = get_weaponinfo(self.weapon); + + // our weapon is fully loaded, no need to reload if (self.ammo_counter >= cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) return 0; - if(!ammo_amount) // when we get here, ammo_counter must be 0 or -1 + // no ammo, so nothing to load + if(!ammo_amount) { - print("cannot reload... not enough ammo\n"); + print("Cannot reload, not enough ammo\n"); self.ammo_counter = -1; // reload later W_SwitchToOtherWeapon(self); return 0; @@ -1650,13 +1650,9 @@ float W_ReloadCheck(float ammo_amount) if (self.weaponentity.wframe == WFRAME_RELOAD) return 0; - // allow to switch away while reloading, but this will cause a new reload! + // allow switching away while reloading, but this will cause a new reload! self.weaponentity.state = WS_READY; } return 1; -} - -// ---------------------------------------------------------------- -// end of weapon reload code -// ---------------------------------------------------------------- \ No newline at end of file +} \ No newline at end of file diff --git a/qcsrc/server/w_shotgun.qc b/qcsrc/server/w_shotgun.qc index 328be10c0..c0e57b8c0 100644 --- a/qcsrc/server/w_shotgun.qc +++ b/qcsrc/server/w_shotgun.qc @@ -7,9 +7,9 @@ REGISTER_WEAPON(SHOTGUN, w_shotgun, IT_SHELLS, 2, WEP_FLAG_NORMAL | WEP_TYPE_HIT void W_Shotgun_SetAmmoCounter() { - // set ammo counter to the weapon we have switched to + // set ammo_counter to the weapon we have switched to, if the gun uses reloading if(!autocvar_g_balance_shotgun_reload_ammo) - self.ammo_counter = 0; // also keeps the crosshair ammo from displaying + self.ammo_counter = 0; // also keeps crosshair ammo from displaying else self.ammo_counter = self.shotgun_load; } @@ -18,9 +18,9 @@ void W_Shotgun_ReloadedAndReady() { float t; - // now do the ammo maths - self.ammo_counter = self.old_ammo_counter; // restore ammo counter, in case we still had ammo in the weapon while reloading - while(self.ammo_counter < autocvar_g_balance_shotgun_reload_ammo && self.ammo_shells) // make sure we don't add more than the amount of ammo we have + // now do the ammo transfer + self.ammo_counter = self.old_ammo_counter; // restore the ammo counter, in case we still had ammo in the weapon before reloading + while(self.ammo_counter < autocvar_g_balance_shotgun_reload_ammo && self.ammo_shells) // make sure we don't add more ammo than we have { self.ammo_counter += 1; self.ammo_shells -= 1; @@ -34,15 +34,15 @@ void W_Shotgun_ReloadedAndReady() void W_Shotgun_Reload() { - // reloading is disabled for this weapon + // return if reloading is disabled for this weapon if(!autocvar_g_balance_shotgun_reload_ammo) return; - float t; - if(!W_ReloadCheck(self.ammo_shells)) return; + float t; + sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM); t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_shotgun_reload_time + 1; @@ -97,6 +97,7 @@ void W_Shotgun_Attack (void) flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION; W_AttachToShotorg(flash, '5 0 0'); + // if this weapon is reloadable, decrease its load. Else decrease the player's ammo if not(self.items & IT_UNLIMITED_WEAPON_AMMO) { if(!autocvar_g_balance_shotgun_reload_ammo) @@ -230,6 +231,10 @@ float w_shotgun(float req) { return TRUE; } + else if (req == WR_RELOAD) + { + W_Shotgun_Reload(); + } return TRUE; }; #endif diff --git a/qcsrc/server/w_sniperrifle.qc b/qcsrc/server/w_sniperrifle.qc index b6465044b..23a0609a7 100644 --- a/qcsrc/server/w_sniperrifle.qc +++ b/qcsrc/server/w_sniperrifle.qc @@ -11,9 +11,9 @@ REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_T void W_SniperRifle_SetAmmoCounter() { - // set ammo counter to the weapon we have switched to + // set ammo_counter to the weapon we have switched to, if the gun uses reloading if(!autocvar_g_balance_sniperrifle_reload_ammo) - self.ammo_counter = 0; // also keeps the crosshair ammo from displaying + self.ammo_counter = 0; // also keeps crosshair ammo from displaying else self.ammo_counter = self.sniperrifle_load; } @@ -22,9 +22,9 @@ void W_SniperRifle_ReloadedAndReady() { float t; - // now do the ammo maths - self.ammo_counter = self.old_ammo_counter; // restore ammo counter, in case we still had ammo in the weapon while reloading - while(self.ammo_counter < autocvar_g_balance_sniperrifle_reload_ammo && self.ammo_nails) // make sure we don't add more than the amount of ammo we have + // now do the ammo transfer + self.ammo_counter = self.old_ammo_counter; // restore the ammo counter, in case we still had ammo in the weapon before reloading + while(self.ammo_counter < autocvar_g_balance_sniperrifle_reload_ammo && self.ammo_nails) // make sure we don't add more ammo than we have { self.ammo_counter += 1; self.ammo_nails -= 1; @@ -38,15 +38,15 @@ void W_SniperRifle_ReloadedAndReady() void W_SniperRifle_Reload() { - // reloading is disabled for this weapon + // return if reloading is disabled for this weapon if(!autocvar_g_balance_sniperrifle_reload_ammo) return; - float t; - if(!W_ReloadCheck(self.ammo_nails)) return; + float t; + sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM); t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_sniperrifle_reload_time + 1; @@ -82,6 +82,7 @@ void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAdded if (autocvar_g_casings >= 2) 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); + // if this weapon is reloadable, decrease its load. Else decrease the player's ammo if not(self.items & IT_UNLIMITED_WEAPON_AMMO) { if(!autocvar_g_balance_sniperrifle_reload_ammo)