]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Convert 5 trivial Item_* functions to macros
authorbones_was_here <bones_was_here@xonotic.au>
Sun, 18 Jun 2023 22:54:03 +0000 (08:54 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Wed, 21 Jun 2023 10:59:05 +0000 (20:59 +1000)
15 files changed:
qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc
qcsrc/common/gamemodes/gamemode/nexball/sv_nexball.qc
qcsrc/common/mapobjects/triggers.qc
qcsrc/common/mutators/mutator/buffs/sv_buffs.qc
qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
qcsrc/common/mutators/mutator/powerups/sv_powerups.qc
qcsrc/common/mutators/mutator/random_items/sv_random_items.qc
qcsrc/server/bot/default/havocbot/havocbot.qc
qcsrc/server/bot/default/havocbot/roles.qc
qcsrc/server/items/items.qc
qcsrc/server/items/spawning.qc
qcsrc/server/items/spawning.qh
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/spawning.qc
qcsrc/server/weapons/throwing.qc

index 0fbab7ae51f54159e1913b7fe723bd4795b77ed4..fc13875b159471b43f23f83ca748ba727b326fa4 100644 (file)
@@ -283,7 +283,7 @@ MUTATOR_HOOKFUNCTION(cts, FilterItem)
 {
        entity item = M_ARGV(0, entity);
 
-       if (Item_IsLoot(item))
+       if (ITEM_IS_LOOT(item))
        {
                if(item.monster_loot && autocvar_g_cts_drop_monster_items)
                        return false;
index 5fed894b9685e6ae088035b84cf2020c7f6e99cb..c8a82b0c1b4a7e53d121b4d8254481966220330e 100644 (file)
@@ -895,7 +895,7 @@ MUTATOR_HOOKFUNCTION(nb, FilterItem)
 {
        entity item = M_ARGV(0, entity);
 
-       if(Item_IsLoot(item))
+       if(ITEM_IS_LOOT(item))
        if(item.weapon == WEP_NEXBALL.m_id)
                return true;
 
index 0f0f7f788e99d7445dbd7b41fe7ffb2c6d89fb29..5fc5f4f3fb1bea0af0fc09682ab7b6196e857aeb 100644 (file)
@@ -9,7 +9,7 @@ bool isPushable(entity e)
                return false;
        if(e.iscreature)
                return true;
-       if (Item_IsLoot(e))
+       if (ITEM_IS_LOOT(e))
        {
                return true;
        }
index 367277e7f2159acb1adfca535c686131a79a0e00..5014aaed55f6fa7e9027e7964b91631b33d9ab43 100644 (file)
@@ -490,7 +490,7 @@ void buff_SpawnReplacement(entity ent, entity old)
 {
        setorigin(ent, old.origin);
        ent.angles = old.angles;
-       ent.noalign = Item_ShouldKeepPosition(old);
+       ent.noalign = ITEM_SHOULD_KEEP_POSITION(old);
 
        buff_Init(ent);
 }
index bd84a445f7511711244fdd9c214ab11bda9dc238..15856ad6a834de0187328aafbf8cf0297321abde 100644 (file)
@@ -362,7 +362,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
                return true;
        }
 
-       if(item.weapon == WEP_VAPORIZER.m_id && Item_IsLoot(item))
+       if(item.weapon == WEP_VAPORIZER.m_id && ITEM_IS_LOOT(item))
        {
                SetResource(item, RES_CELLS, autocvar_g_instagib_ammo_drop);
                return false;
index 03e66ee6c1bf92331eb65578c706bcb6dc85a863..ef09f54e9b66518b963c993240351703833176ee 100644 (file)
@@ -102,7 +102,7 @@ void powerups_DropItem(entity this, StatusEffects effect, bool freezeTimer)
 
        // If we want the timer to keep running, we enable expiring then use the exact time the powerup will finish at.
        // If we want the timer to freeze, we disable expiring and we just use the time left of the powerup.
-       // See Item_SetExpiring() below.
+       // See ITEM_SET_EXPIRING() below.
        float finished = (freezeTimer ? timeleft : t);
 
        // If the timer is frozen, the item will stay on the floor for 20 secs (same as weapons),
@@ -125,7 +125,7 @@ void powerups_DropItem(entity this, StatusEffects effect, bool freezeTimer)
                return;
 
        if(!freezeTimer)
-               Item_SetExpiring(e, true);
+               ITEM_SET_EXPIRING(e, true);
 
        // Use armor as timer freezer
        if(freezeTimer)
index ed2bd91861d9afc3ba1f9e7993f7df095ad92193..9f39278f6f652c48c495613d1124db3f90a2f2f9 100644 (file)
@@ -332,7 +332,7 @@ MUTATOR_HOOKFUNCTION(random_items, FilterItem, CBC_ORDER_LAST)
                return false;
        }
        entity item = M_ARGV(0, entity);
-       if (Item_IsLoot(item))
+       if (ITEM_IS_LOOT(item))
        {
                return false;
        }
@@ -352,7 +352,7 @@ MUTATOR_HOOKFUNCTION(random_items, ItemTouched, CBC_ORDER_LAST)
                return;
        }
        entity item = M_ARGV(0, entity);
-       if (Item_IsLoot(item))
+       if (ITEM_IS_LOOT(item))
        {
                return;
        }
index 477b1c14f19c2574a7e7a5ee53081bf73b98dd68..c8855660a041ea77d9ad16b68d436f2d10009ca6 100644 (file)
@@ -801,7 +801,7 @@ void havocbot_movetogoal(entity this)
                        {
                                if (IS_DEAD(this.goalcurrent))
                                {
-                                       IL_EACH(g_items, it.enemy == this.goalcurrent && Item_IsLoot(it),
+                                       IL_EACH(g_items, it.enemy == this.goalcurrent && ITEM_IS_LOOT(it),
                                        {
                                                if (vdist(it.origin - this.goalcurrent.death_origin, <, 50))
                                                {
@@ -814,7 +814,7 @@ void havocbot_movetogoal(entity this)
                                                }
                                        });
                                }
-                               if (!Item_IsLoot(this.goalcurrent))
+                               if (!ITEM_IS_LOOT(this.goalcurrent))
                                {
                                        navigation_goalrating_timeout_force(this);
                                        return;
index 52aff186aef70e133f390c1851f93dc5c613e6f6..020d993bed9fb03f133e630d3a9df5f771d90b6b 100644 (file)
@@ -141,7 +141,7 @@ void havocbot_goalrating_items(entity this, float ratingscale, vector org, float
                        continue;
 
                // Check if the item can be picked up safely
-               if(Item_IsLoot(it))
+               if(ITEM_IS_LOOT(it))
                {
                        if(!IS_ONGROUND(it))
                                continue;
index d0353866ff9007e0fe5ac16c30fe0f9e60cbde8c..e0013b5ce0d37ff4eff0cd2a5bedd0c52407e189 100644 (file)
@@ -184,7 +184,7 @@ void Item_Show(entity e, int mode)
 
 void Item_Think(entity this)
 {
-       if (Item_IsLoot(this))
+       if (ITEM_IS_LOOT(this))
        {
                if (time < this.wait - IT_DESPAWNFX_TIME)
                        this.nextthink = min(time + IT_UPDATE_INTERVAL, this.wait - IT_DESPAWNFX_TIME); // ensuring full time for effects
@@ -675,7 +675,7 @@ bool Item_GiveTo(entity item, entity player)
 void Item_Touch(entity this, entity toucher)
 {
        // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
-       if (Item_IsLoot(this))
+       if (ITEM_IS_LOOT(this))
        {
                if (ITEM_TOUCH_NEEDKILL())
                {
@@ -700,7 +700,7 @@ void Item_Touch(entity this, entity toucher)
 
        toucher = M_ARGV(1, entity);
 
-       if (Item_IsExpiring(this))
+       if (ITEM_IS_EXPIRING(this))
        {
                this.strength_finished = max(0, this.strength_finished - time);
                this.invincible_finished = max(0, this.invincible_finished - time);
@@ -711,7 +711,7 @@ void Item_Touch(entity this, entity toucher)
        bool gave = ITEM_HANDLE(Pickup, this.itemdef, this, toucher);
        if (!gave)
        {
-               if (Item_IsExpiring(this))
+               if (ITEM_IS_EXPIRING(this))
                {
                        // undo what we did above
                        this.strength_finished += time;
@@ -740,7 +740,7 @@ LABEL(pickup)
                return;
        }
 
-       if (Item_IsLoot(this))
+       if (ITEM_IS_LOOT(this))
        {
                delete(this);
                return;
@@ -774,7 +774,7 @@ void Item_Reset(entity this)
 {
        Item_Show(this, !this.state);
 
-       if (Item_IsLoot(this))
+       if (ITEM_IS_LOOT(this))
        {
                return;
        }
@@ -832,7 +832,7 @@ void Item_CopyFields(entity this, entity to)
 {
        setorigin(to, this.origin);
        to.spawnflags = this.spawnflags;
-       to.noalign = Item_ShouldKeepPosition(this);
+       to.noalign = ITEM_SHOULD_KEEP_POSITION(this);
        to.cnt = this.cnt;
        to.team = this.team;
        to.spawnfunc_checked = true;
@@ -1009,7 +1009,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
        // set item size before we spawn a waypoint or droptofloor or MoveOutOfSolid
        setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
 
-       if (Item_IsLoot(this))
+       if (ITEM_IS_LOOT(this))
        {
                this.reset = RemoveItem;
 
@@ -1029,7 +1029,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
                //this.damagedbycontents = true;
                //IL_PUSH(g_damagedbycontents, this);
 
-               if (Item_IsExpiring(this))
+               if (ITEM_IS_EXPIRING(this))
                {
                        // if item is worthless after a timer, have it expire then
                        this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
@@ -1158,7 +1158,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
 
        if(def.instanceOfWeaponPickup)
        {
-               if (!Item_IsLoot(this)) // if dropped, colormap is already set up nicely
+               if (!ITEM_IS_LOOT(this)) // if dropped, colormap is already set up nicely
                        this.colormap = 1024; // color shirt=0 pants=0 grey
                if (!(this.spawnflags & 1024))
                        this.ItemStatus |= ITS_ANIMATE1;
@@ -1211,7 +1211,7 @@ int group_count = 1;
 
 void setItemGroup(entity this)
 {
-       if(!IS_SMALL(this.itemdef) || Item_IsLoot(this))
+       if(!IS_SMALL(this.itemdef) || ITEM_IS_LOOT(this))
                return;
 
        FOREACH_ENTITY_RADIUS(this.origin, 120, (it != this) && IS_SMALL(it.itemdef),
@@ -1256,7 +1256,7 @@ void setItemGroupCount()
 
 void target_items_use(entity this, entity actor, entity trigger)
 {
-       if(Item_IsLoot(actor))
+       if(ITEM_IS_LOOT(actor))
        {
                EXACTTRIGGER_TOUCH(this, trigger);
                delete(actor);
@@ -1271,7 +1271,7 @@ void target_items_use(entity this, entity actor, entity trigger)
                EXACTTRIGGER_TOUCH(this, trigger);
        }
 
-       IL_EACH(g_items, it.enemy == actor && Item_IsLoot(it),
+       IL_EACH(g_items, it.enemy == actor && ITEM_IS_LOOT(it),
        {
                delete(it);
        });
index f03f9e2173d1e3a9fdf453f62af4a46c9defe9fd..55715f832dd24c21adc2b84e225f75d55b313446 100644 (file)
 #include <server/weapons/spawning.qh>
 #include <server/world.qh>
 
-.bool m_isloot; ///< Holds whether item is loot.
-/// \brief Holds whether strength, shield or superweapon timers expire while
-/// this item is on the ground.
-.bool m_isexpiring;
 
 bool Item_IsDefinitionAllowed(entity definition)
 {
@@ -31,7 +27,7 @@ bool Item_Initialise(entity item)
 {
        if (item.lifetime >= 0)
        {
-               Item_SetLoot(item, true);
+               ITEM_SET_LOOT(item, true);
                item.pickup_anyway = true; // these are ALWAYS pickable
        }
 
@@ -69,30 +65,6 @@ bool Item_Initialise(entity item)
        return true;
 }
 
-bool Item_IsLoot(entity item)
-{
-       return item.m_isloot || item.classname == "droppedweapon";
-}
-
-void Item_SetLoot(entity item, bool loot)
-{
-       item.m_isloot = loot;
-}
-
-bool Item_ShouldKeepPosition(entity item)
-{
-       return item.noalign || (item.spawnflags & 1);
-}
-
-bool Item_IsExpiring(entity item)
-{
-       return item.m_isexpiring;
-}
-
-void Item_SetExpiring(entity item, bool expiring)
-{
-       item.m_isexpiring = expiring;
-}
 
 // Compatibility spawn functions
 
index b44ec15d088a0bcea6cdba685390f27746abe9b5..7b19292c614a99ccc1a4c75af4e9c5e02f116228 100644 (file)
@@ -8,6 +8,10 @@ bool startitem_failed;
 
 /// \brief lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default
 .float lifetime;
+/// \brief Holds whether item is loot.
+.bool m_isloot;
+/// \brief Holds whether strength, shield or superweapon timers expire while this item is on the ground.
+.bool m_isexpiring;
 
 /// \brief Checks whether the items with the specified definition are allowed to
 /// spawn.
@@ -28,30 +32,30 @@ bool Item_Initialise(entity item);
 /// \brief Returns whether the item is loot.
 /// \param[in] item Item to check.
 /// \return True if the item is loot, false otherwise.
-bool Item_IsLoot(entity item);
+#define ITEM_IS_LOOT(item) (item.m_isloot || item.classname == "droppedweapon")
 
 /// \brief Sets the item loot status.
 /// \param[in,out] item Item to adjust.
 /// \param[in] loot Whether item is loot.
 /// \return No return.
-void Item_SetLoot(entity item, bool loot);
+#define ITEM_SET_LOOT(item, loot) (item.m_isloot = loot)
 
 /// \brief Returns whether item should keep its position or be dropped to the
 /// ground.
 /// \param[in] item Item to check.
 /// \return True if item should keep its position or false if it should be
 /// dropped to the ground.
-bool Item_ShouldKeepPosition(entity item);
+#define ITEM_SHOULD_KEEP_POSITION(item) (item.noalign || item.spawnflags & 1)
 
 /// \brief Returns whether the item is expiring (i.e. its strength, shield and
 /// superweapon timers expire while it is on the ground).
 /// \param[in] item Item to check.
 /// \return True if the item is expiring, false otherwise.
-bool Item_IsExpiring(entity item);
+#define ITEM_IS_EXPIRING(item) (item.m_isexpiring)
 
 /// \brief Sets the item expiring status (i.e. whether its strength, shield
 /// and superweapon timers expire while it is on the ground).
 /// \param[in,out] item Item to adjust.
 /// \param[in] expiring Whether item is expiring.
 /// \return No return.
-void Item_SetExpiring(entity item, bool expiring);
+#define ITEM_SET_EXPIRING(item, expiring) (item.m_isexpiring = expiring)
index d2bb32c6fc27f925343f35617941c5b7f50a4e57..1af0881c3400b7df6758b7e275405769a5c1669e 100644 (file)
@@ -28,7 +28,7 @@ void Weapon_whereis(Weapon this, entity cl)
        if (!autocvar_g_showweaponspawns) return;
        IL_EACH(g_items, it.weapon == this.m_id && (!it.team || (it.ItemStatus & ITS_AVAILABLE)),
        {
-               if (Item_IsLoot(it) && (autocvar_g_showweaponspawns < 2))
+               if (ITEM_IS_LOOT(it) && (autocvar_g_showweaponspawns < 2))
                {
                        continue;
                }
index 99049217f3a12e8a854ddd7f1dd6f45e0f32fc6c..3dd040b97132c52db28b70e0ed5d444a97dc3868 100644 (file)
@@ -31,7 +31,7 @@ void weapon_defaultspawnfunc(entity this, Weapon wpn)
 {
        wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
        this.classname = wpn.m_canonical_spawnfunc;
-       if (!Item_IsLoot(this) && !this.m_isreplaced)
+       if (!ITEM_IS_LOOT(this) && !this.m_isreplaced)
        {
                if (wpn.spawnflags & WEP_FLAG_MUTATORBLOCKED)
                {
@@ -79,7 +79,7 @@ void weapon_defaultspawnfunc(entity this, Weapon wpn)
                }
        }
 
-       if(!Item_IsLoot(this))
+       if(!ITEM_IS_LOOT(this))
                weaponsInMapAll |= WepSet_FromWeapon(wpn);
 
        if (!Item_IsDefinitionAllowed(wpn.m_pickup))
index a979b7b0c65f9689e33be33270414fca26d37ba7..782ee3aa39cc5f7c5e83cce6e0ca6bd05a48db95 100644 (file)
@@ -25,7 +25,7 @@ float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector
        Resource ammotype = info.ammo_type;
 
        entity wep = spawn();
-       Item_SetLoot(wep, true);
+       ITEM_SET_LOOT(wep, true);
        setorigin(wep, org);
        wep.velocity = velo;
        wep.owner = wep.enemy = own;
@@ -38,7 +38,7 @@ float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector
 
        if(WepSet_FromWeapon(REGISTRY_GET(Weapons, wpn)) & WEPSET_SUPERWEAPONS)
        {
-               Item_SetExpiring(wep, true);
+               ITEM_SET_EXPIRING(wep, true);
                if(own.items & IT_UNLIMITED_SUPERWEAPONS)
                {
                        wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;