1 // switch between weapons
2 void W_SwitchWeapon(float imp)
4 if (self.weapon != 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(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);
86 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
90 void W_PreviousWeapon()
92 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
95 string W_FixWeaponOrder(string order, float complete)
101 for(i = 0; i < n; ++i)
104 if(w >= WEP_FIRST && w <= WEP_LAST && w == floor(w))
105 neworder = strcat(neworder, ftos(w), " ");
110 n = tokenize(neworder);
111 for(w = WEP_LAST; w >= WEP_FIRST; --w)
113 for(i = 0; i < n; ++i)
114 if(stof(argv(i)) == w)
116 if(i == n) // not found
117 neworder = strcat(neworder, ftos(w), " ");
121 return substring(neworder, 0, strlen(neworder) - 1);
124 string W_FixWeaponOrder_AllowIncomplete(string order)
126 return W_FixWeaponOrder(order, 0);
129 string W_FixWeaponOrder_ForceComplete(string order)
132 order = cvar_string("cl_weaponpriority");
133 return W_FixWeaponOrder(order, 1);
136 float w_getbestweapon(entity e)
138 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, 0);
141 // generic weapons table
142 // TODO should they be macros instead?
143 float weapon_action(float wpn, float wrequest)
145 return (get_weaponinfo(wpn)).weapon_func(wrequest);
148 string W_Name(float weaponid)
150 return (get_weaponinfo(weaponid)).message;
153 float W_WeaponBit(float wpn)
155 return (get_weaponinfo(wpn)).weapons;
158 float W_AmmoItemCode(float wpn)
160 return (get_weaponinfo(wpn)).items;
163 void thrown_wep_think()
165 self.solid = SOLID_TRIGGER;
167 SUB_SetFade(self, time + 20, 1);
170 // returns amount of ammo used, or -1 for failure, or 0 for no ammo count
171 float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
175 var .float ammofield;
180 wep.classname = "droppedweapon";
182 wep.owner = wep.enemy = own;
183 wep.classname = "droppedweapon";
184 wep.flags = wep.flags | FL_TOSSED;
185 wep.colormap = own.colormap;
187 wa = W_AmmoItemCode(wpn);
188 if(wa == IT_SUPERWEAPON || wa == 0)
192 weapon_defaultspawnfunc(wpn);
196 wep.think = thrown_wep_think;
197 wep.nextthink = time + 0.5;
202 ammofield = Item_CounterField(wa);
205 weapon_defaultspawnfunc(wpn);
211 ammo = min(own.ammofield, wep.ammofield);
212 wep.ammofield = ammo;
213 own.ammofield -= ammo;
215 wep.think = thrown_wep_think;
216 wep.nextthink = time + 0.5;
217 return wep.ammofield;
221 // toss current weapon
222 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
224 local float w, a, wb;
228 return; // just in case
230 return; // just in case
237 if (!cvar("g_pickup_items"))
241 self.weapons = self.weapons - (self.weapons & wb);
242 W_SwitchWeapon_Force(self, w_getbestweapon(self));
243 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
249 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
251 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", ftos(a), " ", Item_CounterFieldName(W_AmmoItemCode(w)), "\n"));
255 // Bringed back weapon frame
258 if((arena_roundbased && time < warmup) || ((time < restart_countdown) && !cvar("sv_ready_restart_after_countdown")))
261 if (!self.weaponentity || self.health < 1)
262 return; // Dead player can't use weapons and injure impulse commands
264 if(!self.switchweapon)
267 self.weaponentity.state = WS_CLEAR;
271 makevectors(self.v_angle);
274 if (self.weapon != self.switchweapon)
276 if (self.weaponentity.state == WS_CLEAR)
278 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
279 self.weaponentity.state = WS_RAISE;
280 weapon_action(self.switchweapon, WR_SETUP);
281 // VorteX: add player model weapon select frame here
282 // setcustomframe(PlayerWeaponRaise);
283 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
284 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
286 else if (self.weaponentity.state == WS_READY)
288 #ifndef INDEPENDENT_ATTACK_FINISHED
289 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
292 sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
293 self.weaponentity.state = WS_DROP;
294 // set up weapon switch think in the future, and start drop anim
295 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
296 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
297 #ifndef INDEPENDENT_ATTACK_FINISHED
304 wb = W_WeaponBit(self.weapon);
306 // call the think code which may fire the weapon
307 // and do so multiple times to resolve framerate dependency issues if the
308 // server framerate is very low and the weapon fire rate very high
314 if(wb && self.weapons & wb == 0)
316 W_SwitchWeapon_Force(self, w_getbestweapon(self));
320 weapon_action(self.weapon, WR_THINK);
321 if (time + frametime * 0.5 >= self.weapon_nextthink)
325 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
326 //if (ATTACK_FINISHED(self) < time)
327 // ATTACK_FINISHED(self) = time;
329 //if (self.weapon_nextthink < time)
330 // self.weapon_nextthink = time;
332 // update currentammo incase it has changed
333 if (self.items & IT_CELLS)
334 self.currentammo = self.ammo_cells;
335 else if (self.items & IT_ROCKETS)
336 self.currentammo = self.ammo_rockets;
337 else if (self.items & IT_NAILS)
338 self.currentammo = self.ammo_nails;
339 else if (self.items & IT_SHELLS)
340 self.currentammo = self.ammo_shells;
342 self.currentammo = 1;
347 float nixnex_nextchange;
348 float nixnex_nextweapon;
349 .float nixnex_lastchange_id;
350 .float nixnex_lastinfotime;
351 .float nixnex_nextincr;
353 void Nixnex_ChooseNextWeapon()
356 numberof = WEP_LAST - WEP_FIRST; // all but the current one
357 if(g_nixnex_with_laser)
358 numberof = numberof - 1;
359 id = WEP_FIRST + ceil(random() * numberof) - 1;
361 if(g_nixnex_with_laser) // skip the laser if needed
364 if(id >= nixnex_weapon) // skip the current weapon
367 if(id < WEP_FIRST) // can't happen, but to be sure...
369 dprint("Won't happen (id < WEP_FIRST)\n");
372 if(id > WEP_LAST) // either
374 dprint("Won't happen (id > WEP_LAST)\n");
378 nixnex_nextweapon = id;
381 void Nixnex_GiveCurrentWeapon()
386 if(!nixnex_nextweapon)
387 Nixnex_ChooseNextWeapon();
389 dt = ceil(nixnex_nextchange - time);
393 nixnex_weapon = nixnex_nextweapon;
394 nixnex_nextweapon = 0;
395 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
396 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
399 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
401 self.nixnex_lastchange_id = nixnex_nextchange;
402 if (self.items & IT_UNLIMITED_AMMO)
404 self.ammo_shells = cvar("g_pickup_shells_max");
405 self.ammo_nails = cvar("g_pickup_nails_max");
406 self.ammo_rockets = cvar("g_pickup_rockets_max");
407 self.ammo_cells = cvar("g_pickup_cells_max");
411 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
412 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
413 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
414 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
416 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
417 if(dt >= 1 && dt <= 5)
418 self.nixnex_lastinfotime = -42;
420 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
422 if(self.nixnex_lastinfotime != dt)
424 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
425 if(dt >= 1 && dt <= 5)
426 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
429 if(!(self.items & IT_UNLIMITED_AMMO) && time > self.nixnex_nextincr)
431 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
432 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
433 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
434 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
435 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
439 if(g_nixnex_with_laser)
440 self.weapons = self.weapons | WEPBIT_LASER;
441 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
443 if(self.switchweapon != nixnex_weapon)
444 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
445 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
446 W_SwitchWeapon(nixnex_weapon);
450 void RegisterWeapons()
452 register_dummy_weapon();
454 register_weapon(WEP_LASER, w_laser, 0, 1, 1, 0, "laser", "laser", "Laser");
455 register_weapon(WEP_SHOTGUN, w_shotgun, IT_SHELLS, 2, 1, 2500, "shotgun", "shotgun", "Shotgun");
456 register_weapon(WEP_UZI, w_uzi, IT_NAILS, 3, 1, 5000, "uzi", "uzi", "Machine Gun");
457 register_weapon(WEP_GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS, 4, 1, 5000, "gl", "grenadelauncher", "Mortar");
458 register_weapon(WEP_ELECTRO, w_electro, IT_CELLS, 5, 1, 5000, "electro", "electro", "Electro");
459 register_weapon(WEP_CRYLINK, w_crylink, IT_CELLS, 6, 1, 5000, "crylink", "crylink", "Crylink");
460 register_weapon(WEP_NEX, w_nex, IT_CELLS, 7, 1, 10000, "nex", "nex", "Nex");
461 register_weapon(WEP_HAGAR, w_hagar, IT_ROCKETS, 8, 1, 5000, "hagar", "hagar", "Hagar");
462 register_weapon(WEP_ROCKET_LAUNCHER, w_rlauncher, IT_ROCKETS, 9, 1, 10000, "rl", "rocketlauncher", "Rocket Launcher");
463 register_weapon(WEP_PORTO, w_porto, IT_SUPERWEAPON, 0, 0, 0, "porto" , "porto", "Port-O-Launch");
464 register_weapon(WEP_MINSTANEX, w_minstanex, IT_CELLS, 7, 0, 10000, "minstanex", "minstanex", "MinstaNex");