1 #include "selection.qh"
4 #include "weaponsystem.qh"
5 #include "../t_items.qh"
6 #include "../../common/constants.qh"
7 #include "../../common/util.qh"
8 #include "../../common/weapons/all.qh"
10 // switch between weapons
11 void Send_WeaponComplain(entity e, float wpn, float type)
14 WriteByte(MSG_ONE, SVC_TEMPENTITY);
15 WriteByte(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN);
16 WriteByte(MSG_ONE, wpn);
17 WriteByte(MSG_ONE, type);
20 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
24 if(time < self.hasweapon_complain_spam)
27 if(wpn == WEP_HOOK.m_id && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
31 self.hasweapon_complain_spam = time + 0.2;
33 if (wpn < WEP_FIRST || wpn > WEP_LAST)
36 sprint(self, "Invalid weapon\n");
39 if (cl.weapons & WepSet_FromWeapon(wpn))
43 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
50 f = _WEP_ACTION(wpn, WR_CHECKAMMO1);
51 f = f + _WEP_ACTION(wpn, WR_CHECKAMMO2);
53 // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
55 if(wpn == WEP_MINE_LAYER.m_id)
56 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
64 if(IS_REAL_CLIENT(cl))
66 play2(cl, SND(UNAVAILABLE));
67 Send_WeaponComplain (cl, wpn, 0);
77 // Report Proper Weapon Status / Modified Weapon Ownership Message
78 if (weaponsInMap & WepSet_FromWeapon(wpn))
80 Send_WeaponComplain(cl, wpn, 1);
82 if(autocvar_g_showweaponspawns)
86 for(e = world; (e = findfloat(e, weapon, wpn)); )
88 if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
90 if(!(e.flags & FL_ITEM))
92 entity wp = WaypointSprite_Spawn(
95 world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
107 Send_WeaponComplain (cl, wpn, 2);
110 play2(cl, SND(UNAVAILABLE));
115 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
117 // We cannot tokenize in this function, as GiveItems calls this
118 // function. Thus we must use car/cdr.
119 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
120 WepSet wepset = '0 0 0';
121 switchtonext = switchtolast = 0;
122 first_valid = prev_valid = 0;
126 if(skipmissing || pl.selectweapon == 0)
127 weaponcur = pl.switchweapon;
129 weaponcur = pl.selectweapon;
136 string rest = weaponorder;
139 weaponwant = stof(car(rest)); rest = cdr(rest);
140 wep = get_weaponinfo(weaponwant);
141 wepset = WepSet_FromWeapon(weaponwant);
143 if(wep.impulse != imp)
146 float i, have_other = false;
147 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
150 if((get_weaponinfo(i)).impulse == imp || imp < 0)
151 if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
155 // skip weapons we don't own that aren't normal and aren't in the map
156 if(!(pl.weapons & wepset))
157 if(!(weaponsInMap & wepset))
158 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
163 if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
168 first_valid = weaponwant;
169 if(weaponwant == weaponcur)
178 prev_valid = weaponwant;
188 // complain (but only for one weapon on the button that has been pressed)
191 self.weaponcomplainindex += 1;
192 c = (self.weaponcomplainindex % c) + 1;
196 weaponwant = stof(car(rest)); rest = cdr(rest);
197 wep = get_weaponinfo(weaponwant);
198 wepset = WepSet_FromWeapon(weaponwant);
200 if(wep.impulse != imp)
203 float i, have_other = false;
204 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
207 if((get_weaponinfo(i)).impulse == imp || imp < 0)
208 if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
212 // skip weapons we don't own that aren't normal and aren't in the map
213 if(!(pl.weapons & wepset))
214 if(!(weaponsInMap & wepset))
215 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
221 client_hasweapon(pl, weaponwant, true, true);
229 void W_SwitchWeapon_Force(entity e, float w)
231 e.cnt = e.switchweapon;
236 // perform weapon to attack (weaponstate and attack_finished check is here)
237 void W_SwitchToOtherWeapon(entity pl)
239 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
242 if(pl.weapons & WepSet_FromWeapon(w))
244 pl.weapons &= ~WepSet_FromWeapon(w);
245 ww = w_getbestweapon(pl);
246 pl.weapons |= WepSet_FromWeapon(w);
249 ww = w_getbestweapon(pl);
251 W_SwitchWeapon_Force(pl, ww);
254 void W_SwitchWeapon(float imp)
256 if (self.switchweapon != imp)
258 if (client_hasweapon(self, imp, true, true))
259 W_SwitchWeapon_Force(self, imp);
261 self.selectweapon = imp; // update selectweapon ANYWAY
263 else if(!forbidWeaponUse(self)) { _WEP_ACTION(self.weapon, WR_RELOAD); }
266 void W_CycleWeapon(string weaponorder, float dir)
269 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true);
274 void W_NextWeaponOnImpulse(float imp)
277 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
283 void W_NextWeapon(float list)
286 W_CycleWeapon(weaponorder_byid, -1);
288 W_CycleWeapon(self.weaponorder_byimpulse, -1);
290 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
294 void W_PreviousWeapon(float list)
297 W_CycleWeapon(weaponorder_byid, +1);
299 W_CycleWeapon(self.weaponorder_byimpulse, +1);
301 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
304 // previously used if exists and has ammo, (second) best otherwise
305 void W_LastWeapon(void)
307 if(client_hasweapon(self, self.cnt, true, false))
308 W_SwitchWeapon(self.cnt);
310 W_SwitchToOtherWeapon(self);