]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/nix/sv_nix.qc
Fix vortex chargepol
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / nix / sv_nix.qc
index 76e735e5505b482a34df8cd32d09847a6a21b58b..c174b530f0a48e94cb20d6661fd069ecb0e2ecc4 100644 (file)
@@ -1,5 +1,6 @@
 #include "sv_nix.qh"
 
+string autocvar_g_nix;
 int autocvar_g_balance_nix_ammo_cells;
 int autocvar_g_balance_nix_ammo_plasma;
 int autocvar_g_balance_nix_ammo_fuel;
@@ -35,7 +36,7 @@ float nix_nextweapon;
 
 bool NIX_CanChooseWeapon(int wpn);
 
-REGISTER_MUTATOR(nix, cvar("g_nix") && !cvar("g_instagib") && !cvar("g_overkill"))
+REGISTER_MUTATOR(nix, expr_evaluate(autocvar_g_nix) && !cvar("g_instagib") && !cvar("g_overkill"))
 {
        MUTATOR_ONADD
        {
@@ -44,7 +45,7 @@ REGISTER_MUTATOR(nix, cvar("g_nix") && !cvar("g_instagib") && !cvar("g_overkill"
                nix_nextchange = 0;
                nix_nextweapon = 0;
 
-               FOREACH(Weapons, it != WEP_Null && NIX_CanChooseWeapon(it.m_id), LAMBDA(it.wr_init(it)));
+               FOREACH(Weapons, it != WEP_Null && NIX_CanChooseWeapon(it.m_id), { it.wr_init(it); });
        }
 
        MUTATOR_ONROLLBACK_OR_REMOVE
@@ -56,15 +57,21 @@ REGISTER_MUTATOR(nix, cvar("g_nix") && !cvar("g_instagib") && !cvar("g_overkill"
        {
                // as the PlayerSpawn hook will no longer run, NIX is turned off by this!
                FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
-                       it.ammo_cells = start_ammo_cells;
-                       it.ammo_plasma = start_ammo_plasma;
-                       it.ammo_shells = start_ammo_shells;
-                       it.ammo_nails = start_ammo_nails;
-                       it.ammo_rockets = start_ammo_rockets;
-                       it.ammo_fuel = start_ammo_fuel;
+                       SetResourceAmount(it, RESOURCE_SHELLS, start_ammo_shells);
+                       SetResourceAmount(it, RESOURCE_BULLETS, start_ammo_nails);
+                       SetResourceAmount(it, RESOURCE_ROCKETS, start_ammo_rockets);
+                       SetResourceAmount(it, RESOURCE_CELLS, start_ammo_cells);
+                       SetResourceAmount(it, RESOURCE_PLASMA, start_ammo_plasma);
+                       SetResourceAmount(it, RESOURCE_FUEL, start_ammo_fuel);
                        it.weapons = start_weapons;
-                       if(!client_hasweapon(it, PS(it).m_weapon, true, false))
-                               PS(it).m_switchweapon = w_getbestweapon(it);
+                       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+                       {
+                               .entity weaponentity = weaponentities[slot];
+                               if(it.(weaponentity).m_weapon == WEP_Null && slot != 0)
+                                       continue;
+                               if(!client_hasweapon(it, it.(weaponentity).m_weapon, weaponentity, true, false))
+                                       it.(weaponentity).m_switchweapon = w_getbestweapon(it, weaponentity);
+                       }
                });
        }
 
@@ -94,10 +101,10 @@ bool NIX_CanChooseWeapon(int wpn)
 void NIX_ChooseNextWeapon()
 {
        RandomSelection_Init();
-       FOREACH(Weapons, it != WEP_Null, LAMBDA(
+       FOREACH(Weapons, it != WEP_Null, {
                if(NIX_CanChooseWeapon(it.m_id))
                        RandomSelection_AddFloat(it.m_id, 1, (it.m_id != nix_weapon));
-       ));
+       });
        nix_nextweapon = RandomSelection_chosen_float;
 }
 
@@ -127,30 +134,34 @@ void NIX_GiveCurrentWeapon(entity this)
 
        if(nix_nextchange != this.nix_lastchange_id) // this shall only be called once per round!
        {
-               this.ammo_shells = this.ammo_nails = this.ammo_rockets = this.ammo_cells = this.ammo_plasma = this.ammo_fuel = 0;
-
+               SetResourceAmount(this, RESOURCE_SHELLS, 0);
+               SetResourceAmount(this, RESOURCE_BULLETS, 0);
+               SetResourceAmount(this, RESOURCE_ROCKETS, 0);
+               SetResourceAmount(this, RESOURCE_CELLS, 0);
+               SetResourceAmount(this, RESOURCE_PLASMA, 0);
+               SetResourceAmount(this, RESOURCE_FUEL, 0);
                if(this.items & IT_UNLIMITED_WEAPON_AMMO)
                {
-                       switch(e.ammo_field)
+                       switch (e.ammo_type)
                        {
-                               case ammo_shells:  this.ammo_shells  = autocvar_g_pickup_shells_max;  break;
-                               case ammo_nails:   this.ammo_nails   = autocvar_g_pickup_nails_max;   break;
-                               case ammo_rockets: this.ammo_rockets = autocvar_g_pickup_rockets_max; break;
-                               case ammo_cells:   this.ammo_cells   = autocvar_g_pickup_cells_max;   break;
-                               case ammo_plasma:  this.ammo_plasma  = autocvar_g_pickup_plasma_max;   break;
-                               case ammo_fuel:    this.ammo_fuel    = autocvar_g_pickup_fuel_max;    break;
+                               case RESOURCE_SHELLS:  SetResourceAmount(this, RESOURCE_SHELLS, autocvar_g_pickup_shells_max);  break;
+                               case RESOURCE_BULLETS: SetResourceAmount(this, RESOURCE_BULLETS, autocvar_g_pickup_nails_max);   break;
+                               case RESOURCE_ROCKETS: SetResourceAmount(this, RESOURCE_ROCKETS, autocvar_g_pickup_rockets_max); break;
+                               case RESOURCE_CELLS:   SetResourceAmount(this, RESOURCE_CELLS, autocvar_g_pickup_cells_max);   break;
+                               case RESOURCE_PLASMA:  SetResourceAmount(this, RESOURCE_PLASMA, autocvar_g_pickup_plasma_max);   break;
+                               case RESOURCE_FUEL:    SetResourceAmount(this, RESOURCE_FUEL, autocvar_g_pickup_fuel_max);    break;
                        }
                }
                else
                {
-                       switch(e.ammo_field)
+                       switch (e.ammo_type)
                        {
-                               case ammo_shells:  this.ammo_shells  = autocvar_g_balance_nix_ammo_shells;  break;
-                               case ammo_nails:   this.ammo_nails   = autocvar_g_balance_nix_ammo_nails;   break;
-                               case ammo_rockets: this.ammo_rockets = autocvar_g_balance_nix_ammo_rockets; break;
-                               case ammo_cells:   this.ammo_cells   = autocvar_g_balance_nix_ammo_cells;   break;
-                               case ammo_plasma:  this.ammo_plasma  = autocvar_g_balance_nix_ammo_plasma;   break;
-                               case ammo_fuel:    this.ammo_fuel    = autocvar_g_balance_nix_ammo_fuel;    break;
+                               case RESOURCE_SHELLS:  SetResourceAmount(this, RESOURCE_SHELLS, autocvar_g_balance_nix_ammo_shells);  break;
+                               case RESOURCE_BULLETS: SetResourceAmount(this, RESOURCE_BULLETS, autocvar_g_balance_nix_ammo_nails);   break;
+                               case RESOURCE_ROCKETS: SetResourceAmount(this, RESOURCE_ROCKETS, autocvar_g_balance_nix_ammo_rockets); break;
+                               case RESOURCE_CELLS:   SetResourceAmount(this, RESOURCE_CELLS, autocvar_g_balance_nix_ammo_cells);   break;
+                               case RESOURCE_PLASMA:  SetResourceAmount(this, RESOURCE_PLASMA, autocvar_g_balance_nix_ammo_plasma);   break;
+                               case RESOURCE_FUEL:    SetResourceAmount(this, RESOURCE_FUEL, autocvar_g_balance_nix_ammo_fuel);    break;
                        }
                }
 
@@ -164,14 +175,12 @@ void NIX_GiveCurrentWeapon(entity this)
 
                // all weapons must be fully loaded when we spawn
                if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
-                       this.(weapon_load[nix_weapon]) = e.reloading_ammo;
-
-               // vortex too
-               if(WEP_CVAR(vortex, charge))
                {
-                       if(WEP_CVAR_SEC(vortex, chargepool))
-                               this.vortex_chargepool_ammo = 1;
-                       this.vortex_charge = WEP_CVAR(vortex, charge_start);
+                       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+                       {
+                               .entity weaponentity = weaponentities[slot];
+                               this.(weaponentity).(weapon_load[nix_weapon]) = e.reloading_ammo;
+                       }
                }
 
                // set last change info
@@ -186,14 +195,14 @@ void NIX_GiveCurrentWeapon(entity this)
 
        if(!(this.items & IT_UNLIMITED_WEAPON_AMMO) && time > this.nix_nextincr)
        {
-               switch(e.ammo_field)
+               switch (e.ammo_type)
                {
-                       case ammo_shells:  this.ammo_shells  += autocvar_g_balance_nix_ammoincr_shells;  break;
-                       case ammo_nails:   this.ammo_nails   += autocvar_g_balance_nix_ammoincr_nails;   break;
-                       case ammo_rockets: this.ammo_rockets += autocvar_g_balance_nix_ammoincr_rockets; break;
-                       case ammo_cells:   this.ammo_cells   += autocvar_g_balance_nix_ammoincr_cells;   break;
-                       case ammo_plasma:  this.ammo_plasma  += autocvar_g_balance_nix_ammoincr_plasma;   break;
-                       case ammo_fuel:    this.ammo_fuel    += autocvar_g_balance_nix_ammoincr_fuel;    break;
+                       case RESOURCE_SHELLS:  GiveResource(this, RESOURCE_SHELLS, autocvar_g_balance_nix_ammoincr_shells);  break;
+                       case RESOURCE_BULLETS: GiveResource(this, RESOURCE_BULLETS, autocvar_g_balance_nix_ammoincr_nails);   break;
+                       case RESOURCE_ROCKETS: GiveResource(this, RESOURCE_ROCKETS, autocvar_g_balance_nix_ammoincr_rockets); break;
+                       case RESOURCE_CELLS:   GiveResource(this, RESOURCE_CELLS, autocvar_g_balance_nix_ammoincr_cells);   break;
+                       case RESOURCE_PLASMA:  GiveResource(this, RESOURCE_PLASMA, autocvar_g_balance_nix_ammoincr_plasma);   break;
+                       case RESOURCE_FUEL:    GiveResource(this, RESOURCE_FUEL, autocvar_g_balance_nix_ammoincr_fuel);    break;
                }
 
                this.nix_nextincr = time + autocvar_g_balance_nix_incrtime;
@@ -205,12 +214,19 @@ void NIX_GiveCurrentWeapon(entity this)
        this.weapons |= e.m_wepset;
 
     Weapon w = Weapons_from(nix_weapon);
-       if(PS(this).m_switchweapon != w)
-               if(!client_hasweapon(this, PS(this).m_switchweapon, true, false))
+    for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+    {
+       .entity weaponentity = weaponentities[slot];
+       if(this.(weaponentity).m_weapon == WEP_Null && slot != 0)
+               continue;
+
+               if(this.(weaponentity).m_switchweapon != w)
+               if(!client_hasweapon(this, this.(weaponentity).m_switchweapon, weaponentity, true, false))
                {
-                       if(client_hasweapon(this, w, true, false))
-                               W_SwitchWeapon(this, w);
+                       if(client_hasweapon(this, w, weaponentity, true, false))
+                               W_SwitchWeapon(this, w, weaponentity);
                }
+       }
 }
 
 MUTATOR_HOOKFUNCTION(nix, ForbidThrowCurrentWeapon)
@@ -256,12 +272,17 @@ MUTATOR_HOOKFUNCTION(nix, PlayerPreThink)
 {
        entity player = M_ARGV(0, entity);
 
-       if(!gameover)
+       if(!game_stopped)
        if(!IS_DEAD(player))
        if(IS_PLAYER(player))
                NIX_GiveCurrentWeapon(player);
 }
 
+MUTATOR_HOOKFUNCTION(nix, ForbidRandomStartWeapons)
+{
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(nix, PlayerSpawn)
 {
        entity player = M_ARGV(0, entity);