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(self.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(self.weaponorder_byimpulse, +1);
139 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
142 float w_getbestweapon(entity e)
144 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, FALSE, TRUE);
147 // generic weapons table
148 // TODO should they be macros instead?
149 float weapon_action(float wpn, float wrequest)
151 return (get_weaponinfo(wpn)).weapon_func(wrequest);
154 string W_Name(float weaponid)
156 return (get_weaponinfo(weaponid)).message;
159 float W_WeaponBit(float wpn)
161 return (get_weaponinfo(wpn)).weapons;
164 float W_AmmoItemCode(float wpn)
166 return (get_weaponinfo(wpn)).items;
169 void thrown_wep_think()
171 self.solid = SOLID_TRIGGER;
173 SUB_SetFade(self, time + 20, 1);
176 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
177 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
180 float wa, thisammo, i, j;
182 var .float ammofield;
187 wep.classname = "droppedweapon";
189 wep.owner = wep.enemy = own;
190 wep.flags |= FL_TOSSED;
191 wep.colormap = own.colormap;
193 wa = W_AmmoItemCode(wpn);
194 if(wa == IT_SUPERWEAPON || wa == 0)
198 weapon_defaultspawnfunc(wpn);
202 wep.think = thrown_wep_think;
203 wep.nextthink = time + 0.5;
211 weapon_defaultspawnfunc(wpn);
217 for(i = 0, j = 1; i < 24; ++i, j *= 2)
221 ammofield = Item_CounterField(j);
222 thisammo = min(own.ammofield, wep.ammofield);
223 wep.ammofield = thisammo;
224 own.ammofield -= thisammo;
225 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
228 s = substring(s, 5, -1);
230 wep.think = thrown_wep_think;
231 wep.nextthink = time + 0.5;
236 float W_IsWeaponThrowable(float w)
242 wa = W_AmmoItemCode(w);
243 if(start_weapons & wb)
245 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
247 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
249 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
257 // toss current weapon
258 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
265 return; // just in case
266 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
272 if (g_nexball && w == WEP_GRENADE_LAUNCHER)
274 if (!cvar("g_pickup_items"))
278 if(!cvar("g_weapon_throwable"))
280 if(cvar("g_weapon_stay") == 1)
282 if(!W_IsWeaponThrowable(w))
284 if(self.deadflag == DEAD_NO && self.weaponentity.state != WS_READY)
288 if(self.weapons & wb != wb)
292 W_SwitchWeapon_Force(self, w_getbestweapon(self));
293 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
299 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
301 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", a, "\n"));
305 // Bringed back weapon frame
311 self.weapon_frametime = frametime;
313 if(((arena_roundbased || g_ca) && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
316 if (!self.weaponentity || self.health < 1)
317 return; // Dead player can't use weapons and injure impulse commands
319 if(!self.switchweapon)
322 self.weaponentity.state = WS_CLEAR;
323 self.weaponname = "";
324 self.items &~= IT_AMMO;
328 makevectors(self.v_angle);
329 fo = v_forward; // save them in case the weapon think functions change it
334 if (self.weapon != self.switchweapon)
336 if (self.weaponentity.state == WS_CLEAR)
338 setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
339 self.weaponentity.state = WS_RAISE;
340 weapon_action(self.switchweapon, WR_SETUP);
341 // VorteX: add player model weapon select frame here
342 // setcustomframe(PlayerWeaponRaise);
343 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
344 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
346 else if (self.weaponentity.state == WS_READY)
348 #ifndef INDEPENDENT_ATTACK_FINISHED
349 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
352 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
353 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
354 self.weaponentity.state = WS_DROP;
355 // set up weapon switch think in the future, and start drop anim
356 weapon_thinkf(WFRAME_DONTCHANGE, cvar("g_balance_weaponswitchdelay"), w_clear);
357 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
358 #ifndef INDEPENDENT_ATTACK_FINISHED
364 // LordHavoc: network timing test code
366 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
369 wb = W_WeaponBit(self.weapon);
371 // call the think code which may fire the weapon
372 // and do so multiple times to resolve framerate dependency issues if the
373 // server framerate is very low and the weapon fire rate very high
376 while (c < W_TICSPERFRAME)
379 if(wb && ((self.weapons & wb) == 0))
381 W_SwitchWeapon_Force(self, w_getbestweapon(self));
389 weapon_action(self.weapon, WR_THINK);
391 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
393 if(self.weapon_think)
401 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
405 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
406 //if (ATTACK_FINISHED(self) < time)
407 // ATTACK_FINISHED(self) = time;
409 //if (self.weapon_nextthink < time)
410 // self.weapon_nextthink = time;
412 // update currentammo incase it has changed
414 if (self.items & IT_CELLS)
415 self.currentammo = self.ammo_cells;
416 else if (self.items & IT_ROCKETS)
417 self.currentammo = self.ammo_rockets;
418 else if (self.items & IT_NAILS)
419 self.currentammo = self.ammo_nails;
420 else if (self.items & IT_SHELLS)
421 self.currentammo = self.ammo_shells;
423 self.currentammo = 1;