From b7610530401882c79ab403b32c12d7f233716ff6 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Mon, 19 Jun 2023 08:54:03 +1000 Subject: [PATCH] Convert 5 trivial Item_* functions to macros --- qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc | 2 +- .../gamemodes/gamemode/nexball/sv_nexball.qc | 2 +- qcsrc/common/mapobjects/triggers.qc | 2 +- .../common/mutators/mutator/buffs/sv_buffs.qc | 2 +- .../mutators/mutator/instagib/sv_instagib.qc | 2 +- .../mutators/mutator/powerups/sv_powerups.qc | 4 +-- .../mutator/random_items/sv_random_items.qc | 4 +-- qcsrc/server/bot/default/havocbot/havocbot.qc | 4 +-- qcsrc/server/bot/default/havocbot/roles.qc | 2 +- qcsrc/server/items/items.qc | 26 ++++++++-------- qcsrc/server/items/spawning.qc | 30 +------------------ qcsrc/server/items/spawning.qh | 14 +++++---- qcsrc/server/weapons/selection.qc | 2 +- qcsrc/server/weapons/spawning.qc | 4 +-- qcsrc/server/weapons/throwing.qc | 4 +-- 15 files changed, 40 insertions(+), 64 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index 0fbab7ae5..fc13875b1 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -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; diff --git a/qcsrc/common/gamemodes/gamemode/nexball/sv_nexball.qc b/qcsrc/common/gamemodes/gamemode/nexball/sv_nexball.qc index 5fed894b9..c8a82b0c1 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/sv_nexball.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/sv_nexball.qc @@ -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; diff --git a/qcsrc/common/mapobjects/triggers.qc b/qcsrc/common/mapobjects/triggers.qc index 0f0f7f788..5fc5f4f3f 100644 --- a/qcsrc/common/mapobjects/triggers.qc +++ b/qcsrc/common/mapobjects/triggers.qc @@ -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; } diff --git a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc index 367277e7f..5014aaed5 100644 --- a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc +++ b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc @@ -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); } diff --git a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc index bd84a445f..15856ad6a 100644 --- a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc +++ b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc @@ -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; diff --git a/qcsrc/common/mutators/mutator/powerups/sv_powerups.qc b/qcsrc/common/mutators/mutator/powerups/sv_powerups.qc index 03e66ee6c..ef09f54e9 100644 --- a/qcsrc/common/mutators/mutator/powerups/sv_powerups.qc +++ b/qcsrc/common/mutators/mutator/powerups/sv_powerups.qc @@ -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) diff --git a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc index ed2bd9186..9f39278f6 100644 --- a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc +++ b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc @@ -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; } diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 477b1c14f..c8855660a 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -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; diff --git a/qcsrc/server/bot/default/havocbot/roles.qc b/qcsrc/server/bot/default/havocbot/roles.qc index 52aff186a..020d993be 100644 --- a/qcsrc/server/bot/default/havocbot/roles.qc +++ b/qcsrc/server/bot/default/havocbot/roles.qc @@ -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; diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index d0353866f..e0013b5ce 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -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); }); diff --git a/qcsrc/server/items/spawning.qc b/qcsrc/server/items/spawning.qc index f03f9e217..55715f832 100644 --- a/qcsrc/server/items/spawning.qc +++ b/qcsrc/server/items/spawning.qc @@ -12,10 +12,6 @@ #include #include -.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 diff --git a/qcsrc/server/items/spawning.qh b/qcsrc/server/items/spawning.qh index b44ec15d0..7b19292c6 100644 --- a/qcsrc/server/items/spawning.qh +++ b/qcsrc/server/items/spawning.qh @@ -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) diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index d2bb32c6f..1af0881c3 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -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; } diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 99049217f..3dd040b97 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -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)) diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index a979b7b0c..782ee3aa3 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -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; -- 2.39.2