]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/t_items.qc
Add a networked entity to hold weapon state
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / t_items.qc
index ebc971141447e77c2a5a72ad18f11e05746b392b..6949035771def8d53ad46eddd5885735e02081e0 100644 (file)
@@ -18,7 +18,7 @@
        #include "triggers/subs.qh"
     #include "util.qh"
 
-    #include <common/monsters/all.qh>
+    #include <common/monsters/_mod.qh>
 
     #include <common/weapons/_all.qh>
 
@@ -675,6 +675,8 @@ float Item_GiveTo(entity item, entity player)
        float _switchweapon;
        float pickedup;
 
+       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+
        // if nothing happens to player, just return without taking the item
        pickedup = false;
        _switchweapon = false;
@@ -682,10 +684,10 @@ float Item_GiveTo(entity item, entity player)
        // 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))
+       if (player.(weaponentity).m_switchweapon == w_getbestweapon(player))
                _switchweapon = true;
 
-       if (!(player.weapons & WepSet_FromWeapon(PS(player).m_switchweapon)))
+       if (!(player.weapons & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
                _switchweapon = true;
 
        pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
@@ -760,13 +762,13 @@ LABEL(skip)
        // crude hack to enforce switching weapons
        if(g_cts && item.itemdef.instanceOfWeaponPickup)
        {
-               W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
+               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 (player.(weaponentity).m_switchweapon != w_getbestweapon(player))
+                       W_SwitchWeapon_Force(player, w_getbestweapon(player), weaponentity);
 
        return 1;
 }
@@ -835,10 +837,9 @@ LABEL(pickup)
                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);
@@ -880,10 +881,9 @@ void Item_FindTeam(entity this)
                // marker for item team search
                LOG_TRACE("Initializing item team ", ftos(this.team));
                RandomSelection_Init();
-               FOREACH_ENTITY_FLOAT(team, this.team,
+               IL_EACH(g_items, it.team == this.team,
                {
-                       if(it.flags & FL_ITEM)
-                       if(it.classname != "item_flag_team" && it.classname != "item_key_team")
+                       if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
                                RandomSelection_Add(it, 0, string_null, it.cnt, 0);
                });
 
@@ -891,10 +891,9 @@ void Item_FindTeam(entity this)
                e.state = 0;
                Item_Show(e, 1);
 
-               FOREACH_ENTITY_FLOAT(team, this.team,
+               IL_EACH(g_items, it.team == this.team,
                {
-                       if(it.flags & FL_ITEM)
-                       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)
                                {
@@ -1076,6 +1075,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
                this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
 
        this.flags = FL_ITEM | itemflags;
+       IL_PUSH(g_items, this);
 
        if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
        {
@@ -1447,10 +1447,9 @@ void target_items_use(entity this, entity actor, entity trigger)
                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)))
@@ -1656,9 +1655,11 @@ float GiveItems(entity e, float beginarg, float endarg)
 
        got = 0;
 
+       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+
        _switchweapon = false;
        if (e.autoswitch)
-               if (PS(e).m_switchweapon == w_getbestweapon(e))
+               if (e.(weaponentity).m_switchweapon == w_getbestweapon(e))
                        _switchweapon = true;
 
        e.strength_finished = max(0, e.strength_finished - time);
@@ -1824,10 +1825,10 @@ float GiveItems(entity e, float beginarg, float endarg)
        else
                e.superweapons_finished += time;
 
-       if (!(e.weapons & WepSet_FromWeapon(PS(e).m_switchweapon)))
+       if (!(e.weapons & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
                _switchweapon = true;
        if(_switchweapon)
-               W_SwitchWeapon_Force(e, w_getbestweapon(e));
+               W_SwitchWeapon_Force(e, w_getbestweapon(e), weaponentity);
 
        return got;
 }