1 // switch between weapons
2 void W_SwitchWeapon(float imp)
4 if (self.weapon != imp)
5 if (client_hasweapon(self, imp, TRUE, TRUE))
7 self.cnt = self.weapon ? self.weapon : self.switchweapon;
8 self.switchweapon = imp;
12 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float complain)
14 float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
15 n = tokenize(weaponorder);
16 switchtonext = switchtolast = 0;
17 first_valid = prev_valid = 0;
22 for(i = 0; i < n; ++i)
24 weaponwant = stof(argv(i));
25 if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
30 first_valid = weaponwant;
31 if(weaponwant == pl.switchweapon)
40 prev_valid = weaponwant;
53 for(i = 0; i < n; ++i)
55 weaponwant = stof(argv(i));
56 client_hasweapon(pl, weaponwant, TRUE, TRUE);
62 void W_CycleWeapon(string weaponorder, float dir)
65 w = W_GetCycleWeapon(self, weaponorder, dir, 1);
73 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
77 void W_PreviousWeapon()
79 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
82 string W_FixWeaponOrder(string order, float complete)
88 for(i = 0; i < n; ++i)
91 if(w >= WEP_FIRST && w <= WEP_LAST && w == floor(w))
92 neworder = strcat(neworder, ftos(w), " ");
97 n = tokenize(neworder);
98 for(w = WEP_FIRST; w <= WEP_LAST; ++w)
100 for(i = 0; i < n; ++i)
101 if(stof(argv(i)) == w)
103 if(i == n) // not found
104 neworder = strcat(neworder, ftos(w), " ");
108 return substring(neworder, 0, strlen(neworder) - 1);
111 string W_FixWeaponOrder_AllowIncomplete(string order)
113 return W_FixWeaponOrder(order, 0);
116 string W_FixWeaponOrder_ForceComplete(string order)
118 return W_FixWeaponOrder(order, 1);
121 float w_getbestweapon(entity e)
123 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, 0);
126 // generic weapons table
127 // add new weapons here
128 float weapon_action(float wpn, float wrequest)
131 if (wpn == WEP_LASER)
132 return w_laser(wrequest);
133 else if (wpn == WEP_SHOTGUN)
134 return w_shotgun(wrequest);
135 else if (wpn == WEP_UZI)
136 return w_uzi(wrequest);
137 else if (wpn == WEP_GRENADE_LAUNCHER)
138 return w_glauncher(wrequest);
139 else if (wpn == WEP_ELECTRO)
140 return w_electro(wrequest);
141 else if (wpn == WEP_CRYLINK)
142 return w_crylink(wrequest);
143 else if (wpn == WEP_NEX)
144 return w_nex(wrequest);
145 else if (wpn == WEP_HAGAR)
146 return w_hagar(wrequest);
147 else if (wpn == WEP_ROCKET_LAUNCHER)
148 return w_rlauncher(wrequest);
152 string W_Name(float weaponid)
155 if(weaponid == WEP_LASER) return "Laser";
156 if(weaponid == WEP_UZI) return "Machine Gun";
157 if(weaponid == WEP_SHOTGUN) return "Shotgun";
158 if(weaponid == WEP_GRENADE_LAUNCHER) return "Mortar";
159 if(weaponid == WEP_ELECTRO) return "Electro";
160 if(weaponid == WEP_NEX) return "Nex";
161 if(weaponid == WEP_HAGAR) return "Hagar";
162 if(weaponid == WEP_ROCKET_LAUNCHER) return "Rocket Launcher";
163 if(weaponid == WEP_CRYLINK) return "Crylink";
164 return "@!#%'n Tuba";
167 float W_WeaponBit(float wpn)
172 case WEP_LASER: return WEPBIT_LASER;
173 case WEP_SHOTGUN: return WEPBIT_SHOTGUN;
174 case WEP_UZI: return WEPBIT_UZI;
175 case WEP_GRENADE_LAUNCHER: return WEPBIT_GRENADE_LAUNCHER;
176 case WEP_ELECTRO: return WEPBIT_ELECTRO;
177 case WEP_CRYLINK: return WEPBIT_CRYLINK;
178 case WEP_NEX: return WEPBIT_NEX;
179 case WEP_HAGAR: return WEPBIT_HAGAR;
180 case WEP_ROCKET_LAUNCHER: return WEPBIT_ROCKET_LAUNCHER;
185 float W_AmmoItemCode(float wpn)
190 case WEP_SHOTGUN: return IT_SHELLS;
191 case WEP_UZI: return IT_NAILS;
192 case WEP_GRENADE_LAUNCHER: return IT_ROCKETS;
193 case WEP_ELECTRO: return IT_CELLS;
194 case WEP_CRYLINK: return IT_CELLS;
195 case WEP_NEX: return IT_CELLS;
196 case WEP_HAGAR: return IT_ROCKETS;
197 case WEP_ROCKET_LAUNCHER: return IT_ROCKETS;
202 // think function for tossed weapons
203 void thrown_wep_think()
205 self.solid = SOLID_TRIGGER;
207 SUB_SetFade(self, time + 20, 1);
208 setorigin(self, self.origin);
211 // toss current weapon
212 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
214 local float w, ammo, wb;
216 local .float ammofield;
220 return; // just in case
231 if (!cvar("g_pickup_weapons"))
238 setorigin(wep, e.origin + delta);
239 makevectors(e.angles);
240 wep.classname = "droppedweapon";
241 wep.velocity = velo; // e.velocity * 0.5 + v_forward * 750;
242 SUB_SetFade(wep, time + 20, 1);
244 ammofield = Item_CounterField(W_AmmoItemCode(w));
246 if(!(e.weapons & wb))
251 Item_SpawnByWeaponCode(w);
256 ammo = min(e.ammofield, wep.ammofield);
257 wep.ammofield = ammo;
263 sprint(e, strcat("You dropped the ^2", wep.netname, " with ", ftos(wep.ammofield), " ammo", "\n"));
266 setorigin(wep, wep.origin);
267 wep.nextthink = time + 0.5;
268 wep.think = thrown_wep_think;
269 wep.classname = "droppedweapon";
270 wep.flags = wep.flags | FL_TOSSED;
271 e.weapons = e.weapons - (e.weapons & wb);
272 e.switchweapon = w_getbestweapon(e);
273 wep.colormap = e.colormap;
274 if (e.switchweapon != e.weapon)
281 // Bringed back weapon frame
284 if((arena_roundbased && time < warmup) || ((time < restart_countdown) && !cvar("sv_ready_restart_after_countdown")))
287 if (!self.weaponentity || self.health < 1)
288 return; // Dead player can't use weapons and injure impulse commands
290 if(!self.switchweapon)
293 self.weaponentity.state = WS_CLEAR;
297 makevectors(self.v_angle);
300 if (self.weapon != self.switchweapon)
302 if (self.weaponentity.state == WS_CLEAR)
304 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
305 self.weaponentity.state = WS_RAISE;
306 weapon_action(self.switchweapon, WR_SETUP);
307 // VorteX: add player model weapon select frame here
308 // setcustomframe(PlayerWeaponRaise);
309 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
310 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
312 else if (self.weaponentity.state == WS_READY)
314 #ifndef INDEPENDENT_ATTACK_FINISHED
315 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
318 sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
319 self.weaponentity.state = WS_DROP;
320 // set up weapon switch think in the future, and start drop anim
321 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
322 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
323 #ifndef INDEPENDENT_ATTACK_FINISHED
329 // call the think code which may fire the weapon
330 // and do so multiple times to resolve framerate dependency issues if the
331 // server framerate is very low and the weapon fire rate very high
337 weapon_action(self.weapon, WR_THINK);
338 if (time + frametime * 0.5 >= self.weapon_nextthink)
342 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
343 //if (ATTACK_FINISHED(self) < time)
344 // ATTACK_FINISHED(self) = time;
346 //if (self.weapon_nextthink < time)
347 // self.weapon_nextthink = time;
349 // update currentammo incase it has changed
350 if (self.items & IT_CELLS)
351 self.currentammo = self.ammo_cells;
352 else if (self.items & IT_ROCKETS)
353 self.currentammo = self.ammo_rockets;
354 else if (self.items & IT_NAILS)
355 self.currentammo = self.ammo_nails;
356 else if (self.items & IT_SHELLS)
357 self.currentammo = self.ammo_shells;
359 self.currentammo = 1;
364 float nixnex_nextchange;
365 float nixnex_nextweapon;
366 .float nixnex_lastchange_id;
367 .float nixnex_lastinfotime;
368 .float nixnex_nextincr;
370 void Nixnex_ChooseNextWeapon()
373 numberof = WEP_LAST - WEP_FIRST; // all but the current one
374 if(g_nixnex_with_laser)
375 numberof = numberof - 1;
376 id = WEP_FIRST + ceil(random() * numberof) - 1;
378 if(g_nixnex_with_laser) // skip the laser if needed
381 if(id >= nixnex_weapon) // skip the current weapon
384 if(id < WEP_FIRST) // can't happen, but to be sure...
386 dprint("Won't happen (id < WEP_FIRST)\n");
389 if(id > WEP_LAST) // either
391 dprint("Won't happen (id > WEP_LAST)\n");
395 nixnex_nextweapon = id;
398 void Nixnex_GiveCurrentWeapon()
403 if(!nixnex_nextweapon)
404 Nixnex_ChooseNextWeapon();
406 dt = ceil(nixnex_nextchange - time);
410 nixnex_weapon = nixnex_nextweapon;
411 nixnex_nextweapon = 0;
412 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
413 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
416 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
418 self.nixnex_lastchange_id = nixnex_nextchange;
419 if (cvar("g_use_ammunition"))
421 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
422 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
423 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
424 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
428 self.ammo_shells = cvar("g_pickup_shells_max");
429 self.ammo_nails = cvar("g_pickup_nails_max");
430 self.ammo_rockets = cvar("g_pickup_rockets_max");
431 self.ammo_cells = cvar("g_pickup_cells_max");
433 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
434 if(dt >= 1 && dt <= 5)
435 self.nixnex_lastinfotime = -42;
437 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
439 if(self.nixnex_lastinfotime != dt)
441 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
442 if(dt >= 1 && dt <= 5)
443 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
446 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
448 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
449 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
450 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
451 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
452 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
456 if(g_nixnex_with_laser)
457 self.weapons = self.weapons | WEPBIT_LASER;
458 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
460 if(self.switchweapon != nixnex_weapon)
461 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
462 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
463 W_SwitchWeapon(nixnex_weapon);