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