]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator_nix.qc
Make most server includes order insensitive
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_nix.qc
index 4a11e564bdd18990915c7a9f602f9bad6bf597e2..eb7f8f75b6bc48338f4fbf5b29e6100cc4599ba6 100644 (file)
@@ -1,10 +1,12 @@
-float g_nix_with_laser;
+#include "../_.qh"
 
-float nix_weapon;
-float nix_weapon_ammo;
+#include "mutator.qh"
+
+float g_nix_with_blaster;
+// WEAPONTODO
+int nix_weapon;
 float nix_nextchange;
 float nix_nextweapon;
-float nix_nextweapon_ammo;
 .float nix_lastchange_id;
 .float nix_lastinfotime;
 .float nix_nextincr;
@@ -14,22 +16,22 @@ float NIX_CanChooseWeapon(float wpn)
        entity e;
        e = get_weaponinfo(wpn);
        if(!e.weapon) // skip dummies
-               return FALSE;
+               return false;
        if(g_weaponarena)
        {
                if(!(g_weaponarena_weapons & WepSet_FromWeapon(wpn)))
-                       return FALSE;
+                       return false;
        }
        else
        {
-               if(wpn == WEP_LASER && g_nix_with_laser)
-                       return FALSE;
+               if(wpn == WEP_BLASTER && g_nix_with_blaster) // WEAPONTODO: rename to g_nix_with_blaster
+                       return false;
                if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
-                       return FALSE;
-               if not(e.spawnflags & WEP_FLAG_NORMAL)
-                       return FALSE;
+                       return false;
+               if (!(e.spawnflags & WEP_FLAG_NORMAL))
+                       return false;
        }
-       return TRUE;
+       return true;
 }
 void NIX_ChooseNextWeapon()
 {
@@ -39,7 +41,6 @@ void NIX_ChooseNextWeapon()
                if(NIX_CanChooseWeapon(j))
                        RandomSelection_Add(world, j, string_null, 1, (j != nix_weapon));
        nix_nextweapon = RandomSelection_chosen_float;
-       nix_nextweapon_ammo = W_AmmoItemCode(nix_nextweapon);
 }
 
 void NIX_GiveCurrentWeapon()
@@ -54,65 +55,68 @@ void NIX_GiveCurrentWeapon()
        if(dt <= 0)
        {
                nix_weapon = nix_nextweapon;
-               nix_weapon_ammo = nix_nextweapon_ammo;
                nix_nextweapon = 0;
                if (!nix_nextchange) // no round played yet?
                        nix_nextchange = time; // start the first round now!
                else
                        nix_nextchange = time + autocvar_g_balance_nix_roundtime;
-               //weapon_action(nix_weapon, WR_PRECACHE); // forget it, too slow
+               //WEP_ACTION(nix_weapon, WR_INIT); // forget it, too slow
        }
 
+       // get weapon info
+       entity e = get_weaponinfo(nix_weapon);
+
        if(nix_nextchange != self.nix_lastchange_id) // this shall only be called once per round!
        {
-               self.nix_lastchange_id = nix_nextchange;
-               if (self.items & IT_UNLIMITED_WEAPON_AMMO)
+               self.ammo_shells = self.ammo_nails = self.ammo_rockets = self.ammo_cells = self.ammo_plasma = self.ammo_fuel = 0;
+
+               if(self.items & IT_UNLIMITED_WEAPON_AMMO)
                {
-                       self.ammo_shells = (nix_weapon_ammo & IT_SHELLS) ?
-                               autocvar_g_pickup_shells_max : 0;
-                       self.ammo_nails = (nix_weapon_ammo & IT_NAILS) ?
-                               autocvar_g_pickup_nails_max : 0;
-                       self.ammo_rockets = (nix_weapon_ammo & IT_ROCKETS) ?
-                               autocvar_g_pickup_rockets_max : 0;
-                       self.ammo_cells = (nix_weapon_ammo & IT_CELLS) ?
-                               autocvar_g_pickup_cells_max : 0;
-                       self.ammo_fuel = (nix_weapon_ammo & IT_FUEL) ?
-                               autocvar_g_pickup_fuel_max : 0;
+                       switch(e.ammo_field)
+                       {
+                               case ammo_shells:  self.ammo_shells  = autocvar_g_pickup_shells_max;  break;
+                               case ammo_nails:   self.ammo_nails   = autocvar_g_pickup_nails_max;   break;
+                               case ammo_rockets: self.ammo_rockets = autocvar_g_pickup_rockets_max; break;
+                               case ammo_cells:   self.ammo_cells   = autocvar_g_pickup_cells_max;   break;
+                               case ammo_plasma:  self.ammo_plasma  = autocvar_g_pickup_plasma_max;   break;
+                               case ammo_fuel:    self.ammo_fuel    = autocvar_g_pickup_fuel_max;    break;
+                       }
                }
                else
                {
-                       self.ammo_shells = (nix_weapon_ammo & IT_SHELLS) ?
-                               autocvar_g_balance_nix_ammo_shells : 0;
-                       self.ammo_nails = (nix_weapon_ammo & IT_NAILS) ?
-                               autocvar_g_balance_nix_ammo_nails : 0;
-                       self.ammo_rockets = (nix_weapon_ammo & IT_ROCKETS) ?
-                               autocvar_g_balance_nix_ammo_rockets : 0;
-                       self.ammo_cells = (nix_weapon_ammo & IT_CELLS) ?
-                               autocvar_g_balance_nix_ammo_cells : 0;
-                       self.ammo_fuel = (nix_weapon_ammo & IT_FUEL) ?
-                               autocvar_g_balance_nix_ammo_fuel : 0;
+                       switch(e.ammo_field)
+                       {
+                               case ammo_shells:  self.ammo_shells  = autocvar_g_balance_nix_ammo_shells;  break;
+                               case ammo_nails:   self.ammo_nails   = autocvar_g_balance_nix_ammo_nails;   break;
+                               case ammo_rockets: self.ammo_rockets = autocvar_g_balance_nix_ammo_rockets; break;
+                               case ammo_cells:   self.ammo_cells   = autocvar_g_balance_nix_ammo_cells;   break;
+                               case ammo_plasma:  self.ammo_plasma  = autocvar_g_balance_nix_ammo_plasma;   break;
+                               case ammo_fuel:    self.ammo_fuel    = autocvar_g_balance_nix_ammo_fuel;    break;
+                       }
                }
+
                self.nix_nextincr = time + autocvar_g_balance_nix_incrtime;
                if(dt >= 1 && dt <= 5)
                        self.nix_lastinfotime = -42;
                else
                        Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_NIX_NEWWEAPON, nix_weapon);
 
-               weapon_action(nix_weapon, WR_RESETPLAYER);
+               WEP_ACTION(nix_weapon, WR_RESETPLAYER);
 
                // all weapons must be fully loaded when we spawn
-               entity e;
-               e = get_weaponinfo(nix_weapon);
                if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
-                       self.(weapon_load[nix_weapon]) = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
+                       self.(weapon_load[nix_weapon]) = e.reloading_ammo;
 
-               // nex too
-               if(autocvar_g_balance_nex_charge)
+               // vortex too
+               if(WEP_CVAR(vortex, charge))
                {
-                       if(autocvar_g_balance_nex_secondary_chargepool)
-                               self.nex_chargepool_ammo = 1;
-                       self.nex_charge = autocvar_g_balance_nex_charge_start;
+                       if(WEP_CVAR_SEC(vortex, chargepool))
+                               self.vortex_chargepool_ammo = 1;
+                       self.vortex_charge = WEP_CVAR(vortex, charge_start);
                }
+
+               // set last change info
+               self.nix_lastchange_id = nix_nextchange;
        }
        if(self.nix_lastinfotime != dt)
        {
@@ -123,27 +127,27 @@ void NIX_GiveCurrentWeapon()
 
        if(!(self.items & IT_UNLIMITED_WEAPON_AMMO) && time > self.nix_nextincr)
        {
-               if (nix_weapon_ammo & IT_SHELLS)
-                       self.ammo_shells = self.ammo_shells + autocvar_g_balance_nix_ammoincr_shells;
-               else if (nix_weapon_ammo & IT_NAILS)
-                       self.ammo_nails = self.ammo_nails + autocvar_g_balance_nix_ammoincr_nails;
-               else if (nix_weapon_ammo & IT_ROCKETS)
-                       self.ammo_rockets = self.ammo_rockets + autocvar_g_balance_nix_ammoincr_rockets;
-               else if (nix_weapon_ammo & IT_CELLS)
-                       self.ammo_cells = self.ammo_cells + autocvar_g_balance_nix_ammoincr_cells;
-               if (nix_weapon_ammo & IT_FUEL) // hook uses cells and fuel
-                       self.ammo_fuel = self.ammo_fuel + autocvar_g_balance_nix_ammoincr_fuel;
+               switch(e.ammo_field)
+               {
+                       case ammo_shells:  self.ammo_shells  += autocvar_g_balance_nix_ammoincr_shells;  break;
+                       case ammo_nails:   self.ammo_nails   += autocvar_g_balance_nix_ammoincr_nails;   break;
+                       case ammo_rockets: self.ammo_rockets += autocvar_g_balance_nix_ammoincr_rockets; break;
+                       case ammo_cells:   self.ammo_cells   += autocvar_g_balance_nix_ammoincr_cells;   break;
+                       case ammo_plasma:  self.ammo_plasma  += autocvar_g_balance_nix_ammoincr_plasma;   break;
+                       case ammo_fuel:    self.ammo_fuel    += autocvar_g_balance_nix_ammoincr_fuel;    break;
+               }
+
                self.nix_nextincr = time + autocvar_g_balance_nix_incrtime;
        }
 
        self.weapons = '0 0 0';
-       if(g_nix_with_laser)
-               self.weapons &= ~WEPSET_LASER;
+       if(g_nix_with_blaster)
+               self.weapons |= WEPSET_BLASTER;
        self.weapons |= WepSet_FromWeapon(nix_weapon);
 
        if(self.switchweapon != nix_weapon)
-               if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
-                       if(client_hasweapon(self, nix_weapon, TRUE, FALSE))
+               if(!client_hasweapon(self, self.switchweapon, true, false))
+                       if(client_hasweapon(self, nix_weapon, true, false))
                                W_SwitchWeapon(nix_weapon);
 }
 
@@ -152,7 +156,7 @@ void NIX_precache()
        float i;
        for (i = WEP_FIRST; i <= WEP_LAST; ++i)
                if (NIX_CanChooseWeapon(i))
-                       weapon_action(i, WR_PRECACHE);
+                       WEP_ACTION(i, WR_INIT);
 }
 
 MUTATOR_HOOKFUNCTION(nix_ForbidThrowCurrentWeapon)
@@ -239,7 +243,7 @@ MUTATOR_DEFINITION(mutator_nix)
 
        MUTATOR_ONADD
        {
-               g_nix_with_laser = autocvar_g_nix_with_laser;
+               g_nix_with_blaster = autocvar_g_nix_with_blaster;
 
                nix_nextchange = 0;
                nix_nextweapon = 0;
@@ -259,12 +263,13 @@ MUTATOR_DEFINITION(mutator_nix)
                FOR_EACH_PLAYER(e) if(e.deadflag == DEAD_NO)
                {
                        e.ammo_cells = start_ammo_cells;
+                       e.ammo_plasma = start_ammo_plasma;
                        e.ammo_shells = start_ammo_shells;
                        e.ammo_nails = start_ammo_nails;
                        e.ammo_rockets = start_ammo_rockets;
                        e.ammo_fuel = start_ammo_fuel;
                        e.weapons = start_weapons;
-                       if(!client_hasweapon(e, e.weapon, TRUE, FALSE))
+                       if(!client_hasweapon(e, e.weapon, true, false))
                                e.switchweapon = w_getbestweapon(self);
                }
        }