3 if(self.switchweapon == self.weapon)
4 if(self.weaponentity.state == WS_READY)
5 weapon_action(self.weapon, WR_RELOAD);
8 // switch between weapons
9 void W_SwitchWeapon(float imp)
11 if (self.switchweapon != imp)
13 if (client_hasweapon(self, imp, TRUE, TRUE))
14 W_SwitchWeapon_Force(self, imp);
16 self.selectweapon = imp; // update selectweapon ANYWAY
24 .float weaponcomplainindex;
25 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
27 // We cannot tokenize in this function, as GiveItems calls this
28 // function. Thus we must use car/cdr.
29 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
31 switchtonext = switchtolast = 0;
32 first_valid = prev_valid = 0;
35 if(skipmissing || pl.selectweapon == 0)
36 weaponcur = pl.switchweapon;
38 weaponcur = pl.selectweapon;
48 weaponwant = stof(car(rest)); rest = cdr(rest);
50 if((get_weaponinfo(weaponwant)).impulse != imp)
55 if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE))
60 first_valid = weaponwant;
61 if(weaponwant == weaponcur)
70 prev_valid = weaponwant;
80 // complain (but only for one weapon on the button that has been pressed)
83 self.weaponcomplainindex += 1;
84 c = mod(self.weaponcomplainindex, c) + 1;
88 weaponwant = stof(car(rest)); rest = cdr(rest);
90 if((get_weaponinfo(weaponwant)).impulse != imp)
96 client_hasweapon(pl, weaponwant, TRUE, TRUE);
104 void W_CycleWeapon(string weaponorder, float dir)
107 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, TRUE);
112 void W_NextWeaponOnImpulse(float imp)
115 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
121 void W_NextWeapon(float list)
124 W_CycleWeapon(weaponorder_byid, -1);
126 W_CycleWeapon(weaponorder_byimpulse, -1);
128 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
132 void W_PreviousWeapon(float list)
135 W_CycleWeapon(weaponorder_byid, +1);
137 W_CycleWeapon(weaponorder_byimpulse, +1);
139 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
142 string W_FixWeaponOrder_AllowIncomplete(string order)
144 return W_FixWeaponOrder(order, 0);
147 string W_FixWeaponOrder_ForceComplete(string order)
150 order = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
151 return W_FixWeaponOrder(order, 1);
154 float w_getbestweapon(entity e)
156 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, FALSE, TRUE);
159 // generic weapons table
160 // TODO should they be macros instead?
161 float weapon_action(float wpn, float wrequest)
163 return (get_weaponinfo(wpn)).weapon_func(wrequest);
166 string W_Name(float weaponid)
168 return (get_weaponinfo(weaponid)).message;
171 float W_WeaponBit(float wpn)
173 return (get_weaponinfo(wpn)).weapons;
176 float W_AmmoItemCode(float wpn)
178 return (get_weaponinfo(wpn)).items;
181 void thrown_wep_think()
183 self.solid = SOLID_TRIGGER;
185 SUB_SetFade(self, time + 20, 1);
188 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
189 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
192 float wa, thisammo, i, j;
194 var .float ammofield;
199 wep.classname = "droppedweapon";
201 wep.owner = wep.enemy = own;
202 wep.flags |= FL_TOSSED;
203 wep.colormap = own.colormap;
205 wa = W_AmmoItemCode(wpn);
206 if(wa == IT_SUPERWEAPON || wa == 0)
210 weapon_defaultspawnfunc(wpn);
214 wep.think = thrown_wep_think;
215 wep.nextthink = time + 0.5;
223 weapon_defaultspawnfunc(wpn);
229 for(i = 0, j = 1; i < 24; ++i, j *= 2)
233 ammofield = Item_CounterField(j);
234 thisammo = min(own.ammofield, wep.ammofield);
235 wep.ammofield = thisammo;
236 own.ammofield -= thisammo;
237 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
240 s = substring(s, 5, -1);
242 wep.think = thrown_wep_think;
243 wep.nextthink = time + 0.5;
248 float W_IsWeaponThrowable(float w)
254 wa = W_AmmoItemCode(w);
255 if(start_weapons & wb)
257 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
259 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
261 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
269 // toss current weapon
270 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
277 return; // just in case
278 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
284 if (g_nexball && w == WEP_GRENADE_LAUNCHER)
286 if (!cvar("g_pickup_items"))
290 if(!cvar("g_weapon_throwable"))
292 if(cvar("g_weapon_stay") == 1)
294 if(!W_IsWeaponThrowable(w))
296 if(self.weaponentity.state != WS_READY)
300 if(self.weapons & wb != wb)
304 W_SwitchWeapon_Force(self, w_getbestweapon(self));
305 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
311 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
313 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", a, "\n"));
317 // Bringed back weapon frame
323 self.weapon_frametime = frametime;
325 if(((arena_roundbased || g_ca) && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
328 if (!self.weaponentity || self.health < 1)
329 return; // Dead player can't use weapons and injure impulse commands
331 if(!self.switchweapon)
334 self.weaponentity.state = WS_CLEAR;
335 self.weaponname = "";
336 self.items &~= IT_AMMO;
340 makevectors(self.v_angle);
341 fo = v_forward; // save them in case the weapon think functions change it
346 if (self.weapon != self.switchweapon)
348 if (self.weaponentity.state == WS_CLEAR)
350 setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
351 self.weaponentity.state = WS_RAISE;
352 weapon_action(self.switchweapon, WR_SETUP);
353 // VorteX: add player model weapon select frame here
354 // setcustomframe(PlayerWeaponRaise);
355 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
356 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
358 else if (self.weaponentity.state == WS_READY)
360 #ifndef INDEPENDENT_ATTACK_FINISHED
361 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
364 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
365 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
366 self.weaponentity.state = WS_DROP;
367 // set up weapon switch think in the future, and start drop anim
368 weapon_thinkf(WFRAME_DONTCHANGE, cvar("g_balance_weaponswitchdelay"), w_clear);
369 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
370 #ifndef INDEPENDENT_ATTACK_FINISHED
376 // LordHavoc: network timing test code
378 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
381 wb = W_WeaponBit(self.weapon);
383 // call the think code which may fire the weapon
384 // and do so multiple times to resolve framerate dependency issues if the
385 // server framerate is very low and the weapon fire rate very high
391 if(wb && ((self.weapons & wb) == 0))
393 W_SwitchWeapon_Force(self, w_getbestweapon(self));
401 weapon_action(self.weapon, WR_THINK);
403 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
405 if(self.weapon_think)
413 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
417 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
418 //if (ATTACK_FINISHED(self) < time)
419 // ATTACK_FINISHED(self) = time;
421 //if (self.weapon_nextthink < time)
422 // self.weapon_nextthink = time;
424 // update currentammo incase it has changed
426 if (self.items & IT_CELLS)
427 self.currentammo = self.ammo_cells;
428 else if (self.items & IT_ROCKETS)
429 self.currentammo = self.ammo_rockets;
430 else if (self.items & IT_NAILS)
431 self.currentammo = self.ammo_nails;
432 else if (self.items & IT_SHELLS)
433 self.currentammo = self.ammo_shells;
435 self.currentammo = 1;