1 #include "selection.qh"
3 #include "weaponsystem.qh"
4 #include "../t_items.qh"
5 #include "../../common/constants.qh"
6 #include "../../common/util.qh"
7 #include "../../common/items/item.qh"
8 #include "../../common/weapons/all.qh"
9 #include "../../common/mutators/mutator/waypoints/waypointsprites.qh"
11 // switch between weapons
12 void Send_WeaponComplain(entity e, float wpn, float type)
15 WriteHeader(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 // ignore hook button when using other offhand equipment
28 if (cl.offhand != OFFHAND_HOOK)
29 if (wpn == WEP_HOOK.m_id && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
33 self.hasweapon_complain_spam = time + 0.2;
35 if (wpn < WEP_FIRST || wpn > WEP_LAST)
38 sprint(self, "Invalid weapon\n");
41 if (cl.weapons & WepSet_FromWeapon(wpn))
45 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
52 Weapon w = get_weaponinfo(wpn);
53 f = w.wr_checkammo1(w) + w.wr_checkammo2(w);
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, SND(UNAVAILABLE));
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))
94 entity wp = WaypointSprite_Spawn(
97 world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
109 Send_WeaponComplain (cl, wpn, 2);
112 play2(cl, SND(UNAVAILABLE));
117 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
119 // We cannot tokenize in this function, as GiveItems calls this
120 // function. Thus we must use car/cdr.
121 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
122 WepSet wepset = '0 0 0';
123 switchtonext = switchtolast = 0;
124 first_valid = prev_valid = 0;
128 if(skipmissing || pl.selectweapon == 0)
129 weaponcur = pl.switchweapon;
131 weaponcur = pl.selectweapon;
138 string rest = weaponorder;
141 weaponwant = stof(car(rest)); rest = cdr(rest);
142 wep = get_weaponinfo(weaponwant);
143 wepset = wep.m_wepset;
145 if(wep.impulse != imp)
148 float i, have_other = false;
149 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
151 Weapon e = get_weaponinfo(i);
153 if(e.impulse == imp || imp < 0)
154 if((pl.weapons & (e.m_wepset)) || (weaponsInMap & (e.m_wepset)))
158 // skip weapons we don't own that aren't normal and aren't in the map
159 if(!(pl.weapons & wepset))
160 if(!(weaponsInMap & wepset))
161 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
166 if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
171 first_valid = weaponwant;
172 if(weaponwant == weaponcur)
181 prev_valid = weaponwant;
191 // complain (but only for one weapon on the button that has been pressed)
194 self.weaponcomplainindex += 1;
195 c = (self.weaponcomplainindex % c) + 1;
199 weaponwant = stof(car(rest)); rest = cdr(rest);
200 wep = get_weaponinfo(weaponwant);
201 wepset = wep.m_wepset;
203 if(wep.impulse != imp)
206 float i, have_other = false;
207 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
209 Weapon w = get_weaponinfo(i);
211 if(w.impulse == imp || imp < 0)
212 if((pl.weapons & (w.m_wepset)) || (weaponsInMap & (w.m_wepset)))
216 // skip weapons we don't own that aren't normal and aren't in the map
217 if(!(pl.weapons & wepset))
218 if(!(weaponsInMap & wepset))
219 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
225 client_hasweapon(pl, weaponwant, true, true);
233 void W_SwitchWeapon_Force(entity e, float w)
235 e.cnt = e.switchweapon;
240 // perform weapon to attack (weaponstate and attack_finished check is here)
241 void W_SwitchToOtherWeapon(entity pl)
243 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
245 WepSet set = WepSet_FromWeapon(pl.weapon);
249 ww = w_getbestweapon(pl);
253 ww = w_getbestweapon(pl);
255 W_SwitchWeapon_Force(pl, ww);
258 void W_SwitchWeapon(float imp)
260 if (self.switchweapon != imp)
262 if (client_hasweapon(self, imp, true, true))
263 W_SwitchWeapon_Force(self, imp);
265 self.selectweapon = imp; // update selectweapon ANYWAY
267 else if(!forbidWeaponUse(self)) {
268 Weapon w = get_weaponinfo(self.weapon);
273 void W_CycleWeapon(string weaponorder, float dir)
276 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true);
281 void W_NextWeaponOnImpulse(float imp)
284 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
290 void W_NextWeapon(float list)
293 W_CycleWeapon(weaponorder_byid, -1);
295 W_CycleWeapon(self.weaponorder_byimpulse, -1);
297 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
301 void W_PreviousWeapon(float list)
304 W_CycleWeapon(weaponorder_byid, +1);
306 W_CycleWeapon(self.weaponorder_byimpulse, +1);
308 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
311 // previously used if exists and has ammo, (second) best otherwise
314 if(client_hasweapon(self, self.cnt, true, false))
315 W_SwitchWeapon(self.cnt);
317 W_SwitchToOtherWeapon(self);