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