]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_sniperrifle.qc
Use only WR_SWITCHABLE to check if we can select our weapon. The ammo checks still...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_sniperrifle.qc
index 454e1db7a4e32d165a39877bff65aa29351c9e9a..00e96bed13a3b0b45fd8a856e4da38365aa9bf2c 100644 (file)
@@ -7,7 +7,6 @@ REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_T
 //** In fully automatic mode some of the gas is used to extract and reload the next cartrige, thus there is less power and range.
 
 .float sniperrifle_accumulator;
-.float sniperrifle_load;
 
 void W_SniperRifle_SetAmmoCounter()
 {
@@ -63,13 +62,6 @@ void W_SniperRifle_Reload()
 
 void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAddedDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant)
 {
-       // if there's not enough ammo for this attack (but we still have the weapon), reload
-       if(autocvar_g_balance_sniperrifle_reload_ammo && self.clip_load < autocvar_g_balance_sniperrifle_primary_ammo)
-       {
-               W_SniperRifle_Reload();
-               return;
-       }
-
        // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
        if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
        {
@@ -235,17 +227,6 @@ float w_sniperrifle(float req)
                                }
                        }
                }
-        if(self.wish_reload)
-        {
-            if(self.switchweapon == self.weapon)
-            {
-                if(self.weaponentity.state == WS_READY)
-                {
-                    self.wish_reload = 0;
-                    W_SniperRifle_Reload();
-                }
-            }
-        }
        }
        else if (req == WR_PRECACHE)
        {
@@ -271,7 +252,7 @@ float w_sniperrifle(float req)
        else if (req == WR_CHECKAMMO2)
        {
                if(autocvar_g_balance_sniperrifle_reload_ammo)
-                       return self.sniperrifle_load >= autocvar_g_balance_sniperrifle_primary_ammo;
+                       return self.sniperrifle_load >= autocvar_g_balance_sniperrifle_secondary_ammo;
                else
                        return self.ammo_nails >= autocvar_g_balance_sniperrifle_secondary_ammo;
        }
@@ -284,6 +265,15 @@ float w_sniperrifle(float req)
                self.sniperrifle_accumulator = time - autocvar_g_balance_sniperrifle_bursttime;
                self.clip_load = autocvar_g_balance_sniperrifle_reload_ammo;
        }
+       else if (req == WR_SWITCHABLE)
+       {
+               // checks if this weapon can be switched to, when reloading is enabled
+               // returns true if there's either enough load in the weapon to use it,
+               // or we have enough ammo to reload the weapon to a usable point
+               float ammo_amount;
+               ammo_amount = min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo);
+               return (autocvar_g_balance_sniperrifle_reload_ammo && self.sniperrifle_load >= ammo_amount) || self.ammo_nails >= ammo_amount;
+       }
        return TRUE;
 };
 #endif