#include "triggers/subs.qh"
#include "util.qh"
- #include <common/monsters/all.qh>
+ #include <common/monsters/_mod.qh>
#include <common/weapons/_all.qh>
float Item_GiveTo(entity item, entity player)
{
- float _switchweapon;
float pickedup;
// if nothing happens to player, just return without taking the item
pickedup = false;
- _switchweapon = false;
+ int _switchweapon = 0;
// in case the player has autoswitch enabled do the following:
// if the player is using their best weapon before items are given, they
// probably want to switch to an even better weapon after items are given
- if (player.autoswitch)
- if (PS(player).m_switchweapon == w_getbestweapon(player))
- _switchweapon = true;
- if (!(player.weapons & WepSet_FromWeapon(PS(player).m_switchweapon)))
- _switchweapon = true;
+ if(player.autoswitch)
+ {
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ {
+ .entity weaponentity = weaponentities[slot];
+ if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
+ {
+ if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
+ _switchweapon |= BIT(slot);
+
+ if(!(player.weapons & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
+ _switchweapon |= BIT(slot);
+ }
+ }
+ }
pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
FOREACH(Weapons, it != WEP_Null, {
if(w & (it.m_wepset))
{
- W_DropEvent(wr_pickup, player, it.m_id, item);
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ {
+ .entity weaponentity = weaponentities[slot];
+ if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
+ W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
+ }
W_GiveWeapon(player, it.m_id);
}
});
// crude hack to enforce switching weapons
if(g_cts && item.itemdef.instanceOfWeaponPickup)
{
- W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ {
+ .entity weaponentity = weaponentities[slot];
+ if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
+ W_SwitchWeapon_Force(player, Weapons_from(item.weapon), weaponentity);
+ }
return 1;
}
- if (_switchweapon)
- if (PS(player).m_switchweapon != w_getbestweapon(player))
- W_SwitchWeapon_Force(player, w_getbestweapon(player));
+ if(_switchweapon)
+ {
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ {
+ .entity weaponentity = weaponentities[slot];
+ if(_switchweapon & BIT(slot))
+ if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
+ W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
+ }
+ }
return 1;
}
if(this.team)
{
RandomSelection_Init();
- FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
+ IL_EACH(g_items, it.team == this.team,
{
- if(it.team == this.team)
- if(it.classname != "item_flag_team" && it.classname != "item_key_team")
+ if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
{
Item_Show(it, -1);
- RandomSelection_Add(it, 0, string_null, it.cnt, 0);
+ RandomSelection_AddEnt(it, it.cnt, 0);
}
});
e = RandomSelection_chosen_ent;
RandomSelection_Init();
IL_EACH(g_items, it.team == this.team,
{
- if(it.classname != "item_flag_team" && it.classname != "item_key_team")
- RandomSelection_Add(it, 0, string_null, it.cnt, 0);
+ if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
+ RandomSelection_AddEnt(it, it.cnt, 0);
});
e = RandomSelection_chosen_ent;
IL_EACH(g_items, it.team == this.team,
{
- if(it.classname != "item_flag_team" && it.classname != "item_key_team")
+ if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
{
if(it != e)
{
EXACTTRIGGER_TOUCH(this, trigger);
}
- FOREACH_ENTITY_ENT(enemy, actor,
+ IL_EACH(g_items, it.enemy == actor && it.classname == "droppedweapon",
{
- if(it.classname == "droppedweapon")
- delete(it);
+ delete(it);
});
if(GiveItems(actor, 0, tokenize_console(this.netname)))
float GiveItems(entity e, float beginarg, float endarg)
{
float got, i, val, op;
- float _switchweapon;
string cmd;
val = 999;
got = 0;
- _switchweapon = false;
- if (e.autoswitch)
- if (PS(e).m_switchweapon == w_getbestweapon(e))
- _switchweapon = true;
+ int _switchweapon = 0;
+
+ if(e.autoswitch)
+ {
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ {
+ .entity weaponentity = weaponentities[slot];
+ if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
+ if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
+ _switchweapon |= BIT(slot);
+ }
+ }
e.strength_finished = max(0, e.strength_finished - time);
e.invincible_finished = max(0, e.invincible_finished - time);
else
e.superweapons_finished += time;
- if (!(e.weapons & WepSet_FromWeapon(PS(e).m_switchweapon)))
- _switchweapon = true;
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ {
+ .entity weaponentity = weaponentities[slot];
+ if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
+ if(!(e.weapons & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
+ _switchweapon |= BIT(slot);
+ }
+
if(_switchweapon)
- W_SwitchWeapon_Force(e, w_getbestweapon(e));
+ {
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ {
+ .entity weaponentity = weaponentities[slot];
+ if(_switchweapon & BIT(slot))
+ W_SwitchWeapon_Force(e, w_getbestweapon(e, weaponentity), weaponentity);
+ }
+ }
return got;
}