]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_sniperrifle.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_sniperrifle.qc
index 34fab001ee14afd932a86480e0f79e3775f688c9..0b5ae414dc8a33b8774b721fd0c0211ec10459f7 100644 (file)
@@ -1,5 +1,5 @@
 #ifdef REGISTER_WEAPON
-REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "campingrifle", "sniperrifle", _("Sniper Rifle"))
+REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "campingrifle", "sniperrifle", _("Sniper Rifle"))
 #else
 #ifdef SVQC
 //Sniper rifle Primary mode: manually operated bolt*, Secondary: full automatic**
@@ -8,42 +8,9 @@ REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_T
 
 .float sniperrifle_accumulator;
 
-void W_SniperRifle_SetAmmoCounter()
-{
-       // set clip_load to the weapon we have switched to, if the gun uses reloading
-       if(!autocvar_g_balance_sniperrifle_reload_ammo)
-               self.clip_load = 0; // also keeps crosshair ammo from displaying
-       else
-       {
-               self.clip_load = self.weapon_load[WEP_SNIPERRIFLE];
-               self.clip_size = autocvar_g_balance_sniperrifle_reload_ammo; // for the crosshair ammo display
-       }
-}
-
-void W_SniperRifle_Reload()
-{
-       self.reload_ammo_player = ammo_fuel;
-       self.reload_ammo_min = min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo);
-       self.reload_ammo_amount = autocvar_g_balance_sniperrifle_reload_ammo;
-       self.reload_time = autocvar_g_balance_sniperrifle_reload_time;
-       self.reload_sound = "weapons/reload.wav";
-
-       W_Reload();
-}
-
 void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAddedDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant)
 {
-       // 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)
-               {
-                       self.clip_load -= pAmmo;
-                       self.weapon_load[WEP_SNIPERRIFLE] = self.clip_load;
-               }
-               else
-                       self.ammo_nails -= pAmmo;
-       }
+       W_DecreaseAmmo(ammo_nails, pAmmo, autocvar_g_balance_sniperrifle_reload_ammo);
 
        if(deathtype & HITTYPE_SECONDARY)
                W_SetupShot (self, autocvar_g_antilag_bullets && pSpeed >= autocvar_g_antilag_bullets, 2, "weapons/campingrifle_fire2.wav", CHAN_WEAPON, autocvar_g_balance_sniperrifle_secondary_damage + autocvar_g_balance_sniperrifle_secondary_headshotaddeddamage);
@@ -169,7 +136,7 @@ float w_sniperrifle(float req)
        else if (req == WR_THINK)
        {
                if(autocvar_g_balance_sniperrifle_reload_ammo && self.clip_load < min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo)) // forced reload
-            W_SniperRifle_Reload();
+            weapon_action(self.weapon, WR_RELOAD);
                else
                {
                        self.sniperrifle_accumulator = bound(time - autocvar_g_balance_sniperrifle_bursttime, self.sniperrifle_accumulator, time);
@@ -186,7 +153,7 @@ float w_sniperrifle(float req)
                                if (autocvar_g_balance_sniperrifle_secondary)
                                {
                     if(autocvar_g_balance_sniperrifle_secondary_reload)
-                        W_SniperRifle_Reload();
+                        weapon_action(self.weapon, WR_RELOAD);
                     else
                     {
                         if (weapon_prepareattack_check(1, autocvar_g_balance_sniperrifle_secondary_refire))
@@ -213,30 +180,27 @@ float w_sniperrifle(float req)
        else if (req == WR_SETUP)
        {
                weapon_setup(WEP_SNIPERRIFLE);
-               W_SniperRifle_SetAmmoCounter();
+               self.current_ammo = ammo_nails;
        }
        else if (req == WR_CHECKAMMO1)
        {
-               ammo_amount = self.ammo_cells >= autocvar_g_balance_sniperrifle_primary_ammo;
+               ammo_amount = self.ammo_nails >= autocvar_g_balance_sniperrifle_primary_ammo;
                ammo_amount += self.weapon_load[WEP_SNIPERRIFLE] >= autocvar_g_balance_sniperrifle_primary_ammo;
                return ammo_amount;
        }
        else if (req == WR_CHECKAMMO2)
        {
-               ammo_amount = self.ammo_cells >= autocvar_g_balance_sniperrifle_secondary_ammo;
+               ammo_amount = self.ammo_nails >= autocvar_g_balance_sniperrifle_secondary_ammo;
                ammo_amount += self.weapon_load[WEP_SNIPERRIFLE] >= autocvar_g_balance_sniperrifle_secondary_ammo;
                return ammo_amount;
        }
        else if (req == WR_RESETPLAYER)
        {
                self.sniperrifle_accumulator = time - autocvar_g_balance_sniperrifle_bursttime;
-
-               // all weapons must be fully loaded when we spawn
-               self.weapon_load[WEP_SNIPERRIFLE] = autocvar_g_balance_sniperrifle_reload_ammo;
        }
        else if (req == WR_RELOAD)
        {
-               W_SniperRifle_Reload();
+               W_Reload(min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo), autocvar_g_balance_sniperrifle_reload_ammo, autocvar_g_balance_sniperrifle_reload_time, "weapons/reload.wav");
        }
        return TRUE;
 };