]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_electro.qc
Reload if we don't have ammo for a certain attack. Prevents situations in which you...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_electro.qc
index ad6284db8bd6c1c462b1d678a8b1410a37a2db39..bbcdc06df39d9fd16e4f47f53ed6b803e18eb1ea 100644 (file)
@@ -43,7 +43,7 @@ void W_Electro_Reload()
        if(!autocvar_g_balance_electro_reload_ammo)
                return;
 
-       if(!W_ReloadCheck(self.ammo_cells))
+       if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo)))
                return;
 
        float t;
@@ -164,6 +164,25 @@ void W_Electro_Attack()
 {
        local entity proj;
 
+       // if there's not enough ammo for this attack (but we still have the weapon), reload
+       if(autocvar_g_balance_electro_reload_ammo && self.clip_load < autocvar_g_balance_electro_primary_ammo)
+       {
+               W_Electro_Reload();
+               return;
+       }
+
+       // 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_electro_reload_ammo)
+               {
+                       self.clip_load -= autocvar_g_balance_electro_primary_ammo;
+                       self.electro_load = self.clip_load;
+               }
+               else
+                       self.ammo_cells -= autocvar_g_balance_electro_primary_ammo;
+       }
+
        W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
 
        pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
@@ -193,23 +212,30 @@ void W_Electro_Attack()
        CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
 
        other = proj; MUTATOR_CALLHOOK(EditProjectile);
+}
+
+void W_Electro_Attack2()
+{
+       local entity proj;
+
+       // if there's not enough ammo for this attack (but we still have the weapon), reload
+       if(autocvar_g_balance_electro_reload_ammo && self.clip_load < autocvar_g_balance_electro_secondary_ammo)
+       {
+               W_Electro_Reload();
+               return;
+       }
 
        // 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_electro_reload_ammo)
                {
-                       self.clip_load -= autocvar_g_balance_electro_primary_ammo;
+                       self.clip_load -= autocvar_g_balance_electro_secondary_ammo;
                        self.electro_load = self.clip_load;
                }
                else
-                       self.ammo_cells -= autocvar_g_balance_electro_primary_ammo;
+                       self.ammo_cells -= autocvar_g_balance_electro_secondary_ammo;
        }
-}
-
-void W_Electro_Attack2()
-{
-       local entity proj;
 
        W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
 
@@ -255,18 +281,6 @@ void W_Electro_Attack2()
        CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
 
        other = proj; MUTATOR_CALLHOOK(EditProjectile);
-
-       // 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_electro_reload_ammo)
-               {
-                       self.clip_load -= autocvar_g_balance_electro_secondary_ammo;
-                       self.electro_load = self.clip_load;
-               }
-               else
-                       self.ammo_cells -= autocvar_g_balance_electro_secondary_ammo;
-       }
 }
 
 .vector hook_start, hook_end;
@@ -316,7 +330,6 @@ void lgbeam_think()
                remove(self);
                return;
        }
-       if(autocvar_g_balance_electro_reload_ammo)
 
        if (self.owner.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
        {
@@ -332,9 +345,9 @@ void lgbeam_think()
 
        float dt, f;
        dt = frametime;
+       // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
        if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
        {
-               // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
                if(autocvar_g_balance_electro_primary_ammo)
                {
                        if(autocvar_g_balance_electro_reload_ammo)