]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/items/spawning.qc
Add g_powerups_dropondeath setting (off by default, whitelisted)
[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
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.
17 .bool m_isexpiring;
18
19 entity Item_FindDefinition(string class_name)
20 {
21         FOREACH(Items, it.m_canonical_spawnfunc == class_name,
22         {
23                 return it;
24         });
25         FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
26         {
27                 return it.m_pickup;
28         });
29         return NULL;
30 }
31
32 entity Item_DefinitionFromInternalName(string item_name)
33 {
34         FOREACH(Items, it.netname == item_name,
35         {
36                 return it;
37         });
38         FOREACH(Weapons, it.netname == item_name,
39         {
40                 return it.m_pickup;
41         });
42         return NULL;
43 }
44
45 bool Item_IsAllowed(string class_name)
46 {
47         entity definition = Item_FindDefinition(class_name);
48         if (definition == NULL)
49         {
50                 return false;
51         }
52         return Item_IsDefinitionAllowed(definition);
53 }
54
55 bool Item_IsDefinitionAllowed(entity definition)
56 {
57         return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
58 }
59
60 entity Item_Create(string class_name, vector position, bool no_align)
61 {
62         entity item = spawn();
63         item.classname = class_name;
64         item.spawnfunc_checked = true;
65         setorigin(item, position);
66         item.noalign = no_align;
67         Item_Initialize(item, class_name);
68         if (wasfreed(item))
69         {
70                 return NULL;
71         }
72         return item;
73 }
74
75 void Item_Initialize(entity item, string class_name)
76 {
77         FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
78         {
79                 weapon_defaultspawnfunc(item, it);
80                 return;
81         });
82         FOREACH(Items, it.m_canonical_spawnfunc == class_name,
83         {
84                 StartItem(item, it);
85                 return;
86         });
87         LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
88 }
89
90 entity Item_CreateLoot(string class_name, vector position, vector vel,
91         float time_to_live)
92 {
93         entity item = spawn();
94         if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
95         {
96                 return NULL;
97         }
98         return item;
99 }
100
101 bool Item_InitializeLoot(entity item, string class_name, vector position,
102         vector vel, float time_to_live)
103 {
104         item.classname = class_name;
105         Item_SetLoot(item, true);
106         item.noalign = true;
107         setorigin(item, position);
108         item.pickup_anyway = true;
109         item.spawnfunc_checked = true;
110         Item_Initialize(item, class_name);
111         if (wasfreed(item))
112         {
113                 return false;
114         }
115         item.gravity = 1;
116         item.velocity = vel;
117         SUB_SetFade(item, time + time_to_live, 1);
118         return true;
119 }
120
121 bool Item_IsLoot(entity item)
122 {
123         return item.m_isloot || item.classname == "droppedweapon";
124 }
125
126 void Item_SetLoot(entity item, bool loot)
127 {
128         item.m_isloot = loot;
129 }
130
131 bool Item_ShouldKeepPosition(entity item)
132 {
133         return item.noalign || (item.spawnflags & 1);
134 }
135
136 bool Item_IsExpiring(entity item)
137 {
138         return item.m_isexpiring;
139 }
140
141 void Item_SetExpiring(entity item, bool expiring)
142 {
143         item.m_isexpiring = expiring;
144 }
145
146 // Compatibility spawn functions
147
148 // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
149 SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall)
150
151 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega)
152
153 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
154
155 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
156
157 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
158
159 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
160
161 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
162
163 SPAWNFUNC_ITEM(item_quad, ITEM_Strength)