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);
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(string order, float complete)
107 return fixPriorityList(order, WEP_FIRST, WEP_LAST, complete);
110 string W_FixWeaponOrder_AllowIncomplete(string order)
112 return W_FixWeaponOrder(order, 0);
115 string W_FixWeaponOrder_ForceComplete(string order)
118 order = cvar_string("cl_weaponpriority");
119 return W_FixWeaponOrder(order, 1);
122 float w_getbestweapon(entity e)
124 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, 0);
127 // generic weapons table
128 // TODO should they be macros instead?
129 float weapon_action(float wpn, float wrequest)
131 return (get_weaponinfo(wpn)).weapon_func(wrequest);
134 string W_Name(float weaponid)
136 return (get_weaponinfo(weaponid)).message;
139 float W_WeaponBit(float wpn)
141 return (get_weaponinfo(wpn)).weapons;
144 float W_AmmoItemCode(float wpn)
146 return (get_weaponinfo(wpn)).items;
149 void thrown_wep_think()
151 self.solid = SOLID_TRIGGER;
153 SUB_SetFade(self, time + 20, 1);
156 // returns amount of ammo used, or -1 for failure, or 0 for no ammo count
157 float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
161 var .float ammofield;
166 wep.classname = "droppedweapon";
168 wep.owner = wep.enemy = own;
169 wep.classname = "droppedweapon";
170 wep.flags = wep.flags | FL_TOSSED;
171 wep.colormap = own.colormap;
173 wa = W_AmmoItemCode(wpn);
174 if(wa == IT_SUPERWEAPON || wa == 0)
178 weapon_defaultspawnfunc(wpn);
182 wep.think = thrown_wep_think;
183 wep.nextthink = time + 0.5;
188 ammofield = Item_CounterField(wa);
191 weapon_defaultspawnfunc(wpn);
197 thisammo = min(own.ammofield, wep.ammofield);
198 wep.ammofield = thisammo;
199 own.ammofield -= thisammo;
201 wep.think = thrown_wep_think;
202 wep.nextthink = time + 0.5;
203 return wep.ammofield;
207 // toss current weapon
208 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
210 local float w, a, wb;
214 return; // just in case
216 return; // just in case
223 if (!cvar("g_pickup_items"))
227 if(self.weapons & wb != wb)
230 self.weapons = self.weapons - wb;
231 W_SwitchWeapon_Force(self, w_getbestweapon(self));
232 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
238 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
240 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", ftos(a), " ", Item_CounterFieldName(W_AmmoItemCode(w)), "\n"));
244 // Bringed back weapon frame
247 if((arena_roundbased && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
250 if (!self.weaponentity || self.health < 1)
251 return; // Dead player can't use weapons and injure impulse commands
253 if(!self.switchweapon)
256 self.weaponentity.state = WS_CLEAR;
260 makevectors(self.v_angle);
263 if (self.weapon != self.switchweapon)
265 if (self.weaponentity.state == WS_CLEAR)
267 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
268 self.weaponentity.state = WS_RAISE;
269 weapon_action(self.switchweapon, WR_SETUP);
270 // VorteX: add player model weapon select frame here
271 // setcustomframe(PlayerWeaponRaise);
272 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
273 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
275 else if (self.weaponentity.state == WS_READY)
277 #ifndef INDEPENDENT_ATTACK_FINISHED
278 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
281 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
282 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
283 self.weaponentity.state = WS_DROP;
284 // set up weapon switch think in the future, and start drop anim
285 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
286 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
287 #ifndef INDEPENDENT_ATTACK_FINISHED
294 wb = W_WeaponBit(self.weapon);
296 // call the think code which may fire the weapon
297 // and do so multiple times to resolve framerate dependency issues if the
298 // server framerate is very low and the weapon fire rate very high
304 if(wb && self.weapons & wb == 0)
306 W_SwitchWeapon_Force(self, w_getbestweapon(self));
310 weapon_action(self.weapon, WR_THINK);
311 if (time + frametime * 0.5 >= self.weapon_nextthink)
315 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
316 //if (ATTACK_FINISHED(self) < time)
317 // ATTACK_FINISHED(self) = time;
319 //if (self.weapon_nextthink < time)
320 // self.weapon_nextthink = time;
322 // update currentammo incase it has changed
323 if (self.items & IT_CELLS)
324 self.currentammo = self.ammo_cells;
325 else if (self.items & IT_ROCKETS)
326 self.currentammo = self.ammo_rockets;
327 else if (self.items & IT_NAILS)
328 self.currentammo = self.ammo_nails;
329 else if (self.items & IT_SHELLS)
330 self.currentammo = self.ammo_shells;
332 self.currentammo = 1;
337 float nixnex_nextchange;
338 float nixnex_nextweapon;
339 .float nixnex_lastchange_id;
340 .float nixnex_lastinfotime;
341 .float nixnex_nextincr;
343 void Nixnex_ChooseNextWeapon()
346 numberof = WEP_LAST - WEP_FIRST; // all but the current one
347 if(g_nixnex_with_laser)
348 numberof = numberof - 1;
349 id = WEP_FIRST + ceil(random() * numberof) - 1;
351 if(g_nixnex_with_laser) // skip the laser if needed
354 if(id >= nixnex_weapon) // skip the current weapon
357 if(id < WEP_FIRST) // can't happen, but to be sure...
359 dprint("Won't happen (id < WEP_FIRST)\n");
362 if(id > WEP_LAST) // either
364 dprint("Won't happen (id > WEP_LAST)\n");
368 nixnex_nextweapon = id;
371 void Nixnex_GiveCurrentWeapon()
376 if(!nixnex_nextweapon)
377 Nixnex_ChooseNextWeapon();
379 dt = ceil(nixnex_nextchange - time);
383 nixnex_weapon = nixnex_nextweapon;
384 nixnex_nextweapon = 0;
385 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
386 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
389 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
391 self.nixnex_lastchange_id = nixnex_nextchange;
392 if (self.items & IT_UNLIMITED_AMMO)
394 self.ammo_shells = cvar("g_pickup_shells_max");
395 self.ammo_nails = cvar("g_pickup_nails_max");
396 self.ammo_rockets = cvar("g_pickup_rockets_max");
397 self.ammo_cells = cvar("g_pickup_cells_max");
401 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
402 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
403 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
404 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
406 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
407 if(dt >= 1 && dt <= 5)
408 self.nixnex_lastinfotime = -42;
410 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
412 if(self.nixnex_lastinfotime != dt)
414 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
415 if(dt >= 1 && dt <= 5)
416 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
419 if(!(self.items & IT_UNLIMITED_AMMO) && time > self.nixnex_nextincr)
421 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
422 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
423 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
424 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
425 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
429 if(g_nixnex_with_laser)
430 self.weapons = self.weapons | WEPBIT_LASER;
431 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
433 if(self.switchweapon != nixnex_weapon)
434 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
435 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
436 W_SwitchWeapon(nixnex_weapon);
440 void RegisterWeapons()
443 register_weapon(WEP_LASER, w_laser, 0, 1, 1, 0, "laser", "laser", "Laser");
444 register_weapon(WEP_SHOTGUN, w_shotgun, IT_SHELLS, 2, 1, 2500, "shotgun", "shotgun", "Shotgun");
445 register_weapon(WEP_UZI, w_uzi, IT_NAILS, 3, 1, 5000, "uzi", "uzi", "Machine Gun");
446 register_weapon(WEP_GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS, 4, 1, 5000, "gl", "grenadelauncher", "Mortar");
447 register_weapon(WEP_ELECTRO, w_electro, IT_CELLS, 5, 1, 5000, "electro", "electro", "Electro");
448 register_weapon(WEP_CRYLINK, w_crylink, IT_CELLS, 6, 1, 5000, "crylink", "crylink", "Crylink");
449 register_weapon(WEP_NEX, w_nex, IT_CELLS, 7, 1, 10000, "nex", "nex", "Nex");
450 register_weapon(WEP_HAGAR, w_hagar, IT_ROCKETS, 8, 1, 5000, "hagar", "hagar", "Hagar");
451 register_weapon(WEP_ROCKET_LAUNCHER, w_rlauncher, IT_ROCKETS, 9, 1, 10000, "rl", "rocketlauncher", "Rocket Launcher");
452 register_weapon(WEP_PORTO, w_porto, IT_SUPERWEAPON, 0, 0, 0, "porto" , "porto", "Port-O-Launch");
453 register_weapon(WEP_MINSTANEX, w_minstanex, IT_CELLS, 7, 0, 10000, "minstanex", "minstanex", "MinstaNex");
454 register_weapons_done();