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 float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
26 n = tokenize_console(weaponorder);
27 switchtonext = switchtolast = 0;
28 first_valid = prev_valid = 0;
35 for(i = 0; i < n; ++i)
37 weaponwant = stof(argv(i));
39 if((get_weaponinfo(weaponwant)).impulse != imp)
44 if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
49 first_valid = weaponwant;
50 if(weaponwant == pl.switchweapon)
59 prev_valid = weaponwant;
69 // complain (but only for one weapon on the button that has been pressed)
72 self.weaponcomplainindex += 1;
73 c = mod(self.weaponcomplainindex, c) + 1;
74 for(i = 0; i < n; ++i)
76 weaponwant = stof(argv(i));
78 if((get_weaponinfo(weaponwant)).impulse != imp)
84 client_hasweapon(pl, weaponwant, TRUE, TRUE);
92 void W_CycleWeapon(string weaponorder, float dir)
95 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1);
100 void W_NextWeaponOnImpulse(float imp)
103 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1);
109 void W_NextWeapon(float list)
112 W_CycleWeapon(weaponpriority_hudselector_0, -1);
114 W_CycleWeapon(weaponpriority_hudselector_1, -1);
116 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
120 void W_PreviousWeapon(float list)
123 W_CycleWeapon(weaponpriority_hudselector_0, +1);
125 W_CycleWeapon(weaponpriority_hudselector_1, +1);
127 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
130 string W_FixWeaponOrder_AllowIncomplete(string order)
132 return W_FixWeaponOrder(order, 0);
135 string W_FixWeaponOrder_ForceComplete(string order)
138 order = cvar_string("cl_weaponpriority");
139 return W_FixWeaponOrder(order, 1);
142 float w_getbestweapon(entity e)
144 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, 0);
147 // generic weapons table
148 // TODO should they be macros instead?
149 float weapon_action(float wpn, float wrequest)
151 return (get_weaponinfo(wpn)).weapon_func(wrequest);
154 string W_Name(float weaponid)
156 return (get_weaponinfo(weaponid)).message;
159 float W_WeaponBit(float wpn)
161 return (get_weaponinfo(wpn)).weapons;
164 float W_AmmoItemCode(float wpn)
166 return (get_weaponinfo(wpn)).items;
169 void thrown_wep_think()
171 self.solid = SOLID_TRIGGER;
173 SUB_SetFade(self, time + 20, 1);
176 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
177 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
180 float wa, thisammo, i, j;
182 var .float ammofield;
187 wep.classname = "droppedweapon";
189 wep.owner = wep.enemy = own;
190 wep.flags |= FL_TOSSED;
191 wep.colormap = own.colormap;
193 wa = W_AmmoItemCode(wpn);
194 if(wa == IT_SUPERWEAPON || wa == 0)
198 weapon_defaultspawnfunc(wpn);
202 wep.think = thrown_wep_think;
203 wep.nextthink = time + 0.5;
211 weapon_defaultspawnfunc(wpn);
217 for(i = 0, j = 1; i < 24; ++i, j *= 2)
221 ammofield = Item_CounterField(j);
222 thisammo = min(own.ammofield, wep.ammofield);
223 wep.ammofield = thisammo;
224 own.ammofield -= thisammo;
225 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
228 s = substring(s, 5, -1);
230 wep.think = thrown_wep_think;
231 wep.nextthink = time + 0.5;
236 float W_IsWeaponThrowable(float w)
242 wa = W_AmmoItemCode(w);
243 if(start_weapons & wb)
245 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
247 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
249 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
257 // toss current weapon
258 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
265 return; // just in case
272 if (g_nexball && w == WEP_GRENADE_LAUNCHER)
274 if (!cvar("g_pickup_items"))
276 if(!W_IsWeaponThrowable(w))
280 if(self.weapons & wb != wb)
284 W_SwitchWeapon_Force(self, w_getbestweapon(self));
285 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
291 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
293 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", a, "\n"));
297 // Bringed back weapon frame
303 self.weapon_frametime = frametime;
305 if(((arena_roundbased || g_ca) && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
308 if (!self.weaponentity || self.health < 1)
309 return; // Dead player can't use weapons and injure impulse commands
311 if(!self.switchweapon)
314 self.weaponentity.state = WS_CLEAR;
315 self.weaponname = "";
316 self.items &~= IT_AMMO;
320 makevectors(self.v_angle);
321 fo = v_forward; // save them in case the weapon think functions change it
326 if (self.weapon != self.switchweapon)
328 if (self.weaponentity.state == WS_CLEAR)
330 setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
331 self.weaponentity.state = WS_RAISE;
332 weapon_action(self.switchweapon, WR_SETUP);
333 // VorteX: add player model weapon select frame here
334 // setcustomframe(PlayerWeaponRaise);
335 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
336 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
338 else if (self.weaponentity.state == WS_READY)
340 #ifndef INDEPENDENT_ATTACK_FINISHED
341 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
344 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
345 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
346 self.weaponentity.state = WS_DROP;
347 // set up weapon switch think in the future, and start drop anim
348 weapon_thinkf(WFRAME_DONTCHANGE, cvar("g_balance_weaponswitchdelay"), w_clear);
349 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
350 #ifndef INDEPENDENT_ATTACK_FINISHED
356 // LordHavoc: network timing test code
358 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
361 wb = W_WeaponBit(self.weapon);
363 // call the think code which may fire the weapon
364 // and do so multiple times to resolve framerate dependency issues if the
365 // server framerate is very low and the weapon fire rate very high
371 if(wb && ((self.weapons & wb) == 0))
373 W_SwitchWeapon_Force(self, w_getbestweapon(self));
381 weapon_action(self.weapon, WR_THINK);
383 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
385 if(self.weapon_think)
393 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
397 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
398 //if (ATTACK_FINISHED(self) < time)
399 // ATTACK_FINISHED(self) = time;
401 //if (self.weapon_nextthink < time)
402 // self.weapon_nextthink = time;
404 // update currentammo incase it has changed
406 if (self.items & IT_CELLS)
407 self.currentammo = self.ammo_cells;
408 else if (self.items & IT_ROCKETS)
409 self.currentammo = self.ammo_rockets;
410 else if (self.items & IT_NAILS)
411 self.currentammo = self.ammo_nails;
412 else if (self.items & IT_SHELLS)
413 self.currentammo = self.ammo_shells;
415 self.currentammo = 1;
420 float nixnex_weapon_ammo;
421 float nixnex_nextchange;
422 float nixnex_nextweapon;
423 float nixnex_nextweapon_ammo;
424 .float nixnex_lastchange_id;
425 .float nixnex_lastinfotime;
426 .float nixnex_nextincr;
428 float NixNex_CanChooseWeapon(float wpn)
431 e = get_weaponinfo(wpn);
432 if(!e.weapons) // skip dummies
436 if not(g_weaponarena & e.weapons)
441 if(wpn == WEP_LASER && g_nixnex_with_laser)
443 if not(e.spawnflags & WEPSPAWNFLAG_NORMAL)
448 void Nixnex_ChooseNextWeapon()
451 RandomSelection_Init();
452 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
453 if(NixNex_CanChooseWeapon(j))
454 RandomSelection_Add(world, j, string_null, 1, (j != nixnex_weapon));
455 nixnex_nextweapon = RandomSelection_chosen_float;
456 nixnex_nextweapon_ammo = W_AmmoItemCode(nixnex_nextweapon);
459 void Nixnex_GiveCurrentWeapon()
464 if(!nixnex_nextweapon)
465 Nixnex_ChooseNextWeapon();
467 dt = ceil(nixnex_nextchange - time);
471 nixnex_weapon = nixnex_nextweapon;
472 nixnex_weapon_ammo = nixnex_nextweapon_ammo;
473 nixnex_nextweapon = 0;
474 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
475 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
478 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
480 self.nixnex_lastchange_id = nixnex_nextchange;
481 if (self.items & IT_UNLIMITED_WEAPON_AMMO)
483 self.ammo_shells = (nixnex_weapon_ammo & IT_SHELLS) ?
484 cvar("g_pickup_shells_max") : 0;
485 self.ammo_nails = (nixnex_weapon_ammo & IT_NAILS) ?
486 cvar("g_pickup_nails_max") : 0;
487 self.ammo_rockets = (nixnex_weapon_ammo & IT_ROCKETS) ?
488 cvar("g_pickup_rockets_max") : 0;
489 self.ammo_cells = (nixnex_weapon_ammo & IT_CELLS) ?
490 cvar("g_pickup_cells_max") : 0;
491 self.ammo_fuel = (nixnex_weapon_ammo & IT_FUEL) ?
492 cvar("g_pickup_fuel_max") : 0;
496 self.ammo_shells = (nixnex_weapon_ammo & IT_SHELLS) ?
497 cvar("g_balance_nixnex_ammo_shells") : 0;
498 self.ammo_nails = (nixnex_weapon_ammo & IT_NAILS) ?
499 cvar("g_balance_nixnex_ammo_nails") : 0;
500 self.ammo_rockets = (nixnex_weapon_ammo & IT_ROCKETS) ?
501 cvar("g_balance_nixnex_ammo_rockets") : 0;
502 self.ammo_cells = (nixnex_weapon_ammo & IT_CELLS) ?
503 cvar("g_balance_nixnex_ammo_cells") : 0;
504 self.ammo_fuel = (nixnex_weapon_ammo & IT_FUEL) ?
505 cvar("g_balance_nixnex_ammo_fuel") : 0;
507 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
508 if(dt >= 1 && dt <= 5)
509 self.nixnex_lastinfotime = -42;
511 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon)));
513 if(self.nixnex_lastinfotime != dt)
515 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
516 if(dt >= 1 && dt <= 5)
517 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
520 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO) && time > self.nixnex_nextincr)
522 if (nixnex_weapon_ammo & IT_SHELLS)
523 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
524 else if (nixnex_weapon_ammo & IT_NAILS)
525 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
526 else if (nixnex_weapon_ammo & IT_ROCKETS)
527 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
528 else if (nixnex_weapon_ammo & IT_CELLS)
529 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
530 if (nixnex_weapon_ammo & IT_FUEL) // hook uses cells and fuel
531 self.ammo_fuel = self.ammo_fuel + cvar("g_balance_nixnex_ammoincr_fuel");
532 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
536 if(g_nixnex_with_laser)
537 self.weapons = self.weapons | WEPBIT_LASER;
538 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
540 if(self.switchweapon != nixnex_weapon)
541 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
542 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
543 W_SwitchWeapon(nixnex_weapon);