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)
14 float n, i, weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
15 n = tokenize(weaponorder);
16 switchtonext = switchtolast = 0;
17 first_valid = prev_valid = -1;
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)
36 else if(prev_valid >= 0)
56 void W_CycleWeapon(string weaponorder, float dir)
59 w = W_GetCycleWeapon(self, weaponorder, dir);
64 sprint(self, "You do not have any of the specified weapons.\n");
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);
123 // generic weapons table
124 // add new weapons here
125 float weapon_action(float wpn, float wrequest)
127 if (wpn == WEP_LASER)
128 return w_laser(wrequest);
129 else if (wpn == WEP_SHOTGUN)
130 return w_shotgun(wrequest);
131 else if (wpn == WEP_UZI)
132 return w_uzi(wrequest);
133 else if (wpn == WEP_GRENADE_LAUNCHER)
134 return w_glauncher(wrequest);
135 else if (wpn == WEP_ELECTRO)
136 return w_electro(wrequest);
137 else if (wpn == WEP_CRYLINK)
138 return w_crylink(wrequest);
139 else if (wpn == WEP_NEX)
140 return w_nex(wrequest);
141 else if (wpn == WEP_HAGAR)
142 return w_hagar(wrequest);
143 else if (wpn == WEP_ROCKET_LAUNCHER)
144 return w_rlauncher(wrequest);
148 string W_Name(float weaponid)
150 if(weaponid == WEP_LASER) return "Laser";
151 if(weaponid == WEP_UZI) return "Machine Gun";
152 if(weaponid == WEP_SHOTGUN) return "Shotgun";
153 if(weaponid == WEP_GRENADE_LAUNCHER) return "Mortar";
154 if(weaponid == WEP_ELECTRO) return "Electro";
155 if(weaponid == WEP_NEX) return "Nex";
156 if(weaponid == WEP_HAGAR) return "Hagar";
157 if(weaponid == WEP_ROCKET_LAUNCHER) return "Rocket Launcher";
158 if(weaponid == WEP_CRYLINK) return "Crylink";
159 return "@!#%'n Tuba";
162 float W_ItemCode(float wpn)
166 case WEP_LASER: return IT_LASER;
167 case WEP_SHOTGUN: return IT_SHOTGUN;
168 case WEP_UZI: return IT_UZI;
169 case WEP_GRENADE_LAUNCHER: return IT_GRENADE_LAUNCHER;
170 case WEP_ELECTRO: return IT_ELECTRO;
171 case WEP_CRYLINK: return IT_CRYLINK;
172 case WEP_NEX: return IT_NEX;
173 case WEP_HAGAR: return IT_HAGAR;
174 case WEP_ROCKET_LAUNCHER: return IT_ROCKET_LAUNCHER;
179 float W_AmmoItemCode(float wpn)
183 case WEP_SHOTGUN: return IT_SHELLS;
184 case WEP_UZI: return IT_NAILS;
185 case WEP_GRENADE_LAUNCHER: return IT_ROCKETS;
186 case WEP_ELECTRO: return IT_CELLS;
187 case WEP_CRYLINK: return IT_CELLS;
188 case WEP_NEX: return IT_CELLS;
189 case WEP_HAGAR: return IT_ROCKETS;
190 case WEP_ROCKET_LAUNCHER: return IT_ROCKETS;
195 // think function for tossed weapons
196 void thrown_wep_think()
198 self.solid = SOLID_TRIGGER;
200 SUB_SetFade(self, time + 20, 1);
201 setorigin(self, self.origin);
204 // toss current weapon
205 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
209 local .float ammofield;
213 return; // just in case
224 if (!cvar("g_pickup_items"))
231 setorigin(wep, e.origin + delta);
232 makevectors(e.angles);
233 wep.classname = "droppedweapon";
234 wep.velocity = velo; // e.velocity * 0.5 + v_forward * 750;
235 SUB_SetFade(wep, time + 20, 1);
237 ammofield = Item_CounterField(W_AmmoItemCode(w));
244 Item_SpawnByItemCode(w);
249 ammo = min(e.ammofield, wep.ammofield);
250 wep.ammofield = ammo;
256 sprint(e, strcat("You dropped the ^2", wep.netname, " with ", ftos(wep.ammofield), " ammo", "\n"));
259 setorigin(wep, wep.origin);
260 wep.nextthink = time + 0.5;
261 wep.think = thrown_wep_think;
262 wep.classname = "droppedweapon";
263 wep.flags = wep.flags | FL_TOSSED;
264 e.items = e.items - (e.items & w);
265 e.switchweapon = w_getbestweapon(e);
266 wep.colormap = e.colormap;
267 if (e.switchweapon != e.weapon)
274 // Bringed back weapon frame
277 if((arena_roundbased && time < warmup) || ((time < restart_countdown) && !cvar("sv_ready_restart_after_countdown")))
280 if (!self.weaponentity || self.health < 1)
281 return; // Dead player can't use weapons and injure impulse commands
283 if(!self.switchweapon)
286 self.weaponentity.state = WS_CLEAR;
290 makevectors(self.v_angle);
293 if (self.weapon != self.switchweapon)
295 if (self.weaponentity.state == WS_CLEAR)
297 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
298 self.weaponentity.state = WS_RAISE;
299 weapon_action(self.switchweapon, WR_SETUP);
300 // VorteX: add player model weapon select frame here
301 // setcustomframe(PlayerWeaponRaise);
302 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
303 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
305 else if (self.weaponentity.state == WS_READY)
307 #ifndef INDEPENDENT_ATTACK_FINISHED
308 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
311 sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
312 self.weaponentity.state = WS_DROP;
313 // set up weapon switch think in the future, and start drop anim
314 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
315 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
316 #ifndef INDEPENDENT_ATTACK_FINISHED
322 // call the think code which may fire the weapon
323 // and do so multiple times to resolve framerate dependency issues if the
324 // server framerate is very low and the weapon fire rate very high
330 weapon_action(self.weapon, WR_THINK);
331 if (time + frametime * 0.5 >= self.weapon_nextthink)
335 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
336 //if (ATTACK_FINISHED(self) < time)
337 // ATTACK_FINISHED(self) = time;
339 //if (self.weapon_nextthink < time)
340 // self.weapon_nextthink = time;
342 // update currentammo incase it has changed
343 if (self.items & IT_CELLS)
344 self.currentammo = self.ammo_cells;
345 else if (self.items & IT_ROCKETS)
346 self.currentammo = self.ammo_rockets;
347 else if (self.items & IT_NAILS)
348 self.currentammo = self.ammo_nails;
349 else if (self.items & IT_SHELLS)
350 self.currentammo = self.ammo_shells;
352 self.currentammo = 1;
357 float nixnex_nextchange;
358 float nixnex_nextweapon;
359 .float nixnex_lastchange_id;
360 .float nixnex_lastinfotime;
361 .float nixnex_nextincr;
363 void Nixnex_ChooseNextWeapon()
366 numberof = WEP_LAST - WEP_FIRST; // all but the current one
367 if(g_nixnex_with_laser)
368 numberof = numberof - 1;
369 id = WEP_FIRST + ceil(random() * numberof) - 1;
371 if(g_nixnex_with_laser) // skip the laser if needed
374 if(id >= nixnex_weapon) // skip the current weapon
377 if(id < WEP_FIRST) // can't happen, but to be sure...
379 dprint("Won't happen (id < WEP_FIRST)\n");
382 if(id > WEP_LAST) // either
384 dprint("Won't happen (id > WEP_LAST)\n");
388 nixnex_nextweapon = id;
391 void Nixnex_GiveCurrentWeapon()
396 if(!nixnex_nextweapon)
397 Nixnex_ChooseNextWeapon();
399 dt = ceil(nixnex_nextchange - time);
403 nixnex_weapon = nixnex_nextweapon;
404 nixnex_nextweapon = 0;
405 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
406 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
409 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
411 self.nixnex_lastchange_id = nixnex_nextchange;
412 if (cvar("g_use_ammunition"))
414 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
415 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
416 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
417 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
421 self.ammo_shells = cvar("g_pickup_shells_max");
422 self.ammo_nails = cvar("g_pickup_nails_max");
423 self.ammo_rockets = cvar("g_pickup_rockets_max");
424 self.ammo_cells = cvar("g_pickup_cells_max");
426 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
427 if(dt >= 1 && dt <= 5)
428 self.nixnex_lastinfotime = -42;
430 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
432 if(self.nixnex_lastinfotime != dt)
434 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
435 if(dt >= 1 && dt <= 5)
436 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
439 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
441 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
442 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
443 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
444 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
445 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
448 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));
449 if(g_nixnex_with_laser)
450 self.items = self.items | IT_LASER;
451 self.items = self.items | W_ItemCode(nixnex_weapon);
453 if(self.switchweapon != nixnex_weapon)
454 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
455 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
456 W_SwitchWeapon(nixnex_weapon);