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 bool Item_IsAllowed(string class_name)
34 entity definition = Item_FindDefinition(class_name);
35 if (definition == NULL)
39 return Item_IsDefinitionAllowed(definition);
42 bool Item_IsDefinitionAllowed(entity definition)
44 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
47 entity Item_Create(string class_name, vector position, bool no_align)
49 entity item = spawn();
50 item.classname = class_name;
51 item.spawnfunc_checked = true;
52 setorigin(item, position);
53 item.noalign = no_align;
54 Item_Initialize(item, class_name);
62 void Item_Initialize(entity item, string class_name)
64 FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
66 weapon_defaultspawnfunc(item, it);
69 FOREACH(Items, it.m_canonical_spawnfunc == class_name,
74 LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
77 entity Item_CreateLoot(string class_name, vector position, vector vel,
80 entity item = spawn();
81 if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
88 bool Item_InitializeLoot(entity item, string class_name, vector position,
89 vector vel, float time_to_live)
91 item.classname = class_name;
92 Item_SetLoot(item, true);
94 setorigin(item, position);
95 item.pickup_anyway = true;
96 item.spawnfunc_checked = true;
97 Item_Initialize(item, class_name);
104 SUB_SetFade(item, time + time_to_live, 1);
108 bool Item_IsLoot(entity item)
110 return item.m_isloot || item.classname == "droppedweapon";
113 void Item_SetLoot(entity item, bool loot)
115 item.m_isloot = loot;
118 bool Item_ShouldKeepPosition(entity item)
120 return item.noalign || (item.spawnflags & 1);
123 bool Item_IsExpiring(entity item)
125 return item.m_isexpiring;
128 void Item_SetExpiring(entity item, bool expiring)
130 item.m_isexpiring = expiring;
133 // Compatibility spawn functions
135 // in Quake this is green armor, in Xonotic maps it is an armor shard
136 SPAWNFUNC_ITEM_COND(item_armor1, cvar("sv_mapformat_is_quake3"), ITEM_ArmorSmall, ITEM_ArmorMedium)
138 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega)
140 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
142 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
144 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
146 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
148 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)