]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/items.qc
Partially fixed compilation units.
[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 <common/mutators/mutator/instagib/sv_instagib.qh>
9
10 .bool m_isloot; ///< Holds whether item is loot.
11
12 entity Item_Create(string class_name, vector position)
13 {
14         entity item = spawn();
15         item.classname = class_name;
16         item.spawnfunc_checked = true;
17         Item_Initialize(item, class_name);
18         if (wasfreed(item))
19         {
20                 return NULL;
21         }
22         setorigin(item, position);
23         return item;
24 }
25
26 void Item_Initialize(entity item, string class_name)
27 {
28         switch (class_name)
29         {
30                 case "item_health_small":
31                 {
32                         spawnfunc_item_health_small(item);
33                         return;
34                 }
35                 case "item_health_medium":
36                 {
37                         spawnfunc_item_health_medium(item);
38                         return;
39                 }
40                 case "item_health_big":
41                 case "item_health_large":
42                 {
43                         spawnfunc_item_health_big(item);
44                         return;
45                 }
46                 case "item_health_mega":
47                 {
48                         spawnfunc_item_health_mega(item);
49                         return;
50                 }
51                 case "item_armor_small":
52                 {
53                         spawnfunc_item_armor_small(item);
54                         return;
55                 }
56                 case "item_armor_medium":
57                 {
58                         spawnfunc_item_armor_medium(item);
59                         return;
60                 }
61                 case "item_armor_big":
62                 case "item_armor_large":
63                 {
64                         spawnfunc_item_armor_big(item);
65                         return;
66                 }
67                 case "item_armor_mega":
68                 {
69                         spawnfunc_item_armor_mega(item);
70                         return;
71                 }
72                 case "item_shells":
73                 {
74                         spawnfunc_item_shells(item);
75                         return;
76                 }
77                 case "item_bullets":
78                 {
79                         spawnfunc_item_bullets(item);
80                         return;
81                 }
82                 case "item_rockets":
83                 {
84                         spawnfunc_item_rockets(item);
85                         return;
86                 }
87                 case "item_cells":
88                 {
89                         spawnfunc_item_cells(item);
90                         return;
91                 }
92                 case "item_plasma":
93                 {
94                         spawnfunc_item_plasma(item);
95                         return;
96                 }
97                 case "item_fuel":
98                 {
99                         spawnfunc_item_fuel(item);
100                         return;
101                 }
102                 case "weapon_blaster":
103                 case "weapon_laser":
104                 {
105                         spawnfunc_weapon_blaster(item);
106                         return;
107                 }
108                 case "weapon_shotgun":
109                 {
110                         spawnfunc_weapon_shotgun(item);
111                         return;
112                 }
113                 case "weapon_machinegun":
114                 case "weapon_uzi":
115                 {
116                         spawnfunc_weapon_machinegun(item);
117                         return;
118                 }
119                 case "weapon_mortar":
120                 case "weapon_grenadelauncher":
121                 {
122                         spawnfunc_weapon_mortar(item);
123                         return;
124                 }
125                 case "weapon_electro":
126                 {
127                         spawnfunc_weapon_electro(item);
128                         return;
129                 }
130                 case "weapon_crylink":
131                 {
132                         spawnfunc_weapon_crylink(item);
133                         return;
134                 }
135                 case "weapon_vortex":
136                 case "weapon_nex":
137                 {
138                         spawnfunc_weapon_vortex(item);
139                         return;
140                 }
141                 case "weapon_hagar":
142                 {
143                         spawnfunc_weapon_hagar(item);
144                         return;
145                 }
146                 case "weapon_devastator":
147                 case "weapon_rocketlauncher":
148                 {
149                         spawnfunc_weapon_devastator(item);
150                         return;
151                 }
152                 case "weapon_shockwave":
153                 {
154                         spawnfunc_weapon_shockwave(item);
155                         return;
156                 }
157                 case "weapon_arc":
158                 {
159                         spawnfunc_weapon_arc(item);
160                         return;
161                 }
162                 case "weapon_hook":
163                 {
164                         spawnfunc_weapon_hook(item);
165                         return;
166                 }
167                 case "weapon_tuba":
168                 {
169                         spawnfunc_weapon_tuba(item);
170                         return;
171                 }
172                 case "weapon_porto":
173                 {
174                         spawnfunc_weapon_porto(item);
175                         return;
176                 }
177                 case "weapon_fireball":
178                 {
179                         spawnfunc_weapon_fireball(item);
180                         return;
181                 }
182                 case "weapon_minelayer":
183                 {
184                         spawnfunc_weapon_minelayer(item);
185                         return;
186                 }
187                 case "weapon_hlac":
188                 {
189                         spawnfunc_weapon_hlac(item);
190                         return;
191                 }
192                 case "weapon_rifle":
193                 case "weapon_campingrifle":
194                 case "weapon_sniperrifle":
195                 {
196                         spawnfunc_weapon_rifle(item);
197                         return;
198                 }
199                 case "weapon_seeker":
200                 {
201                         spawnfunc_weapon_seeker(item);
202                         return;
203                 }
204                 case "weapon_vaporizer":
205                 case "weapon_minstanex":
206                 {
207                         spawnfunc_weapon_vaporizer(item);
208                         return;
209                 }
210                 case "item_strength":
211                 {
212                         spawnfunc_item_strength(item);
213                         return;
214                 }
215                 case "item_invincible":
216                 {
217                         spawnfunc_item_invincible(item);
218                         return;
219                 }
220                 case "item_fuel_regen":
221                 {
222                         spawnfunc_item_fuel_regen(item);
223                         return;
224                 }
225                 case "item_jetpack":
226                 {
227                         spawnfunc_item_jetpack(item);
228                         return;
229                 }
230                 case "item_vaporizer_cells":
231                 {
232                         spawnfunc_item_vaporizer_cells(item);
233                         return;
234                 }
235                 case "item_invisibility":
236                 {
237                         instagib_invisibility(item);
238                         return;
239                 }
240                 case "item_extralife":
241                 {
242                         instagib_extralife(item);
243                         return;
244                 }
245                 case "item_speed":
246                 {
247                         instagib_speed(item);
248                         return;
249                 }
250         }
251         error("Item_Initialize: Invalid classname ", class_name);
252 }
253
254 entity Item_CreateLoot(string class_name, vector position, vector vel,
255         float time_to_live)
256 {
257         entity item = spawn();
258         if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
259         {
260                 return NULL;
261         }
262         return item;
263 }
264
265 bool Item_InitializeLoot(entity item, string class_name, vector position,
266         vector vel, float time_to_live)
267 {
268         item.classname = class_name;
269         Item_SetLoot(item, true);
270         item.noalign = true;
271         item.pickup_anyway = true;
272         item.spawnfunc_checked = true;
273         Item_Initialize(item, class_name);
274         if (wasfreed(item))
275         {
276                 return false;
277         }
278         item.gravity = 1;
279         setorigin(item, position);
280         item.velocity = vel;
281         SUB_SetFade(item, time + time_to_live, 1);
282         return true;
283 }
284
285 bool Item_IsLoot(entity item)
286 {
287         return item.m_isloot || (item.classname == "droppedweapon");
288 }
289
290 void Item_SetLoot(entity item, bool loot)
291 {
292         item.m_isloot = loot;
293 }
294
295 spawnfunc(item_health_small)
296 {
297         StartItem(this, ITEM_HealthSmall);
298 }
299
300 spawnfunc(item_health_medium)
301 {
302         StartItem(this, ITEM_HealthMedium);
303 }
304
305 spawnfunc(item_health_big)
306 {
307         StartItem(this, ITEM_HealthBig);
308 }
309
310 spawnfunc(item_health_mega)
311 {
312         StartItem(this, ITEM_HealthMega);
313 }
314
315 spawnfunc(item_armor_small)
316 {
317         StartItem(this, ITEM_ArmorSmall);
318 }
319
320 spawnfunc(item_armor_medium)
321 {
322         StartItem(this, ITEM_ArmorMedium);
323 }
324
325 spawnfunc(item_armor_big)
326 {
327         StartItem(this, ITEM_ArmorBig);
328 }
329
330 spawnfunc(item_armor_mega)
331 {
332         StartItem(this, ITEM_ArmorMega);
333 }
334
335 spawnfunc(item_shells)
336 {
337         if (!weaponswapping && autocvar_sv_q3acompat_machineshotgunswap &&
338                 (this.classname != "droppedweapon"))
339         {
340                 weaponswapping = true;
341                 spawnfunc_item_bullets(this);
342                 weaponswapping = false;
343                 return;
344         }
345         StartItem(this, ITEM_Shells);
346 }
347
348 spawnfunc(item_bullets)
349 {
350         if (!weaponswapping && autocvar_sv_q3acompat_machineshotgunswap &&
351                 (this.classname != "droppedweapon"))
352         {
353                 weaponswapping = true;
354                 spawnfunc_item_shells(this);
355                 weaponswapping = false;
356                 return;
357         }
358         StartItem(this, ITEM_Bullets);
359 }
360
361 spawnfunc(item_rockets)
362 {
363         StartItem(this, ITEM_Rockets);
364 }
365
366 spawnfunc(item_cells)
367 {
368         StartItem(this, ITEM_Cells);
369 }
370
371 spawnfunc(item_plasma)
372 {
373         StartItem(this, ITEM_Plasma);
374 }
375
376 spawnfunc(item_fuel)
377 {
378         StartItem(this, ITEM_JetpackFuel);
379 }
380
381 spawnfunc(item_strength)
382 {
383         StartItem(this, ITEM_Strength);
384 }
385
386 spawnfunc(item_invincible)
387 {
388         StartItem(this, ITEM_Shield);
389 }
390
391 spawnfunc(item_fuel_regen)
392 {
393         if (start_items & ITEM_JetpackRegen.m_itemid)
394         {
395                 spawnfunc_item_fuel(this);
396                 return;
397         }
398         StartItem(this, ITEM_JetpackRegen);
399 }
400
401 spawnfunc(item_jetpack)
402 {
403         if(start_items & ITEM_Jetpack.m_itemid)
404         {
405                 spawnfunc_item_fuel(this);
406                 return;
407         }
408         StartItem(this, ITEM_Jetpack);
409 }
410
411 // Compatibility spawn functions
412
413 spawnfunc(item_armor1) { spawnfunc_item_armor_small(this); }  // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
414 spawnfunc(item_armor25) { spawnfunc_item_armor_mega(this); }
415 spawnfunc(item_armor_large) { spawnfunc_item_armor_mega(this); }
416 spawnfunc(item_health1) { spawnfunc_item_health_small(this); }
417 spawnfunc(item_health25) { spawnfunc_item_health_medium(this); }
418 spawnfunc(item_health_large) { spawnfunc_item_health_big(this); }
419 spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }