From ed9620c3b71d0e25e0bdab205d099d378b564d4f Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Mon, 19 Jun 2023 11:50:18 +1000 Subject: [PATCH] Remove redundant Item_* functions --- qcsrc/server/items/spawning.qc | 99 ---------------------------------- qcsrc/server/items/spawning.qh | 55 ------------------- 2 files changed, 154 deletions(-) diff --git a/qcsrc/server/items/spawning.qc b/qcsrc/server/items/spawning.qc index 8307a70b9..f03f9e217 100644 --- a/qcsrc/server/items/spawning.qc +++ b/qcsrc/server/items/spawning.qc @@ -17,110 +17,11 @@ /// this item is on the ground. .bool m_isexpiring; -entity Item_FindDefinition(string class_name) -{ - FOREACH(Items, it.m_canonical_spawnfunc == class_name, - { - return it; - }); - FOREACH(Weapons, it.m_canonical_spawnfunc == class_name, - { - return it.m_pickup; - }); - return NULL; -} - -entity Item_DefinitionFromInternalName(string item_name) -{ - FOREACH(Items, it.netname == item_name, - { - return it; - }); - FOREACH(Weapons, it.netname == item_name, - { - return it.m_pickup; - }); - return NULL; -} - -bool Item_IsAllowed(string class_name) -{ - entity definition = Item_FindDefinition(class_name); - if (definition == NULL) - { - return false; - } - return Item_IsDefinitionAllowed(definition); -} - bool Item_IsDefinitionAllowed(entity definition) { return !MUTATOR_CALLHOOK(FilterItemDefinition, definition); } -entity Item_Create(string class_name, vector position, bool no_align) -{ - entity item = spawn(); - item.classname = class_name; - item.spawnfunc_checked = true; - setorigin(item, position); - item.noalign = no_align; - Item_Initialize(item, class_name); - if (wasfreed(item)) - { - return NULL; - } - return item; -} - -void Item_Initialize(entity item, string class_name) -{ - FOREACH(Weapons, it.m_canonical_spawnfunc == class_name, - { - weapon_defaultspawnfunc(item, it); - return; - }); - FOREACH(Items, it.m_canonical_spawnfunc == class_name, - { - StartItem(item, it); - return; - }); - LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name); -} - -entity Item_CreateLoot(string class_name, vector position, vector vel, - float time_to_live) -{ - entity item = spawn(); - if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live)) - { - return NULL; - } - return item; -} - -bool Item_InitializeLoot(entity item, string class_name, vector position, - vector vel, float time_to_live) -{ - item.classname = class_name; - Item_SetLoot(item, true); - item.noalign = true; - setorigin(item, position); - item.pickup_anyway = true; - item.spawnfunc_checked = true; - Item_Initialize(item, class_name); - if (wasfreed(item)) - { - return false; - } - item.gravity = 1; - item.velocity = vel; - // StartItem sets the default .wait expiry time which is respected by Item_Think() - if (time_to_live) - item.wait = time + time_to_live; - return true; -} - // An optimised and generic way to initialise items (loot or permanent) // required field: itemdef (faster, preferred) OR classname // optional fields: origin, velocity, lifetime, noalign diff --git a/qcsrc/server/items/spawning.qh b/qcsrc/server/items/spawning.qh index 4915830ab..b44ec15d0 100644 --- a/qcsrc/server/items/spawning.qh +++ b/qcsrc/server/items/spawning.qh @@ -9,25 +9,6 @@ bool startitem_failed; /// \brief lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default .float lifetime; -/// \brief Returns the item definition corresponding to the given class name. -/// \param[in] class_name Class name to search for. -/// \return Item definition corresponding to the given class name or NULL is not -/// found. -entity Item_FindDefinition(string class_name); - -/// \brief Returns the item definition corresponding to the given internal name. -/// \param[in] item_name Internal netname to search for. -/// \return Item definition corresponding to the given internal name or NULL is not -/// found. -entity Item_DefinitionFromInternalName(string item_name); - -/// \brief Checks whether the items with the specified class name are allowed to -/// spawn. -/// \param[in] class_name Item class name to check. -/// \return True items with the specified class name are allowed to spawn, false -/// otherwise. -bool Item_IsAllowed(string class_name); - /// \brief Checks whether the items with the specified definition are allowed to /// spawn. /// \param[in] definition Item definition to check. @@ -35,42 +16,6 @@ bool Item_IsAllowed(string class_name); /// otherwise. bool Item_IsDefinitionAllowed(entity definition); -/// \brief Creates a new item. -/// \param[in] class_name Class name of the item. -/// \param[in] position Position of the item. -/// \param[in] no_align True if item should be placed directly at specified -/// position, false to let it drop to the ground. -/// \return Item on success, NULL otherwise. -entity Item_Create(string class_name, vector position, bool no_align); - -/// \brief Initializes the item according to class name. -/// \param[in,out] item Item to initialize. -/// \param[in] class_name Class name to use. -/// \return No return. -/// \nore This function is useful if you want to set some item properties before -/// initialization. -void Item_Initialize(entity item, string class_name); - -/// \brief Creates a loot item. -/// \param[in] class_name Class name of the item. -/// \param[in] position Position of the item. -/// \param[in] velocity of the item. -/// \param[in] time_to_live Amount of time after which the item will disappear. -/// \return Item on success, NULL otherwise. -entity Item_CreateLoot(string class_name, vector position, vector vel, - float time_to_live); - -/// \brief Initializes the loot item. -/// \param[in] class_name Class name of the item. -/// \param[in] position Position of the item. -/// \param[in] velocity of the item. -/// \param[in] time_to_live Amount of time after which the item will disappear. -/// \return True on success, false otherwise. -/// \nore This function is useful if you want to set some item properties before -/// initialization. -bool Item_InitializeLoot(entity item, string class_name, vector position, - vector vel, float time_to_live); - /// \brief An optimised and generic way to initialise items (loot or permanent) /// \param[in] item The item entity to initialise /// \return True on success, false otherwise. -- 2.39.2