4 /// \brief Source file that contains implementation of the functions related to
6 /// \copyright GNU GPLv2 or any later version.
8 #include <server/mutators/_mod.qh>
9 #include <common/weapons/all.qh>
10 #include <common/mapobjects/subs.qh>
12 .bool m_isloot; ///< Holds whether item is loot.
13 /// \brief Holds whether strength, shield or superweapon timers expire while
14 /// this item is on the ground.
17 entity Item_FindDefinition(string class_name)
19 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
23 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
30 bool Item_IsAllowed(string class_name)
32 entity definition = Item_FindDefinition(class_name);
33 if (definition == NULL)
37 return Item_IsDefinitionAllowed(definition);
40 bool Item_IsDefinitionAllowed(entity definition)
42 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
45 entity Item_Create(string class_name, vector position, bool no_align)
47 entity item = spawn();
48 item.classname = class_name;
49 item.spawnfunc_checked = true;
50 setorigin(item, position);
51 item.noalign = no_align;
52 Item_Initialize(item, class_name);
60 void Item_Initialize(entity item, string class_name)
62 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
64 weapon_defaultspawnfunc(item, it);
67 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
72 LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
75 entity Item_CreateLoot(string class_name, vector position, vector vel,
78 entity item = spawn();
79 if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
86 bool Item_InitializeLoot(entity item, string class_name, vector position,
87 vector vel, float time_to_live)
89 item.classname = class_name;
90 Item_SetLoot(item, true);
92 setorigin(item, position);
93 item.pickup_anyway = true;
94 item.spawnfunc_checked = true;
95 Item_Initialize(item, class_name);
102 SUB_SetFade(item, time + time_to_live, 1);
106 bool Item_IsLoot(entity item)
108 return item.m_isloot;
111 void Item_SetLoot(entity item, bool loot)
113 item.m_isloot = loot;
116 bool Item_ShouldKeepPosition(entity item)
118 return item.noalign || (item.spawnflags & 1);
121 bool Item_IsExpiring(entity item)
123 return item.m_isexpiring;
126 void Item_SetExpiring(entity item, bool expiring)
128 item.m_isexpiring = expiring;
131 // Compatibility spawn functions
133 // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
134 SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall)
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)