1 // switch between weapons
2 void Send_WeaponComplain(entity e, float wpn, float type)
5 WriteByte(MSG_ONE, SVC_TEMPENTITY);
6 WriteByte(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN);
7 WriteByte(MSG_ONE, wpn);
8 WriteByte(MSG_ONE, type);
11 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
16 if(time < self.hasweapon_complain_spam)
19 if(wpn == WEP_HOOK && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
23 self.hasweapon_complain_spam = time + 0.2;
25 if (wpn < WEP_FIRST || wpn > WEP_LAST)
28 sprint(self, "Invalid weapon\n");
31 if (cl.weapons & WepSet_FromWeapon(wpn))
35 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
43 f = WEP_ACTION(wpn, WR_CHECKAMMO1);
44 f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
46 // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
48 if(wpn == WEP_MINE_LAYER)
49 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
57 if(IS_REAL_CLIENT(cl))
59 play2(cl, "weapons/unavailable.wav");
60 Send_WeaponComplain (cl, wpn, 0);
70 // Report Proper Weapon Status / Modified Weapon Ownership Message
71 if (weaponsInMap & WepSet_FromWeapon(wpn))
73 Send_WeaponComplain(cl, wpn, 1);
75 if(autocvar_g_showweaponspawns)
79 for(e = world; (e = findfloat(e, weapon, wpn)); )
81 if(e.classname == "droppedweapon")
83 if(!(e.flags & FL_ITEM))
86 (get_weaponinfo(wpn)).wpmodel,
92 RADARICON_NONE, '0 0 0'
99 Send_WeaponComplain (cl, wpn, 2);
102 play2(cl, "weapons/unavailable.wav");
107 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
109 // We cannot tokenize in this function, as GiveItems calls this
110 // function. Thus we must use car/cdr.
111 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
113 switchtonext = switchtolast = 0;
114 first_valid = prev_valid = 0;
118 if(skipmissing || pl.selectweapon == 0)
119 weaponcur = pl.switchweapon;
121 weaponcur = pl.selectweapon;
131 weaponwant = stof(car(rest)); rest = cdr(rest);
132 wep = get_weaponinfo(weaponwant);
134 if(wep.impulse != imp)
137 // skip weapons we don't own that aren't normal and aren't in the map
138 if(!(pl.weapons & WepSet_FromWeapon(weaponwant)))
139 if(!((get_weaponinfo(weaponwant)).spawnflags & WEP_FLAG_NORMAL))
140 if(!(weaponsInMap & WepSet_FromWeapon(weaponwant)))
145 if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE))
150 first_valid = weaponwant;
151 if(weaponwant == weaponcur)
160 prev_valid = weaponwant;
170 // complain (but only for one weapon on the button that has been pressed)
173 self.weaponcomplainindex += 1;
174 c = mod(self.weaponcomplainindex, c) + 1;
178 weaponwant = stof(car(rest)); rest = cdr(rest);
179 wep = get_weaponinfo(weaponwant);
181 if(wep.impulse != imp)
184 // skip weapons we don't own that aren't normal and aren't in the map
185 if(!(pl.weapons & WepSet_FromWeapon(weaponwant)))
186 if(!((get_weaponinfo(weaponwant)).spawnflags & WEP_FLAG_NORMAL))
187 if(!(weaponsInMap & WepSet_FromWeapon(weaponwant)))
193 client_hasweapon(pl, weaponwant, TRUE, TRUE);
201 void W_SwitchWeapon_Force(entity e, float w)
203 e.cnt = e.switchweapon;
208 // perform weapon to attack (weaponstate and attack_finished check is here)
209 void W_SwitchToOtherWeapon(entity pl)
211 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
214 if(pl.weapons & WepSet_FromWeapon(w))
216 pl.weapons &= ~WepSet_FromWeapon(w);
217 ww = w_getbestweapon(pl);
218 pl.weapons |= WepSet_FromWeapon(w);
221 ww = w_getbestweapon(pl);
223 W_SwitchWeapon_Force(pl, ww);
226 void W_SwitchWeapon(float imp)
228 if (self.switchweapon != imp)
230 if (client_hasweapon(self, imp, TRUE, TRUE))
231 W_SwitchWeapon_Force(self, imp);
233 self.selectweapon = imp; // update selectweapon ANYWAY
235 else { WEP_ACTION(self.weapon, WR_RELOAD); }
238 void W_CycleWeapon(string weaponorder, float dir)
241 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, TRUE);
246 void W_NextWeaponOnImpulse(float imp)
249 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
255 void W_NextWeapon(float list)
258 W_CycleWeapon(weaponorder_byid, -1);
260 W_CycleWeapon(self.weaponorder_byimpulse, -1);
262 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
266 void W_PreviousWeapon(float list)
269 W_CycleWeapon(weaponorder_byid, +1);
271 W_CycleWeapon(self.weaponorder_byimpulse, +1);
273 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
276 // previously used if exists and has ammo, (second) best otherwise
277 void W_LastWeapon(void)
279 if(client_hasweapon(self, self.cnt, TRUE, FALSE))
280 W_SwitchWeapon(self.cnt);
282 W_SwitchToOtherWeapon(self);