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