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 // TODO should they be macros instead?
128 float weapon_action(float wpn, float wrequest)
130 return (get_weaponinfo(wpn)).weapon_func(wrequest);
133 string W_Name(float weaponid)
135 return (get_weaponinfo(weaponid)).message;
138 float W_WeaponBit(float wpn)
140 return (get_weaponinfo(wpn)).weapons;
143 float W_AmmoItemCode(float wpn)
145 return (get_weaponinfo(wpn)).items;
148 // think function for tossed weapons
149 void thrown_wep_think()
151 self.solid = SOLID_TRIGGER;
153 SUB_SetFade(self, time + 20, 1);
154 setorigin(self, self.origin);
157 // toss current weapon
158 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
160 local float w, ammo, wb;
162 local .float ammofield;
166 return; // just in case
177 if (!cvar("g_pickup_items"))
184 setorigin(wep, e.origin + delta);
185 makevectors(e.angles);
186 wep.classname = "droppedweapon";
187 wep.velocity = velo; // e.velocity * 0.5 + v_forward * 750;
188 SUB_SetFade(wep, time + 20, 1);
190 ammofield = Item_CounterField(W_AmmoItemCode(w));
192 if(!(e.weapons & wb))
197 Item_SpawnByWeaponCode(w);
204 ammo = min(e.ammofield, wep.ammofield);
205 wep.ammofield = ammo;
211 sprint(e, strcat("You dropped the ^2", wep.netname, " with ", ftos(wep.ammofield), " ammo", "\n"));
214 setorigin(wep, wep.origin);
215 wep.nextthink = time + 0.5;
216 wep.think = thrown_wep_think;
217 wep.classname = "droppedweapon";
218 wep.flags = wep.flags | FL_TOSSED;
219 e.weapons = e.weapons - (e.weapons & wb);
220 e.switchweapon = w_getbestweapon(e);
221 wep.colormap = e.colormap;
222 if (e.switchweapon != e.weapon)
229 // Bringed back weapon frame
232 if((arena_roundbased && time < warmup) || ((time < restart_countdown) && !cvar("sv_ready_restart_after_countdown")))
235 if (!self.weaponentity || self.health < 1)
236 return; // Dead player can't use weapons and injure impulse commands
238 if(!self.switchweapon)
241 self.weaponentity.state = WS_CLEAR;
245 makevectors(self.v_angle);
248 if (self.weapon != self.switchweapon)
250 if (self.weaponentity.state == WS_CLEAR)
252 player_setanim(self.anim_draw, FALSE, TRUE, TRUE);
253 self.weaponentity.state = WS_RAISE;
254 weapon_action(self.switchweapon, WR_SETUP);
255 // VorteX: add player model weapon select frame here
256 // setcustomframe(PlayerWeaponRaise);
257 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
258 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
260 else if (self.weaponentity.state == WS_READY)
262 #ifndef INDEPENDENT_ATTACK_FINISHED
263 if(ATTACK_FINISHED(self) <= time + frametime * 0.5)
266 sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
267 self.weaponentity.state = WS_DROP;
268 // set up weapon switch think in the future, and start drop anim
269 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
270 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
271 #ifndef INDEPENDENT_ATTACK_FINISHED
277 // call the think code which may fire the weapon
278 // and do so multiple times to resolve framerate dependency issues if the
279 // server framerate is very low and the weapon fire rate very high
285 weapon_action(self.weapon, WR_THINK);
286 if (time + frametime * 0.5 >= self.weapon_nextthink)
290 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
291 //if (ATTACK_FINISHED(self) < time)
292 // ATTACK_FINISHED(self) = time;
294 //if (self.weapon_nextthink < time)
295 // self.weapon_nextthink = time;
297 // update currentammo incase it has changed
298 if (self.items & IT_CELLS)
299 self.currentammo = self.ammo_cells;
300 else if (self.items & IT_ROCKETS)
301 self.currentammo = self.ammo_rockets;
302 else if (self.items & IT_NAILS)
303 self.currentammo = self.ammo_nails;
304 else if (self.items & IT_SHELLS)
305 self.currentammo = self.ammo_shells;
307 self.currentammo = 1;
312 float nixnex_nextchange;
313 float nixnex_nextweapon;
314 .float nixnex_lastchange_id;
315 .float nixnex_lastinfotime;
316 .float nixnex_nextincr;
318 void Nixnex_ChooseNextWeapon()
321 numberof = WEP_LAST - WEP_FIRST; // all but the current one
322 if(g_nixnex_with_laser)
323 numberof = numberof - 1;
324 id = WEP_FIRST + ceil(random() * numberof) - 1;
326 if(g_nixnex_with_laser) // skip the laser if needed
329 if(id >= nixnex_weapon) // skip the current weapon
332 if(id < WEP_FIRST) // can't happen, but to be sure...
334 dprint("Won't happen (id < WEP_FIRST)\n");
337 if(id > WEP_LAST) // either
339 dprint("Won't happen (id > WEP_LAST)\n");
343 nixnex_nextweapon = id;
346 void Nixnex_GiveCurrentWeapon()
351 if(!nixnex_nextweapon)
352 Nixnex_ChooseNextWeapon();
354 dt = ceil(nixnex_nextchange - time);
358 nixnex_weapon = nixnex_nextweapon;
359 nixnex_nextweapon = 0;
360 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
361 //weapon_action(nixnex_weapon, WR_PRECACHE); // forget it, too slow
364 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
366 self.nixnex_lastchange_id = nixnex_nextchange;
367 if (cvar("g_use_ammunition"))
369 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
370 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
371 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
372 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
376 self.ammo_shells = cvar("g_pickup_shells_max");
377 self.ammo_nails = cvar("g_pickup_nails_max");
378 self.ammo_rockets = cvar("g_pickup_rockets_max");
379 self.ammo_cells = cvar("g_pickup_cells_max");
381 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
382 if(dt >= 1 && dt <= 5)
383 self.nixnex_lastinfotime = -42;
385 centerprint(self, strcat("\n\n^2Active weapon: ^3", W_Name(nixnex_weapon), "\n"));
387 if(self.nixnex_lastinfotime != dt)
389 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
390 if(dt >= 1 && dt <= 5)
391 centerprint(self, strcat("^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nixnex_nextweapon), "\n"));
394 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
396 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
397 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
398 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
399 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
400 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
404 if(g_nixnex_with_laser)
405 self.weapons = self.weapons | WEPBIT_LASER;
406 self.weapons = self.weapons | W_WeaponBit(nixnex_weapon);
408 if(self.switchweapon != nixnex_weapon)
409 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
410 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
411 W_SwitchWeapon(nixnex_weapon);
415 void RegisterWeapons()
418 register_weapon(WEP_LASER, w_laser, 0, "laser", "laser", "Laser");
419 register_weapon(WEP_SHOTGUN, w_shotgun, IT_SHELLS, "shotgun", "shotgun", "Shotgun");
420 register_weapon(WEP_UZI, w_uzi, IT_NAILS, "uzi", "uzi", "Machine Gun");
421 register_weapon(WEP_GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS, "gl", "grenadelauncher", "Mortar");
422 register_weapon(WEP_ELECTRO, w_electro, IT_CELLS, "electro", "electro", "Electro");
423 register_weapon(WEP_CRYLINK, w_crylink, IT_CELLS, "crylink", "crylink", "Crylink");
424 register_weapon(WEP_NEX, w_nex, IT_CELLS, "nex", "nex", "Nex");
425 register_weapon(WEP_HAGAR, w_hagar, IT_ROCKETS, "hagar", "hagar", "Hagar");
426 register_weapon(WEP_ROCKET_LAUNCHER, w_rlauncher, IT_ROCKETS, "rl", "rocketlauncher", "Rocket Launcher");