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)
25 if(time < self.hasweapon_complain_spam)
28 if(wpn == WEP_HOOK.m_id && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
32 self.hasweapon_complain_spam = time + 0.2;
34 if (wpn < WEP_FIRST || wpn > WEP_LAST)
37 sprint(self, "Invalid weapon\n");
40 if (cl.weapons & WepSet_FromWeapon(wpn))
44 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
52 f = WEP_ACTION(wpn, WR_CHECKAMMO1);
53 f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
55 // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
57 if(wpn == WEP_MINE_LAYER.m_id)
58 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
66 if(IS_REAL_CLIENT(cl))
68 play2(cl, "weapons/unavailable.wav");
69 Send_WeaponComplain (cl, wpn, 0);
79 // Report Proper Weapon Status / Modified Weapon Ownership Message
80 if (weaponsInMap & WepSet_FromWeapon(wpn))
82 Send_WeaponComplain(cl, wpn, 1);
84 if(autocvar_g_showweaponspawns)
88 for(e = world; (e = findfloat(e, weapon, wpn)); )
90 if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
92 if(!(e.flags & FL_ITEM))
95 (get_weaponinfo(wpn)).wpmodel,
97 world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
101 RADARICON_NONE, '0 0 0'
108 Send_WeaponComplain (cl, wpn, 2);
111 play2(cl, "weapons/unavailable.wav");
116 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
118 // We cannot tokenize in this function, as GiveItems calls this
119 // function. Thus we must use car/cdr.
120 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
121 WepSet wepset = '0 0 0';
122 switchtonext = switchtolast = 0;
123 first_valid = prev_valid = 0;
127 if(skipmissing || pl.selectweapon == 0)
128 weaponcur = pl.switchweapon;
130 weaponcur = pl.selectweapon;
137 string rest = weaponorder;
140 weaponwant = stof(car(rest)); rest = cdr(rest);
141 wep = get_weaponinfo(weaponwant);
142 wepset = WepSet_FromWeapon(weaponwant);
144 if(wep.impulse != imp)
147 float i, have_other = false;
148 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
151 if((get_weaponinfo(i)).impulse == imp || imp < 0)
152 if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
156 // skip weapons we don't own that aren't normal and aren't in the map
157 if(!(pl.weapons & wepset))
158 if(!(weaponsInMap & wepset))
159 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
164 if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
169 first_valid = weaponwant;
170 if(weaponwant == weaponcur)
179 prev_valid = weaponwant;
189 // complain (but only for one weapon on the button that has been pressed)
192 self.weaponcomplainindex += 1;
193 c = (self.weaponcomplainindex % c) + 1;
197 weaponwant = stof(car(rest)); rest = cdr(rest);
198 wep = get_weaponinfo(weaponwant);
199 wepset = WepSet_FromWeapon(weaponwant);
201 if(wep.impulse != imp)
204 float i, have_other = false;
205 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
208 if((get_weaponinfo(i)).impulse == imp || imp < 0)
209 if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
213 // skip weapons we don't own that aren't normal and aren't in the map
214 if(!(pl.weapons & wepset))
215 if(!(weaponsInMap & wepset))
216 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
222 client_hasweapon(pl, weaponwant, true, true);
230 void W_SwitchWeapon_Force(entity e, float w)
232 e.cnt = e.switchweapon;
237 // perform weapon to attack (weaponstate and attack_finished check is here)
238 void W_SwitchToOtherWeapon(entity pl)
240 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
243 if(pl.weapons & WepSet_FromWeapon(w))
245 pl.weapons &= ~WepSet_FromWeapon(w);
246 ww = w_getbestweapon(pl);
247 pl.weapons |= WepSet_FromWeapon(w);
250 ww = w_getbestweapon(pl);
252 W_SwitchWeapon_Force(pl, ww);
255 void W_SwitchWeapon(float imp)
257 if (self.switchweapon != imp)
259 if (client_hasweapon(self, imp, true, true))
260 W_SwitchWeapon_Force(self, imp);
262 self.selectweapon = imp; // update selectweapon ANYWAY
264 else if(!forbidWeaponUse(self)) { WEP_ACTION(self.weapon, WR_RELOAD); }
267 void W_CycleWeapon(string weaponorder, float dir)
270 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true);
275 void W_NextWeaponOnImpulse(float imp)
278 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
284 void W_NextWeapon(float list)
287 W_CycleWeapon(weaponorder_byid, -1);
289 W_CycleWeapon(self.weaponorder_byimpulse, -1);
291 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
295 void W_PreviousWeapon(float list)
298 W_CycleWeapon(weaponorder_byid, +1);
300 W_CycleWeapon(self.weaponorder_byimpulse, +1);
302 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
305 // previously used if exists and has ammo, (second) best otherwise
306 void W_LastWeapon(void)
308 if(client_hasweapon(self, self.cnt, true, false))
309 W_SwitchWeapon(self.cnt);
311 W_SwitchToOtherWeapon(self);