Weapon w = WEP_NEXBALL;
w.wr_resetplayer(w);
plyr.switchweapon = WEP_NEXBALL.m_id;
- W_SwitchWeapon(WEP_NEXBALL.m_id);
+ W_SwitchWeapon(WEP_NEXBALL);
setself(this);
}
Weapon w = WEP_NEXBALL;
w.wr_resetplayer(w);
self.switchweapon = self.(weaponentity).switchweapon;
- W_SwitchWeapon(self.switchweapon);
+ W_SwitchWeapon(Weapons_from(self.switchweapon));
self.(weaponentity).weapons = '0 0 0';
}
e.ammo_rockets = start_ammo_rockets;
e.ammo_fuel = start_ammo_fuel;
e.weapons = start_weapons;
- if(!client_hasweapon(e, e.weapon, true, false))
+ if(!client_hasweapon(e, Weapons_from(e.weapon), true, false))
e.switchweapon = w_getbestweapon(self);
}
}
self.weapons |= e.m_wepset;
if(self.switchweapon != nix_weapon)
- if(!client_hasweapon(self, self.switchweapon, true, false))
- if(client_hasweapon(self, nix_weapon, true, false))
- W_SwitchWeapon(nix_weapon);
+ if(!client_hasweapon(self, Weapons_from(self.switchweapon), true, false))
+ {
+ Weapon w = Weapons_from(nix_weapon);
+ if(client_hasweapon(self, w, true, false))
+ W_SwitchWeapon(w);
+ }
}
MUTATOR_HOOKFUNCTION(nix, ForbidThrowCurrentWeapon)
if(!thiswep.wr_checkammo1(thiswep))
if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
{
- W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
w_ready(thiswep, actor, weaponentity, fire);
return;
}
}
METHOD(Arc, wr_pickup, void(entity thiswep))
{
- if ( !client_hasweapon(self, WEP_ARC.m_id, false, false) &&
+ if ( !client_hasweapon(self, thiswep, false, false) &&
weapon_dropevent_item.arc_overheat > time )
{
self.arc_overheat = weapon_dropevent_item.arc_overheat;
if(!thiswep.wr_checkammo1(thiswep))
if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
{
- W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
w_ready(thiswep, actor, weaponentity, fire);
return;
}
{
actor.ammo_fuel = 0;
actor.hook_state |= HOOK_REMOVING;
- W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
}
}
}
if(!thiswep.wr_checkammo2(thiswep))
if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
{
- W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
w_ready(thiswep, actor, weaponentity, fire);
return;
}
if(!thiswep.wr_checkammo1(thiswep))
if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
{
- W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
w_ready(thiswep, actor, weaponentity, fire);
return;
}
if(!thiswep.wr_checkammo2(thiswep))
if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
{
- W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
w_ready(thiswep, actor, weaponentity, fire);
return;
}
if (!thiswep.wr_checkammo2(thiswep))
if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
{
- W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
w_ready(thiswep, actor, weaponentity, fire);
return;
}
if (!thiswep.wr_checkammo2(thiswep))
if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
{
- W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
w_ready(thiswep, actor, weaponentity, fire);
return;
}
else if(self.health>WEP_CVAR(devastator, damage)*0.5)
{
if(self.velocity.z < 0)
- if(client_hasweapon(self, WEP_DEVASTATOR.m_id, true, false))
+ if(client_hasweapon(self, WEP_DEVASTATOR, true, false))
{
self.movement_x = maxspeed;
if(self.weapon==0)
for(i = WEP_FIRST; i <= WEP_LAST; ++i) if(i != WEP_BLASTER.m_id)
{
- if(client_hasweapon(self, i, true, false))
+ if(client_hasweapon(self, Weapons_from(i), true, false))
{
self.switchweapon = i;
return;
if ( distance > bot_distance_far ) {
for(i=0; i < Weapons_COUNT && bot_weapons_far[i] != -1 ; ++i){
w = bot_weapons_far[i];
- if ( client_hasweapon(self, w, true, false) )
+ if ( client_hasweapon(self, Weapons_from(w), true, false) )
{
if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
continue;
if ( distance > bot_distance_close) {
for(i=0; i < Weapons_COUNT && bot_weapons_mid[i] != -1 ; ++i){
w = bot_weapons_mid[i];
- if ( client_hasweapon(self, w, true, false) )
+ if ( client_hasweapon(self, Weapons_from(w), true, false) )
{
if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
continue;
// Choose weapons for close distance
for(i=0; i < Weapons_COUNT && bot_weapons_close[i] != -1 ; ++i){
w = bot_weapons_close[i];
- if ( client_hasweapon(self, w, true, false) )
+ if ( client_hasweapon(self, Weapons_from(w), true, false) )
{
if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
continue;
float bot_cmd_select_weapon()
{SELFPARAM();
- float id;
-
- id = bot_cmd.bot_cmd_parm_float;
+ float id = bot_cmd.bot_cmd_parm_float;
if(id < WEP_FIRST || id > WEP_LAST)
return CMD_STATUS_ERROR;
- if(client_hasweapon(self, id, true, false))
+ if(client_hasweapon(self, Weapons_from(id), true, false))
self.switchweapon = id;
else
return CMD_STATUS_ERROR;
{ \
if (this.vehicle) return; \
if (this.deadflag != DEAD_NO) return; \
- W_SwitchWeapon(WEP_FIRST + i); \
+ W_SwitchWeapon(Weapons_from(WEP_FIRST + i)); \
}
X(0)
X(1)
{
if (this.vehicle) return;
if (this.deadflag != DEAD_NO) return;
- W_SwitchWeapon(w_getbestweapon(this));
+ W_SwitchWeapon(Weapons_from(w_getbestweapon(this)));
}
IMPULSE(weapon_drop)
// WEAPONTODO
.float autoswitch;
-float client_hasweapon(entity cl, float wpn, float andammo, float complain);
+bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain);
void w_clear(Weapon thiswep, entity actor, .entity weaponentity, int fire);
void w_ready(Weapon thiswep, entity actor, .entity weaponentity, int fire);
// VorteX: standalone think for weapons, so normal think on weaponentity can be reserved by weaponflashes (which needs update even player dies)
// after a frag, choose another random weapon set
if (!(attacker.weapons & WepSet_FromWeapon(Weapons_from(attacker.weapon))))
- W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
+ W_SwitchWeapon_Force(attacker, Weapons_from(w_getbestweapon(attacker)));
}
// FIXME fix the mess this is (we have REAL points now!)
void UpdateFrags(entity player, float f);
// NOTE: f=0 means still count as a (positive) kill, but count no frags for it
-void W_SwitchWeapon_Force(entity e, float w);
+void W_SwitchWeapon_Force(entity e, Weapon w);
entity GiveFrags_randomweapons;
void GiveFrags (entity attacker, entity targ, float f, int deathtype);
// crude hack to enforce switching weapons
if(g_cts && item.itemdef.instanceOfWeaponPickup)
{
- W_SwitchWeapon_Force(player, item.weapon);
+ W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
return 1;
}
if (_switchweapon)
if (player.switchweapon != w_getbestweapon(player))
- W_SwitchWeapon_Force(player, w_getbestweapon(player));
+ W_SwitchWeapon_Force(player, Weapons_from(w_getbestweapon(player)));
return 1;
}
if (!(e.weapons & WepSet_FromWeapon(Weapons_from(e.switchweapon))))
_switchweapon = true;
if(_switchweapon)
- W_SwitchWeapon_Force(e, w_getbestweapon(e));
+ W_SwitchWeapon_Force(e, Weapons_from(w_getbestweapon(e)));
return got;
}
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;
// ignore hook button when using other offhand equipment
if (cl.offhand != OFFHAND_HOOK)
- if (wpn == WEP_HOOK.m_id && !((cl.weapons | weaponsInMap) & WepSet_FromWeapon(Weapons_from(wpn))))
+ 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(Weapons_from(wpn)))
+ if (cl.weapons & WepSet_FromWeapon(wpn))
{
if (andammo)
{
}
else
{
- setself(cl);
- Weapon w = Weapons_from(wpn);
- f = w.wr_checkammo1(w) + w.wr_checkammo2(w);
+ 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;
}
{
// DRESK - 3/16/07
// Report Proper Weapon Status / Modified Weapon Ownership Message
- if (weaponsInMap & WepSet_FromWeapon(Weapons_from(wpn)))
+ 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(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));
if(wep.impulse != imp)
continue;
- float i, have_other = false;
- for(i = WEP_FIRST; i <= WEP_LAST; ++i)
- {
- Weapon e = Weapons_from(i);
+ bool have_other = false;
+ FOREACH(Weapons, it != WEP_Null, {
if(i != weaponwant)
- if(e.impulse == imp || imp < 0)
- if((pl.weapons & (e.m_wepset)) || (weaponsInMap & (e.m_wepset)))
+ 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;
if(wep.impulse != imp)
continue;
- float i, have_other = false;
- for(i = WEP_FIRST; i <= WEP_LAST; ++i)
- {
- Weapon w = Weapons_from(i);
+ bool have_other = false;
+ FOREACH(Weapons, it != WEP_Null, {
if(i != weaponwant)
- if(w.impulse == imp || imp < 0)
- if((pl.weapons & (w.m_wepset)) || (weaponsInMap & (w.m_wepset)))
+ 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)
{
+ int w = wep.m_id;
e.cnt = e.switchweapon;
e.switchweapon = w;
e.selectweapon = w;
else
ww = w_getbestweapon(pl);
if(ww)
- W_SwitchWeapon_Force(pl, ww);
+ W_SwitchWeapon_Force(pl, Weapons_from(ww));
}
-void W_SwitchWeapon(float imp)
+void W_SwitchWeapon(Weapon w)
{SELFPARAM();
+ int imp = w.m_id;
if (self.switchweapon != imp)
{
- 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
}
else if(!forbidWeaponUse(self)) {
- Weapon w = Weapons_from(self.weapon);
w.wr_reload(w);
}
}
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()
{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);
}
void Send_WeaponComplain(entity e, float wpn, float type);
.float hasweapon_complain_spam;
-float client_hasweapon(entity cl, float wpn, float andammo, float complain);
+bool client_hasweapon(entity cl, Weapon wpn, float andammo, bool complain);
.int weaponcomplainindex;
float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, float complain, float skipmissing);
#define w_getbestweapon(ent) W_GetCycleWeapon(ent, ent.cvar_cl_weaponpriority, 0, -1, false, true)
-void W_SwitchWeapon_Force(entity e, float w);
+void W_SwitchWeapon_Force(entity e, Weapon w);
// perform weapon to attack (weaponstate and attack_finished check is here)
void W_SwitchToOtherWeapon(entity pl);
-void W_SwitchWeapon(float imp);
+void W_SwitchWeapon(Weapon imp);
void W_CycleWeapon(string weaponorder, float dir);
if(!(self.weapons & set)) return;
self.weapons &= ~set;
- W_SwitchWeapon_Force(self, w_getbestweapon(self));
+ W_SwitchWeapon_Force(self, Weapons_from(w_getbestweapon(self)));
string a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
if(!a) return;
{
if (w && !(actor.weapons & WepSet_FromWeapon(Weapons_from(w))))
{
- if (actor.weapon == actor.switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
+ if (actor.weapon == actor.switchweapon) W_SwitchWeapon_Force(actor, Weapons_from(w_getbestweapon(actor)));
w = 0;
}
}
else
{
- if (key_pressed && actor.switchweapon != WEP_HOOK.m_id && !actor.hook_switchweapon) W_SwitchWeapon(
- WEP_HOOK.m_id);
+ if (key_pressed && actor.switchweapon != WEP_HOOK.m_id && !actor.hook_switchweapon)
+ W_SwitchWeapon(WEP_HOOK);
actor.hook_switchweapon = key_pressed;
Weapon h = WEP_HOOK;
block_weapon = (actor.weapon == h.m_id && (actor.BUTTON_ATCK || key_pressed));