4 #include "../../dpdefs/progsdefs.qc"
5 #include "../../dpdefs/dpextensions.qc"
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, c;
128 WepSet wepset = '0 0 0';
129 switchtonext = switchtolast = 0;
130 first_valid = prev_valid = 0;
134 if(skipmissing || pl.selectweapon == 0)
135 weaponcur = pl.switchweapon;
137 weaponcur = pl.selectweapon;
147 weaponwant = stof(car(rest)); rest = cdr(rest);
148 wep = get_weaponinfo(weaponwant);
149 wepset = WepSet_FromWeapon(weaponwant);
151 if(wep.impulse != imp)
154 float i, have_other = false;
155 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
158 if((get_weaponinfo(i)).impulse == imp || imp < 0)
159 if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
163 // skip weapons we don't own that aren't normal and aren't in the map
164 if(!(pl.weapons & wepset))
165 if(!(weaponsInMap & wepset))
166 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
171 if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
176 first_valid = weaponwant;
177 if(weaponwant == weaponcur)
186 prev_valid = weaponwant;
196 // complain (but only for one weapon on the button that has been pressed)
199 self.weaponcomplainindex += 1;
200 c = (self.weaponcomplainindex % c) + 1;
204 weaponwant = stof(car(rest)); rest = cdr(rest);
205 wep = get_weaponinfo(weaponwant);
206 wepset = WepSet_FromWeapon(weaponwant);
208 if(wep.impulse != imp)
211 float i, have_other = false;
212 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
215 if((get_weaponinfo(i)).impulse == imp || imp < 0)
216 if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
220 // skip weapons we don't own that aren't normal and aren't in the map
221 if(!(pl.weapons & wepset))
222 if(!(weaponsInMap & wepset))
223 if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other)
229 client_hasweapon(pl, weaponwant, true, true);
237 void W_SwitchWeapon_Force(entity e, float w)
239 e.cnt = e.switchweapon;
244 // perform weapon to attack (weaponstate and attack_finished check is here)
245 void W_SwitchToOtherWeapon(entity pl)
247 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
250 if(pl.weapons & WepSet_FromWeapon(w))
252 pl.weapons &= ~WepSet_FromWeapon(w);
253 ww = w_getbestweapon(pl);
254 pl.weapons |= WepSet_FromWeapon(w);
257 ww = w_getbestweapon(pl);
259 W_SwitchWeapon_Force(pl, ww);
262 void W_SwitchWeapon(float imp)
264 if (self.switchweapon != imp)
266 if (client_hasweapon(self, imp, true, true))
267 W_SwitchWeapon_Force(self, imp);
269 self.selectweapon = imp; // update selectweapon ANYWAY
271 else if(!forbidWeaponUse()) { WEP_ACTION(self.weapon, WR_RELOAD); }
274 void W_CycleWeapon(string weaponorder, float dir)
277 w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true);
282 void W_NextWeaponOnImpulse(float imp)
285 w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
291 void W_NextWeapon(float list)
294 W_CycleWeapon(weaponorder_byid, -1);
296 W_CycleWeapon(self.weaponorder_byimpulse, -1);
298 W_CycleWeapon(self.cvar_cl_weaponpriority, -1);
302 void W_PreviousWeapon(float list)
305 W_CycleWeapon(weaponorder_byid, +1);
307 W_CycleWeapon(self.weaponorder_byimpulse, +1);
309 W_CycleWeapon(self.cvar_cl_weaponpriority, +1);
312 // previously used if exists and has ammo, (second) best otherwise
313 void W_LastWeapon(void)
315 if(client_hasweapon(self, self.cnt, true, false))
316 W_SwitchWeapon(self.cnt);
318 W_SwitchToOtherWeapon(self);