1 // switch between weapons
2 void Send_WeaponComplain(entity e, float wpn, string wpnname, float type)
5 WriteByte(MSG_ONE, SVC_TEMPENTITY);
6 WriteByte(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN);
7 WriteByte(MSG_ONE, wpn);
8 WriteString(MSG_ONE, wpnname);
9 WriteByte(MSG_ONE, type);
12 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
17 if(time < self.hasweapon_complain_spam)
20 if(wpn == WEP_HOOK && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
24 self.hasweapon_complain_spam = time + 0.2;
26 if (wpn < WEP_FIRST || wpn > WEP_LAST)
29 sprint(self, "Invalid weapon\n");
32 if (cl.weapons & WepSet_FromWeapon(wpn))
36 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
44 f = WEP_ACTION(wpn, WR_CHECKAMMO1);
45 f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
47 // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
49 if(wpn == WEP_MINE_LAYER)
50 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
58 if(IS_REAL_CLIENT(cl))
60 play2(cl, "weapons/unavailable.wav");
61 Send_WeaponComplain (cl, wpn, W_Name(wpn), 0);
71 // Report Proper Weapon Status / Modified Weapon Ownership Message
72 if (weaponsInMap & WepSet_FromWeapon(wpn))
74 Send_WeaponComplain(cl, wpn, W_Name(wpn), 1);
76 if(autocvar_g_showweaponspawns)
81 e = get_weaponinfo(wpn);
84 for(e = world; (e = findfloat(e, weapon, wpn)); )
86 if(e.classname == "droppedweapon")
88 if(!(e.flags & FL_ITEM))
97 RADARICON_NONE, '0 0 0'
104 Send_WeaponComplain (cl, wpn, W_Name(wpn), 2);
107 play2(cl, "weapons/unavailable.wav");
112 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
114 // We cannot tokenize in this function, as GiveItems calls this
115 // function. Thus we must use car/cdr.
116 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
118 switchtonext = switchtolast = 0;
119 first_valid = prev_valid = 0;
123 if(skipmissing || pl.selectweapon == 0)
124 weaponcur = pl.switchweapon;
126 weaponcur = pl.selectweapon;
136 weaponwant = stof(car(rest)); rest = cdr(rest);
137 wep = get_weaponinfo(weaponwant);
139 if(wep.impulse != imp)
142 // skip weapons we don't own that aren't normal and aren't in the map
143 if(!(pl.weapons & WepSet_FromWeapon(weaponwant)))
144 if(!((get_weaponinfo(weaponwant)).spawnflags & WEP_FLAG_NORMAL))
145 if(!(weaponsInMap & WepSet_FromWeapon(weaponwant)))
150 if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE))
155 first_valid = weaponwant;
156 if(weaponwant == weaponcur)
165 prev_valid = weaponwant;
175 // complain (but only for one weapon on the button that has been pressed)
178 self.weaponcomplainindex += 1;
179 c = mod(self.weaponcomplainindex, c) + 1;
183 weaponwant = stof(car(rest)); rest = cdr(rest);
184 wep = get_weaponinfo(weaponwant);
186 if(wep.impulse != imp)
189 // skip weapons we don't own that aren't normal and aren't in the map
190 if(!(pl.weapons & WepSet_FromWeapon(weaponwant)))
191 if(!((get_weaponinfo(weaponwant)).spawnflags & WEP_FLAG_NORMAL))
192 if(!(weaponsInMap & WepSet_FromWeapon(weaponwant)))
198 client_hasweapon(pl, weaponwant, TRUE, TRUE);
206 void W_SwitchWeapon_Force(entity e, float w)
208 e.cnt = e.switchweapon;
213 // perform weapon to attack (weaponstate and attack_finished check is here)
214 void W_SwitchToOtherWeapon(entity pl)
216 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
219 if(pl.weapons & WepSet_FromWeapon(w))
221 pl.weapons &= ~WepSet_FromWeapon(w);
222 ww = w_getbestweapon(pl);
223 pl.weapons |= WepSet_FromWeapon(w);
226 ww = w_getbestweapon(pl);
228 W_SwitchWeapon_Force(pl, ww);
231 void W_SwitchWeapon(float imp)
233 if (self.switchweapon != imp)
235 if (client_hasweapon(self, imp, TRUE, TRUE))
236 W_SwitchWeapon_Force(self, imp);
238 self.selectweapon = imp; // update selectweapon ANYWAY
240 else { WEP_ACTION(self.weapon, WR_RELOAD); }
243 void W_CycleWeapon(string weaponorder, float dir)
246 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, TRUE);
251 void W_NextWeaponOnImpulse(float imp)
254 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
260 void W_NextWeapon(float list)
263 W_CycleWeapon(weaponorder_byid, -1);
265 W_CycleWeapon(self.weaponorder_byimpulse, -1);
267 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
271 void W_PreviousWeapon(float list)
274 W_CycleWeapon(weaponorder_byid, +1);
276 W_CycleWeapon(self.weaponorder_byimpulse, +1);
278 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
281 // previously used if exists and has ammo, (second) best otherwise
282 void W_LastWeapon(void)
284 if(client_hasweapon(self, self.cnt, TRUE, FALSE))
285 W_SwitchWeapon(self.cnt);
287 W_SwitchToOtherWeapon(self);