4 /// \brief Source file that contains implementation of the functions related to
5 /// creation of game items.
6 /// \copyright GNU GPLv2 or any later version.
8 #include <server/mutators/_mod.qh>
9 #include <server/weapons/spawning.qh>
10 #include <common/weapons/all.qh>
11 #include <common/mapobjects/subs.qh>
13 .bool m_isloot; ///< Holds whether item is loot.
14 /// \brief Holds whether strength, shield or superweapon timers expire while
15 /// this item is on the ground.
18 entity Item_FindDefinition(string class_name)
20 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
24 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
31 bool Item_IsAllowed(string class_name)
33 entity definition = Item_FindDefinition(class_name);
34 if (definition == NULL)
38 return Item_IsDefinitionAllowed(definition);
41 bool Item_IsDefinitionAllowed(entity definition)
43 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
46 entity Item_Create(string class_name, vector position, bool no_align)
48 entity item = spawn();
49 item.classname = class_name;
50 item.spawnfunc_checked = true;
51 setorigin(item, position);
52 item.noalign = no_align;
53 Item_Initialize(item, class_name);
61 void Item_Initialize(entity item, string class_name)
63 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
65 weapon_defaultspawnfunc(item, it);
68 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
73 LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
76 entity Item_CreateLoot(string class_name, vector position, vector vel,
79 entity item = spawn();
80 if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
87 bool Item_InitializeLoot(entity item, string class_name, vector position,
88 vector vel, float time_to_live)
90 item.classname = class_name;
91 Item_SetLoot(item, true);
93 setorigin(item, position);
94 item.pickup_anyway = true;
95 item.spawnfunc_checked = true;
96 Item_Initialize(item, class_name);
103 SUB_SetFade(item, time + time_to_live, 1);
107 bool Item_IsLoot(entity item)
109 return item.m_isloot || item.classname == "droppedweapon";
112 void Item_SetLoot(entity item, bool loot)
114 item.m_isloot = loot;
117 bool Item_ShouldKeepPosition(entity item)
119 return item.noalign || (item.spawnflags & 1);
122 bool Item_IsExpiring(entity item)
124 return item.m_isexpiring;
127 void Item_SetExpiring(entity item, bool expiring)
129 item.m_isexpiring = expiring;
132 // Compatibility spawn functions
134 SPAWNFUNC_ITEM_COND(item_armor1, cvar("sv_mapformat_is_quake3"), ITEM_ArmorSmall, ITEM_ArmorMedium)
136 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega)
138 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
140 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
142 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
144 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
146 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
148 SPAWNFUNC_ITEM(item_quad, ITEM_Strength)