1 float g_nix_with_laser;
7 float nix_nextweapon_ammo;
8 .float nix_lastchange_id;
9 .float nix_lastinfotime;
12 .float nix_save_cells;
13 .float nix_save_shells;
14 .float nix_save_nails;
15 .float nix_save_rockets;
17 .float nix_save_weapons;
19 float NIX_CanChooseWeapon(float wpn)
22 e = get_weaponinfo(wpn);
23 if(!e.weapons) // skip dummies
27 if not(g_weaponarena & e.weapons)
32 if(wpn == WEP_LASER && g_nix_with_laser)
34 if not(e.spawnflags & WEP_FLAG_NORMAL)
39 void NIX_ChooseNextWeapon()
42 RandomSelection_Init();
43 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
44 if(NIX_CanChooseWeapon(j))
45 RandomSelection_Add(world, j, string_null, 1, (j != nix_weapon));
46 nix_nextweapon = RandomSelection_chosen_float;
47 nix_nextweapon_ammo = W_AmmoItemCode(nix_nextweapon);
50 void NIX_GiveCurrentWeapon()
55 NIX_ChooseNextWeapon();
57 dt = ceil(nix_nextchange - time);
61 nix_weapon = nix_nextweapon;
62 nix_weapon_ammo = nix_nextweapon_ammo;
64 if (!nix_nextchange) // no round played yet?
65 nix_nextchange = time; // start the first round now!
67 nix_nextchange = time + autocvar_g_balance_nix_roundtime;
68 //weapon_action(nix_weapon, WR_PRECACHE); // forget it, too slow
71 if(nix_nextchange != self.nix_lastchange_id) // this shall only be called once per round!
73 self.nix_lastchange_id = nix_nextchange;
74 if (self.items & IT_UNLIMITED_WEAPON_AMMO)
76 self.ammo_shells = (nix_weapon_ammo & IT_SHELLS) ?
77 autocvar_g_pickup_shells_max : 0;
78 self.ammo_nails = (nix_weapon_ammo & IT_NAILS) ?
79 autocvar_g_pickup_nails_max : 0;
80 self.ammo_rockets = (nix_weapon_ammo & IT_ROCKETS) ?
81 autocvar_g_pickup_rockets_max : 0;
82 self.ammo_cells = (nix_weapon_ammo & IT_CELLS) ?
83 autocvar_g_pickup_cells_max : 0;
84 self.ammo_fuel = (nix_weapon_ammo & IT_FUEL) ?
85 autocvar_g_pickup_fuel_max : 0;
89 self.ammo_shells = (nix_weapon_ammo & IT_SHELLS) ?
90 autocvar_g_balance_nix_ammo_shells : 0;
91 self.ammo_nails = (nix_weapon_ammo & IT_NAILS) ?
92 autocvar_g_balance_nix_ammo_nails : 0;
93 self.ammo_rockets = (nix_weapon_ammo & IT_ROCKETS) ?
94 autocvar_g_balance_nix_ammo_rockets : 0;
95 self.ammo_cells = (nix_weapon_ammo & IT_CELLS) ?
96 autocvar_g_balance_nix_ammo_cells : 0;
97 self.ammo_fuel = (nix_weapon_ammo & IT_FUEL) ?
98 autocvar_g_balance_nix_ammo_fuel : 0;
100 self.nix_nextincr = time + autocvar_g_balance_nix_incrtime;
101 if(dt >= 1 && dt <= 5)
102 self.nix_lastinfotime = -42;
104 Send_CSQC_Centerprint_Generic(self, CPID_NIX_WPNCHANGE, strcat("^2Active weapon: ^3", W_Name(nix_weapon)), 0, 0);
106 weapon_action(nix_weapon, WR_RESETPLAYER);
108 // all weapons must be fully loaded when we spawn
110 e = get_weaponinfo(nix_weapon);
111 if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
112 self.weapon_load[nix_weapon] = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
115 if(autocvar_g_balance_nex_charge)
117 if(autocvar_g_balance_nex_secondary_chargepool)
118 self.nex_chargepool_ammo = 1;
119 self.nex_charge = autocvar_g_balance_nex_charge_start;
122 if(self.nix_lastinfotime != dt)
124 self.nix_lastinfotime = dt; // initial value 0 should count as "not seen"
125 if(dt >= 1 && dt <= 5)
126 Send_CSQC_Centerprint_Generic(self, CPID_NIX_WPNCHANGE, strcat("^3%d^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nix_nextweapon)), 1, dt);
129 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO) && time > self.nix_nextincr)
131 if (nix_weapon_ammo & IT_SHELLS)
132 self.ammo_shells = self.ammo_shells + autocvar_g_balance_nix_ammoincr_shells;
133 else if (nix_weapon_ammo & IT_NAILS)
134 self.ammo_nails = self.ammo_nails + autocvar_g_balance_nix_ammoincr_nails;
135 else if (nix_weapon_ammo & IT_ROCKETS)
136 self.ammo_rockets = self.ammo_rockets + autocvar_g_balance_nix_ammoincr_rockets;
137 else if (nix_weapon_ammo & IT_CELLS)
138 self.ammo_cells = self.ammo_cells + autocvar_g_balance_nix_ammoincr_cells;
139 if (nix_weapon_ammo & IT_FUEL) // hook uses cells and fuel
140 self.ammo_fuel = self.ammo_fuel + autocvar_g_balance_nix_ammoincr_fuel;
141 self.nix_nextincr = time + autocvar_g_balance_nix_incrtime;
146 self.weapons = self.weapons | WEPBIT_LASER;
147 self.weapons = self.weapons | W_WeaponBit(nix_weapon);
149 if(self.switchweapon != nix_weapon)
150 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
151 if(client_hasweapon(self, nix_weapon, TRUE, FALSE))
152 W_SwitchWeapon(nix_weapon);
158 for (i = WEP_FIRST; i <= WEP_LAST; ++i)
159 if (NIX_CanChooseWeapon(i))
160 weapon_action(i, WR_PRECACHE);
163 MUTATOR_HOOKFUNCTION(nix_ForbidThrowCurrentWeapon)
165 return 1; // no throwing in NIX
168 MUTATOR_HOOKFUNCTION(nix_SetStartItems)
171 // we do NOT change the start weapons any more, so we can later turn off the mutator!
172 // start_weapons = 0; // will be done later, when player spawns
173 // warmup_start_weapons = 0; // will be done later, when player spawns
177 MUTATOR_HOOKFUNCTION(nix_BuildMutatorsString)
179 ret_string = strcat(ret_string, ":NIX");
183 MUTATOR_HOOKFUNCTION(nix_BuildMutatorsPrettyString)
185 ret_string = strcat(ret_string, ", NIX");
189 MUTATOR_HOOKFUNCTION(nix_FilterItem)
198 if (autocvar_g_nix_with_healtharmor)
203 if (autocvar_g_nix_with_powerups)
208 return 1; // delete all other items
211 MUTATOR_HOOKFUNCTION(nix_OnEntityPreSpawn)
213 if(self.classname == "target_items") // items triggers cannot work in nix (as they change weapons/ammo)
218 MUTATOR_HOOKFUNCTION(nix_PlayerPreThink)
220 if(!intermission_running)
221 if(self.deadflag == DEAD_NO)
222 if(self.classname == "player")
223 NIX_GiveCurrentWeapon();
227 MUTATOR_HOOKFUNCTION(nix_PlayerSpawn)
229 self.nix_lastchange_id = -1;
230 NIX_GiveCurrentWeapon(); // overrides the weapons you got when spawning
234 MUTATOR_DEFINITION(mutator_nix)
238 MUTATOR_HOOK(ForbidThrowCurrentWeapon, nix_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
239 MUTATOR_HOOK(SetStartItems, nix_SetStartItems, CBC_ORDER_EXCLUSIVE);
240 MUTATOR_HOOK(BuildMutatorsString, nix_BuildMutatorsString, CBC_ORDER_ANY);
241 MUTATOR_HOOK(BuildMutatorsPrettyString, nix_BuildMutatorsPrettyString, CBC_ORDER_ANY);
242 MUTATOR_HOOK(FilterItem, nix_FilterItem, CBC_ORDER_ANY);
243 MUTATOR_HOOK(OnEntityPreSpawn, nix_OnEntityPreSpawn, CBC_ORDER_ANY);
244 MUTATOR_HOOK(PlayerPreThink, nix_PlayerPreThink, CBC_ORDER_ANY);
245 MUTATOR_HOOK(PlayerSpawn, nix_PlayerSpawn, CBC_ORDER_ANY);
249 g_nix_with_laser = autocvar_g_nix_with_laser;
258 if(e.deadflag == DEAD_NO)
260 e.nix_save_cells = e.ammo_cells;
261 e.nix_save_shells = e.ammo_shells;
262 e.nix_save_nails = e.ammo_nails;
263 e.nix_save_rockets = e.ammo_rockets;
264 e.nix_save_fuel = e.ammo_fuel;
265 e.nix_save_weapons = e.weapons;
269 e.nix_save_cells = 0;
270 e.nix_save_shells = 0;
271 e.nix_save_nails = 0;
272 e.nix_save_rockets = 0;
274 e.nix_save_weapons = 0;
281 // as the PlayerSpawn hook will no longer run, NIX is turned off by this!
283 FOR_EACH_PLAYER(e) if(e.deadflag == DEAD_NO)
285 e.ammo_cells = max(start_ammo_cells, e.nix_save_cells);
286 e.ammo_shells = max(start_ammo_shells, e.nix_save_shells);
287 e.ammo_nails = max(start_ammo_nails, e.nix_save_nails);
288 e.ammo_rockets = max(start_ammo_rockets, e.nix_save_rockets);
289 e.ammo_fuel = max(start_ammo_fuel, e.nix_save_fuel);
290 e.weapons = (start_weapons | e.nix_save_weapons);
291 if(!client_hasweapon(e, e.weapon, TRUE, FALSE))
292 e.switchweapon = w_getbestweapon(self);