]> 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 437d3f704b508641ea2a6a292afbc67ae51e4a96..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;
@@ -298,6 +312,16 @@ float lgbeam_send(entity to, float sf)
 }
 .entity lgbeam;
 .float prevlgfire;
+float lgbeam_checkammo()
+{
+       if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
+               return TRUE;
+       else if(autocvar_g_balance_electro_reload_ammo)
+               return self.owner.clip_load > 0;
+       else
+               return self.owner.ammo_cells > 0;
+}
+
 void lgbeam_think()
 {
        self.owner.prevlgfire = time;
@@ -306,7 +330,8 @@ void lgbeam_think()
                remove(self);
                return;
        }
-       if (self.owner.weaponentity.state != WS_INUSE || (self.owner.ammo_cells <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)) || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
+
+       if (self.owner.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
        {
                if(self == self.owner.lgbeam)
                        self.owner.lgbeam = world;
@@ -320,16 +345,16 @@ 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)
                        {
                                dt = min(dt, self.owner.clip_load / autocvar_g_balance_electro_primary_ammo);
                                self.owner.clip_load = max(0, self.owner.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
-                               self.electro_load = self.clip_load;
+                               self.owner.electro_load = self.owner.clip_load;
                        }
                        else
                        {