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 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));
22 if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
27 first_valid = weaponwant;
28 if(weaponwant == pl.switchweapon)
37 prev_valid = weaponwant;
50 for(i = 0; i < n; ++i)
52 weaponwant = stof(argv(i));
53 client_hasweapon(pl, weaponwant, TRUE, TRUE);
59 void W_CycleWeapon(string weaponorder, float dir)
62 w = W_GetCycleWeapon(self, weaponorder, dir, 1);
70 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
74 void W_PreviousWeapon()
76 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
79 string W_FixWeaponOrder(string order, float complete)
85 for(i = 0; i < n; ++i)
88 if(w >= WEP_FIRST && w <= WEP_LAST && w == floor(w))
89 neworder = strcat(neworder, ftos(w), " ");
94 n = tokenize(neworder);
95 for(w = WEP_FIRST; w <= WEP_LAST; ++w)
97 for(i = 0; i < n; ++i)
98 if(stof(argv(i)) == w)
100 if(i == n) // not found
101 neworder = strcat(neworder, ftos(w), " ");
105 return substring(neworder, 0, strlen(neworder) - 1);
108 string W_FixWeaponOrder_AllowIncomplete(string order)
110 return W_FixWeaponOrder(order, 0);
113 string W_FixWeaponOrder_ForceComplete(string order)
115 return W_FixWeaponOrder(order, 1);
118 float w_getbestweapon(entity e)
120 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, 0);
123 // generic weapons table
124 // TODO should they be macros instead?
125 float weapon_action(float wpn, float wrequest)
127 return (get_weaponinfo(wpn)).weapon_func(wrequest);
130 string W_Name(float weaponid)
132 return (get_weaponinfo(weaponid)).message;
135 float W_WeaponBit(float wpn)
137 return (get_weaponinfo(wpn)).weapons;
140 float W_AmmoItemCode(float wpn)
142 return (get_weaponinfo(wpn)).items;
145 // think function for tossed weapons
146 void thrown_wep_think()
148 self.solid = SOLID_TRIGGER;
150 SUB_SetFade(self, time + 20, 1);
151 setorigin(self, self.origin);
154 // toss current weapon
155 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
157 local float w, ammo, wb, wa;
159 local .float ammofield;
163 return; // just in case
174 if (!cvar("g_pickup_items"))
181 setorigin(wep, e.origin + delta);
182 makevectors(e.angles);
183 wep.classname = "droppedweapon";
184 wep.velocity = velo; // e.velocity * 0.5 + v_forward * 750;
185 SUB_SetFade(wep, time + 20, 1);
187 wa = W_AmmoItemCode(w);
188 if(wa == IT_SUPERWEAPON || wa == 0)
191 if(!(e.weapons & wb))
196 Item_SpawnByWeaponCode(w);
201 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
205 ammofield = Item_CounterField(wa);
207 if(!(e.weapons & wb))
212 Item_SpawnByWeaponCode(w);
217 ammo = min(e.ammofield, wep.ammofield);
218 wep.ammofield = ammo;
223 sprint(e, strcat("You dropped the ^2", wep.netname, " with ", ftos(wep.ammofield), " ammo", "\n"));
227 setorigin(wep, wep.origin);
228 wep.nextthink = time + 0.5;
229 wep.think = thrown_wep_think;
230 wep.classname = "droppedweapon";
231 wep.flags = wep.flags | FL_TOSSED;
232 e.weapons = e.weapons - (e.weapons & wb);
233 wep.colormap = e.colormap;
234 W_SwitchWeapon_Force(e, w_getbestweapon(e));
240 // Bringed back weapon frame
243 if((arena_roundbased && time < warmup) || ((time < restart_countdown) && !cvar("sv_ready_restart_after_countdown")))
246 if (!self.weaponentity || self.health < 1)
247 return; // Dead player can't use weapons and injure impulse commands
249 if(!self.switchweapon)
252 self.weaponentity.state = WS_CLEAR;
256 makevectors(self.v_angle);
259 if (self.weapon != self.switchweapon)
261 if (self.weaponentity.state == WS_CLEAR)
263 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
264 self.weaponentity.state = WS_RAISE;
265 weapon_action(self.switchweapon, WR_SETUP);
266 // VorteX: add player model weapon select frame here
267 // setcustomframe(PlayerWeaponRaise);
268 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
269 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
271 else if (self.weaponentity.state == WS_READY)
273 #ifndef INDEPENDENT_ATTACK_FINISHED
274 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
277 sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
278 self.weaponentity.state = WS_DROP;
279 // set up weapon switch think in the future, and start drop anim
280 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
281 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
282 #ifndef INDEPENDENT_ATTACK_FINISHED
289 wb = W_WeaponBit(self.weapon);
291 // call the think code which may fire the weapon
292 // and do so multiple times to resolve framerate dependency issues if the
293 // server framerate is very low and the weapon fire rate very high
299 if(wb && self.weapons & wb == 0)
301 W_SwitchWeapon_Force(self, w_getbestweapon(self));
305 weapon_action(self.weapon, WR_THINK);
306 if (time + frametime * 0.5 >= self.weapon_nextthink)
310 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
311 //if (ATTACK_FINISHED(self) < time)
312 // ATTACK_FINISHED(self) = time;
314 //if (self.weapon_nextthink < time)
315 // self.weapon_nextthink = time;
317 // update currentammo incase it has changed
318 if (self.items & IT_CELLS)
319 self.currentammo = self.ammo_cells;
320 else if (self.items & IT_ROCKETS)
321 self.currentammo = self.ammo_rockets;
322 else if (self.items & IT_NAILS)
323 self.currentammo = self.ammo_nails;
324 else if (self.items & IT_SHELLS)
325 self.currentammo = self.ammo_shells;
327 self.currentammo = 1;
332 float nixnex_nextchange;
333 float nixnex_nextweapon;
334 .float nixnex_lastchange_id;
335 .float nixnex_lastinfotime;
336 .float nixnex_nextincr;
338 void Nixnex_ChooseNextWeapon()
341 numberof = WEP_LAST - WEP_FIRST; // all but the current one
342 if(g_nixnex_with_laser)
343 numberof = numberof - 1;
344 id = WEP_FIRST + ceil(random() * numberof) - 1;
346 if(g_nixnex_with_laser) // skip the laser if needed
349 if(id >= nixnex_weapon) // skip the current weapon
352 if(id < WEP_FIRST) // can't happen, but to be sure...
354 dprint("Won't happen (id < WEP_FIRST)\n");
357 if(id > WEP_LAST) // either
359 dprint("Won't happen (id > WEP_LAST)\n");
363 nixnex_nextweapon = id;
366 void Nixnex_GiveCurrentWeapon()
371 if(!nixnex_nextweapon)
372 Nixnex_ChooseNextWeapon();
374 dt = ceil(nixnex_nextchange - time);
378 nixnex_weapon = nixnex_nextweapon;
379 nixnex_nextweapon = 0;
380 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
381 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
384 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
386 self.nixnex_lastchange_id = nixnex_nextchange;
387 if (cvar("g_use_ammunition"))
389 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
390 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
391 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
392 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
396 self.ammo_shells = cvar("g_pickup_shells_max");
397 self.ammo_nails = cvar("g_pickup_nails_max");
398 self.ammo_rockets = cvar("g_pickup_rockets_max");
399 self.ammo_cells = cvar("g_pickup_cells_max");
401 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
402 if(dt >= 1 && dt <= 5)
403 self.nixnex_lastinfotime = -42;
405 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
407 if(self.nixnex_lastinfotime != dt)
409 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
410 if(dt >= 1 && dt <= 5)
411 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
414 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
416 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
417 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
418 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
419 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
420 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
424 if(g_nixnex_with_laser)
425 self.weapons = self.weapons | WEPBIT_LASER;
426 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
428 if(self.switchweapon != nixnex_weapon)
429 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
430 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
431 W_SwitchWeapon(nixnex_weapon);
435 void RegisterWeapons()
438 register_weapon(WEP_LASER, w_laser, 0, "laser", "laser", "Laser");
439 register_weapon(WEP_SHOTGUN, w_shotgun, IT_SHELLS, "shotgun", "shotgun", "Shotgun");
440 register_weapon(WEP_UZI, w_uzi, IT_NAILS, "uzi", "uzi", "Machine Gun");
441 register_weapon(WEP_GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS, "gl", "grenadelauncher", "Mortar");
442 register_weapon(WEP_ELECTRO, w_electro, IT_CELLS, "electro", "electro", "Electro");
443 register_weapon(WEP_CRYLINK, w_crylink, IT_CELLS, "crylink", "crylink", "Crylink");
444 register_weapon(WEP_NEX, w_nex, IT_CELLS, "nex", "nex", "Nex");
445 register_weapon(WEP_HAGAR, w_hagar, IT_ROCKETS, "hagar", "hagar", "Hagar");
446 register_weapon(WEP_ROCKET_LAUNCHER, w_rlauncher, IT_ROCKETS, "rl", "rocketlauncher", "Rocket Launcher");
447 register_weapon(WEP_PORTO, w_porto, IT_SUPERWEAPON, "porto" , "porto", "Port-O-Launch");