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 <common/mapobjects/subs.qh>
9 #include <common/weapons/all.qh>
10 #include <server/items/items.qh>
11 #include <server/mutators/_mod.qh>
12 #include <server/weapons/spawning.qh>
14 .bool m_isloot; ///< Holds whether item is loot.
15 /// \brief Holds whether strength, shield or superweapon timers expire while
16 /// this item is on the ground.
19 entity Item_FindDefinition(string class_name)
21 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
25 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
32 entity Item_DefinitionFromInternalName(string item_name)
34 FOREACH(Items, it.netname == item_name,
38 FOREACH(Weapons, it.netname == item_name,
45 bool Item_IsAllowed(string class_name)
47 entity definition = Item_FindDefinition(class_name);
48 if (definition == NULL)
52 return Item_IsDefinitionAllowed(definition);
55 bool Item_IsDefinitionAllowed(entity definition)
57 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
60 entity Item_Create(string class_name, vector position, bool no_align)
62 entity item = spawn();
63 item.classname = class_name;
64 item.spawnfunc_checked = true;
65 setorigin(item, position);
66 item.noalign = no_align;
67 Item_Initialize(item, class_name);
75 void Item_Initialize(entity item, string class_name)
77 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
79 weapon_defaultspawnfunc(item, it);
82 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
87 LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
90 entity Item_CreateLoot(string class_name, vector position, vector vel,
93 entity item = spawn();
94 if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
101 bool Item_InitializeLoot(entity item, string class_name, vector position,
102 vector vel, float time_to_live)
104 item.classname = class_name;
105 Item_SetLoot(item, true);
107 setorigin(item, position);
108 item.pickup_anyway = true;
109 item.spawnfunc_checked = true;
110 Item_Initialize(item, class_name);
117 SUB_SetFade(item, time + time_to_live, 1);
121 bool Item_IsLoot(entity item)
123 return item.m_isloot || item.classname == "droppedweapon";
126 void Item_SetLoot(entity item, bool loot)
128 item.m_isloot = loot;
131 bool Item_ShouldKeepPosition(entity item)
133 return item.noalign || (item.spawnflags & 1);
136 bool Item_IsExpiring(entity item)
138 return item.m_isexpiring;
141 void Item_SetExpiring(entity item, bool expiring)
143 item.m_isexpiring = expiring;
146 // Compatibility spawn functions
148 // in Quake this is green armor, in Xonotic maps it is an armor shard
149 SPAWNFUNC_ITEM_COND(item_armor1, cvar("sv_mapformat_is_quake3"), ITEM_ArmorSmall, ITEM_ArmorMedium)
151 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega)
153 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
155 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
157 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
159 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
161 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)