]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/items/spawning.qc
Merge branch 'master' into bones_was_here/q3compat
[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 bool Item_IsAllowed(string class_name)
33 {
34         entity definition = Item_FindDefinition(class_name);
35         if (definition == NULL)
36         {
37                 return false;
38         }
39         return Item_IsDefinitionAllowed(definition);
40 }
41
42 bool Item_IsDefinitionAllowed(entity definition)
43 {
44         return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
45 }
46
47 entity Item_Create(string class_name, vector position, bool no_align)
48 {
49         entity item = spawn();
50         item.classname = class_name;
51         item.spawnfunc_checked = true;
52         setorigin(item, position);
53         item.noalign = no_align;
54         Item_Initialize(item, class_name);
55         if (wasfreed(item))
56         {
57                 return NULL;
58         }
59         return item;
60 }
61
62 void Item_Initialize(entity item, string class_name)
63 {
64         FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
65         {
66                 weapon_defaultspawnfunc(item, it);
67                 return;
68         });
69         FOREACH(Items, it.m_canonical_spawnfunc == class_name,
70         {
71                 StartItem(item, it);
72                 return;
73         });
74         LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
75 }
76
77 entity Item_CreateLoot(string class_name, vector position, vector vel,
78         float time_to_live)
79 {
80         entity item = spawn();
81         if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
82         {
83                 return NULL;
84         }
85         return item;
86 }
87
88 bool Item_InitializeLoot(entity item, string class_name, vector position,
89         vector vel, float time_to_live)
90 {
91         item.classname = class_name;
92         Item_SetLoot(item, true);
93         item.noalign = true;
94         setorigin(item, position);
95         item.pickup_anyway = true;
96         item.spawnfunc_checked = true;
97         Item_Initialize(item, class_name);
98         if (wasfreed(item))
99         {
100                 return false;
101         }
102         item.gravity = 1;
103         item.velocity = vel;
104         SUB_SetFade(item, time + time_to_live, 1);
105         return true;
106 }
107
108 bool Item_IsLoot(entity item)
109 {
110         return item.m_isloot || item.classname == "droppedweapon";
111 }
112
113 void Item_SetLoot(entity item, bool loot)
114 {
115         item.m_isloot = loot;
116 }
117
118 bool Item_ShouldKeepPosition(entity item)
119 {
120         return item.noalign || (item.spawnflags & 1);
121 }
122
123 bool Item_IsExpiring(entity item)
124 {
125         return item.m_isexpiring;
126 }
127
128 void Item_SetExpiring(entity item, bool expiring)
129 {
130         item.m_isexpiring = expiring;
131 }
132
133 // Compatibility spawn functions
134
135 SPAWNFUNC_ITEM_COND(item_armor1, cvar("sv_mapformat_is_quake3"), ITEM_ArmorSmall, ITEM_ArmorMedium)
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)