2 // generic weapons table
3 // add new weapons here
4 float weapon_action(float wpn, float wrequest)
7 return w_laser(wrequest);
8 else if (wpn == WEP_SHOTGUN)
9 return w_shotgun(wrequest);
10 else if (wpn == WEP_UZI)
11 return w_uzi(wrequest);
12 else if (wpn == WEP_GRENADE_LAUNCHER)
13 return w_glauncher(wrequest);
14 else if (wpn == WEP_ELECTRO)
15 return w_electro(wrequest);
16 else if (wpn == WEP_CRYLINK)
17 return w_crylink(wrequest);
18 else if (wpn == WEP_NEX)
19 return w_nex(wrequest);
20 else if (wpn == WEP_HAGAR)
21 return w_hagar(wrequest);
22 else if (wpn == WEP_ROCKET_LAUNCHER)
23 return w_rlauncher(wrequest);
27 string W_Name(float weaponid)
29 if(weaponid == WEP_LASER) return "Laser";
30 if(weaponid == WEP_UZI) return "Machine Gun";
31 if(weaponid == WEP_SHOTGUN) return "Shotgun";
32 if(weaponid == WEP_GRENADE_LAUNCHER) return "Mortar";
33 if(weaponid == WEP_ELECTRO) return "Electro";
34 if(weaponid == WEP_NEX) return "Nex";
35 if(weaponid == WEP_HAGAR) return "Hagar";
36 if(weaponid == WEP_ROCKET_LAUNCHER) return "Rocket Launcher";
37 if(weaponid == WEP_CRYLINK) return "Crylink";
41 float W_ItemCode(float wpn)
45 case WEP_LASER: return IT_LASER;
46 case WEP_SHOTGUN: return IT_SHOTGUN;
47 case WEP_UZI: return IT_UZI;
48 case WEP_GRENADE_LAUNCHER: return IT_GRENADE_LAUNCHER;
49 case WEP_ELECTRO: return IT_ELECTRO;
50 case WEP_CRYLINK: return IT_CRYLINK;
51 case WEP_NEX: return IT_NEX;
52 case WEP_HAGAR: return IT_HAGAR;
53 case WEP_ROCKET_LAUNCHER: return IT_ROCKET_LAUNCHER;
58 float W_AmmoItemCode(float wpn)
62 case WEP_SHOTGUN: return IT_SHELLS;
63 case WEP_UZI: return IT_NAILS;
64 case WEP_GRENADE_LAUNCHER: return IT_ROCKETS;
65 case WEP_ELECTRO: return IT_CELLS;
66 case WEP_CRYLINK: return IT_CELLS;
67 case WEP_NEX: return IT_CELLS;
68 case WEP_HAGAR: return IT_ROCKETS;
69 case WEP_ROCKET_LAUNCHER: return IT_ROCKETS;
74 // think function for tossed weapons
75 void thrown_wep_think()
77 self.solid = SOLID_TRIGGER;
79 SUB_SetFade(self, time + 20, 1);
80 setorigin(self, self.origin);
83 // toss current weapon
84 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
88 local .float ammofield;
92 return; // just in case
103 if (!cvar("g_pickup_items"))
110 setorigin(wep, e.origin + delta);
111 makevectors(e.angles);
112 wep.classname = "droppedweapon";
113 wep.velocity = velo; // e.velocity * 0.5 + v_forward * 750;
114 SUB_SetFade(wep, time + 20, 1);
116 ammofield = Item_CounterField(W_AmmoItemCode(w));
123 Item_SpawnByItemCode(w);
128 ammo = min(e.ammofield, wep.ammofield);
129 wep.ammofield = ammo;
135 sprint(e, strcat("You dropped the ^2", wep.netname, " with ", ftos(wep.ammofield), " ammo", "\n"));
138 setorigin(wep, wep.origin);
139 wep.nextthink = time + 0.5;
140 wep.think = thrown_wep_think;
141 wep.classname = "droppedweapon";
142 wep.flags = wep.flags | FL_TOSSED;
143 e.items = e.items - (e.items & w);
144 e.switchweapon = w_getbestweapon(e);
145 wep.colormap = e.colormap;
146 if (e.switchweapon != e.weapon)
153 // switch between weapons
154 void W_SwitchWeapon(float imp)
156 if (self.weapon != imp)
157 if (client_hasweapon(self, imp, TRUE, TRUE))
159 self.cnt = self.weapon ? self.weapon : self.switchweapon;
160 self.switchweapon = imp;
167 local float weaponwant, maxtries;
171 weaponwant = self.switchweapon + 1;
172 if (weaponwant < WEP_FIRST)
173 weaponwant = WEP_LAST;
174 if (weaponwant > WEP_LAST)
175 weaponwant = WEP_FIRST;
176 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
182 weaponwant = weaponwant + 1;
183 if (weaponwant < WEP_FIRST)
184 weaponwant = WEP_LAST;
185 if (weaponwant > WEP_LAST)
186 weaponwant = WEP_FIRST;
188 self.cnt = self.weapon ? self.weapon : self.switchweapon;
189 self.switchweapon = weaponwant;
193 void W_PreviousWeapon()
195 local float weaponwant, maxtries;
199 weaponwant = self.switchweapon - 1;
200 if (weaponwant < WEP_FIRST)
201 weaponwant = WEP_LAST;
202 if (weaponwant > WEP_LAST)
203 weaponwant = WEP_FIRST;
204 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
210 weaponwant = weaponwant - 1;
211 if (weaponwant < WEP_FIRST)
212 weaponwant = WEP_LAST;
213 if (weaponwant > WEP_LAST)
214 weaponwant = WEP_FIRST;
216 self.cnt = self.weapon ? self.weapon : self.switchweapon;
217 self.switchweapon = weaponwant;
220 float W_GetCycleWeapon(string weaponorder, float dir)
222 float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
223 n = tokenize(weaponorder);
224 switchtonext = switchtolast = 0;
225 first_valid = prev_valid = -1;
230 for(i = 0; i < n; ++i)
232 weaponwant = stof(argv(i));
233 if(client_hasweapon(self, weaponwant, TRUE, FALSE))
238 first_valid = weaponwant;
239 prev_valid = weaponwant;
240 if(weaponwant == self.weapon)
244 else if(prev_valid >= 0)
264 void W_CycleWeapon(string weaponorder, float dir)
267 w = W_GetCycleWeapon(weaponorder, dir);
272 sprint(self, "You do not have any of the specified weapons.\n");
275 // Bringed back weapon frame
278 if((arena_roundbased && time < warmup) || ((time < restart_countdown) && !cvar("sv_ready_restart_after_countdown")))
281 if (!self.weaponentity || self.health < 1)
282 return; // Dead player can't use weapons and injure impulse commands
284 if(!self.switchweapon)
287 self.weaponentity.state = WS_CLEAR;
291 makevectors(self.v_angle);
294 if (self.weapon != self.switchweapon)
296 if (self.weaponentity.state == WS_CLEAR)
298 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
299 self.weaponentity.state = WS_RAISE;
300 weapon_action(self.switchweapon, WR_SETUP);
301 // VorteX: add player model weapon select frame here
302 // setcustomframe(PlayerWeaponRaise);
303 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
304 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
306 else if (self.weaponentity.state == WS_READY)
308 #ifndef INDEPENDENT_ATTACK_FINISHED
309 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
312 sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
313 self.weaponentity.state = WS_DROP;
314 // set up weapon switch think in the future, and start drop anim
315 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
316 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
317 #ifndef INDEPENDENT_ATTACK_FINISHED
323 // call the think code which may fire the weapon
324 // and do so multiple times to resolve framerate dependency issues if the
325 // server framerate is very low and the weapon fire rate very high
331 weapon_action(self.weapon, WR_THINK);
332 if (time + frametime * 0.5 >= self.weapon_nextthink)
336 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
337 //if (ATTACK_FINISHED(self) < time)
338 // ATTACK_FINISHED(self) = time;
340 //if (self.weapon_nextthink < time)
341 // self.weapon_nextthink = time;
343 // update currentammo incase it has changed
344 if (self.items & IT_CELLS)
345 self.currentammo = self.ammo_cells;
346 else if (self.items & IT_ROCKETS)
347 self.currentammo = self.ammo_rockets;
348 else if (self.items & IT_NAILS)
349 self.currentammo = self.ammo_nails;
350 else if (self.items & IT_SHELLS)
351 self.currentammo = self.ammo_shells;
353 self.currentammo = 1;
358 float nixnex_nextchange;
359 float nixnex_nextweapon;
360 .float nixnex_lastchange_id;
361 .float nixnex_lastinfotime;
362 .float nixnex_nextincr;
364 void Nixnex_ChooseNextWeapon()
367 numberof = WEP_LAST - WEP_FIRST; // all but the current one
368 if(g_nixnex_with_laser)
369 numberof = numberof - 1;
370 id = WEP_FIRST + ceil(random() * numberof) - 1;
372 if(g_nixnex_with_laser) // skip the laser if needed
375 if(id >= nixnex_weapon) // skip the current weapon
378 if(id < WEP_FIRST) // can't happen, but to be sure...
380 dprint("Won't happen (id < WEP_FIRST)\n");
383 if(id > WEP_LAST) // either
385 dprint("Won't happen (id > WEP_LAST)\n");
389 nixnex_nextweapon = id;
392 void Nixnex_GiveCurrentWeapon()
397 if(!nixnex_nextweapon)
398 Nixnex_ChooseNextWeapon();
400 dt = ceil(nixnex_nextchange - time);
404 nixnex_weapon = nixnex_nextweapon;
405 nixnex_nextweapon = 0;
406 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
407 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
410 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
412 self.nixnex_lastchange_id = nixnex_nextchange;
413 if (cvar("g_use_ammunition"))
415 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
416 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
417 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
418 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
422 self.ammo_shells = cvar("g_pickup_shells_max");
423 self.ammo_nails = cvar("g_pickup_nails_max");
424 self.ammo_rockets = cvar("g_pickup_rockets_max");
425 self.ammo_cells = cvar("g_pickup_cells_max");
427 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
428 if(dt >= 1 && dt <= 5)
429 self.nixnex_lastinfotime = -42;
431 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
433 if(self.nixnex_lastinfotime != dt)
435 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
436 if(dt >= 1 && dt <= 5)
437 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
440 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
442 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
443 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
444 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
445 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
446 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
449 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));
450 if(g_nixnex_with_laser)
451 self.items = self.items | IT_LASER;
452 self.items = self.items | W_ItemCode(nixnex_weapon);
454 if(self.switchweapon != nixnex_weapon)
455 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
456 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
457 W_SwitchWeapon(nixnex_weapon);