]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_nex.qc
Commonize even more code, now that its possible
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_nex.qc
index 7abde095f299c7946ce0a64bff3d0cce9bd65c53..e6c2aaafe2092f8d250dbd201cbc827255b0f255 100644 (file)
@@ -3,8 +3,6 @@ REGISTER_WEAPON(NEX, w_nex, IT_CELLS, 7, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT
 #else
 #ifdef SVQC
 
-.float nex_load;
-
 void W_Nex_SetAmmoCounter()
 {
        // set clip_load to the weapon we have switched to, if the gun uses reloading
@@ -12,49 +10,20 @@ void W_Nex_SetAmmoCounter()
                self.clip_load = 0; // also keeps crosshair ammo from displaying
        else
        {
-               self.clip_load = self.nex_load;
+               self.clip_load = self.weapon_load[WEP_NEX];
                self.clip_size = autocvar_g_balance_nex_reload_ammo; // for the crosshair ammo display
        }
 }
 
-void W_Nex_ReloadedAndReady()
-{
-       float t;
-
-       // now do the ammo transfer
-       self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
-       while(self.clip_load < autocvar_g_balance_nex_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
-       {
-               self.clip_load += 1;
-               self.ammo_cells -= 1;
-       }
-       self.nex_load = self.clip_load;
-
-       t = ATTACK_FINISHED(self) - autocvar_g_balance_nex_reload_time - 1;
-       ATTACK_FINISHED(self) = t;
-       w_ready();
-}
-
 void W_Nex_Reload()
 {
-       // return if reloading is disabled for this weapon
-       if(!autocvar_g_balance_nex_reload_ammo)
-               return;
-
-       if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo)))
-               return;
+       self.reload_ammo_player = ammo_cells;
+       self.reload_ammo_min = min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo);
+       self.reload_ammo_amount = autocvar_g_balance_nex_reload_ammo;
+       self.reload_time = autocvar_g_balance_nex_reload_time;
+       self.reload_sound = "weapons/reload.wav";
 
-       float t;
-
-       sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
-
-       t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_nex_reload_time + 1;
-       ATTACK_FINISHED(self) = t;
-
-       weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_nex_reload_time, W_Nex_ReloadedAndReady);
-
-       self.old_clip_load = self.clip_load;
-       self.clip_load = -1;
+       W_Reload();
 }
 
 void SendCSQCNexBeamParticle(float charge) {
@@ -135,7 +104,7 @@ void W_Nex_Attack (float issecondary)
                if(autocvar_g_balance_nex_reload_ammo)
                {
                        self.clip_load -= myammo;
-                       self.nex_load = self.clip_load;
+                       self.weapon_load[WEP_NEX] = self.clip_load;
                }
                else
                        self.ammo_cells -= myammo;
@@ -148,6 +117,7 @@ void spawnfunc_weapon_nex (void); // defined in t_items.qc
 float w_nex(float req)
 {
        float dt;
+       float ammo_amount;
        if (req == WR_AIM)
        {
                self.BUTTON_ATCK = bot_aim(1000000, 0, 1, FALSE);
@@ -219,7 +189,7 @@ float w_nex(float req)
                                                                                {
                                                                                        self.clip_load = max(autocvar_g_balance_nex_secondary_ammo, self.clip_load - autocvar_g_balance_nex_secondary_ammo * dt);
                                                                                }
-                                                                               self.nex_load = self.clip_load;
+                                                                               self.weapon_load[WEP_NEX] = self.clip_load;
                                                                        }
                                                                        else
                                                                        {
@@ -266,18 +236,6 @@ float w_nex(float req)
                                self.weaponentity_glowmod_z = self.weaponentity_glowmod_z + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (self.nex_charge - autocvar_g_balance_nex_charge_limit) / (1 - autocvar_g_balance_nex_charge_limit);
                        }
                }
-
-        if(self.wish_reload)
-        {
-            if(self.switchweapon == self.weapon)
-            {
-                if(self.weaponentity.state == WS_READY)
-                {
-                    self.wish_reload = 0;
-                    W_Nex_Reload();
-                }
-            }
-        }
        }
        else if (req == WR_PRECACHE)
        {
@@ -299,17 +257,16 @@ float w_nex(float req)
        }
        else if (req == WR_CHECKAMMO1)
        {
-               if(autocvar_g_balance_nex_reload_ammo)
-                       return self.clip_load >= autocvar_g_balance_nex_primary_ammo;
-               else
-                       return self.ammo_cells >= autocvar_g_balance_nex_primary_ammo;
+               ammo_amount = self.ammo_cells >= autocvar_g_balance_nex_primary_ammo;
+               ammo_amount += (autocvar_g_balance_nex_reload_ammo && self.weapon_load[WEP_NEX] >= autocvar_g_balance_nex_primary_ammo);
+               return ammo_amount;
        }
        else if (req == WR_CHECKAMMO2)
        {
-               if(autocvar_g_balance_nex_reload_ammo)
-                       return self.clip_load >= autocvar_g_balance_nex_primary_ammo; // don't allow charging if we don't have enough ammo
-               else
-                       return self.ammo_cells >= autocvar_g_balance_nex_primary_ammo; // don't allow charging if we don't have enough ammo
+               // don't allow charging if we don't have enough ammo
+               ammo_amount = self.ammo_cells >= autocvar_g_balance_nex_secondary_ammo;
+               ammo_amount += self.weapon_load[WEP_NEX] >= autocvar_g_balance_nex_secondary_ammo;
+               return ammo_amount;
        }
        else if (req == WR_RELOAD)
        {
@@ -335,9 +292,9 @@ float w_nex(float req)
                precache_sound("weapons/neximpact.wav");
        }
        else if (req == WR_SUICIDEMESSAGE)
-               w_deathtypestring = "%s did the impossible";
+               w_deathtypestring = _("%s did the impossible");
        else if (req == WR_KILLMESSAGE)
-               w_deathtypestring = "%s has been vaporized by %s";
+               w_deathtypestring = _("%s has been vaporized by %s");
        return TRUE;
 }
 #endif