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 bool Item_IsDefinitionAllowed(entity definition)
22 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
25 // An optimised and generic way to initialise items (loot or permanent)
26 // required field: itemdef (faster, preferred) OR classname
27 // optional fields: origin, velocity, lifetime, noalign
28 // lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default
29 // permanent items only: noalign means the item is suspended (won't drop to floor)
30 bool Item_Initialise(entity item)
32 if (item.lifetime >= 0)
34 Item_SetLoot(item, true);
35 item.pickup_anyway = true; // these are ALWAYS pickable
38 if (item.itemdef) // no search required
40 if (item.itemdef.instanceOfWeapon)
41 weapon_defaultspawnfunc(item, item.itemdef);
43 StartItem(item, item.itemdef);
45 else // fall back to classname search
47 FOREACH(Weapons, it.m_canonical_spawnfunc == item.classname,
49 weapon_defaultspawnfunc(item, it);
52 FOREACH(Items, it.m_canonical_spawnfunc == item.classname,
57 LOG_FATALF("Item_Initialize: Invalid classname: %s", item.classname);
58 LABEL(classname_found)
64 // StartItem sets the default .wait expiry time which is respected by Item_Think()
65 if (item.lifetime > 0)
66 item.wait = time + item.lifetime;
68 item.spawnfunc_checked = true;
72 bool Item_IsLoot(entity item)
74 return item.m_isloot || item.classname == "droppedweapon";
77 void Item_SetLoot(entity item, bool loot)
82 bool Item_ShouldKeepPosition(entity item)
84 return item.noalign || (item.spawnflags & 1);
87 bool Item_IsExpiring(entity item)
89 return item.m_isexpiring;
92 void Item_SetExpiring(entity item, bool expiring)
94 item.m_isexpiring = expiring;
97 // Compatibility spawn functions
99 // in Quake this is green armor, in Xonotic maps it is an armor shard
100 SPAWNFUNC_ITEM_COND(item_armor1, autocvar_sv_mapformat_is_quake3, ITEM_ArmorSmall, ITEM_ArmorMedium)
101 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) // Nexuiz used item_armor25 to spawn a Mega Armor
102 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
103 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
104 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
105 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
106 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)