]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/items/spawning.qc
Some more cleanup of defs.qh, use a flag to indicate crouch state instead of a separa...
[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 <server/mutators/_mod.qh>
9 #include <server/weapons/spawning.qh>
10 #include <common/weapons/all.qh>
11 #include <common/mapobjects/subs.qh>
12
13 .bool m_isloot; ///< Holds whether item is loot.
14 /// \brief Holds whether strength, shield or superweapon timers expire while
15 /// this item is on the ground.
16 .bool m_isexpiring;
17
18 entity Item_FindDefinition(string class_name)
19 {
20         FOREACH(Items, it.m_canonical_spawnfunc == class_name,
21         {
22                 return it;
23         });
24         FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
25         {
26                 return it.m_pickup;
27         });
28         return NULL;
29 }
30
31 bool Item_IsAllowed(string class_name)
32 {
33         entity definition = Item_FindDefinition(class_name);
34         if (definition == NULL)
35         {
36                 return false;
37         }
38         return Item_IsDefinitionAllowed(definition);
39 }
40
41 bool Item_IsDefinitionAllowed(entity definition)
42 {
43         return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
44 }
45
46 entity Item_Create(string class_name, vector position, bool no_align)
47 {
48         entity item = spawn();
49         item.classname = class_name;
50         item.spawnfunc_checked = true;
51         setorigin(item, position);
52         item.noalign = no_align;
53         Item_Initialize(item, class_name);
54         if (wasfreed(item))
55         {
56                 return NULL;
57         }
58         return item;
59 }
60
61 void Item_Initialize(entity item, string class_name)
62 {
63         FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
64         {
65                 weapon_defaultspawnfunc(item, it);
66                 return;
67         });
68         FOREACH(Items, it.m_canonical_spawnfunc == class_name,
69         {
70                 StartItem(item, it);
71                 return;
72         });
73         LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
74 }
75
76 entity Item_CreateLoot(string class_name, vector position, vector vel,
77         float time_to_live)
78 {
79         entity item = spawn();
80         if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
81         {
82                 return NULL;
83         }
84         return item;
85 }
86
87 bool Item_InitializeLoot(entity item, string class_name, vector position,
88         vector vel, float time_to_live)
89 {
90         item.classname = class_name;
91         Item_SetLoot(item, true);
92         item.noalign = true;
93         setorigin(item, position);
94         item.pickup_anyway = true;
95         item.spawnfunc_checked = true;
96         Item_Initialize(item, class_name);
97         if (wasfreed(item))
98         {
99                 return false;
100         }
101         item.gravity = 1;
102         item.velocity = vel;
103         SUB_SetFade(item, time + time_to_live, 1);
104         return true;
105 }
106
107 bool Item_IsLoot(entity item)
108 {
109         return item.m_isloot || item.classname == "droppedweapon";
110 }
111
112 void Item_SetLoot(entity item, bool loot)
113 {
114         item.m_isloot = loot;
115 }
116
117 bool Item_ShouldKeepPosition(entity item)
118 {
119         return item.noalign || (item.spawnflags & 1);
120 }
121
122 bool Item_IsExpiring(entity item)
123 {
124         return item.m_isexpiring;
125 }
126
127 void Item_SetExpiring(entity item, bool expiring)
128 {
129         item.m_isexpiring = expiring;
130 }
131
132 // Compatibility spawn functions
133
134 // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
135 SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall)
136
137 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega)
138
139 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
140
141 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
142
143 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
144
145 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
146
147 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
148
149 SPAWNFUNC_ITEM(item_quad, ITEM_Strength)