1 float forbidWeaponUse()
3 if(time < game_starttime && !autocvar_sv_ready_restart_after_countdown)
5 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
7 if(self.player_blocked)
9 if(self.freezetag_frozen)
19 self.weapon_frametime = frametime;
21 if (!self.weaponentity || self.health < 1)
22 return; // Dead player can't use weapons and injure impulse commands
25 if(self.weaponentity.state != WS_CLEAR)
31 if(!self.switchweapon)
34 self.switchingweapon = 0;
35 self.weaponentity.state = WS_CLEAR;
37 self.items &~= IT_AMMO;
41 makevectors(self.v_angle);
42 fo = v_forward; // save them in case the weapon think functions change it
47 if (self.weapon != self.switchweapon)
49 if (self.weaponentity.state == WS_CLEAR)
52 self.switchingweapon = self.switchweapon;
53 entity newwep = get_weaponinfo(self.switchweapon);
55 self.items &~= IT_AMMO;
56 self.items = self.items | (newwep.items & IT_AMMO);
58 // the two weapon entities will notice this has changed and update their models
59 self.weapon = self.switchweapon;
60 self.weaponname = newwep.mdl;
61 self.bulletcounter = 0; // WEAPONTODO
62 WEP_ACTION(self.switchweapon, WR_SETUP);
63 self.weaponentity.state = WS_RAISE;
65 // set our clip load to the load of the weapon we switched to, if it's reloadable
66 if(newwep.spawnflags & WEP_FLAG_RELOADABLE && cvar(strcat("g_balance_", newwep.netname, "_reload_ammo"))) // prevent accessing undefined cvars
68 self.clip_load = self.(weapon_load[self.switchweapon]);
69 self.clip_size = cvar(strcat("g_balance_", newwep.netname, "_reload_ammo"));
72 self.clip_load = self.clip_size = 0;
74 // VorteX: add player model weapon select frame here
75 // setcustomframe(PlayerWeaponRaise);
76 weapon_thinkf(WFRAME_IDLE, newwep.switchdelay_raise, w_ready);
77 //print(sprintf("W_WeaponFrame(): cvar: %s, value: %f\n", sprintf("g_balance_%s_switchdelay_raise", newwep.netname), cvar(sprintf("g_balance_%s_switchdelay_raise", newwep.netname))));
78 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
80 else if (self.weaponentity.state == WS_DROP)
82 // in dropping phase we can switch at any time
83 self.switchingweapon = self.switchweapon;
85 else if (self.weaponentity.state == WS_READY)
88 self.switchingweapon = self.switchweapon;
90 entity oldwep = get_weaponinfo(self.weapon);
92 #ifndef INDEPENDENT_ATTACK_FINISHED
93 if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
96 sound (self, CH_WEAPON_SINGLE, "weapons/weapon_switch.wav", VOL_BASE, ATTN_NORM);
97 self.weaponentity.state = WS_DROP;
98 // set up weapon switch think in the future, and start drop anim
99 weapon_thinkf(WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
100 //print(sprintf("W_WeaponFrame(): cvar: %s, value: %f\n", sprintf("g_balance_%s_switchdelay_drop", oldwep.netname), cvar(sprintf("g_balance_%s_switchdelay_drop", oldwep.netname))));
101 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
102 #ifndef INDEPENDENT_ATTACK_FINISHED
108 // LordHavoc: network timing test code
110 // print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(self)), " >= ", ftos(self.weapon_nextthink), "\n");
115 // call the think code which may fire the weapon
116 // and do so multiple times to resolve framerate dependency issues if the
117 // server framerate is very low and the weapon fire rate very high
120 while (c < W_TICSPERFRAME)
123 if(w && !WEPSET_CONTAINS_EW(self, w))
125 if(self.weapon == self.switchweapon)
126 W_SwitchWeapon_Force(self, w_getbestweapon(self));
135 WEP_ACTION(self.weapon, WR_THINK);
137 WEP_ACTION(self.weapon, WR_GONETHINK);
139 if (time + self.weapon_frametime * 0.5 >= self.weapon_nextthink)
141 if(self.weapon_think)
149 bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n");
154 if (self.items & IT_CELLS)
155 self.currentammo = self.ammo_cells;
156 else if (self.items & IT_ROCKETS)
157 self.currentammo = self.ammo_rockets;
158 else if (self.items & IT_NAILS)
159 self.currentammo = self.ammo_nails;
160 else if (self.items & IT_SHELLS)
161 self.currentammo = self.ammo_shells;
163 self.currentammo = 1;
167 string W_Apply_Weaponreplace(string in)
169 float n = tokenize_console(in);
172 for(i = 0; i < n; ++i)
175 string r = cvar_string(strcat("g_weaponreplace_", s));
177 out = strcat(out, " ", s);
179 out = strcat(out, " ", r);
181 return substring(out, 1, -1);
184 void weapon_defaultspawnfunc(float wpn)
188 var .float ammofield;
194 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
196 e = get_weaponinfo(wpn);
198 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
200 objerror("Attempted to spawn a mutator-blocked weapon rejected");
201 startitem_failed = TRUE;
205 s = W_Apply_Weaponreplace(e.netname);
208 MUTATOR_CALLHOOK(SetWeaponreplace);
213 startitem_failed = TRUE;
216 t = tokenize_console(s);
219 self.team = --internalteam;
221 for(i = 1; i < t; ++i)
224 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
226 e = get_weaponinfo(j);
230 copyentity(oldself, self);
231 self.classname = "replacedweapon";
232 weapon_defaultspawnfunc(j);
238 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
243 if(t >= 1) // always the case!
247 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
249 e = get_weaponinfo(j);
258 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
264 startitem_failed = TRUE;
269 e = get_weaponinfo(wpn);
271 if(!self.respawntime)
273 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
275 self.respawntime = g_pickup_respawntime_superweapon;
276 self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
280 self.respawntime = g_pickup_respawntime_weapon;
281 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
285 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
286 if(!self.superweapons_finished)
287 self.superweapons_finished = autocvar_g_balance_superweapons_time;
291 for(i = 0, j = 1; i < 24; ++i, j *= 2)
295 ammofield = Item_CounterField(j);
297 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
303 if(g_pickup_weapons_anyway)
304 self.pickup_anyway = TRUE;
308 // no weapon-stay on superweapons
309 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
310 f |= FL_NO_WEAPON_STAY;
312 // weapon stay isn't supported for teamed weapons
314 f |= FL_NO_WEAPON_STAY;
316 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
317 if (self.modelindex) // don't precache if self was removed
318 WEP_ACTION(e.weapon, WR_INIT);