4 /// \brief Source file that contains implementation of the functions related to
6 /// \copyright GNU GPLv2 or any later version.
8 #include "mutators/events.qh"
9 #include <common/weapons/all.qh>
11 .bool m_isloot; ///< Holds whether item is loot.
12 /// \brief Holds whether strength, shield or superweapon timers expire while
13 /// this item is on the ground.
16 entity Item_FindDefinition(string class_name)
18 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
22 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
29 bool Item_IsAllowed(string class_name)
31 entity definition = Item_FindDefinition(class_name);
32 if (definition == NULL)
36 return Item_IsDefinitionAllowed(definition);
39 bool Item_IsDefinitionAllowed(entity definition)
41 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
44 entity Item_Create(string class_name, vector position, bool no_align)
46 entity item = spawn();
47 item.classname = class_name;
48 item.spawnfunc_checked = true;
49 setorigin(item, position);
50 item.noalign = no_align;
51 Item_Initialize(item, class_name);
59 void Item_Initialize(entity item, string class_name)
61 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
63 weapon_defaultspawnfunc(item, it);
66 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
71 LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
74 entity Item_CreateLoot(string class_name, vector position, vector vel,
77 entity item = spawn();
78 if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
85 bool Item_InitializeLoot(entity item, string class_name, vector position,
86 vector vel, float time_to_live)
88 item.classname = class_name;
89 Item_SetLoot(item, true);
91 setorigin(item, position);
92 item.pickup_anyway = true;
93 item.spawnfunc_checked = true;
94 Item_Initialize(item, class_name);
101 SUB_SetFade(item, time + time_to_live, 1);
105 bool Item_IsLoot(entity item)
107 return item.m_isloot;
110 void Item_SetLoot(entity item, bool loot)
112 item.m_isloot = loot;
115 bool Item_ShouldKeepPosition(entity item)
117 return item.noalign || (item.spawnflags & 1);
120 bool Item_IsExpiring(entity item)
122 return item.m_isexpiring;
125 void Item_SetExpiring(entity item, bool expiring)
127 item.m_isexpiring = expiring;
130 // Compatibility spawn functions
132 // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
133 SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall)
135 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega)
137 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
139 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
141 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
143 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
145 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
147 SPAWNFUNC_ITEM(item_quad, ITEM_Strength)