From: Mario Date: Sat, 1 Aug 2020 22:07:07 +0000 (+1000) Subject: Rename server/items.qc to server/items/spawning.qc X-Git-Tag: xonotic-v0.8.5~810 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2d3ed896c16fcbad16cdf83b1ffae348053aab96;p=xonotic%2Fxonotic-data.pk3dir.git Rename server/items.qc to server/items/spawning.qc --- diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index c08176cf8..3f787fa3c 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -2,7 +2,7 @@ #include #include -#include +#include float autocvar_g_cts_finish_kill_delay; bool autocvar_g_cts_selfdamage; diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index a8b8b4675..ef909382b 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -8,7 +8,7 @@ #endif #ifdef SVQC -#include +#include #endif const int IT_UNLIMITED_AMMO = BIT(0); // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup. diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index bca6cc8a8..92727b4c0 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -31,7 +31,7 @@ #include "config.qh" #include #include - #include "../items.qh" + #include #include #include #include diff --git a/qcsrc/server/_mod.inc b/qcsrc/server/_mod.inc index 6c66dd95f..7634e7635 100644 --- a/qcsrc/server/_mod.inc +++ b/qcsrc/server/_mod.inc @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/server/_mod.qh b/qcsrc/server/_mod.qh index 06bb03df3..331fdcd85 100644 --- a/qcsrc/server/_mod.qh +++ b/qcsrc/server/_mod.qh @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/server/bot/default/havocbot/roles.qc b/qcsrc/server/bot/default/havocbot/roles.qc index d078cae86..8081097b4 100644 --- a/qcsrc/server/bot/default/havocbot/roles.qc +++ b/qcsrc/server/bot/default/havocbot/roles.qc @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include "havocbot.qh" diff --git a/qcsrc/server/compat/quake3.qc b/qcsrc/server/compat/quake3.qc index baf20c633..4103ccf29 100644 --- a/qcsrc/server/compat/quake3.qc +++ b/qcsrc/server/compat/quake3.qc @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/qcsrc/server/compat/wop.qc b/qcsrc/server/compat/wop.qc index d2577b46a..bd399bffd 100644 --- a/qcsrc/server/compat/wop.qc +++ b/qcsrc/server/compat/wop.qc @@ -2,7 +2,7 @@ #include #include -#include +#include #include spawnfunc(item_haste); diff --git a/qcsrc/server/items.qc b/qcsrc/server/items.qc deleted file mode 100644 index ab53a10fc..000000000 --- a/qcsrc/server/items.qc +++ /dev/null @@ -1,148 +0,0 @@ -#include "items.qh" - -/// \file -/// \brief Source file that contains implementation of the functions related to -/// game items. -/// \copyright GNU GPLv2 or any later version. - -#include -#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; - -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; -} - -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; - SUB_SetFade(item, time + time_to_live, 1); - 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 - -// FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard -SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall) - -SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) - -SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega) - -SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall) - -SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium) - -SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig) - -SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega) - -SPAWNFUNC_ITEM(item_quad, ITEM_Strength) diff --git a/qcsrc/server/items.qh b/qcsrc/server/items.qh deleted file mode 100644 index b52449e71..000000000 --- a/qcsrc/server/items.qh +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once - -/// \file -/// \brief Header file that describes the functions related to game items. -/// \copyright GNU GPLv2 or any later version. - -bool startitem_failed; - -/// \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 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. -/// \return True items with the specified definition are allowed to spawn, false -/// 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 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); - -/// \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); - -/// \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); - -/// \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); - -/// \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); diff --git a/qcsrc/server/items/_mod.inc b/qcsrc/server/items/_mod.inc new file mode 100644 index 000000000..9c55d0b5c --- /dev/null +++ b/qcsrc/server/items/_mod.inc @@ -0,0 +1,2 @@ +// generated file; do not modify +#include diff --git a/qcsrc/server/items/_mod.qh b/qcsrc/server/items/_mod.qh new file mode 100644 index 000000000..eb6ff1ce5 --- /dev/null +++ b/qcsrc/server/items/_mod.qh @@ -0,0 +1,2 @@ +// generated file; do not modify +#include diff --git a/qcsrc/server/items/spawning.qc b/qcsrc/server/items/spawning.qc new file mode 100644 index 000000000..bbe662227 --- /dev/null +++ b/qcsrc/server/items/spawning.qc @@ -0,0 +1,148 @@ +#include "spawning.qh" + +/// \file +/// \brief Source file that contains implementation of the functions related to +/// creation of game items. +/// \copyright GNU GPLv2 or any later version. + +#include +#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; + +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; +} + +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; + SUB_SetFade(item, time + time_to_live, 1); + 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 + +// FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard +SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall) + +SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) + +SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega) + +SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall) + +SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium) + +SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig) + +SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega) + +SPAWNFUNC_ITEM(item_quad, ITEM_Strength) diff --git a/qcsrc/server/items/spawning.qh b/qcsrc/server/items/spawning.qh new file mode 100644 index 000000000..b52449e71 --- /dev/null +++ b/qcsrc/server/items/spawning.qh @@ -0,0 +1,94 @@ +#pragma once + +/// \file +/// \brief Header file that describes the functions related to game items. +/// \copyright GNU GPLv2 or any later version. + +bool startitem_failed; + +/// \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 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. +/// \return True items with the specified definition are allowed to spawn, false +/// 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 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); + +/// \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); + +/// \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); + +/// \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); + +/// \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); diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 39f26b9bf..bb99abb4b 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -10,7 +10,7 @@ #include "../common/items.qh" #include "mapvoting.qh" #include "resources.qh" -#include "items.qh" +#include #include "player.qh" #include "weapons/accuracy.qh" #include "weapons/csqcprojectile.qh" diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index 7e9354f7d..94034bdbb 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -2,7 +2,7 @@ #include "weaponsystem.qh" #include -#include +#include #include #include #include diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 56f81a8aa..684ea842b 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -4,7 +4,7 @@ #include "../resources.qh" #include #include -#include +#include #include .bool m_isreplaced; ///< Holds whether the weapon has been replaced. diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index 8730cc140..d111a7a4f 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -2,7 +2,7 @@ #include "weaponsystem.qh" #include "../resources.qh" -#include "../items.qh" +#include #include #include #include "../g_damage.qh"