1 // switch between weapons
2 void W_SwitchWeapon(float imp)
4 if (self.switchweapon != imp)
5 if (client_hasweapon(self, imp, TRUE, TRUE))
6 W_SwitchWeapon_Force(self, imp);
9 .float weaponcomplainindex;
10 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain)
12 float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
13 n = tokenize_sane(weaponorder);
14 switchtonext = switchtolast = 0;
15 first_valid = prev_valid = 0;
22 for(i = 0; i < n; ++i)
24 weaponwant = stof(argv(i));
26 if((get_weaponinfo(weaponwant)).impulse != imp)
31 if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
36 first_valid = weaponwant;
37 if(weaponwant == pl.switchweapon)
46 prev_valid = weaponwant;
56 // complain (but only for one weapon on the button that has been pressed)
59 self.weaponcomplainindex += 1;
60 c = mod(self.weaponcomplainindex, c) + 1;
61 for(i = 0; i < n; ++i)
63 weaponwant = stof(argv(i));
65 if((get_weaponinfo(weaponwant)).impulse != imp)
71 client_hasweapon(pl, weaponwant, TRUE, TRUE);
79 void W_CycleWeapon(string weaponorder, float dir)
82 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1);
87 void W_NextWeaponOnImpulse(float imp)
90 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1);
96 void W_NextWeapon(float list)
99 W_CycleWeapon(weaponpriority_hudselector_0, -1);
101 W_CycleWeapon(weaponpriority_hudselector_1, -1);
103 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
107 void W_PreviousWeapon(float list)
110 W_CycleWeapon(weaponpriority_hudselector_0, +1);
112 W_CycleWeapon(weaponpriority_hudselector_1, +1);
114 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
117 string W_FixWeaponOrder_AllowIncomplete(string order)
119 return W_FixWeaponOrder(order, 0);
122 string W_FixWeaponOrder_ForceComplete(string order)
125 order = cvar_string("cl_weaponpriority");
126 return W_FixWeaponOrder(order, 1);
129 float w_getbestweapon(entity e)
131 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, 0);
134 // generic weapons table
135 // TODO should they be macros instead?
136 float weapon_action(float wpn, float wrequest)
138 return (get_weaponinfo(wpn)).weapon_func(wrequest);
141 string W_Name(float weaponid)
143 return (get_weaponinfo(weaponid)).message;
146 float W_WeaponBit(float wpn)
148 return (get_weaponinfo(wpn)).weapons;
151 float W_AmmoItemCode(float wpn)
153 return (get_weaponinfo(wpn)).items;
156 void thrown_wep_think()
158 self.solid = SOLID_TRIGGER;
160 SUB_SetFade(self, time + 20, 1);
163 // returns amount of ammo used, or -1 for failure, or 0 for no ammo count
164 float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
168 var .float ammofield;
173 wep.classname = "droppedweapon";
175 wep.owner = wep.enemy = own;
176 wep.classname = "droppedweapon";
177 wep.flags = wep.flags | FL_TOSSED;
178 wep.colormap = own.colormap;
180 wa = W_AmmoItemCode(wpn);
181 if(wa == IT_SUPERWEAPON || wa == 0)
185 weapon_defaultspawnfunc(wpn);
189 wep.think = thrown_wep_think;
190 wep.nextthink = time + 0.5;
195 ammofield = Item_CounterField(wa);
198 weapon_defaultspawnfunc(wpn);
204 thisammo = min(own.ammofield, wep.ammofield);
205 wep.ammofield = thisammo;
206 own.ammofield -= thisammo;
208 wep.think = thrown_wep_think;
209 wep.nextthink = time + 0.5;
210 return wep.ammofield;
214 // toss current weapon
215 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
217 local float w, a, wb, wa;
221 return; // just in case
223 return; // just in case
230 if (!cvar("g_pickup_items"))
234 wa = W_AmmoItemCode(w);
237 if(self.weapons & wb != wb)
239 if(start_weapons & wb)
241 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
243 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
249 self.weapons = self.weapons - wb;
250 W_SwitchWeapon_Force(self, w_getbestweapon(self));
251 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
257 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
259 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", ftos(a), " ", Item_CounterFieldName(W_AmmoItemCode(w)), "\n"));
263 // Bringed back weapon frame
266 if((arena_roundbased && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
269 if (!self.weaponentity || self.health < 1)
270 return; // Dead player can't use weapons and injure impulse commands
272 if(!self.switchweapon)
275 self.weaponentity.state = WS_CLEAR;
279 makevectors(self.v_angle);
282 if (self.weapon != self.switchweapon)
284 if (self.weaponentity.state == WS_CLEAR)
286 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
287 self.weaponentity.state = WS_RAISE;
288 weapon_action(self.switchweapon, WR_SETUP);
289 // VorteX: add player model weapon select frame here
290 // setcustomframe(PlayerWeaponRaise);
291 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
292 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
294 else if (self.weaponentity.state == WS_READY)
296 #ifndef INDEPENDENT_ATTACK_FINISHED
297 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
300 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
301 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
302 self.weaponentity.state = WS_DROP;
303 // set up weapon switch think in the future, and start drop anim
304 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
305 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
306 #ifndef INDEPENDENT_ATTACK_FINISHED
313 wb = W_WeaponBit(self.weapon);
315 // call the think code which may fire the weapon
316 // and do so multiple times to resolve framerate dependency issues if the
317 // server framerate is very low and the weapon fire rate very high
323 if(wb && self.weapons & wb == 0)
325 W_SwitchWeapon_Force(self, w_getbestweapon(self));
329 weapon_action(self.weapon, WR_THINK);
330 if (time + frametime * 0.5 >= self.weapon_nextthink)
332 if(self.weapon_think)
335 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
339 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
340 //if (ATTACK_FINISHED(self) < time)
341 // ATTACK_FINISHED(self) = time;
343 //if (self.weapon_nextthink < time)
344 // self.weapon_nextthink = time;
346 // update currentammo incase it has changed
347 if (self.items & IT_CELLS)
348 self.currentammo = self.ammo_cells;
349 else if (self.items & IT_ROCKETS)
350 self.currentammo = self.ammo_rockets;
351 else if (self.items & IT_NAILS)
352 self.currentammo = self.ammo_nails;
353 else if (self.items & IT_SHELLS)
354 self.currentammo = self.ammo_shells;
356 self.currentammo = 1;
361 float nixnex_nextchange;
362 float nixnex_nextweapon;
363 .float nixnex_lastchange_id;
364 .float nixnex_lastinfotime;
365 .float nixnex_nextincr;
367 void Nixnex_ChooseNextWeapon()
370 numberof = WEP_LAST - WEP_FIRST; // all but the current one
371 if(g_nixnex_with_laser)
372 numberof = numberof - 1;
373 id = WEP_FIRST + floor(random() * numberof);
375 if(g_nixnex_with_laser) // skip the laser if needed
378 if(id >= nixnex_weapon) // skip the current weapon
381 if(id < WEP_FIRST) // can't happen, but to be sure...
383 dprint("Won't happen (id < WEP_FIRST)\n");
386 if(id > WEP_LAST) // either
388 dprint("Won't happen (id > WEP_LAST)\n");
392 nixnex_nextweapon = id;
395 void Nixnex_GiveCurrentWeapon()
400 if(!nixnex_nextweapon)
401 Nixnex_ChooseNextWeapon();
403 dt = ceil(nixnex_nextchange - time);
407 nixnex_weapon = nixnex_nextweapon;
408 nixnex_nextweapon = 0;
409 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
410 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
413 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
415 self.nixnex_lastchange_id = nixnex_nextchange;
416 if (self.items & IT_UNLIMITED_WEAPON_AMMO)
418 self.ammo_shells = cvar("g_pickup_shells_max");
419 self.ammo_nails = cvar("g_pickup_nails_max");
420 self.ammo_rockets = cvar("g_pickup_rockets_max");
421 self.ammo_cells = cvar("g_pickup_cells_max");
425 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
426 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
427 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
428 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
430 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
431 if(dt >= 1 && dt <= 5)
432 self.nixnex_lastinfotime = -42;
434 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
436 if(self.nixnex_lastinfotime != dt)
438 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
439 if(dt >= 1 && dt <= 5)
440 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
443 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO) && time > self.nixnex_nextincr)
445 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
446 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
447 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
448 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
449 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
453 if(g_nixnex_with_laser)
454 self.weapons = self.weapons | WEPBIT_LASER;
455 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
457 if(self.switchweapon != nixnex_weapon)
458 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
459 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
460 W_SwitchWeapon(nixnex_weapon);