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