4 #include "../../dpdefs/progsdefs.qh"
5 #include "../../dpdefs/dpextensions.qh"
6 #include "../../common/constants.qh"
7 #include "../../common/util.qh"
8 #include "../../common/weapons/weapons.qh"
9 #include "selection.qh"
10 #include "weaponsystem.qh"
11 #include "../t_items.qh"
12 #include "../autocvars.qh"
16 // switch between weapons
17 void Send_WeaponComplain(entity e, float wpn, float type)
20 WriteByte(MSG_ONE, SVC_TEMPENTITY);
21 WriteByte(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN);
22 WriteByte(MSG_ONE, wpn);
23 WriteByte(MSG_ONE, type);
26 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
31 if(time < self.hasweapon_complain_spam)
34 if(wpn == WEP_HOOK && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
38 self.hasweapon_complain_spam = time + 0.2;
40 if (wpn < WEP_FIRST || wpn > WEP_LAST)
43 sprint(self, "Invalid weapon\n");
46 if (cl.weapons & WepSet_FromWeapon(wpn))
50 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
58 f = WEP_ACTION(wpn, WR_CHECKAMMO1);
59 f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
61 // always allow selecting the Mine Layer if we placed mines, so that we can detonate them
63 if(wpn == WEP_MINE_LAYER)
64 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
72 if(IS_REAL_CLIENT(cl))
74 play2(cl, "weapons/unavailable.wav");
75 Send_WeaponComplain (cl, wpn, 0);
85 // Report Proper Weapon Status / Modified Weapon Ownership Message
86 if (weaponsInMap & WepSet_FromWeapon(wpn))
88 Send_WeaponComplain(cl, wpn, 1);
90 if(autocvar_g_showweaponspawns)
94 for(e = world; (e = findfloat(e, weapon, wpn)); )
96 if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
98 if(!(e.flags & FL_ITEM))
100 WaypointSprite_Spawn(
101 (get_weaponinfo(wpn)).wpmodel,
103 world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
107 RADARICON_NONE, '0 0 0'
114 Send_WeaponComplain (cl, wpn, 2);
117 play2(cl, "weapons/unavailable.wav");
122 float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing)
124 // We cannot tokenize in this function, as GiveItems calls this
125 // function. Thus we must use car/cdr.
126 float weaponwant, first_valid, prev_valid, switchtonext, switchtolast;
127 WepSet wepset = '0 0 0';
128 switchtonext = switchtolast = 0;
129 first_valid = prev_valid = 0;
133 if(skipmissing || pl.selectweapon == 0)
134 weaponcur = pl.switchweapon;
136 weaponcur = pl.selectweapon;
143 string rest = weaponorder;
146 weaponwant = stof(car(rest)); rest = cdr(rest);
147 wep = get_weaponinfo(weaponwant);
148 wepset = WepSet_FromWeapon(weaponwant);
150 if(wep.impulse != imp)
153 float i, have_other = false;
154 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
157 if((get_weaponinfo(i)).impulse == imp || imp < 0)
158 if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
162 // skip weapons we don't own that aren't normal and aren't in the map
163 if(!(pl.weapons & wepset))
164 if(!(weaponsInMap & wepset))
165 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
170 if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
175 first_valid = weaponwant;
176 if(weaponwant == weaponcur)
185 prev_valid = weaponwant;
195 // complain (but only for one weapon on the button that has been pressed)
198 self.weaponcomplainindex += 1;
199 c = (self.weaponcomplainindex % c) + 1;
203 weaponwant = stof(car(rest)); rest = cdr(rest);
204 wep = get_weaponinfo(weaponwant);
205 wepset = WepSet_FromWeapon(weaponwant);
207 if(wep.impulse != imp)
210 float i, have_other = false;
211 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
214 if((get_weaponinfo(i)).impulse == imp || imp < 0)
215 if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
219 // skip weapons we don't own that aren't normal and aren't in the map
220 if(!(pl.weapons & wepset))
221 if(!(weaponsInMap & wepset))
222 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
228 client_hasweapon(pl, weaponwant, true, true);
236 void W_SwitchWeapon_Force(entity e, float w)
238 e.cnt = e.switchweapon;
243 // perform weapon to attack (weaponstate and attack_finished check is here)
244 void W_SwitchToOtherWeapon(entity pl)
246 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
249 if(pl.weapons & WepSet_FromWeapon(w))
251 pl.weapons &= ~WepSet_FromWeapon(w);
252 ww = w_getbestweapon(pl);
253 pl.weapons |= WepSet_FromWeapon(w);
256 ww = w_getbestweapon(pl);
258 W_SwitchWeapon_Force(pl, ww);
261 void W_SwitchWeapon(float imp)
263 if (self.switchweapon != imp)
265 if (client_hasweapon(self, imp, true, true))
266 W_SwitchWeapon_Force(self, imp);
268 self.selectweapon = imp; // update selectweapon ANYWAY
270 else if(!forbidWeaponUse()) { WEP_ACTION(self.weapon, WR_RELOAD); }
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
312 void W_LastWeapon(void)
314 if(client_hasweapon(self, self.cnt, true, false))
315 W_SwitchWeapon(self.cnt);
317 W_SwitchToOtherWeapon(self);