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_sane(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, or -1 for failure, or 0 for no ammo count
177 float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
181 var .float ammofield;
186 wep.classname = "droppedweapon";
188 wep.owner = wep.enemy = own;
189 wep.classname = "droppedweapon";
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;
208 ammofield = Item_CounterField(wa);
211 weapon_defaultspawnfunc(wpn);
217 thisammo = min(own.ammofield, wep.ammofield);
218 wep.ammofield = thisammo;
219 own.ammofield -= thisammo;
221 wep.think = thrown_wep_think;
222 wep.nextthink = time + 0.5;
223 return wep.ammofield;
227 // toss current weapon
228 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
230 local float w, a, wb, wa;
234 return; // just in case
236 return; // just in case
243 if (!cvar("g_pickup_items"))
247 wa = W_AmmoItemCode(w);
250 if(self.weapons & wb != wb)
252 if(start_weapons & wb)
254 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
256 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
262 self.weapons = self.weapons - wb;
263 W_SwitchWeapon_Force(self, w_getbestweapon(self));
264 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
270 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
272 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", ftos(a), " ", Item_CounterFieldName(W_AmmoItemCode(w)), "\n"));
276 // Bringed back weapon frame
279 if((arena_roundbased && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
282 if (!self.weaponentity || self.health < 1)
283 return; // Dead player can't use weapons and injure impulse commands
285 if(!self.switchweapon)
288 self.weaponentity.state = WS_CLEAR;
292 makevectors(self.v_angle);
295 if (self.weapon != self.switchweapon)
297 if (self.weaponentity.state == WS_CLEAR)
299 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
300 self.weaponentity.state = WS_RAISE;
301 weapon_action(self.switchweapon, WR_SETUP);
302 // VorteX: add player model weapon select frame here
303 // setcustomframe(PlayerWeaponRaise);
304 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
305 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
307 else if (self.weaponentity.state == WS_READY)
309 #ifndef INDEPENDENT_ATTACK_FINISHED
310 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
313 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
314 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
315 self.weaponentity.state = WS_DROP;
316 // set up weapon switch think in the future, and start drop anim
317 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
318 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
319 #ifndef INDEPENDENT_ATTACK_FINISHED
326 wb = W_WeaponBit(self.weapon);
328 // call the think code which may fire the weapon
329 // and do so multiple times to resolve framerate dependency issues if the
330 // server framerate is very low and the weapon fire rate very high
336 if(wb && self.weapons & wb == 0)
338 W_SwitchWeapon_Force(self, w_getbestweapon(self));
342 weapon_action(self.weapon, WR_THINK);
343 if (time + frametime * 0.5 >= self.weapon_nextthink)
345 if(self.weapon_think)
348 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
352 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
353 //if (ATTACK_FINISHED(self) < time)
354 // ATTACK_FINISHED(self) = time;
356 //if (self.weapon_nextthink < time)
357 // self.weapon_nextthink = time;
359 // update currentammo incase it has changed
360 if (self.items & IT_CELLS)
361 self.currentammo = self.ammo_cells;
362 else if (self.items & IT_ROCKETS)
363 self.currentammo = self.ammo_rockets;
364 else if (self.items & IT_NAILS)
365 self.currentammo = self.ammo_nails;
366 else if (self.items & IT_SHELLS)
367 self.currentammo = self.ammo_shells;
369 self.currentammo = 1;
374 float nixnex_nextchange;
375 float nixnex_nextweapon;
376 .float nixnex_lastchange_id;
377 .float nixnex_lastinfotime;
378 .float nixnex_nextincr;
380 void Nixnex_ChooseNextWeapon()
383 numberof = WEP_LAST - WEP_FIRST; // all but the current one
384 if(g_nixnex_with_laser)
385 numberof = numberof - 1;
386 id = WEP_FIRST + floor(random() * numberof);
388 if(g_nixnex_with_laser) // skip the laser if needed
391 if(id >= nixnex_weapon) // skip the current weapon
394 if(id < WEP_FIRST) // can't happen, but to be sure...
396 dprint("Won't happen (id < WEP_FIRST)\n");
399 if(id > WEP_LAST) // either
401 dprint("Won't happen (id > WEP_LAST)\n");
405 nixnex_nextweapon = id;
408 void Nixnex_GiveCurrentWeapon()
413 if(!nixnex_nextweapon)
414 Nixnex_ChooseNextWeapon();
416 dt = ceil(nixnex_nextchange - time);
420 nixnex_weapon = nixnex_nextweapon;
421 nixnex_nextweapon = 0;
422 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
423 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
426 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
428 self.nixnex_lastchange_id = nixnex_nextchange;
429 if (self.items & IT_UNLIMITED_WEAPON_AMMO)
431 self.ammo_shells = cvar("g_pickup_shells_max");
432 self.ammo_nails = cvar("g_pickup_nails_max");
433 self.ammo_rockets = cvar("g_pickup_rockets_max");
434 self.ammo_cells = cvar("g_pickup_cells_max");
438 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
439 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
440 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
441 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
443 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
444 if(dt >= 1 && dt <= 5)
445 self.nixnex_lastinfotime = -42;
447 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
449 if(self.nixnex_lastinfotime != dt)
451 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
452 if(dt >= 1 && dt <= 5)
453 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
456 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO) && time > self.nixnex_nextincr)
458 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
459 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
460 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
461 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
462 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
466 if(g_nixnex_with_laser)
467 self.weapons = self.weapons | WEPBIT_LASER;
468 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
470 if(self.switchweapon != nixnex_weapon)
471 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
472 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
473 W_SwitchWeapon(nixnex_weapon);