]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make the reload code use the proper type of ammo
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Thu, 20 Jan 2011 23:43:56 +0000 (01:43 +0200)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Thu, 20 Jan 2011 23:43:56 +0000 (01:43 +0200)
qcsrc/server/cl_weaponsystem.qc
qcsrc/server/w_shotgun.qc
qcsrc/server/w_sniperrifle.qc

index bd161253669311b8d5affb45bb53013b80adf69b..8c510bba7721a336df26d7ccd0fb76661943df90 100644 (file)
@@ -1616,6 +1616,37 @@ void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread)
 // weapon reload code
 // ----------------------------------------------------------------
 
+float ammo_amount;
+void W_SniperRifle_Ammo(string ammo_string, float ammo_reduce)
+{
+       // sets ammo_amount to our current ammo level, and can optionally reduce ammo
+       switch(ammo_string)
+       {
+               case "shells":
+                       ammo_amount = self.ammo_shells;
+                       self.ammo_shells -= ammo_reduce;
+                       return;
+               case "nails":
+                       ammo_amount = self.ammo_nails;
+                       self.ammo_nails -= ammo_reduce;
+                       return;
+               case "cells":
+                       ammo_amount = self.ammo_cells;
+                       self.ammo_cells -= ammo_reduce;
+                       return;
+               case "rockets":
+                       ammo_amount = self.ammo_rockets;
+                       self.ammo_rockets -= ammo_reduce;
+                       return;
+               case "fuel":
+                       ammo_amount = self.ammo_fuel;
+                       self.ammo_fuel -= ammo_reduce;
+                       return;
+               default:
+                       return;
+       }
+}
+
 float W_SniperRifle_CheckMaxBullets(float checkammo)
 {
        float maxbulls;
@@ -1624,7 +1655,7 @@ float W_SniperRifle_CheckMaxBullets(float checkammo)
                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)));
+                       maxbulls = min(maxbulls, floor(ammo_amount / 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);
@@ -1640,13 +1671,14 @@ void W_SniperRifle_ReloadedAndReady()
        w_ready();
 }
 
-float W_SniperRifle_Reload()
+float W_SniperRifle_Reload(string ammo_type)
 {
        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
+       W_SniperRifle_Ammo(ammo_type, 0); // set ammo_amount to the ammo type specified
+       if(ammo_amount < 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
@@ -1678,14 +1710,6 @@ float W_SniperRifle_Reload()
        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
index 9b914794c42b9ee16bac5642b03275c9a64eee4d..470acac348a8cdaaa3a410dac563d426a39b312e 100644 (file)
@@ -2,6 +2,15 @@
 REGISTER_WEAPON(SHOTGUN, w_shotgun, IT_SHELLS, 2, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_LOW, "shotgun", "shotgun", _("Shotgun"))
 #else
 #ifdef SVQC
+
+void W_Shotgun_CheckReloadAndReady()
+{
+       w_ready();
+       if(self.sniperrifle_bulletcounter <= 0)
+               if(W_SniperRifle_Reload("shells"))
+                       return;
+}
+
 void W_Shotgun_Attack (void)
 {
        float   sc;
@@ -14,7 +23,7 @@ void W_Shotgun_Attack (void)
        float   bulletconstant;
        local entity flash;
 
-       W_SniperRifle_CheckReloadAndReady();
+       W_Shotgun_CheckReloadAndReady();
        if(self.sniperrifle_bulletcounter < 0)
                return; // reloading, so we are done
 
@@ -144,7 +153,7 @@ float w_shotgun(float req)
                 if(self.weaponentity.state == WS_READY)
                 {
                     self.wish_reload = 0;
-                    W_SniperRifle_Reload();
+                    W_SniperRifle_Reload("shells");
                 }
             }
         }
index 102769aa5933554824cee48255a9d8c1500ec0d6..655c1204a1076fedd26bc4b2e964ddb7b5fc5958 100644 (file)
@@ -8,6 +8,14 @@ REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_T
 
 .float sniperrifle_accumulator;
 
+void W_SniperRifle_CheckReloadAndReady()
+{
+       w_ready();
+       if(self.sniperrifle_bulletcounter <= 0)
+               if(W_SniperRifle_Reload("nails"))
+                       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)
@@ -180,7 +188,7 @@ float w_sniperrifle(float req)
                 if(self.weaponentity.state == WS_READY)
                 {
                     self.wish_reload = 0;
-                    W_SniperRifle_Reload();
+                    W_SniperRifle_Reload("nails");
                 }
             }
         }