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 W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain)
11 float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
12 n = tokenize_sane(weaponorder);
13 switchtonext = switchtolast = 0;
14 first_valid = prev_valid = 0;
19 for(i = 0; i < n; ++i)
21 weaponwant = stof(argv(i));
24 if((get_weaponinfo(weaponwant)).impulse != imp)
27 if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
32 first_valid = weaponwant;
33 if(weaponwant == pl.switchweapon)
42 prev_valid = weaponwant;
55 for(i = 0; i < n; ++i)
57 weaponwant = stof(argv(i));
59 if((get_weaponinfo(weaponwant)).impulse != imp)
61 client_hasweapon(pl, weaponwant, TRUE, TRUE);
67 void W_CycleWeapon(string weaponorder, float dir)
70 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1);
75 void W_NextWeaponOnImpulse(float imp)
78 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1);
84 void W_NextWeapon(float list)
87 W_CycleWeapon(weaponpriority_hudselector_0, -1);
89 W_CycleWeapon(weaponpriority_hudselector_1, -1);
91 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
95 void W_PreviousWeapon(float list)
98 W_CycleWeapon(weaponpriority_hudselector_0, +1);
100 W_CycleWeapon(weaponpriority_hudselector_1, +1);
102 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
105 string W_FixWeaponOrder_AllowIncomplete(string order)
107 return W_FixWeaponOrder(order, 0);
110 string W_FixWeaponOrder_ForceComplete(string order)
113 order = cvar_string("cl_weaponpriority");
114 return W_FixWeaponOrder(order, 1);
117 float w_getbestweapon(entity e)
119 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, 0);
122 // generic weapons table
123 // TODO should they be macros instead?
124 float weapon_action(float wpn, float wrequest)
126 return (get_weaponinfo(wpn)).weapon_func(wrequest);
129 string W_Name(float weaponid)
131 return (get_weaponinfo(weaponid)).message;
134 float W_WeaponBit(float wpn)
136 return (get_weaponinfo(wpn)).weapons;
139 float W_AmmoItemCode(float wpn)
141 return (get_weaponinfo(wpn)).items;
144 void thrown_wep_think()
146 self.solid = SOLID_TRIGGER;
148 SUB_SetFade(self, time + 20, 1);
151 // returns amount of ammo used, or -1 for failure, or 0 for no ammo count
152 float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
156 var .float ammofield;
161 wep.classname = "droppedweapon";
163 wep.owner = wep.enemy = own;
164 wep.classname = "droppedweapon";
165 wep.flags = wep.flags | FL_TOSSED;
166 wep.colormap = own.colormap;
168 wa = W_AmmoItemCode(wpn);
169 if(wa == IT_SUPERWEAPON || wa == 0)
173 weapon_defaultspawnfunc(wpn);
177 wep.think = thrown_wep_think;
178 wep.nextthink = time + 0.5;
183 ammofield = Item_CounterField(wa);
186 weapon_defaultspawnfunc(wpn);
192 thisammo = min(own.ammofield, wep.ammofield);
193 wep.ammofield = thisammo;
194 own.ammofield -= thisammo;
196 wep.think = thrown_wep_think;
197 wep.nextthink = time + 0.5;
198 return wep.ammofield;
202 // toss current weapon
203 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
205 local float w, a, wb, wa;
209 return; // just in case
211 return; // just in case
218 if (!cvar("g_pickup_items"))
222 wa = W_AmmoItemCode(w);
225 if(self.weapons & wb != wb)
227 if(start_weapons & wb)
229 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
231 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
237 self.weapons = self.weapons - wb;
238 W_SwitchWeapon_Force(self, w_getbestweapon(self));
239 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
245 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
247 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", ftos(a), " ", Item_CounterFieldName(W_AmmoItemCode(w)), "\n"));
251 // Bringed back weapon frame
254 if((arena_roundbased && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
257 if (!self.weaponentity || self.health < 1)
258 return; // Dead player can't use weapons and injure impulse commands
260 if(!self.switchweapon)
263 self.weaponentity.state = WS_CLEAR;
267 makevectors(self.v_angle);
270 if (self.weapon != self.switchweapon)
272 if (self.weaponentity.state == WS_CLEAR)
274 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
275 self.weaponentity.state = WS_RAISE;
276 weapon_action(self.switchweapon, WR_SETUP);
277 // VorteX: add player model weapon select frame here
278 // setcustomframe(PlayerWeaponRaise);
279 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
280 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
282 else if (self.weaponentity.state == WS_READY)
284 #ifndef INDEPENDENT_ATTACK_FINISHED
285 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
288 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
289 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
290 self.weaponentity.state = WS_DROP;
291 // set up weapon switch think in the future, and start drop anim
292 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
293 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
294 #ifndef INDEPENDENT_ATTACK_FINISHED
301 wb = W_WeaponBit(self.weapon);
303 // call the think code which may fire the weapon
304 // and do so multiple times to resolve framerate dependency issues if the
305 // server framerate is very low and the weapon fire rate very high
311 if(wb && self.weapons & wb == 0)
313 W_SwitchWeapon_Force(self, w_getbestweapon(self));
317 weapon_action(self.weapon, WR_THINK);
318 if (time + frametime * 0.5 >= self.weapon_nextthink)
320 if(self.weapon_think)
323 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
327 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
328 //if (ATTACK_FINISHED(self) < time)
329 // ATTACK_FINISHED(self) = time;
331 //if (self.weapon_nextthink < time)
332 // self.weapon_nextthink = time;
334 // update currentammo incase it has changed
335 if (self.items & IT_CELLS)
336 self.currentammo = self.ammo_cells;
337 else if (self.items & IT_ROCKETS)
338 self.currentammo = self.ammo_rockets;
339 else if (self.items & IT_NAILS)
340 self.currentammo = self.ammo_nails;
341 else if (self.items & IT_SHELLS)
342 self.currentammo = self.ammo_shells;
344 self.currentammo = 1;
349 float nixnex_nextchange;
350 float nixnex_nextweapon;
351 .float nixnex_lastchange_id;
352 .float nixnex_lastinfotime;
353 .float nixnex_nextincr;
355 void Nixnex_ChooseNextWeapon()
358 numberof = WEP_LAST - WEP_FIRST; // all but the current one
359 if(g_nixnex_with_laser)
360 numberof = numberof - 1;
361 id = WEP_FIRST + floor(random() * numberof);
363 if(g_nixnex_with_laser) // skip the laser if needed
366 if(id >= nixnex_weapon) // skip the current weapon
369 if(id < WEP_FIRST) // can't happen, but to be sure...
371 dprint("Won't happen (id < WEP_FIRST)\n");
374 if(id > WEP_LAST) // either
376 dprint("Won't happen (id > WEP_LAST)\n");
380 nixnex_nextweapon = id;
383 void Nixnex_GiveCurrentWeapon()
388 if(!nixnex_nextweapon)
389 Nixnex_ChooseNextWeapon();
391 dt = ceil(nixnex_nextchange - time);
395 nixnex_weapon = nixnex_nextweapon;
396 nixnex_nextweapon = 0;
397 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
398 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
401 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
403 self.nixnex_lastchange_id = nixnex_nextchange;
404 if (self.items & IT_UNLIMITED_WEAPON_AMMO)
406 self.ammo_shells = cvar("g_pickup_shells_max");
407 self.ammo_nails = cvar("g_pickup_nails_max");
408 self.ammo_rockets = cvar("g_pickup_rockets_max");
409 self.ammo_cells = cvar("g_pickup_cells_max");
413 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
414 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
415 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
416 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
418 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
419 if(dt >= 1 && dt <= 5)
420 self.nixnex_lastinfotime = -42;
422 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
424 if(self.nixnex_lastinfotime != dt)
426 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
427 if(dt >= 1 && dt <= 5)
428 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
431 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO) && time > self.nixnex_nextincr)
433 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
434 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
435 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
436 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
437 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
441 if(g_nixnex_with_laser)
442 self.weapons = self.weapons | WEPBIT_LASER;
443 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
445 if(self.switchweapon != nixnex_weapon)
446 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
447 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
448 W_SwitchWeapon(nixnex_weapon);