3 if(self.switchweapon == self.weapon)
4 if(self.weaponentity.state == WS_READY)
5 weapon_action(self.weapon, WR_RELOAD);
8 // switch between weapons
9 void W_SwitchWeapon(float imp)
11 if (self.switchweapon != imp)
13 if (client_hasweapon(self, imp, TRUE, TRUE))
14 W_SwitchWeapon_Force(self, imp);
22 .float weaponcomplainindex;
23 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain)
25 // We cannot tokenize in this function, as GiveItems calls this
26 // function. Thus we must use car/cdr.
27 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
29 switchtonext = switchtolast = 0;
30 first_valid = prev_valid = 0;
40 weaponwant = stof(car(rest)); rest = cdr(rest);
42 if((get_weaponinfo(weaponwant)).impulse != imp)
47 if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
52 first_valid = weaponwant;
53 if(weaponwant == pl.switchweapon)
62 prev_valid = weaponwant;
72 // complain (but only for one weapon on the button that has been pressed)
75 self.weaponcomplainindex += 1;
76 c = mod(self.weaponcomplainindex, c) + 1;
80 weaponwant = stof(car(rest)); rest = cdr(rest);
82 if((get_weaponinfo(weaponwant)).impulse != imp)
88 client_hasweapon(pl, weaponwant, TRUE, TRUE);
96 void W_CycleWeapon(string weaponorder, float dir)
99 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1);
104 void W_NextWeaponOnImpulse(float imp)
107 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1);
113 void W_NextWeapon(float list)
116 W_CycleWeapon(weaponpriority_hudselector_0, -1);
118 W_CycleWeapon(weaponpriority_hudselector_1, -1);
120 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
124 void W_PreviousWeapon(float list)
127 W_CycleWeapon(weaponpriority_hudselector_0, +1);
129 W_CycleWeapon(weaponpriority_hudselector_1, +1);
131 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
134 string W_FixWeaponOrder_AllowIncomplete(string order)
136 return W_FixWeaponOrder(order, 0);
139 string W_FixWeaponOrder_ForceComplete(string order)
142 order = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
143 return W_FixWeaponOrder(order, 1);
146 float w_getbestweapon(entity e)
148 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, 0);
151 // generic weapons table
152 // TODO should they be macros instead?
153 float weapon_action(float wpn, float wrequest)
155 return (get_weaponinfo(wpn)).weapon_func(wrequest);
158 string W_Name(float weaponid)
160 return (get_weaponinfo(weaponid)).message;
163 float W_WeaponBit(float wpn)
165 return (get_weaponinfo(wpn)).weapons;
168 float W_AmmoItemCode(float wpn)
170 return (get_weaponinfo(wpn)).items;
173 void thrown_wep_think()
175 self.solid = SOLID_TRIGGER;
177 SUB_SetFade(self, time + 20, 1);
180 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
181 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
184 float wa, thisammo, i, j;
186 var .float ammofield;
191 wep.classname = "droppedweapon";
193 wep.owner = wep.enemy = own;
194 wep.flags |= FL_TOSSED;
195 wep.colormap = own.colormap;
197 wa = W_AmmoItemCode(wpn);
198 if(wa == IT_SUPERWEAPON || wa == 0)
202 weapon_defaultspawnfunc(wpn);
206 wep.think = thrown_wep_think;
207 wep.nextthink = time + 0.5;
215 weapon_defaultspawnfunc(wpn);
221 for(i = 0, j = 1; i < 24; ++i, j *= 2)
225 ammofield = Item_CounterField(j);
226 thisammo = min(own.ammofield, wep.ammofield);
227 wep.ammofield = thisammo;
228 own.ammofield -= thisammo;
229 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
232 s = substring(s, 5, -1);
234 wep.think = thrown_wep_think;
235 wep.nextthink = time + 0.5;
240 float W_IsWeaponThrowable(float w)
246 wa = W_AmmoItemCode(w);
247 if(start_weapons & wb)
249 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
251 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
253 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
261 // toss current weapon
262 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
269 return; // just in case
276 if (g_nexball && w == WEP_GRENADE_LAUNCHER)
278 if (!cvar("g_pickup_items"))
282 if(!cvar("g_weapon_throwable"))
284 if(cvar("g_weapon_stay") == 1)
286 if(!W_IsWeaponThrowable(w))
290 if(self.weapons & wb != wb)
294 W_SwitchWeapon_Force(self, w_getbestweapon(self));
295 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
301 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
303 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", a, "\n"));
307 // Bringed back weapon frame
313 self.weapon_frametime = frametime;
315 if(((arena_roundbased || g_ca) && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
318 if (!self.weaponentity || self.health < 1)
319 return; // Dead player can't use weapons and injure impulse commands
321 if(!self.switchweapon)
324 self.weaponentity.state = WS_CLEAR;
325 self.weaponname = "";
326 self.items &~= IT_AMMO;
330 makevectors(self.v_angle);
331 fo = v_forward; // save them in case the weapon think functions change it
336 if (self.weapon != self.switchweapon)
338 if (self.weaponentity.state == WS_CLEAR)
340 setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
341 self.weaponentity.state = WS_RAISE;
342 weapon_action(self.switchweapon, WR_SETUP);
343 // VorteX: add player model weapon select frame here
344 // setcustomframe(PlayerWeaponRaise);
345 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
346 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
348 else if (self.weaponentity.state == WS_READY)
350 #ifndef INDEPENDENT_ATTACK_FINISHED
351 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
354 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
355 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
356 self.weaponentity.state = WS_DROP;
357 // set up weapon switch think in the future, and start drop anim
358 weapon_thinkf(WFRAME_DONTCHANGE, cvar("g_balance_weaponswitchdelay"), w_clear);
359 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
360 #ifndef INDEPENDENT_ATTACK_FINISHED
366 // LordHavoc: network timing test code
368 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
371 wb = W_WeaponBit(self.weapon);
373 // call the think code which may fire the weapon
374 // and do so multiple times to resolve framerate dependency issues if the
375 // server framerate is very low and the weapon fire rate very high
381 if(wb && ((self.weapons & wb) == 0))
383 W_SwitchWeapon_Force(self, w_getbestweapon(self));
391 weapon_action(self.weapon, WR_THINK);
393 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
395 if(self.weapon_think)
403 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
407 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
408 //if (ATTACK_FINISHED(self) < time)
409 // ATTACK_FINISHED(self) = time;
411 //if (self.weapon_nextthink < time)
412 // self.weapon_nextthink = time;
414 // update currentammo incase it has changed
416 if (self.items & IT_CELLS)
417 self.currentammo = self.ammo_cells;
418 else if (self.items & IT_ROCKETS)
419 self.currentammo = self.ammo_rockets;
420 else if (self.items & IT_NAILS)
421 self.currentammo = self.ammo_nails;
422 else if (self.items & IT_SHELLS)
423 self.currentammo = self.ammo_shells;
425 self.currentammo = 1;
430 float nixnex_weapon_ammo;
431 float nixnex_nextchange;
432 float nixnex_nextweapon;
433 float nixnex_nextweapon_ammo;
434 .float nixnex_lastchange_id;
435 .float nixnex_lastinfotime;
436 .float nixnex_nextincr;
438 float NixNex_CanChooseWeapon(float wpn)
441 e = get_weaponinfo(wpn);
442 if(!e.weapons) // skip dummies
446 if not(g_weaponarena & e.weapons)
451 if(wpn == WEP_LASER && g_nixnex_with_laser)
453 if not(e.spawnflags & WEP_FLAG_NORMAL)
458 void Nixnex_ChooseNextWeapon()
461 RandomSelection_Init();
462 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
463 if(NixNex_CanChooseWeapon(j))
464 RandomSelection_Add(world, j, string_null, 1, (j != nixnex_weapon));
465 nixnex_nextweapon = RandomSelection_chosen_float;
466 nixnex_nextweapon_ammo = W_AmmoItemCode(nixnex_nextweapon);
469 void Nixnex_GiveCurrentWeapon()
474 if(!nixnex_nextweapon)
475 Nixnex_ChooseNextWeapon();
477 dt = ceil(nixnex_nextchange - time);
481 nixnex_weapon = nixnex_nextweapon;
482 nixnex_weapon_ammo = nixnex_nextweapon_ammo;
483 nixnex_nextweapon = 0;
484 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
485 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
488 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
490 self.nixnex_lastchange_id = nixnex_nextchange;
491 if (self.items & IT_UNLIMITED_WEAPON_AMMO)
493 self.ammo_shells = (nixnex_weapon_ammo & IT_SHELLS) ?
494 cvar("g_pickup_shells_max") : 0;
495 self.ammo_nails = (nixnex_weapon_ammo & IT_NAILS) ?
496 cvar("g_pickup_nails_max") : 0;
497 self.ammo_rockets = (nixnex_weapon_ammo & IT_ROCKETS) ?
498 cvar("g_pickup_rockets_max") : 0;
499 self.ammo_cells = (nixnex_weapon_ammo & IT_CELLS) ?
500 cvar("g_pickup_cells_max") : 0;
501 self.ammo_fuel = (nixnex_weapon_ammo & IT_FUEL) ?
502 cvar("g_pickup_fuel_max") : 0;
506 self.ammo_shells = (nixnex_weapon_ammo & IT_SHELLS) ?
507 cvar("g_balance_nixnex_ammo_shells") : 0;
508 self.ammo_nails = (nixnex_weapon_ammo & IT_NAILS) ?
509 cvar("g_balance_nixnex_ammo_nails") : 0;
510 self.ammo_rockets = (nixnex_weapon_ammo & IT_ROCKETS) ?
511 cvar("g_balance_nixnex_ammo_rockets") : 0;
512 self.ammo_cells = (nixnex_weapon_ammo & IT_CELLS) ?
513 cvar("g_balance_nixnex_ammo_cells") : 0;
514 self.ammo_fuel = (nixnex_weapon_ammo & IT_FUEL) ?
515 cvar("g_balance_nixnex_ammo_fuel") : 0;
517 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
518 if(dt >= 1 && dt <= 5)
519 self.nixnex_lastinfotime = -42;
521 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon)));
523 if(self.nixnex_lastinfotime != dt)
525 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
526 if(dt >= 1 && dt <= 5)
527 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
530 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO) && time > self.nixnex_nextincr)
532 if (nixnex_weapon_ammo & IT_SHELLS)
533 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
534 else if (nixnex_weapon_ammo & IT_NAILS)
535 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
536 else if (nixnex_weapon_ammo & IT_ROCKETS)
537 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
538 else if (nixnex_weapon_ammo & IT_CELLS)
539 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
540 if (nixnex_weapon_ammo & IT_FUEL) // hook uses cells and fuel
541 self.ammo_fuel = self.ammo_fuel + cvar("g_balance_nixnex_ammoincr_fuel");
542 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
546 if(g_nixnex_with_laser)
547 self.weapons = self.weapons | WEPBIT_LASER;
548 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
550 if(self.switchweapon != nixnex_weapon)
551 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
552 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
553 W_SwitchWeapon(nixnex_weapon);