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);
22 .float weaponcomplainindex;
23 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain)
25 // We cannot tokenize in this function, as GiveItems calls this
26 // function. Thus we must use car/cdr.
27 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
29 switchtonext = switchtolast = 0;
30 first_valid = prev_valid = 0;
40 weaponwant = stof(car(rest)); rest = cdr(rest);
42 if((get_weaponinfo(weaponwant)).impulse != imp)
47 if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
52 first_valid = weaponwant;
53 if(weaponwant == pl.switchweapon)
62 prev_valid = weaponwant;
72 // complain (but only for one weapon on the button that has been pressed)
75 self.weaponcomplainindex += 1;
76 c = mod(self.weaponcomplainindex, c) + 1;
80 weaponwant = stof(car(rest)); rest = cdr(rest);
82 if((get_weaponinfo(weaponwant)).impulse != imp)
88 client_hasweapon(pl, weaponwant, TRUE, TRUE);
96 void W_CycleWeapon(string weaponorder, float dir)
99 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1);
104 void W_NextWeaponOnImpulse(float imp)
107 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1);
113 void W_NextWeapon(float list)
116 W_CycleWeapon(weaponpriority_hudselector_0, -1);
118 W_CycleWeapon(weaponpriority_hudselector_1, -1);
120 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
124 void W_PreviousWeapon(float list)
127 W_CycleWeapon(weaponpriority_hudselector_0, +1);
129 W_CycleWeapon(weaponpriority_hudselector_1, +1);
131 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
134 string W_FixWeaponOrder_AllowIncomplete(string order)
136 return W_FixWeaponOrder(order, 0);
139 string W_FixWeaponOrder_ForceComplete(string order)
142 order = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
143 return W_FixWeaponOrder(order, 1);
146 float w_getbestweapon(entity e)
148 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, 0);
151 // generic weapons table
152 // TODO should they be macros instead?
153 float weapon_action(float wpn, float wrequest)
155 return (get_weaponinfo(wpn)).weapon_func(wrequest);
158 string W_Name(float weaponid)
160 return (get_weaponinfo(weaponid)).message;
163 float W_WeaponBit(float wpn)
165 return (get_weaponinfo(wpn)).weapons;
168 float W_AmmoItemCode(float wpn)
170 return (get_weaponinfo(wpn)).items;
173 void thrown_wep_think()
175 self.solid = SOLID_TRIGGER;
177 SUB_SetFade(self, time + 20, 1);
180 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
181 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
184 float wa, thisammo, i, j;
186 var .float ammofield;
191 wep.classname = "droppedweapon";
193 wep.owner = wep.enemy = own;
194 wep.flags |= FL_TOSSED;
195 wep.colormap = own.colormap;
197 wa = W_AmmoItemCode(wpn);
198 if(wa == IT_SUPERWEAPON || wa == 0)
202 weapon_defaultspawnfunc(wpn);
206 wep.think = thrown_wep_think;
207 wep.nextthink = time + 0.5;
215 weapon_defaultspawnfunc(wpn);
221 for(i = 0, j = 1; i < 24; ++i, j *= 2)
225 ammofield = Item_CounterField(j);
226 thisammo = min(own.ammofield, wep.ammofield);
227 wep.ammofield = thisammo;
228 own.ammofield -= thisammo;
229 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
232 s = substring(s, 5, -1);
234 wep.think = thrown_wep_think;
235 wep.nextthink = time + 0.5;
240 float W_IsWeaponThrowable(float w)
246 wa = W_AmmoItemCode(w);
247 if(start_weapons & wb)
249 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
251 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
253 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
261 // toss current weapon
262 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
269 return; // just in case
270 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
276 if (g_nexball && w == WEP_GRENADE_LAUNCHER)
278 if (!cvar("g_pickup_items"))
282 if(!cvar("g_weapon_throwable"))
284 if(cvar("g_weapon_stay") == 1)
286 if(!W_IsWeaponThrowable(w))
290 if(self.weapons & wb != wb)
294 W_SwitchWeapon_Force(self, w_getbestweapon(self));
295 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
301 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
303 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", a, "\n"));
307 // Bringed back weapon frame
313 self.weapon_frametime = frametime;
315 if(((arena_roundbased || g_ca) && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
318 if (!self.weaponentity || self.health < 1)
319 return; // Dead player can't use weapons and injure impulse commands
321 if(!self.switchweapon)
324 self.weaponentity.state = WS_CLEAR;
325 self.weaponname = "";
326 self.items &~= IT_AMMO;
330 makevectors(self.v_angle);
331 fo = v_forward; // save them in case the weapon think functions change it
336 if (self.weapon != self.switchweapon)
338 if (self.weaponentity.state == WS_CLEAR)
340 setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
341 self.weaponentity.state = WS_RAISE;
342 weapon_action(self.switchweapon, WR_SETUP);
343 // VorteX: add player model weapon select frame here
344 // setcustomframe(PlayerWeaponRaise);
345 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
346 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
348 else if (self.weaponentity.state == WS_READY)
350 #ifndef INDEPENDENT_ATTACK_FINISHED
351 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
354 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
355 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
356 self.weaponentity.state = WS_DROP;
357 // set up weapon switch think in the future, and start drop anim
358 weapon_thinkf(WFRAME_DONTCHANGE, cvar("g_balance_weaponswitchdelay"), w_clear);
359 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
360 #ifndef INDEPENDENT_ATTACK_FINISHED
366 // LordHavoc: network timing test code
368 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
371 wb = W_WeaponBit(self.weapon);
373 // call the think code which may fire the weapon
374 // and do so multiple times to resolve framerate dependency issues if the
375 // server framerate is very low and the weapon fire rate very high
381 if(wb && ((self.weapons & wb) == 0))
383 W_SwitchWeapon_Force(self, w_getbestweapon(self));
391 weapon_action(self.weapon, WR_THINK);
393 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
395 if(self.weapon_think)
403 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
407 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
408 //if (ATTACK_FINISHED(self) < time)
409 // ATTACK_FINISHED(self) = time;
411 //if (self.weapon_nextthink < time)
412 // self.weapon_nextthink = time;
414 // update currentammo incase it has changed
416 if (self.items & IT_CELLS)
417 self.currentammo = self.ammo_cells;
418 else if (self.items & IT_ROCKETS)
419 self.currentammo = self.ammo_rockets;
420 else if (self.items & IT_NAILS)
421 self.currentammo = self.ammo_nails;
422 else if (self.items & IT_SHELLS)
423 self.currentammo = self.ammo_shells;
425 self.currentammo = 1;