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