]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_electro.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_electro.qc
index 73ebfced76c452098c15c3a59d961d27e236ce8c..247437bc06853735ca1f14bef431d984420e0d95 100644 (file)
@@ -5,8 +5,6 @@ REGISTER_WEAPON(ELECTRO, w_electro, IT_CELLS, 5, WEP_FLAG_NORMAL | WEP_TYPE_SPLA
 .float electro_count;
 .float electro_secondarytime;
 
-.float electro_load;
-
 void W_Electro_SetAmmoCounter()
 {
        // set clip_load to the weapon we have switched to, if the gun uses reloading
@@ -43,7 +41,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 +162,18 @@ void W_Electro_Attack()
 {
        local entity proj;
 
+       // 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 +203,23 @@ void W_Electro_Attack()
        CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
 
        other = proj; MUTATOR_CALLHOOK(EditProjectile);
+}
+
+void W_Electro_Attack2()
+{
+       local entity proj;
 
        // 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 +265,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;
@@ -331,9 +329,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)
@@ -527,18 +525,6 @@ float w_electro(float req)
                                }
                        }
                }
-
-        if(self.wish_reload)
-        {
-            if(self.switchweapon == self.weapon)
-            {
-                if(self.weaponentity.state == WS_READY)
-                {
-                    self.wish_reload = 0;
-                    W_Electro_Reload();
-                }
-            }
-        }
        }
        else if (req == WR_PRECACHE)
        {
@@ -550,6 +536,7 @@ float w_electro(float req)
                precache_sound ("weapons/electro_fire2.wav");
                precache_sound ("weapons/electro_impact.wav");
                precache_sound ("weapons/electro_impact_combo.wav");
+               precache_sound ("weapons/reload.wav");
                if(autocvar_g_balance_electro_lightning)
                {
                        precache_sound ("weapons/lgbeam_fire.wav");
@@ -592,6 +579,15 @@ float w_electro(float req)
        {
                W_Shotgun_Reload();
        }
+       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_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo);
+               return (autocvar_g_balance_electro_reload_ammo && self.electro_load >= ammo_amount) || self.ammo_cells >= ammo_amount;
+       }
        return TRUE;
 };
 #endif