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>
16 bool Item_IsDefinitionAllowed(entity definition)
18 return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
21 // An optimised and generic way to initialise items (loot or permanent)
22 // required field: itemdef (faster, preferred) OR classname
23 // optional fields: origin, velocity, lifetime, noalign
24 // lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default
25 // permanent items only: noalign means the item is suspended (won't drop to floor)
26 bool Item_Initialise(entity item)
28 if (item.lifetime >= 0)
30 ITEM_SET_LOOT(item, true);
31 item.pickup_anyway = true; // these are ALWAYS pickable
34 if (item.itemdef) // no search required
36 if (item.itemdef.instanceOfWeapon)
37 weapon_defaultspawnfunc(item, item.itemdef);
39 StartItem(item, item.itemdef);
41 else // fall back to classname search
43 FOREACH(Weapons, it.m_canonical_spawnfunc == item.classname,
45 weapon_defaultspawnfunc(item, it);
48 FOREACH(Items, it.m_canonical_spawnfunc == item.classname,
53 LOG_FATALF("Item_Initialize: Invalid classname: %s", item.classname);
54 LABEL(classname_found)
60 // StartItem sets the default .wait expiry time which is respected by Item_Think()
61 if (item.lifetime > 0)
62 item.wait = time + item.lifetime;
64 item.spawnfunc_checked = true;
69 // Compatibility spawn functions
71 // in Quake this is green armor, in Xonotic maps it is an armor shard
72 SPAWNFUNC_ITEM_COND(item_armor1, autocvar_sv_mapformat_is_quake3, ITEM_ArmorSmall, ITEM_ArmorMedium)
73 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) // Nexuiz used item_armor25 to spawn a Mega Armor
74 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
75 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
76 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
77 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
78 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)