]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_shotgun.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_shotgun.qc
index 68b4ab2b18408e47976b82088dbfb405e0b5df9f..38ae17a24f579e6ef4ea2d05a849f4a812e3dd1f 100644 (file)
@@ -1,31 +1,8 @@
 #ifdef REGISTER_WEAPON
-REGISTER_WEAPON(SHOTGUN, w_shotgun, IT_SHELLS, 2, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_LOW, "shotgun", "shotgun", _("Shotgun"))
+REGISTER_WEAPON(SHOTGUN, w_shotgun, IT_SHELLS, 2, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_LOW, "shotgun", "shotgun", _("Shotgun"))
 #else
 #ifdef SVQC
 
-void W_Shotgun_SetAmmoCounter()
-{
-       // set clip_load to the weapon we have switched to, if the gun uses reloading
-       if(!autocvar_g_balance_shotgun_reload_ammo)
-               self.clip_load = 0; // also keeps crosshair ammo from displaying
-       else
-       {
-               self.clip_load = self.weapon_load[WEP_SHOTGUN];
-               self.clip_size = autocvar_g_balance_shotgun_reload_ammo; // for the crosshair ammo display
-       }
-}
-
-void W_Shotgun_Reload()
-{
-       self.reload_ammo_player = ammo_shells;
-       self.reload_ammo_min = autocvar_g_balance_shotgun_primary_ammo;
-       self.reload_ammo_amount = autocvar_g_balance_shotgun_reload_ammo;
-       self.reload_time = autocvar_g_balance_shotgun_reload_time;
-       self.reload_sound = "weapons/reload.wav";
-
-       W_Reload();
-}
-
 void W_Shotgun_Attack (void)
 {
        float   sc;
@@ -46,17 +23,7 @@ void W_Shotgun_Attack (void)
        bulletspeed = autocvar_g_balance_shotgun_primary_speed;
        bulletconstant = autocvar_g_balance_shotgun_primary_bulletconstant;
 
-       // 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)
-               {
-                       self.clip_load -= ammoamount;
-                       self.weapon_load[WEP_SHOTGUN] = self.clip_load;
-               }
-               else
-                       self.ammo_shells -= ammoamount;
-       }
+       W_DecreaseAmmo(ammo_shells, ammoamount, autocvar_g_balance_shotgun_reload_ammo);
 
        W_SetupShot (self, autocvar_g_antilag_bullets && bulletspeed >= autocvar_g_antilag_bullets, 5, "weapons/shotgun_fire.wav", CHAN_WEAPON, d * bullets);
        for (sc = 0;sc < bullets;sc = sc + 1)
@@ -147,7 +114,7 @@ float w_shotgun(float req)
                {
                        // don't force reload an empty shotgun if its melee attack is active
                        if not(autocvar_g_balance_shotgun_secondary && self.ammo_shells < autocvar_g_balance_shotgun_primary_ammo)
-                               W_Shotgun_Reload();
+                               weapon_action(self.weapon, WR_RELOAD);
                }
                else
                {
@@ -164,6 +131,7 @@ float w_shotgun(float req)
                                }
                        }
                }
+               if (self.clip_load >= 0) // we are not currently reloading
                if (self.BUTTON_ATCK2 && autocvar_g_balance_shotgun_secondary)
                if (weapon_prepareattack(1, autocvar_g_balance_shotgun_secondary_refire))
                {
@@ -180,12 +148,12 @@ float w_shotgun(float req)
                precache_sound ("misc/itempickup.wav");
                precache_sound ("weapons/shotgun_fire.wav");
                precache_sound ("weapons/shotgun_melee.wav");
-               precache_sound ("weapons/reload.wav");
+               //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
        }
        else if (req == WR_SETUP)
        {
                weapon_setup(WEP_SHOTGUN);
-               W_Shotgun_SetAmmoCounter();
+               self.current_ammo = ammo_shells;
        }
        else if (req == WR_CHECKAMMO1)
        {
@@ -198,14 +166,9 @@ float w_shotgun(float req)
                // melee attack is always available
                return TRUE;
        }
-       else if (req == WR_RESETPLAYER)
-       {
-               // all weapons must be fully loaded when we spawn
-               self.weapon_load[WEP_SHOTGUN] = autocvar_g_balance_shotgun_reload_ammo;
-       }
        else if (req == WR_RELOAD)
        {
-               W_Shotgun_Reload();
+               W_Reload(autocvar_g_balance_shotgun_primary_ammo, autocvar_g_balance_shotgun_reload_ammo, autocvar_g_balance_shotgun_reload_time, "weapons/reload.wav");
        }
        return TRUE;
 };