]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Tidy up code and comments
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Fri, 21 Jan 2011 16:33:11 +0000 (18:33 +0200)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Fri, 21 Jan 2011 16:33:11 +0000 (18:33 +0200)
qcsrc/server/cl_weaponsystem.qc
qcsrc/server/w_shotgun.qc
qcsrc/server/w_sniperrifle.qc

index faf18b8daefa64f0e646a19a1dd85fa16022ebb2..cb8ff3d5985dea0c82729c6d0475a38f03773259 100644 (file)
@@ -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
index 328be10c03a336ed9fd3b8738450a3a9f79f4764..c0e57b8c0c477e9f1dce8f3a2bfd48008dc30f3f 100644 (file)
@@ -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
index b6465044bc67f59cef291d9aaa4e1ed82f7c344f..23a0609a7a8bd6397614757b841a47156d810731 100644 (file)
@@ -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)