#include "selection.qh"
-#include "../_all.qh"
#include "weaponsystem.qh"
#include "../t_items.qh"
#include "../../common/constants.qh"
#include "../../common/util.qh"
+#include "../../common/items/item.qh"
#include "../../common/weapons/all.qh"
+#include "../../common/mutators/mutator/waypoints/waypointsprites.qh"
// switch between weapons
void Send_WeaponComplain(entity e, float wpn, float type)
{
msg_entity = e;
- WriteByte(MSG_ONE, SVC_TEMPENTITY);
- WriteByte(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN);
+ WriteHeader(MSG_ONE, TE_CSQC_WEAPONCOMPLAIN);
WriteByte(MSG_ONE, wpn);
WriteByte(MSG_ONE, type);
}
-float client_hasweapon(entity cl, float wpn, float andammo, float complain)
-{SELFPARAM();
+bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain)
+{
float f;
- if(time < self.hasweapon_complain_spam)
+ if (time < cl.hasweapon_complain_spam)
complain = 0;
- if(wpn == WEP_HOOK.m_id && !g_grappling_hook && autocvar_g_nades && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
- complain = 0;
+ // ignore hook button when using other offhand equipment
+ if (cl.offhand != OFFHAND_HOOK)
+ if (wpn == WEP_HOOK && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(wpn)))
+ complain = 0;
- if(complain)
- self.hasweapon_complain_spam = time + 0.2;
+ if (complain)
+ cl.hasweapon_complain_spam = time + 0.2;
- if (wpn < WEP_FIRST || wpn > WEP_LAST)
+ if (wpn == WEP_Null)
{
if (complain)
- sprint(self, "Invalid weapon\n");
+ sprint(cl, "Invalid weapon\n");
return false;
}
if (cl.weapons & WepSet_FromWeapon(wpn))
}
else
{
- setself(cl);
- f = WEP_ACTION(wpn, WR_CHECKAMMO1);
- f = f + WEP_ACTION(wpn, WR_CHECKAMMO2);
+ WITH(entity, self, cl, f = wpn.wr_checkammo1(wpn) + wpn.wr_checkammo2(wpn));
// always allow selecting the Mine Layer if we placed mines, so that we can detonate them
entity mine;
- if(wpn == WEP_MINE_LAYER.m_id)
- for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
+ if(wpn == WEP_MINE_LAYER)
+ for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == cl)
f = 1;
- setself(this);
}
if (!f)
{
if(IS_REAL_CLIENT(cl))
{
play2(cl, SND(UNAVAILABLE));
- Send_WeaponComplain (cl, wpn, 0);
+ Send_WeaponComplain (cl, wpn.m_id, 0);
}
return false;
}
// Report Proper Weapon Status / Modified Weapon Ownership Message
if (weaponsInMap & WepSet_FromWeapon(wpn))
{
- Send_WeaponComplain(cl, wpn, 1);
+ Send_WeaponComplain(cl, wpn.m_id, 1);
if(autocvar_g_showweaponspawns)
{
- entity e;
-
- for(e = world; (e = findfloat(e, weapon, wpn)); )
+ for(entity e = world; (e = findfloat(e, weapon, wpn.m_id)); )
{
if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
continue;
WP_Weapon,
1, 0,
world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
- self, 0,
+ cl, 0,
world, enemy,
0,
RADARICON_NONE
);
- wp.wp_extra = wpn;
+ wp.wp_extra = wpn.m_id;
}
}
}
else
{
- Send_WeaponComplain (cl, wpn, 2);
+ Send_WeaponComplain (cl, wpn.m_id, 2);
}
play2(cl, SND(UNAVAILABLE));
entity wep;
if(skipmissing || pl.selectweapon == 0)
- weaponcur = pl.switchweapon;
+ weaponcur = PS(pl).m_switchweapon.m_id;
else
weaponcur = pl.selectweapon;
while(rest != "")
{
weaponwant = stof(car(rest)); rest = cdr(rest);
- wep = get_weaponinfo(weaponwant);
- wepset = WepSet_FromWeapon(weaponwant);
+ wep = Weapons_from(weaponwant);
+ wepset = wep.m_wepset;
if(imp >= 0)
if(wep.impulse != imp)
continue;
- float i, have_other = false;
- for(i = WEP_FIRST; i <= WEP_LAST; ++i)
- {
+ bool have_other = false;
+ FOREACH(Weapons, it != WEP_Null, {
if(i != weaponwant)
- if((get_weaponinfo(i)).impulse == imp || imp < 0)
- if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
+ if(it.impulse == imp || imp < 0)
+ if((pl.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset)))
have_other = true;
- }
+ });
// skip weapons we don't own that aren't normal and aren't in the map
if(!(pl.weapons & wepset))
++c;
- if(!skipmissing || client_hasweapon(pl, weaponwant, true, false))
+ if(!skipmissing || client_hasweapon(pl, wep, true, false))
{
if(switchtonext)
return weaponwant;
while(rest != "")
{
weaponwant = stof(car(rest)); rest = cdr(rest);
- wep = get_weaponinfo(weaponwant);
- wepset = WepSet_FromWeapon(weaponwant);
+ wep = Weapons_from(weaponwant);
+ wepset = wep.m_wepset;
if(imp >= 0)
if(wep.impulse != imp)
continue;
- float i, have_other = false;
- for(i = WEP_FIRST; i <= WEP_LAST; ++i)
- {
+ bool have_other = false;
+ FOREACH(Weapons, it != WEP_Null, {
if(i != weaponwant)
- if((get_weaponinfo(i)).impulse == imp || imp < 0)
- if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
+ if(it.impulse == imp || imp < 0)
+ if((pl.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset)))
have_other = true;
- }
+ });
// skip weapons we don't own that aren't normal and aren't in the map
if(!(pl.weapons & wepset))
--c;
if(c == 0)
{
- client_hasweapon(pl, weaponwant, true, true);
+ client_hasweapon(pl, wep, true, true);
break;
}
}
return 0;
}
-void W_SwitchWeapon_Force(entity e, float w)
+void W_SwitchWeapon_Force(entity e, Weapon wep)
{
- e.cnt = e.switchweapon;
- e.switchweapon = w;
- e.selectweapon = w;
+ e.cnt = PS(e).m_switchweapon.m_id;
+ PS(e).m_switchweapon = wep;
+ e.selectweapon = wep.m_id;
}
// perform weapon to attack (weaponstate and attack_finished check is here)
void W_SwitchToOtherWeapon(entity pl)
{
// hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
- float w, ww;
- w = pl.weapon;
- if(pl.weapons & WepSet_FromWeapon(w))
+ Weapon ww;
+ WepSet set = WepSet_FromWeapon(Weapons_from(pl.weapon));
+ if(pl.weapons & set)
{
- pl.weapons &= ~WepSet_FromWeapon(w);
+ pl.weapons &= ~set;
ww = w_getbestweapon(pl);
- pl.weapons |= WepSet_FromWeapon(w);
+ pl.weapons |= set;
}
else
ww = w_getbestweapon(pl);
W_SwitchWeapon_Force(pl, ww);
}
-void W_SwitchWeapon(float imp)
+void W_SwitchWeapon(Weapon w)
{SELFPARAM();
- if (self.switchweapon != imp)
+ if (PS(self).m_switchweapon != w)
{
- if (client_hasweapon(self, imp, true, true))
- W_SwitchWeapon_Force(self, imp);
+ if (client_hasweapon(self, w, true, true))
+ W_SwitchWeapon_Force(self, w);
else
- self.selectweapon = imp; // update selectweapon ANYWAY
+ self.selectweapon = w.m_id; // update selectweapon ANYWAY
+ }
+ else if(!forbidWeaponUse(self)) {
+ w.wr_reload(w);
}
- else if(!forbidWeaponUse(self)) { WEP_ACTION(self.weapon, WR_RELOAD); }
}
void W_CycleWeapon(string weaponorder, float dir)
float w;
w = W_GetCycleWeapon(self, weaponorder, dir, -1, 1, true);
if(w > 0)
- W_SwitchWeapon(w);
+ W_SwitchWeapon(Weapons_from(w));
}
void W_NextWeaponOnImpulse(float imp)
float w;
w = W_GetCycleWeapon(self, self.cvar_cl_weaponpriority, +1, imp, 1, (self.cvar_cl_weaponimpulsemode == 0));
if(w > 0)
- W_SwitchWeapon(w);
+ W_SwitchWeapon(Weapons_from(w));
}
// next weapon
}
// previously used if exists and has ammo, (second) best otherwise
-void W_LastWeapon(void)
+void W_LastWeapon()
{SELFPARAM();
- if(client_hasweapon(self, self.cnt, true, false))
- W_SwitchWeapon(self.cnt);
+ Weapon wep = Weapons_from(self.cnt);
+ if(client_hasweapon(self, wep, true, false))
+ W_SwitchWeapon(wep);
else
W_SwitchToOtherWeapon(self);
}