#include "selection.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"
+#include <common/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)
WriteByte(MSG_ONE, type);
}
+void Weapon_whereis(Weapon this, entity cl)
+{
+ if (!autocvar_g_showweaponspawns) return;
+ for (entity it = NULL; (it = findfloat(it, weapon, this.m_id)); )
+ {
+ if (it.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
+ continue;
+ if (!(it.flags & FL_ITEM))
+ continue;
+ entity wp = WaypointSprite_Spawn(
+ WP_Weapon,
+ 1, 0,
+ NULL, it.origin + ('0 0 1' * it.maxs.z) * 1.2,
+ cl, 0,
+ NULL, enemy,
+ 0,
+ RADARICON_NONE
+ );
+ wp.wp_extra = this.m_id;
+ }
+}
+
bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain)
{
- float f;
+ float f = 0;
if (time < cl.hasweapon_complain_spam)
complain = 0;
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)
- for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == cl)
- f = 1;
-
+ FOREACH_ENTITY_CLASS("mine", it.owner == cl,
+ {
+ f = 1;
+ break; // no need to continue
+ });
}
if (!f)
{
if (weaponsInMap & WepSet_FromWeapon(wpn))
{
Send_WeaponComplain(cl, wpn.m_id, 1);
-
- if(autocvar_g_showweaponspawns)
- {
- entity e;
-
- for(e = world; (e = findfloat(e, weapon, wpn.m_id)); )
- {
- if(e.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2)
- continue;
- if(!(e.flags & FL_ITEM))
- continue;
- entity wp = WaypointSprite_Spawn(
- WP_Weapon,
- 1, 0,
- world, e.origin + ('0 0 1' * e.maxs.z) * 1.2,
- cl, 0,
- world, enemy,
- 0,
- RADARICON_NONE
- );
- wp.wp_extra = wpn.m_id;
- }
- }
+ Weapon_whereis(wpn, cl);
}
else
{
entity wep;
if(skipmissing || pl.selectweapon == 0)
- weaponcur = pl.switchweapon;
+ weaponcur = PS(pl).m_switchweapon.m_id;
else
weaponcur = pl.selectweapon;
void W_SwitchWeapon_Force(entity e, Weapon wep)
{
- int w = wep.m_id;
- 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)
- int ww;
- WepSet set = WepSet_FromWeapon(Weapons_from(pl.weapon));
- if(pl.weapons & set)
+ Weapon ww;
+ WepSet set = WepSet_FromWeapon(PS(pl).m_weapon);
+ if (pl.weapons & set)
{
pl.weapons &= ~set;
ww = w_getbestweapon(pl);
pl.weapons |= set;
}
else
+ {
ww = w_getbestweapon(pl);
- if(ww)
- W_SwitchWeapon_Force(pl, Weapons_from(ww));
+ }
+ if (ww == WEP_Null) return;
+ W_SwitchWeapon_Force(pl, ww);
}
void W_SwitchWeapon(Weapon w)
{SELFPARAM();
- int imp = w.m_id;
- if (self.switchweapon != imp)
+ if (PS(self).m_switchweapon != w)
{
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);
+ entity actor = this;
+ .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+ w.wr_reload(w, actor, weaponentity);
}
}
}
// previously used if exists and has ammo, (second) best otherwise
-void W_LastWeapon()
-{SELFPARAM();
- Weapon wep = Weapons_from(self.cnt);
- if(client_hasweapon(self, wep, true, false))
+void W_LastWeapon(entity this)
+{
+ Weapon wep = Weapons_from(this.cnt);
+ if (client_hasweapon(this, wep, true, false))
W_SwitchWeapon(wep);
else
- W_SwitchToOtherWeapon(self);
+ W_SwitchToOtherWeapon(this);
}