]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/items/spawning.qc
Convert 5 trivial Item_* functions to macros
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / items / spawning.qc
1 #include "spawning.qh"
2
3 /// \file
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.
7
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>
14
15
16 bool Item_IsDefinitionAllowed(entity definition)
17 {
18         return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
19 }
20
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)
27 {
28         if (item.lifetime >= 0)
29         {
30                 ITEM_SET_LOOT(item, true);
31                 item.pickup_anyway = true; // these are ALWAYS pickable
32         }
33
34         if (item.itemdef) // no search required
35         {
36                 if (item.itemdef.instanceOfWeapon)
37                         weapon_defaultspawnfunc(item, item.itemdef);
38                 else
39                         StartItem(item, item.itemdef);
40         }
41         else // fall back to classname search
42         {
43                 FOREACH(Weapons, it.m_canonical_spawnfunc == item.classname,
44                 {
45                         weapon_defaultspawnfunc(item, it);
46                         goto classname_found;
47                 });
48                 FOREACH(Items, it.m_canonical_spawnfunc == item.classname,
49                 {
50                         StartItem(item, it);
51                         goto classname_found;
52                 });
53                 LOG_FATALF("Item_Initialize: Invalid classname: %s", item.classname);
54                 LABEL(classname_found)
55         }
56
57         if (wasfreed(item))
58                 return false;
59
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;
63
64         item.spawnfunc_checked = true;
65         return true;
66 }
67
68
69 // Compatibility spawn functions
70
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)