3 int autocvar_g_balance_nix_ammo_cells;
4 int autocvar_g_balance_nix_ammo_plasma;
5 int autocvar_g_balance_nix_ammo_fuel;
6 int autocvar_g_balance_nix_ammo_nails;
7 int autocvar_g_balance_nix_ammo_rockets;
8 int autocvar_g_balance_nix_ammo_shells;
9 int autocvar_g_balance_nix_ammoincr_cells;
10 int autocvar_g_balance_nix_ammoincr_plasma;
11 int autocvar_g_balance_nix_ammoincr_fuel;
12 int autocvar_g_balance_nix_ammoincr_nails;
13 int autocvar_g_balance_nix_ammoincr_rockets;
14 int autocvar_g_balance_nix_ammoincr_shells;
15 float autocvar_g_balance_nix_incrtime;
16 float autocvar_g_balance_nix_roundtime;
17 bool autocvar_g_nix_with_healtharmor;
18 bool autocvar_g_nix_with_blaster;
19 bool autocvar_g_nix_with_powerups;
20 int autocvar_g_pickup_cells_max;
21 int autocvar_g_pickup_plasma_max;
22 int autocvar_g_pickup_fuel_max;
23 int autocvar_g_pickup_nails_max;
24 int autocvar_g_pickup_rockets_max;
25 int autocvar_g_pickup_shells_max;
27 float g_nix_with_blaster;
32 .float nix_lastchange_id;
33 .float nix_lastinfotime;
36 bool NIX_CanChooseWeapon(int wpn);
38 REGISTER_MUTATOR(nix, cvar("g_nix") && !cvar("g_instagib") && !cvar("g_overkill"))
42 g_nix_with_blaster = autocvar_g_nix_with_blaster;
47 FOREACH(Weapons, it != WEP_Null && NIX_CanChooseWeapon(it.m_id), LAMBDA(it.wr_init(it)));
50 MUTATOR_ONROLLBACK_OR_REMOVE
52 // nothing to roll back
57 // as the PlayerSpawn hook will no longer run, NIX is turned off by this!
58 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
59 it.ammo_cells = start_ammo_cells;
60 it.ammo_plasma = start_ammo_plasma;
61 it.ammo_shells = start_ammo_shells;
62 it.ammo_nails = start_ammo_nails;
63 it.ammo_rockets = start_ammo_rockets;
64 it.ammo_fuel = start_ammo_fuel;
65 it.weapons = start_weapons;
66 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
68 .entity weaponentity = weaponentities[slot];
69 if(it.(weaponentity).m_weapon == WEP_Null && slot != 0)
71 if(!client_hasweapon(it, it.(weaponentity).m_weapon, weaponentity, true, false))
72 it.(weaponentity).m_switchweapon = w_getbestweapon(it, weaponentity);
80 bool NIX_CanChooseWeapon(int wpn)
82 entity e = Weapons_from(wpn);
83 if (e == WEP_Null) return false; // skip dummies
86 if(!(g_weaponarena_weapons & e.m_wepset))
91 if(wpn == WEP_BLASTER.m_id && g_nix_with_blaster)
93 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
95 if (!(e.spawnflags & WEP_FLAG_NORMAL))
100 void NIX_ChooseNextWeapon()
102 RandomSelection_Init();
103 FOREACH(Weapons, it != WEP_Null, LAMBDA(
104 if(NIX_CanChooseWeapon(it.m_id))
105 RandomSelection_AddFloat(it.m_id, 1, (it.m_id != nix_weapon));
107 nix_nextweapon = RandomSelection_chosen_float;
110 void NIX_GiveCurrentWeapon(entity this)
115 NIX_ChooseNextWeapon();
117 dt = ceil(nix_nextchange - time);
121 nix_weapon = nix_nextweapon;
123 if (!nix_nextchange) // no round played yet?
124 nix_nextchange = time; // start the first round now!
126 nix_nextchange = time + autocvar_g_balance_nix_roundtime;
127 // Weapon w = Weapons_from(nix_weapon);
128 // w.wr_init(w); // forget it, too slow
132 entity e = Weapons_from(nix_weapon);
134 if(nix_nextchange != this.nix_lastchange_id) // this shall only be called once per round!
136 this.ammo_shells = this.ammo_nails = this.ammo_rockets = this.ammo_cells = this.ammo_plasma = this.ammo_fuel = 0;
138 if(this.items & IT_UNLIMITED_WEAPON_AMMO)
142 case ammo_shells: this.ammo_shells = autocvar_g_pickup_shells_max; break;
143 case ammo_nails: this.ammo_nails = autocvar_g_pickup_nails_max; break;
144 case ammo_rockets: this.ammo_rockets = autocvar_g_pickup_rockets_max; break;
145 case ammo_cells: this.ammo_cells = autocvar_g_pickup_cells_max; break;
146 case ammo_plasma: this.ammo_plasma = autocvar_g_pickup_plasma_max; break;
147 case ammo_fuel: this.ammo_fuel = autocvar_g_pickup_fuel_max; break;
154 case ammo_shells: this.ammo_shells = autocvar_g_balance_nix_ammo_shells; break;
155 case ammo_nails: this.ammo_nails = autocvar_g_balance_nix_ammo_nails; break;
156 case ammo_rockets: this.ammo_rockets = autocvar_g_balance_nix_ammo_rockets; break;
157 case ammo_cells: this.ammo_cells = autocvar_g_balance_nix_ammo_cells; break;
158 case ammo_plasma: this.ammo_plasma = autocvar_g_balance_nix_ammo_plasma; break;
159 case ammo_fuel: this.ammo_fuel = autocvar_g_balance_nix_ammo_fuel; break;
163 this.nix_nextincr = time + autocvar_g_balance_nix_incrtime;
164 if(dt >= 1 && dt <= 5)
165 this.nix_lastinfotime = -42;
167 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_NIX_NEWWEAPON, nix_weapon);
169 e.wr_resetplayer(e, this);
171 // all weapons must be fully loaded when we spawn
172 if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
174 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
176 .entity weaponentity = weaponentities[slot];
177 this.(weaponentity).(weapon_load[nix_weapon]) = e.reloading_ammo;
182 if(WEP_CVAR(vortex, charge))
184 if(WEP_CVAR_SEC(vortex, chargepool))
185 this.vortex_chargepool_ammo = 1;
186 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
188 .entity weaponentity = weaponentities[slot];
189 this.(weaponentity).vortex_charge = WEP_CVAR(vortex, charge_start);
193 // set last change info
194 this.nix_lastchange_id = nix_nextchange;
196 if(this.nix_lastinfotime != dt)
198 this.nix_lastinfotime = dt; // initial value 0 should count as "not seen"
199 if(dt >= 1 && dt <= 5)
200 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_NIX_COUNTDOWN, nix_nextweapon, dt);
203 if(!(this.items & IT_UNLIMITED_WEAPON_AMMO) && time > this.nix_nextincr)
207 case ammo_shells: this.ammo_shells += autocvar_g_balance_nix_ammoincr_shells; break;
208 case ammo_nails: this.ammo_nails += autocvar_g_balance_nix_ammoincr_nails; break;
209 case ammo_rockets: this.ammo_rockets += autocvar_g_balance_nix_ammoincr_rockets; break;
210 case ammo_cells: this.ammo_cells += autocvar_g_balance_nix_ammoincr_cells; break;
211 case ammo_plasma: this.ammo_plasma += autocvar_g_balance_nix_ammoincr_plasma; break;
212 case ammo_fuel: this.ammo_fuel += autocvar_g_balance_nix_ammoincr_fuel; break;
215 this.nix_nextincr = time + autocvar_g_balance_nix_incrtime;
218 this.weapons = '0 0 0';
219 if(g_nix_with_blaster)
220 this.weapons |= WEPSET(BLASTER);
221 this.weapons |= e.m_wepset;
223 Weapon w = Weapons_from(nix_weapon);
224 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
226 .entity weaponentity = weaponentities[slot];
227 if(this.(weaponentity).m_weapon == WEP_Null && slot != 0)
230 if(this.(weaponentity).m_switchweapon != w)
231 if(!client_hasweapon(this, this.(weaponentity).m_switchweapon, weaponentity, true, false))
233 if(client_hasweapon(this, w, weaponentity, true, false))
234 W_SwitchWeapon(this, w, weaponentity);
239 MUTATOR_HOOKFUNCTION(nix, ForbidThrowCurrentWeapon)
241 return true; // no throwing in NIX
244 MUTATOR_HOOKFUNCTION(nix, BuildMutatorsString)
246 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":NIX");
249 MUTATOR_HOOKFUNCTION(nix, BuildMutatorsPrettyString)
251 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", NIX");
254 MUTATOR_HOOKFUNCTION(nix, FilterItem)
256 entity item = M_ARGV(0, entity);
258 if(item.itemdef.instanceOfHealth || item.itemdef.instanceOfArmor)
260 return !autocvar_g_nix_with_healtharmor;
262 else if(item.itemdef.instanceOfPowerup)
264 return !autocvar_g_nix_with_powerups;
267 return true; // delete all other items
270 MUTATOR_HOOKFUNCTION(nix, OnEntityPreSpawn)
272 entity ent = M_ARGV(0, entity);
274 if(ent.classname == "target_items") // items triggers cannot work in nix (as they change weapons/ammo)
278 MUTATOR_HOOKFUNCTION(nix, PlayerPreThink)
280 entity player = M_ARGV(0, entity);
282 if(!intermission_running)
284 if(IS_PLAYER(player))
285 NIX_GiveCurrentWeapon(player);
288 MUTATOR_HOOKFUNCTION(nix, PlayerSpawn)
290 entity player = M_ARGV(0, entity);
292 player.nix_lastchange_id = -1;
293 NIX_GiveCurrentWeapon(player); // overrides the weapons you got when spawning
294 player.items |= IT_UNLIMITED_SUPERWEAPONS;
297 MUTATOR_HOOKFUNCTION(nix, SetModname, CBC_ORDER_LAST)
299 M_ARGV(0, string) = "NIX";