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>
13 #include <server/world.qh>
15 .bool m_isloot; ///< Holds whether item is loot.
16 /// \brief Holds whether strength, shield or superweapon timers expire while
17 /// this item is on the ground.
20 entity Item_FindDefinition(string class_name)
22 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
26 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
33 entity Item_DefinitionFromInternalName(string item_name)
35 FOREACH(Items, it.netname == item_name,
39 FOREACH(Weapons, it.netname == item_name,
46 bool Item_IsAllowed(string class_name)
48 entity definition = Item_FindDefinition(class_name);
49 if (definition == NULL)
53 return Item_IsDefinitionAllowed(definition);
56 bool Item_IsDefinitionAllowed(entity definition)
58 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
61 entity Item_Create(string class_name, vector position, bool no_align)
63 entity item = spawn();
64 item.classname = class_name;
65 item.spawnfunc_checked = true;
66 setorigin(item, position);
67 item.noalign = no_align;
68 Item_Initialize(item, class_name);
76 void Item_Initialize(entity item, string class_name)
78 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
80 weapon_defaultspawnfunc(item, it);
83 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
88 LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
91 entity Item_CreateLoot(string class_name, vector position, vector vel,
94 entity item = spawn();
95 if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
102 bool Item_InitializeLoot(entity item, string class_name, vector position,
103 vector vel, float time_to_live)
105 item.classname = class_name;
106 Item_SetLoot(item, true);
108 setorigin(item, position);
109 item.pickup_anyway = true;
110 item.spawnfunc_checked = true;
111 Item_Initialize(item, class_name);
118 SUB_SetFade(item, time + time_to_live, 1);
122 bool Item_IsLoot(entity item)
124 return item.m_isloot || item.classname == "droppedweapon";
127 void Item_SetLoot(entity item, bool loot)
129 item.m_isloot = loot;
132 bool Item_ShouldKeepPosition(entity item)
134 return item.noalign || (item.spawnflags & 1);
137 bool Item_IsExpiring(entity item)
139 return item.m_isexpiring;
142 void Item_SetExpiring(entity item, bool expiring)
144 item.m_isexpiring = expiring;
147 // Compatibility spawn functions
149 // in Quake this is green armor, in Xonotic maps it is an armor shard
150 SPAWNFUNC_ITEM_COND(item_armor1, autocvar_sv_mapformat_is_quake3, ITEM_ArmorSmall, ITEM_ArmorMedium)
151 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) // Nexuiz used item_armor25 to spawn a Mega Armor
152 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
153 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
154 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
155 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
156 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)