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 hasweapon_complain_spam;
13 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
18 if(time < self.hasweapon_complain_spam)
21 self.hasweapon_complain_spam = time + 0.2;
23 if (wpn < WEP_FIRST || wpn > WEP_LAST)
26 sprint(self, "Invalid weapon\n");
29 if (WEPSET_CONTAINS_EW(cl, wpn))
33 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
41 f = WEP_ACTION(wpn, WR_CHECKAMMO1);
42 f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
44 // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
46 if(wpn == WEP_MINE_LAYER)
47 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
55 if(IS_REAL_CLIENT(cl))
57 play2(cl, "weapons/unavailable.wav");
58 Send_WeaponComplain (cl, wpn, W_Name(wpn), 0);
68 // Report Proper Weapon Status / Modified Weapon Ownership Message
69 if (WEPSET_CONTAINS_AW(weaponsInMap, wpn))
71 Send_WeaponComplain(cl, wpn, W_Name(wpn), 1);
73 if(autocvar_g_showweaponspawns)
78 e = get_weaponinfo(wpn);
81 for(e = world; (e = findfloat(e, weapon, wpn)); )
83 if(e.classname == "droppedweapon")
85 if not(e.flags & FL_ITEM)
94 RADARICON_NONE, '0 0 0'
101 Send_WeaponComplain (cl, wpn, W_Name(wpn), 2);
104 play2(cl, "weapons/unavailable.wav");
109 .float weaponcomplainindex;
110 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
112 // We cannot tokenize in this function, as GiveItems calls this
113 // function. Thus we must use car/cdr.
114 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast, c;
116 switchtonext = switchtolast = 0;
117 first_valid = prev_valid = 0;
120 if(skipmissing || pl.selectweapon == 0)
121 weaponcur = pl.switchweapon;
123 weaponcur = pl.selectweapon;
133 weaponwant = stof(car(rest)); rest = cdr(rest);
135 if((get_weaponinfo(weaponwant)).impulse != imp)
140 if(!skipmissing || client_hasweapon(pl, weaponwant, TRUE, FALSE))
145 first_valid = weaponwant;
146 if(weaponwant == weaponcur)
155 prev_valid = weaponwant;
165 // complain (but only for one weapon on the button that has been pressed)
168 self.weaponcomplainindex += 1;
169 c = mod(self.weaponcomplainindex, c) + 1;
173 weaponwant = stof(car(rest)); rest = cdr(rest);
175 if((get_weaponinfo(weaponwant)).impulse != imp)
181 client_hasweapon(pl, weaponwant, TRUE, TRUE);
189 #define w_getbestweapon(ent) W_GetCycleWeapon(ent, ent.cvar_cl_weaponpriority, 0, -1, FALSE, TRUE)
191 // perform weapon to attack (weaponstate and attack_finished check is here)
192 void W_SwitchToOtherWeapon(entity pl)
194 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
197 if(WEPSET_CONTAINS_EW(pl, w))
199 WEPSET_ANDNOT_EW(pl, w);
200 ww = w_getbestweapon(pl);
204 ww = w_getbestweapon(pl);
206 W_SwitchWeapon_Force(pl, ww);
209 void W_SwitchWeapon(float imp)
211 if (self.switchweapon != imp)
213 if (client_hasweapon(self, imp, TRUE, TRUE))
214 W_SwitchWeapon_Force(self, imp);
216 self.selectweapon = imp; // update selectweapon ANYWAY
218 else { WEP_ACTION(self.weapon, WR_RELOAD); }
221 void W_CycleWeapon(string weaponorder, float dir)
224 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, TRUE);
229 void W_NextWeaponOnImpulse(float imp)
232 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
238 void W_NextWeapon(float list)
241 W_CycleWeapon(weaponorder_byid, -1);
243 W_CycleWeapon(self.weaponorder_byimpulse, -1);
245 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
249 void W_PreviousWeapon(float list)
252 W_CycleWeapon(weaponorder_byid, +1);
254 W_CycleWeapon(self.weaponorder_byimpulse, +1);
256 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
259 // previously used if exists and has ammo, (second) best otherwise
260 void W_LastWeapon(void)
262 if(client_hasweapon(self, self.cnt, TRUE, FALSE))
263 W_SwitchWeapon(self.cnt);
265 W_SwitchToOtherWeapon(self);