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 self.hasweapon_complain_spam = time + 0.2;
22 if (wpn < WEP_FIRST || wpn > WEP_LAST)
25 sprint(self, "Invalid weapon\n");
28 if (WEPSET_CONTAINS_EW(cl, wpn))
32 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
40 f = WEP_ACTION(wpn, WR_CHECKAMMO1);
41 f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
43 // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
45 if(wpn == WEP_MINE_LAYER)
46 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
54 if(IS_REAL_CLIENT(cl))
56 play2(cl, "weapons/unavailable.wav");
57 Send_WeaponComplain (cl, wpn, W_Name(wpn), 0);
67 // Report Proper Weapon Status / Modified Weapon Ownership Message
68 if (WEPSET_CONTAINS_AW(weaponsInMap, wpn))
70 Send_WeaponComplain(cl, wpn, W_Name(wpn), 1);
72 if(autocvar_g_showweaponspawns)
77 e = get_weaponinfo(wpn);
80 for(e = world; (e = findfloat(e, weapon, wpn)); )
82 if(e.classname == "droppedweapon")
84 if not(e.flags & FL_ITEM)
93 RADARICON_NONE, '0 0 0'
100 Send_WeaponComplain (cl, wpn, W_Name(wpn), 2);
103 play2(cl, "weapons/unavailable.wav");
108 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
110 // We cannot tokenize in this function, as GiveItems calls this
111 // function. Thus we must use car/cdr.
112 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
114 switchtonext = switchtolast = 0;
115 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);
133 if((get_weaponinfo(weaponwant)).impulse != imp)
138 if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE))
143 first_valid = weaponwant;
144 if(weaponwant == weaponcur)
153 prev_valid = weaponwant;
163 // complain (but only for one weapon on the button that has been pressed)
166 self.weaponcomplainindex += 1;
167 c = mod(self.weaponcomplainindex, c) + 1;
171 weaponwant = stof(car(rest)); rest = cdr(rest);
173 if((get_weaponinfo(weaponwant)).impulse != imp)
179 client_hasweapon(pl, weaponwant, TRUE, TRUE);
187 void W_SwitchWeapon_Force(entity e, float w)
189 e.cnt = e.switchweapon;
194 // perform weapon to attack (weaponstate and attack_finished check is here)
195 void W_SwitchToOtherWeapon(entity pl)
197 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
200 if(WEPSET_CONTAINS_EW(pl, w))
202 WEPSET_ANDNOT_EW(pl, w);
203 ww = w_getbestweapon(pl);
207 ww = w_getbestweapon(pl);
209 W_SwitchWeapon_Force(pl, ww);
212 void W_SwitchWeapon(float imp)
214 if (self.switchweapon != imp)
216 if (client_hasweapon(self, imp, TRUE, TRUE))
217 W_SwitchWeapon_Force(self, imp);
219 self.selectweapon = imp; // update selectweapon ANYWAY
221 else { WEP_ACTION(self.weapon, WR_RELOAD); }
224 void W_CycleWeapon(string weaponorder, float dir)
227 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, TRUE);
232 void W_NextWeaponOnImpulse(float imp)
235 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
241 void W_NextWeapon(float list)
244 W_CycleWeapon(weaponorder_byid, -1);
246 W_CycleWeapon(self.weaponorder_byimpulse, -1);
248 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
252 void W_PreviousWeapon(float list)
255 W_CycleWeapon(weaponorder_byid, +1);
257 W_CycleWeapon(self.weaponorder_byimpulse, +1);
259 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
262 // previously used if exists and has ammo, (second) best otherwise
263 void W_LastWeapon(void)
265 if(client_hasweapon(self, self.cnt, TRUE, FALSE))
266 W_SwitchWeapon(self.cnt);
268 W_SwitchToOtherWeapon(self);