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 prev_valid = weaponwant;
32 if(weaponwant == pl.switchweapon)
56 for(i = 0; i < n; ++i)
58 weaponwant = stof(argv(i));
59 client_hasweapon(pl, weaponwant, TRUE, TRUE);
65 void W_CycleWeapon(string weaponorder, float dir)
68 w = W_GetCycleWeapon(self, weaponorder, dir, 1);
76 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
80 void W_PreviousWeapon()
82 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
85 string W_FixWeaponOrder(string order, float complete)
91 for(i = 0; i < n; ++i)
94 if(w >= WEP_FIRST && w <= WEP_LAST && w == floor(w))
95 neworder = strcat(neworder, ftos(w), " ");
100 n = tokenize(neworder);
101 for(w = WEP_FIRST; w <= WEP_LAST; ++w)
103 for(i = 0; i < n; ++i)
104 if(stof(argv(i)) == w)
106 if(i == n) // not found
107 neworder = strcat(neworder, ftos(w), " ");
111 return substring(neworder, 0, strlen(neworder) - 1);
114 string W_FixWeaponOrder_AllowIncomplete(string order)
116 return W_FixWeaponOrder(order, 0);
119 string W_FixWeaponOrder_ForceComplete(string order)
121 return W_FixWeaponOrder(order, 1);
124 float w_getbestweapon(entity e)
126 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, 0);
129 // generic weapons table
130 // add new weapons here
131 float weapon_action(float wpn, float wrequest)
133 if (wpn == WEP_LASER)
134 return w_laser(wrequest);
135 else if (wpn == WEP_SHOTGUN)
136 return w_shotgun(wrequest);
137 else if (wpn == WEP_UZI)
138 return w_uzi(wrequest);
139 else if (wpn == WEP_GRENADE_LAUNCHER)
140 return w_glauncher(wrequest);
141 else if (wpn == WEP_ELECTRO)
142 return w_electro(wrequest);
143 else if (wpn == WEP_CRYLINK)
144 return w_crylink(wrequest);
145 else if (wpn == WEP_NEX)
146 return w_nex(wrequest);
147 else if (wpn == WEP_HAGAR)
148 return w_hagar(wrequest);
149 else if (wpn == WEP_ROCKET_LAUNCHER)
150 return w_rlauncher(wrequest);
154 string W_Name(float weaponid)
156 if(weaponid == WEP_LASER) return "Laser";
157 if(weaponid == WEP_UZI) return "Machine Gun";
158 if(weaponid == WEP_SHOTGUN) return "Shotgun";
159 if(weaponid == WEP_GRENADE_LAUNCHER) return "Mortar";
160 if(weaponid == WEP_ELECTRO) return "Electro";
161 if(weaponid == WEP_NEX) return "Nex";
162 if(weaponid == WEP_HAGAR) return "Hagar";
163 if(weaponid == WEP_ROCKET_LAUNCHER) return "Rocket Launcher";
164 if(weaponid == WEP_CRYLINK) return "Crylink";
165 return "@!#%'n Tuba";
168 float W_ItemCode(float wpn)
172 case WEP_LASER: return IT_LASER;
173 case WEP_SHOTGUN: return IT_SHOTGUN;
174 case WEP_UZI: return IT_UZI;
175 case WEP_GRENADE_LAUNCHER: return IT_GRENADE_LAUNCHER;
176 case WEP_ELECTRO: return IT_ELECTRO;
177 case WEP_CRYLINK: return IT_CRYLINK;
178 case WEP_NEX: return IT_NEX;
179 case WEP_HAGAR: return IT_HAGAR;
180 case WEP_ROCKET_LAUNCHER: return IT_ROCKET_LAUNCHER;
185 float W_AmmoItemCode(float wpn)
189 case WEP_SHOTGUN: return IT_SHELLS;
190 case WEP_UZI: return IT_NAILS;
191 case WEP_GRENADE_LAUNCHER: return IT_ROCKETS;
192 case WEP_ELECTRO: return IT_CELLS;
193 case WEP_CRYLINK: return IT_CELLS;
194 case WEP_NEX: return IT_CELLS;
195 case WEP_HAGAR: return IT_ROCKETS;
196 case WEP_ROCKET_LAUNCHER: return IT_ROCKETS;
201 // think function for tossed weapons
202 void thrown_wep_think()
204 self.solid = SOLID_TRIGGER;
206 SUB_SetFade(self, time + 20, 1);
207 setorigin(self, self.origin);
210 // toss current weapon
211 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
215 local .float ammofield;
219 return; // just in case
230 if (!cvar("g_pickup_items"))
237 setorigin(wep, e.origin + delta);
238 makevectors(e.angles);
239 wep.classname = "droppedweapon";
240 wep.velocity = velo; // e.velocity * 0.5 + v_forward * 750;
241 SUB_SetFade(wep, time + 20, 1);
243 ammofield = Item_CounterField(W_AmmoItemCode(w));
250 Item_SpawnByItemCode(w);
255 ammo = min(e.ammofield, wep.ammofield);
256 wep.ammofield = ammo;
262 sprint(e, strcat("You dropped the ^2", wep.netname, " with ", ftos(wep.ammofield), " ammo", "\n"));
265 setorigin(wep, wep.origin);
266 wep.nextthink = time + 0.5;
267 wep.think = thrown_wep_think;
268 wep.classname = "droppedweapon";
269 wep.flags = wep.flags | FL_TOSSED;
270 e.items = e.items - (e.items & w);
271 e.switchweapon = w_getbestweapon(e);
272 wep.colormap = e.colormap;
273 if (e.switchweapon != e.weapon)
280 // Bringed back weapon frame
283 if((arena_roundbased && time < warmup) || ((time < restart_countdown) && !cvar("sv_ready_restart_after_countdown")))
286 if (!self.weaponentity || self.health < 1)
287 return; // Dead player can't use weapons and injure impulse commands
289 if(!self.switchweapon)
292 self.weaponentity.state = WS_CLEAR;
296 makevectors(self.v_angle);
299 if (self.weapon != self.switchweapon)
301 if (self.weaponentity.state == WS_CLEAR)
303 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
304 self.weaponentity.state = WS_RAISE;
305 weapon_action(self.switchweapon, WR_SETUP);
306 // VorteX: add player model weapon select frame here
307 // setcustomframe(PlayerWeaponRaise);
308 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
309 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
311 else if (self.weaponentity.state == WS_READY)
313 #ifndef INDEPENDENT_ATTACK_FINISHED
314 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
317 sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
318 self.weaponentity.state = WS_DROP;
319 // set up weapon switch think in the future, and start drop anim
320 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
321 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
322 #ifndef INDEPENDENT_ATTACK_FINISHED
328 // call the think code which may fire the weapon
329 // and do so multiple times to resolve framerate dependency issues if the
330 // server framerate is very low and the weapon fire rate very high
336 weapon_action(self.weapon, WR_THINK);
337 if (time + frametime * 0.5 >= self.weapon_nextthink)
341 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
342 //if (ATTACK_FINISHED(self) < time)
343 // ATTACK_FINISHED(self) = time;
345 //if (self.weapon_nextthink < time)
346 // self.weapon_nextthink = time;
348 // update currentammo incase it has changed
349 if (self.items & IT_CELLS)
350 self.currentammo = self.ammo_cells;
351 else if (self.items & IT_ROCKETS)
352 self.currentammo = self.ammo_rockets;
353 else if (self.items & IT_NAILS)
354 self.currentammo = self.ammo_nails;
355 else if (self.items & IT_SHELLS)
356 self.currentammo = self.ammo_shells;
358 self.currentammo = 1;
363 float nixnex_nextchange;
364 float nixnex_nextweapon;
365 .float nixnex_lastchange_id;
366 .float nixnex_lastinfotime;
367 .float nixnex_nextincr;
369 void Nixnex_ChooseNextWeapon()
372 numberof = WEP_LAST - WEP_FIRST; // all but the current one
373 if(g_nixnex_with_laser)
374 numberof = numberof - 1;
375 id = WEP_FIRST + ceil(random() * numberof) - 1;
377 if(g_nixnex_with_laser) // skip the laser if needed
380 if(id >= nixnex_weapon) // skip the current weapon
383 if(id < WEP_FIRST) // can't happen, but to be sure...
385 dprint("Won't happen (id < WEP_FIRST)\n");
388 if(id > WEP_LAST) // either
390 dprint("Won't happen (id > WEP_LAST)\n");
394 nixnex_nextweapon = id;
397 void Nixnex_GiveCurrentWeapon()
402 if(!nixnex_nextweapon)
403 Nixnex_ChooseNextWeapon();
405 dt = ceil(nixnex_nextchange - time);
409 nixnex_weapon = nixnex_nextweapon;
410 nixnex_nextweapon = 0;
411 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
412 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
415 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
417 self.nixnex_lastchange_id = nixnex_nextchange;
418 if (cvar("g_use_ammunition"))
420 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
421 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
422 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
423 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
427 self.ammo_shells = cvar("g_pickup_shells_max");
428 self.ammo_nails = cvar("g_pickup_nails_max");
429 self.ammo_rockets = cvar("g_pickup_rockets_max");
430 self.ammo_cells = cvar("g_pickup_cells_max");
432 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
433 if(dt >= 1 && dt <= 5)
434 self.nixnex_lastinfotime = -42;
436 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
438 if(self.nixnex_lastinfotime != dt)
440 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
441 if(dt >= 1 && dt <= 5)
442 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
445 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
447 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
448 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
449 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
450 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
451 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
454 self.items = self.items - (self.items & (IT_LASER | IT_SHOTGUN | IT_UZI | IT_GRENADE_LAUNCHER | IT_ELECTRO | IT_CRYLINK | IT_NEX | IT_HAGAR | IT_ROCKET_LAUNCHER));
455 if(g_nixnex_with_laser)
456 self.items = self.items | IT_LASER;
457 self.items = self.items | W_ItemCode(nixnex_weapon);
459 if(self.switchweapon != nixnex_weapon)
460 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
461 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
462 W_SwitchWeapon(nixnex_weapon);