1 void W_TriggerReload()
\r
3 weapon_action(self.weapon, WR_RELOAD);
\r
6 // switch between weapons
\r
7 void W_SwitchWeapon(float imp)
\r
9 if (self.switchweapon != imp)
\r
11 if (client_hasweapon(self, imp, TRUE, TRUE))
\r
12 W_SwitchWeapon_Force(self, imp);
\r
20 .float weaponcomplainindex;
\r
21 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain)
\r
23 // We cannot tokenize in this function, as GiveItems calls this
\r
24 // function. Thus we must use car/cdr.
\r
25 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
\r
27 switchtonext = switchtolast = 0;
\r
28 first_valid = prev_valid = 0;
\r
38 weaponwant = stof(car(rest)); rest = cdr(rest);
\r
40 if((get_weaponinfo(weaponwant)).impulse != imp)
\r
45 if(client_hasweapon(pl, weaponwant, TRUE, FALSE))
\r
50 first_valid = weaponwant;
\r
51 if(weaponwant == pl.switchweapon)
\r
60 prev_valid = weaponwant;
\r
70 // complain (but only for one weapon on the button that has been pressed)
\r
73 self.weaponcomplainindex += 1;
\r
74 c = mod(self.weaponcomplainindex, c) + 1;
\r
78 weaponwant = stof(car(rest)); rest = cdr(rest);
\r
80 if((get_weaponinfo(weaponwant)).impulse != imp)
\r
86 client_hasweapon(pl, weaponwant, TRUE, TRUE);
\r
94 void W_CycleWeapon(string weaponorder, float dir)
\r
97 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1);
\r
102 void W_NextWeaponOnImpulse(float imp)
\r
105 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1);
\r
111 void W_NextWeapon(float list)
\r
114 W_CycleWeapon(weaponpriority_hudselector_0, -1);
\r
116 W_CycleWeapon(weaponpriority_hudselector_1, -1);
\r
118 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
\r
122 void W_PreviousWeapon(float list)
\r
125 W_CycleWeapon(weaponpriority_hudselector_0, +1);
\r
127 W_CycleWeapon(weaponpriority_hudselector_1, +1);
\r
129 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
\r
132 string W_FixWeaponOrder_AllowIncomplete(string order)
\r
134 return W_FixWeaponOrder(order, 0);
\r
137 string W_FixWeaponOrder_ForceComplete(string order)
\r
140 order = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
\r
141 return W_FixWeaponOrder(order, 1);
\r
144 float w_getbestweapon(entity e)
\r
146 return W_GetCycleWeapon(e, e.cvar_cl_weaponpriority, 0, -1, 0);
\r
149 // generic weapons table
\r
150 // TODO should they be macros instead?
\r
151 float weapon_action(float wpn, float wrequest)
\r
153 return (get_weaponinfo(wpn)).weapon_func(wrequest);
\r
156 string W_Name(float weaponid)
\r
158 return (get_weaponinfo(weaponid)).message;
\r
161 float W_WeaponBit(float wpn)
\r
163 return (get_weaponinfo(wpn)).weapons;
\r
166 float W_AmmoItemCode(float wpn)
\r
168 return (get_weaponinfo(wpn)).items;
\r
171 void thrown_wep_think()
\r
173 self.solid = SOLID_TRIGGER;
\r
174 self.owner = world;
\r
175 SUB_SetFade(self, time + 20, 1);
\r
178 // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count
\r
179 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo)
\r
181 entity oldself, wep;
\r
182 float wa, thisammo, i, j;
\r
184 var .float ammofield;
\r
188 setorigin(wep, org);
\r
189 wep.classname = "droppedweapon";
\r
190 wep.velocity = velo;
\r
191 wep.owner = wep.enemy = own;
\r
192 wep.flags |= FL_TOSSED;
\r
193 wep.colormap = own.colormap;
\r
195 wa = W_AmmoItemCode(wpn);
\r
196 if(wa == IT_SUPERWEAPON || wa == 0)
\r
200 weapon_defaultspawnfunc(wpn);
\r
202 if(startitem_failed)
\r
203 return string_null;
\r
204 wep.colormod = wep.owner.colormod; // used by the regurgitating colors
\r
205 wep.glowmod = own.weaponentity_glowmod;
\r
206 wep.think = thrown_wep_think;
\r
207 wep.nextthink = time + 0.5;
\r
215 weapon_defaultspawnfunc(wpn);
\r
217 if(startitem_failed)
\r
218 return string_null;
\r
221 for(i = 0, j = 1; i < 24; ++i, j *= 2)
\r
225 ammofield = Item_CounterField(j);
\r
226 thisammo = min(own.ammofield, wep.ammofield);
\r
227 wep.ammofield = thisammo;
\r
228 own.ammofield -= thisammo;
\r
229 s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j));
\r
231 // if our weapon is loaded, give its load back to the player
\r
232 if(self.weapon_load[self.weapon] > 0)
\r
234 own.ammofield += self.weapon_load[self.weapon];
\r
235 self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading
\r
239 s = substring(s, 5, -1);
\r
241 wep.colormod = wep.owner.colormod; // used by the regurgitating colors
\r
242 wep.glowmod = own.weaponentity_glowmod;
\r
243 wep.think = thrown_wep_think;
\r
244 wep.nextthink = time + 0.5;
\r
249 float W_IsWeaponThrowable(float w)
\r
252 wb = W_WeaponBit(w);
\r
255 wa = W_AmmoItemCode(w);
\r
256 if(start_weapons & wb)
\r
258 if(wa == IT_SUPERWEAPON && start_items & IT_UNLIMITED_SUPERWEAPONS)
\r
260 if(wa != IT_SUPERWEAPON && start_items & IT_UNLIMITED_WEAPON_AMMO)
\r
262 // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
\r
270 // toss current weapon
\r
271 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
\r
278 return; // just in case
\r
279 if(self.stat_eaten && self.dropweapon_check)
\r
280 return; // can't drop weapons from the stomach
\r
283 if (!cvar("g_pickup_items"))
\r
285 if(!cvar("g_weapon_throwable"))
\r
287 if(cvar("g_weapon_stay") == 1)
\r
289 if(!W_IsWeaponThrowable(w))
\r
292 wb = W_WeaponBit(w);
\r
293 if(self.weapons & wb != wb)
\r
296 self.weapons &~= wb;
\r
297 W_SwitchWeapon_Force(self, w_getbestweapon(self));
\r
298 a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
\r
301 if(self.health >= 1)
\r
304 sprint(self, strcat("You dropped the ^2", W_Name(w), "\n"));
\r
306 sprint(self, strcat("You dropped the ^2", W_Name(w), " with ", a, "\n"));
\r
310 // Bringed back weapon frame
\r
311 void W_WeaponFrame()
\r
316 self.weapon_frametime = frametime;
\r
318 if(((arena_roundbased || g_ca) && time < warmup) || ((time < game_starttime) && !cvar("sv_ready_restart_after_countdown")))
\r
321 if (!self.weaponentity || self.health < 1)
\r
322 return; // Dead player can't use weapons and injure impulse commands
\r
324 if(!self.switchweapon)
\r
327 self.weaponentity.state = WS_CLEAR;
\r
328 self.weaponname = "";
\r
329 self.items &~= IT_AMMO;
\r
333 makevectors(self.v_angle);
\r
334 fo = v_forward; // save them in case the weapon think functions change it
\r
339 if (self.weapon != self.switchweapon)
\r
341 if (self.weaponentity.state == WS_CLEAR)
\r
343 setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
\r
344 self.weaponentity.state = WS_RAISE;
\r
345 weapon_action(self.switchweapon, WR_SETUP);
\r
347 // set our clip load to the load of the weapon we switched to, if it's reloadable
\r
349 e = get_weaponinfo(self.switchweapon);
\r
350 if(e.spawnflags & WEP_FLAG_RELOADABLE && cvar(strcat("g_balance_", e.netname, "_reload_ammo"))) // prevent accessing undefined cvars
\r
352 self.clip_load = self.weapon_load[self.switchweapon];
\r
353 self.clip_size = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
\r
356 self.clip_load = self.clip_size = 0;
\r
358 // VorteX: add player model weapon select frame here
\r
359 // setcustomframe(PlayerWeaponRaise);
\r
360 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
\r
361 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
\r
363 else if (self.weaponentity.state == WS_READY)
\r
365 #ifndef INDEPENDENT_ATTACK_FINISHED
\r
366 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
\r
369 // UGLY WORKAROUND: play this on CHAN_WEAPON2 so it can't cut off fire sounds
\r
370 sound (self, CHAN_WEAPON2, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
\r
371 self.weaponentity.state = WS_DROP;
\r
372 // set up weapon switch think in the future, and start drop anim
\r
373 weapon_thinkf(WFRAME_DONTCHANGE, cvar("g_balance_weaponswitchdelay"), w_clear);
\r
374 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
\r
375 #ifndef INDEPENDENT_ATTACK_FINISHED
\r
381 // LordHavoc: network timing test code
\r
382 //if (self.button0)
\r
383 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
\r
386 wb = W_WeaponBit(self.weapon);
\r
388 // call the think code which may fire the weapon
\r
389 // and do so multiple times to resolve framerate dependency issues if the
\r
390 // server framerate is very low and the weapon fire rate very high
\r
396 if(wb && ((self.weapons & wb) == 0))
\r
398 W_SwitchWeapon_Force(self, w_getbestweapon(self));
\r
406 weapon_action(self.weapon, WR_THINK);
\r
408 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
\r
410 if(self.weapon_think)
\r
415 self.weapon_think();
\r
418 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
\r
422 // don't let attack_finished fall behind when not firing (must be after weapon_setup calls!)
\r
423 //if (ATTACK_FINISHED(self) < time)
\r
424 // ATTACK_FINISHED(self) = time;
\r
426 //if (self.weapon_nextthink < time)
\r
427 // self.weapon_nextthink = time;
\r