3 weapon_action(self.weapon, WR_RELOAD);
6 // switch between weapons
7 void W_SwitchWeapon(float imp)
9 if (self.switchweapon != imp)
11 if (client_hasweapon(self, imp, TRUE, TRUE))
12 W_SwitchWeapon_Force(self, imp);
14 self.selectweapon = imp; // update selectweapon ANYWAY
22 .float weaponcomplainindex;
23 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
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;
33 if(skipmissing || pl.selectweapon == 0)
34 weaponcur = pl.switchweapon;
36 weaponcur = pl.selectweapon;
46 weaponwant = stof(car(rest)); rest = cdr(rest);
48 if((get_weaponinfo(weaponwant)).impulse != imp)
53 if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE))
58 first_valid = weaponwant;
59 if(weaponwant == weaponcur)
68 prev_valid = weaponwant;
78 // complain (but only for one weapon on the button that has been pressed)
81 self.weaponcomplainindex += 1;
82 c = mod(self.weaponcomplainindex, c) + 1;
86 weaponwant = stof(car(rest)); rest = cdr(rest);
88 if((get_weaponinfo(weaponwant)).impulse != imp)
94 client_hasweapon(pl, weaponwant, TRUE, TRUE);
102 void W_CycleWeapon(string weaponorder, float dir)
105 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, TRUE);
110 void W_NextWeaponOnImpulse(float imp)
113 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
119 void W_NextWeapon(float list)
122 W_CycleWeapon(weaponorder_byid, -1);
124 W_CycleWeapon(self.weaponorder_byimpulse, -1);
126 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
130 void W_PreviousWeapon(float list)
133 W_CycleWeapon(weaponorder_byid, +1);
135 W_CycleWeapon(self.weaponorder_byimpulse, +1);
137 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
140 float w_getbestweapon(entity e)
142 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, FALSE, TRUE);
145 // generic weapons table
146 // TODO should they be macros instead?
147 float weapon_action(float wpn, float wrequest)
149 return (get_weaponinfo(wpn)).weapon_func(wrequest);
152 string W_Name(float weaponid)
154 return (get_weaponinfo(weaponid)).message;
157 float W_WeaponBit(float wpn)
159 return (get_weaponinfo(wpn)).weapons;
162 float W_AmmoItemCode(float wpn)
164 return (get_weaponinfo(wpn)).items;
167 void thrown_wep_think()
169 self.solid = SOLID_TRIGGER;
171 SUB_SetFade(self, time + 20, 1);
174 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
175 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
178 float wa, thisammo, i, j;
180 var .float ammofield;
185 wep.classname = "droppedweapon";
187 wep.owner = wep.enemy = own;
188 wep.flags |= FL_TOSSED;
189 wep.colormap = own.colormap;
191 wa = W_AmmoItemCode(wpn);
192 if(wa == IT_SUPERWEAPON || wa == 0)
196 weapon_defaultspawnfunc(wpn);
200 wep.glowmod = own.weaponentity_glowmod;
201 wep.think = thrown_wep_think;
202 wep.nextthink = time + 0.5;
210 weapon_defaultspawnfunc(wpn);
216 for(i = 0, j = 1; i < 24; ++i, j *= 2)
220 ammofield = Item_CounterField(j);
221 thisammo = min(own.ammofield, wep.ammofield);
222 wep.ammofield = thisammo;
223 own.ammofield -= thisammo;
224 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
226 // if our weapon is loaded, give its load back to the player
227 if(self.weapon_load[self.weapon] > 0)
229 own.ammofield += self.weapon_load[self.weapon];
230 self.weapon_load[self.weapon] = -1; // schedule the weapon for reloading
234 s = substring(s, 5, -1);
236 wep.glowmod = own.weaponentity_glowmod;
237 wep.think = thrown_wep_think;
238 wep.nextthink = time + 0.5;
243 float W_IsWeaponThrowable(float w)
247 if (!autocvar_g_pickup_items)
257 if (g_nexball && w == WEP_GRENADE_LAUNCHER)
263 wa = W_AmmoItemCode(w);
264 if(start_weapons & wb)
266 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
268 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
270 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
278 // toss current weapon
279 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
286 return; // just in case
287 if(self.weapon_forbidchange)
289 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
291 if(!autocvar_g_weapon_throwable)
293 if(autocvar_g_weapon_stay == 1)
295 if(self.weaponentity.state != WS_READY)
297 if(!W_IsWeaponThrowable(w))
301 if(self.weapons & wb != wb)
305 W_SwitchWeapon_Force(self, w_getbestweapon(self));
306 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
310 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
312 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", a, "\n"));
315 // Bringed back weapon frame
321 self.weapon_frametime = frametime;
323 if(((arena_roundbased || g_ca || g_freezetag) && time < warmup) || ((time < game_starttime) && !autocvar_sv_ready_restart_after_countdown))
326 if(self.freezetag_frozen == 1)
329 if (!self.weaponentity || self.health < 1)
330 return; // Dead player can't use weapons and injure impulse commands
332 if(!self.switchweapon)
335 self.weaponentity.state = WS_CLEAR;
336 self.weaponname = "";
337 self.items &~= IT_AMMO;
341 makevectors(self.v_angle);
342 fo = v_forward; // save them in case the weapon think functions change it
347 if (self.weapon != self.switchweapon)
349 if (self.weaponentity.state == WS_CLEAR)
351 //setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
352 self.weaponentity.state = WS_RAISE;
353 weapon_action(self.switchweapon, WR_SETUP);
355 // set our clip load to the load of the weapon we switched to, if it's reloadable
357 e = get_weaponinfo(self.switchweapon);
358 if(e.spawnflags & WEP_FLAG_RELOADABLE && cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) // prevent accessing undefined cvars
360 self.clip_load = self.weapon_load[self.switchweapon];
361 self.clip_size = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
364 self.clip_load = self.clip_size = 0;
366 // VorteX: add player model weapon select frame here
367 // setcustomframe(PlayerWeaponRaise);
368 weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_weaponswitchdelay, w_ready);
369 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
371 else if (self.weaponentity.state == WS_READY)
373 #ifndef INDEPENDENT_ATTACK_FINISHED
374 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
377 sound (self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
378 self.weaponentity.state = WS_DROP;
379 // set up weapon switch think in the future, and start drop anim
380 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_weaponswitchdelay, w_clear);
381 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
382 #ifndef INDEPENDENT_ATTACK_FINISHED
388 // LordHavoc: network timing test code
390 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
393 wb = W_WeaponBit(self.weapon);
395 // call the think code which may fire the weapon
396 // and do so multiple times to resolve framerate dependency issues if the
397 // server framerate is very low and the weapon fire rate very high
400 while (c < W_TICSPERFRAME)
403 if(wb && ((self.weapons & wb) == 0))
405 W_SwitchWeapon_Force(self, w_getbestweapon(self));
413 weapon_action(self.weapon, WR_THINK);
415 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
417 if(self.weapon_think)
425 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
429 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
430 //if (ATTACK_FINISHED(self) < time)
431 // ATTACK_FINISHED(self) = time;
433 //if (self.weapon_nextthink < time)
434 // self.weapon_nextthink = time;
436 // update currentammo incase it has changed
438 if (self.items & IT_CELLS)
439 self.currentammo = self.ammo_cells;
440 else if (self.items & IT_ROCKETS)
441 self.currentammo = self.ammo_rockets;
442 else if (self.items & IT_NAILS)
443 self.currentammo = self.ammo_nails;
444 else if (self.items & IT_SHELLS)
445 self.currentammo = self.ammo_shells;
447 self.currentammo = 1;