2 /// \brief Source file that contains implementation of the random items mutator.
4 /// \copyright GNU GPLv2 or any later version.
6 //============================ Constants ======================================
10 RANDOM_ITEM_TYPE_HEALTH,
11 RANDOM_ITEM_TYPE_ARMOR,
12 RANDOM_ITEM_TYPE_RESOURCE,
13 RANDOM_ITEM_TYPE_WEAPON,
14 RANDOM_ITEM_TYPE_POWERUP
19 RANDOM_ITEM_SUBTYPE_HEALTH_SMALL,
20 RANDOM_ITEM_SUBTYPE_HEALTH_MEDIUM,
21 RANDOM_ITEM_SUBTYPE_HEALTH_BIG,
22 RANDOM_ITEM_SUBTYPE_HEALTH_MEGA
27 RANDOM_ITEM_SUBTYPE_ARMOR_SMALL,
28 RANDOM_ITEM_SUBTYPE_ARMOR_MEDIUM,
29 RANDOM_ITEM_SUBTYPE_ARMOR_BIG,
30 RANDOM_ITEM_SUBTYPE_ARMOR_MEGA
35 RANDOM_ITEM_SUBTYPE_RESOURCE_SHELLS,
36 RANDOM_ITEM_SUBTYPE_RESOURCE_BULLETS,
37 RANDOM_ITEM_SUBTYPE_RESOURCE_ROCKETS,
38 RANDOM_ITEM_SUBTYPE_RESOURCE_CELLS,
39 RANDOM_ITEM_SUBTYPE_RESOURCE_PLASMA,
40 RANDOM_ITEM_SUBTYPE_RESOURCE_FUEL,
45 RANDOM_ITEM_SUBTYPE_WEAPON_BLASTER,
46 RANDOM_ITEM_SUBTYPE_WEAPON_SHOTGUN,
47 RANDOM_ITEM_SUBTYPE_WEAPON_MACHINEGUN,
48 RANDOM_ITEM_SUBTYPE_WEAPON_MORTAR,
49 RANDOM_ITEM_SUBTYPE_WEAPON_ELECTRO,
50 RANDOM_ITEM_SUBTYPE_WEAPON_CRYLINK,
51 RANDOM_ITEM_SUBTYPE_WEAPON_VORTEX,
52 RANDOM_ITEM_SUBTYPE_WEAPON_HAGAR,
53 RANDOM_ITEM_SUBTYPE_WEAPON_DEVASTATOR,
54 RANDOM_ITEM_SUBTYPE_WEAPON_SHOCKWAVE,
55 RANDOM_ITEM_SUBTYPE_WEAPON_ARC,
56 RANDOM_ITEM_SUBTYPE_WEAPON_HOOK,
57 RANDOM_ITEM_SUBTYPE_WEAPON_TUBA,
58 RANDOM_ITEM_SUBTYPE_WEAPON_PORTO,
59 RANDOM_ITEM_SUBTYPE_WEAPON_FIREBALL,
60 RANDOM_ITEM_SUBTYPE_WEAPON_MINELAYER,
61 RANDOM_ITEM_SUBTYPE_WEAPON_HLAC,
62 RANDOM_ITEM_SUBTYPE_WEAPON_RIFLE,
63 RANDOM_ITEM_SUBTYPE_WEAPON_SEEKER,
64 RANDOM_ITEM_SUBTYPE_WEAPON_VAPORIZER
69 RANDOM_ITEM_SUBTYPE_POWERUP_STRENGTH,
70 RANDOM_ITEM_SUBTYPE_POWERUP_SHIELD,
71 RANDOM_ITEM_SUBTYPE_POWERUP_FUEL_REGEN,
72 RANDOM_ITEM_SUBTYPE_POWERUP_JETPACK
77 RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS,
78 RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY,
79 RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE,
80 RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED
83 //======================= Global variables ====================================
85 bool autocvar_g_random_items; ///< Whether to enable random items.
89 /// \brief Classnames to replace small health with.
90 string autocvar_g_random_items_replace_health_small;
91 /// \brief Classnames to replace medium health with.
92 string autocvar_g_random_items_replace_health_medium;
93 /// \brief Classnames to replace big health with.
94 string autocvar_g_random_items_replace_health_big;
95 /// \brief Classnames to replace mega health with.
96 string autocvar_g_random_items_replace_health_mega;
98 /// \brief Classnames to replace small armor with.
99 string autocvar_g_random_items_replace_armor_small;
100 /// \brief Classnames to replace medium armor with.
101 string autocvar_g_random_items_replace_armor_medium;
102 /// \brief Classnames to replace big armor with.
103 string autocvar_g_random_items_replace_armor_big;
104 /// \brief Classnames to replace mega armor with.
105 string autocvar_g_random_items_replace_armor_mega;
107 /// \brief Classnames to replace shells with.
108 string autocvar_g_random_items_replace_item_shells;
109 /// \brief Classnames to replace bullets with.
110 string autocvar_g_random_items_replace_item_bullets;
111 /// \brief Classnames to replace rockets with.
112 string autocvar_g_random_items_replace_item_rockets;
113 /// \brief Classnames to replace cells with.
114 string autocvar_g_random_items_replace_item_cells;
115 /// \brief Classnames to replace plasma with.
116 string autocvar_g_random_items_replace_item_plasma;
117 /// \brief Classnames to replace fuel with.
118 string autocvar_g_random_items_replace_item_fuel;
120 /// \brief Classnames to replace blaster with.
121 string autocvar_g_random_items_replace_weapon_blaster;
122 /// \brief Classnames to replace shotgun with.
123 string autocvar_g_random_items_replace_weapon_shotgun;
124 /// \brief Classnames to replace machinegun with.
125 string autocvar_g_random_items_replace_weapon_machinegun;
126 /// \brief Classnames to replace mortar with.
127 string autocvar_g_random_items_replace_weapon_mortar;
128 /// \brief Classnames to replace electro with.
129 string autocvar_g_random_items_replace_weapon_electro;
130 /// \brief Classnames to replace crylink with.
131 string autocvar_g_random_items_replace_weapon_crylink;
132 /// \brief Classnames to replace vortex with.
133 string autocvar_g_random_items_replace_weapon_vortex;
134 /// \brief Classnames to replace hagar with.
135 string autocvar_g_random_items_replace_weapon_hagar;
136 /// \brief Classnames to replace devastator with.
137 string autocvar_g_random_items_replace_weapon_devastator;
138 /// \brief Classnames to replace shockwave with.
139 string autocvar_g_random_items_replace_weapon_shockwave;
140 /// \brief Classnames to replace arc with.
141 string autocvar_g_random_items_replace_weapon_arc;
142 /// \brief Classnames to replace hook with.
143 string autocvar_g_random_items_replace_weapon_hook;
144 /// \brief Classnames to replace tuba with.
145 string autocvar_g_random_items_replace_weapon_tuba;
146 /// \brief Classnames to replace port-o-launch with.
147 string autocvar_g_random_items_replace_weapon_porto;
148 /// \brief Classnames to replace fireball with.
149 string autocvar_g_random_items_replace_weapon_fireball;
150 /// \brief Classnames to replace mine layer with.
151 string autocvar_g_random_items_replace_weapon_minelayer;
152 /// \brief Classnames to replace HLAC with.
153 string autocvar_g_random_items_replace_weapon_hlac;
154 /// \brief Classnames to replace rifle with.
155 string autocvar_g_random_items_replace_weapon_rifle;
156 /// \brief Classnames to replace TAG seeker with.
157 string autocvar_g_random_items_replace_weapon_seeker;
158 /// \brief Classnames to replace vaporizer with.
159 string autocvar_g_random_items_replace_weapon_vaporizer;
161 /// \brief Classnames to replace strength with.
162 string autocvar_g_random_items_replace_item_strength;
163 /// \brief Classnames to replace shield with.
164 string autocvar_g_random_items_replace_item_shield;
165 /// \brief Classnames to replace fuel regeneration with.
166 string autocvar_g_random_items_replace_item_fuel_regen;
167 /// \brief Classnames to replace jetpack with.
168 string autocvar_g_random_items_replace_item_jetpack;
170 /// \brief Classnames to replace vaporizer cells with.
171 string autocvar_g_random_items_replace_item_vaporizer_cells;
172 /// \brief Classnames to replace invisibility with.
173 string autocvar_g_random_items_replace_item_invisibility;
174 /// \brief Classnames to replace extra life with.
175 string autocvar_g_random_items_replace_item_extralife;
176 /// \brief Classnames to replace speed with.
177 string autocvar_g_random_items_replace_item_speed;
179 // Map probability cvars
181 /// \brief Probability of random health items spawning in the map.
182 float autocvar_g_random_items_health_probability;
183 /// \brief Probability of random armor items spawning in the map.
184 float autocvar_g_random_items_armor_probability;
185 /// \brief Probability of random resource items spawning in the map.
186 float autocvar_g_random_items_resource_probability;
187 /// \brief Probability of random weapons spawning in the map.
188 float autocvar_g_random_items_weapon_probability;
189 /// \brief Probability of random powerups spawning in the map.
190 float autocvar_g_random_items_powerup_probability;
192 /// \brief Probability of random small health spawning in the map.
193 float autocvar_g_random_items_health_small_probability;
194 /// \brief Probability of random medium health spawning in the map.
195 float autocvar_g_random_items_health_medium_probability;
196 /// \brief Probability of random big health spawning in the map.
197 float autocvar_g_random_items_health_big_probability;
198 /// \brief Probability of random mega health spawning in the map.
199 float autocvar_g_random_items_health_mega_probability;
201 /// \brief Probability of random small armor spawning in the map.
202 float autocvar_g_random_items_armor_small_probability;
203 /// \brief Probability of random medium armor.spawning in the map.
204 float autocvar_g_random_items_armor_medium_probability;
205 /// \brief Probability of random big armor spawning in the map.
206 float autocvar_g_random_items_armor_big_probability;
207 /// \brief Probability of random mega armor spawning in the map.
208 float autocvar_g_random_items_armor_mega_probability;
210 /// \brief Probability of random shells spawning in the map.
211 float autocvar_g_random_items_resource_shells_probability;
212 /// \brief Probability of random bullets spawning in the map.
213 float autocvar_g_random_items_resource_bullets_probability;
214 /// \brief Probability of random rockets spawning in the map.
215 float autocvar_g_random_items_resource_rockets_probability;
216 /// \brief Probability of random cells spawning in the map.
217 float autocvar_g_random_items_resource_cells_probability;
218 /// \brief Probability of random plasma spawning in the map.
219 float autocvar_g_random_items_resource_plasma_probability;
220 /// \brief Probability of random fuel spawning in the map.
221 float autocvar_g_random_items_resource_fuel_probability;
223 /// \brief Probability of random blaster spawning in the map.
224 float autocvar_g_random_items_weapon_blaster_probability;
225 /// \brief Probability of random shotgun spawning in the map.
226 float autocvar_g_random_items_weapon_shotgun_probability;
227 /// \brief Probability of random machinegun spawning in the map.
228 float autocvar_g_random_items_weapon_machinegun_probability;
229 /// \brief Probability of random mortar spawning in the map.
230 float autocvar_g_random_items_weapon_mortar_probability;
231 /// \brief Probability of random electro spawning in the map.
232 float autocvar_g_random_items_weapon_electro_probability;
233 /// \brief Probability of random crylink spawning in the map.
234 float autocvar_g_random_items_weapon_crylink_probability;
235 /// \brief Probability of random vortex spawning in the map.
236 float autocvar_g_random_items_weapon_vortex_probability;
237 /// \brief Probability of random hagar spawning in the map.
238 float autocvar_g_random_items_weapon_hagar_probability;
239 /// \brief Probability of random devastator spawning in the map.
240 float autocvar_g_random_items_weapon_devastator_probability;
241 /// \brief Probability of random shockwave spawning in the map.
242 float autocvar_g_random_items_weapon_shockwave_probability;
243 /// \brief Probability of random arc spawning in the map.
244 float autocvar_g_random_items_weapon_arc_probability;
245 /// \brief Probability of random hook spawning in the map.
246 float autocvar_g_random_items_weapon_hook_probability;
247 /// \brief Probability of random tuba spawning in the map.
248 float autocvar_g_random_items_weapon_tuba_probability;
249 /// \brief Probability of random port-o-launch spawning in the map.
250 float autocvar_g_random_items_weapon_porto_probability;
251 /// \brief Probability of random fireball spawning in the map.
252 float autocvar_g_random_items_weapon_fireball_probability;
253 /// \brief Probability of random mine layer spawning in the map.
254 float autocvar_g_random_items_weapon_minelayer_probability;
255 /// \brief Probability of random HLAC spawning in the map.
256 float autocvar_g_random_items_weapon_hlac_probability;
257 /// \brief Probability of random rifle spawning in the map.
258 float autocvar_g_random_items_weapon_rifle_probability;
259 /// \brief Probability of random TAG seeker spawning in the map.
260 float autocvar_g_random_items_weapon_seeker_probability;
261 /// \brief Probability of random vaporizer spawning in the map.
262 float autocvar_g_random_items_weapon_vaporizer_probability;
264 /// \brief Probability of random strength spawning in the map.
265 float autocvar_g_random_items_strength_probability;
266 /// \brief Probability of random shield spawning in the map.
267 float autocvar_g_random_items_shield_probability;
268 /// \brief Probability of random fuel regeneration spawning in the map.
269 float autocvar_g_random_items_fuel_regen_probability;
270 /// \brief Probability of random jetpack spawning in the map.
271 float autocvar_g_random_items_jetpack_probability;
273 /// \brief Probability of random vaporizer cells spawning in the map.
274 float autocvar_g_random_items_vaporizer_cells_probability;
275 /// \brief Probability of random invisibility spawning in the map.
276 float autocvar_g_random_items_invisibility_probability;
277 /// \brief Probability of random extra life spawning in the map.
278 float autocvar_g_random_items_extralife_probability;
279 /// \brief Probability of random speed spawning in the map.
280 float autocvar_g_random_items_speed_probability;
284 bool autocvar_g_random_loot; ///< Whether to enable random loot.
286 float autocvar_g_random_loot_min; ///< Minimum amount of loot items.
287 float autocvar_g_random_loot_max; ///< Maximum amount of loot items.
288 float autocvar_g_random_loot_time; ///< Amount of time the loot will stay.
289 float autocvar_g_random_loot_spread; ///< How far can loot be thrown.
291 // Loot probability cvars
293 /// \brief Probability of random health items spawning as loot.
294 float autocvar_g_random_loot_health_probability;
295 /// \brief Probability of random armor items spawning as loot.
296 float autocvar_g_random_loot_armor_probability;
297 /// \brief Probability of random resource items spawning as loot.
298 float autocvar_g_random_loot_resource_probability;
299 /// \brief Probability of random weapons spawning as loot.
300 float autocvar_g_random_loot_weapon_probability;
301 /// \brief Probability of random powerups spawning as loot.
302 float autocvar_g_random_loot_powerup_probability;
304 /// \brief Probability of random small health spawning as loot.
305 float autocvar_g_random_loot_health_small_probability;
306 /// \brief Probability of random medium health spawning as loot.
307 float autocvar_g_random_loot_health_medium_probability;
308 /// \brief Probability of random big health spawning as loot.
309 float autocvar_g_random_loot_health_big_probability;
310 /// \brief Probability of random mega health spawning as loot.
311 float autocvar_g_random_loot_health_mega_probability;
313 /// \brief Probability of random small armor spawning as loot.
314 float autocvar_g_random_loot_armor_small_probability;
315 /// \brief Probability of random medium armor.spawning as loot.
316 float autocvar_g_random_loot_armor_medium_probability;
317 /// \brief Probability of random big armor spawning as loot.
318 float autocvar_g_random_loot_armor_big_probability;
319 /// \brief Probability of random mega armor spawning as loot.
320 float autocvar_g_random_loot_armor_mega_probability;
322 /// \brief Probability of random shells spawning as loot.
323 float autocvar_g_random_loot_resource_shells_probability;
324 /// \brief Probability of random bullets spawning as loot.
325 float autocvar_g_random_loot_resource_bullets_probability;
326 /// \brief Probability of random rockets spawning as loot.
327 float autocvar_g_random_loot_resource_rockets_probability;
328 /// \brief Probability of random cells spawning as loot.
329 float autocvar_g_random_loot_resource_cells_probability;
330 /// \brief Probability of random plasma spawning as loot.
331 float autocvar_g_random_loot_resource_plasma_probability;
332 /// \brief Probability of random fuel spawning as loot.
333 float autocvar_g_random_loot_resource_fuel_probability;
335 /// \brief Probability of random blaster spawning as loot.
336 float autocvar_g_random_loot_weapon_blaster_probability;
337 /// \brief Probability of random shotgun spawning as loot.
338 float autocvar_g_random_loot_weapon_shotgun_probability;
339 /// \brief Probability of random machinegun spawning as loot.
340 float autocvar_g_random_loot_weapon_machinegun_probability;
341 /// \brief Probability of random mortar spawning as loot.
342 float autocvar_g_random_loot_weapon_mortar_probability;
343 /// \brief Probability of random electro spawning as loot.
344 float autocvar_g_random_loot_weapon_electro_probability;
345 /// \brief Probability of random crylink spawning as loot.
346 float autocvar_g_random_loot_weapon_crylink_probability;
347 /// \brief Probability of random vortex spawning as loot.
348 float autocvar_g_random_loot_weapon_vortex_probability;
349 /// \brief Probability of random hagar spawning as loot.
350 float autocvar_g_random_loot_weapon_hagar_probability;
351 /// \brief Probability of random devastator spawning as loot.
352 float autocvar_g_random_loot_weapon_devastator_probability;
353 /// \brief Probability of random shockwave spawning as loot.
354 float autocvar_g_random_loot_weapon_shockwave_probability;
355 /// \brief Probability of random arc spawning as loot.
356 float autocvar_g_random_loot_weapon_arc_probability;
357 /// \brief Probability of random hook spawning as loot.
358 float autocvar_g_random_loot_weapon_hook_probability;
359 /// \brief Probability of random tuba spawning as loot.
360 float autocvar_g_random_loot_weapon_tuba_probability;
361 /// \brief Probability of random port-o-launch spawning as loot.
362 float autocvar_g_random_loot_weapon_porto_probability;
363 /// \brief Probability of random fireball spawning as loot.
364 float autocvar_g_random_loot_weapon_fireball_probability;
365 /// \brief Probability of random mine layer spawning as loot.
366 float autocvar_g_random_loot_weapon_minelayer_probability;
367 /// \brief Probability of random HLAC spawning as loot.
368 float autocvar_g_random_loot_weapon_hlac_probability;
369 /// \brief Probability of random rifle spawning as loot.
370 float autocvar_g_random_loot_weapon_rifle_probability;
371 /// \brief Probability of random TAG seeker spawning as loot.
372 float autocvar_g_random_loot_weapon_seeker_probability;
373 /// \brief Probability of random vaporizer spawning as loot.
374 float autocvar_g_random_loot_weapon_vaporizer_probability;
376 /// \brief Probability of random strength spawning as loot.
377 float autocvar_g_random_loot_strength_probability;
378 /// \brief Probability of random shield spawning as loot.
379 float autocvar_g_random_loot_shield_probability;
380 /// \brief Probability of random fuel regeneration spawning as loot.
381 float autocvar_g_random_loot_fuel_regen_probability;
382 /// \brief Probability of random jetpack spawning as loot.
383 float autocvar_g_random_loot_jetpack_probability;
385 /// \brief Probability of random vaporizer cells spawning as loot.
386 float autocvar_g_random_loot_vaporizer_cells_probability;
387 /// \brief Probability of random invisibility spawning as loot.
388 float autocvar_g_random_loot_invisibility_probability;
389 /// \brief Probability of random extra life spawning as loot.
390 float autocvar_g_random_loot_extralife_probability;
391 /// \brief Probability of random speed spawning as loot.
392 float autocvar_g_random_loot_speed_probability;
394 /// \brief Holds whether random item is spawning. Used to prevent infinite
396 bool random_items_is_spawning = false;
398 //========================= Free functions ====================================
400 /// \brief Returns list of classnames to replace a map item with.
401 /// \param[in] item Item to inspect.
402 /// \return List of classnames to replace a map item with.
403 string RandomItems_GetItemReplacementClassNames(entity item)
405 switch (item.classname)
407 case "item_health_small":
409 return autocvar_g_random_items_replace_health_small;
411 case "item_health_medium":
413 return autocvar_g_random_items_replace_health_medium;
415 case "item_health_big":
416 case "item_health_large":
418 return autocvar_g_random_items_replace_health_big;
420 case "item_health_mega":
422 return autocvar_g_random_items_replace_health_mega;
424 case "item_armor_small":
426 return autocvar_g_random_items_replace_armor_small;
428 case "item_armor_medium":
430 return autocvar_g_random_items_replace_armor_medium;
432 case "item_armor_big":
433 case "item_armor_large":
435 return autocvar_g_random_items_replace_armor_big;
437 case "item_armor_mega":
439 return autocvar_g_random_items_replace_armor_mega;
443 return autocvar_g_random_items_replace_item_shells;
447 return autocvar_g_random_items_replace_item_bullets;
451 return autocvar_g_random_items_replace_item_rockets;
455 return autocvar_g_random_items_replace_item_cells;
459 return autocvar_g_random_items_replace_item_plasma;
463 return autocvar_g_random_items_replace_item_fuel;
465 case "weapon_blaster":
468 return autocvar_g_random_items_replace_weapon_blaster;
470 case "weapon_shotgun":
472 return autocvar_g_random_items_replace_weapon_shotgun;
474 case "weapon_machinegun":
477 return autocvar_g_random_items_replace_weapon_machinegun;
479 case "weapon_mortar":
480 case "weapon_grenadelauncher":
482 return autocvar_g_random_items_replace_weapon_mortar;
484 case "weapon_electro":
486 return autocvar_g_random_items_replace_weapon_electro;
488 case "weapon_crylink":
490 return autocvar_g_random_items_replace_weapon_crylink;
492 case "weapon_vortex":
495 return autocvar_g_random_items_replace_weapon_vortex;
499 return autocvar_g_random_items_replace_weapon_hagar;
501 case "weapon_devastator":
502 case "weapon_rocketlauncher":
504 return autocvar_g_random_items_replace_weapon_devastator;
506 case "weapon_shockwave":
508 return autocvar_g_random_items_replace_weapon_shockwave;
512 return autocvar_g_random_items_replace_weapon_arc;
516 return autocvar_g_random_items_replace_weapon_hook;
520 return autocvar_g_random_items_replace_weapon_tuba;
524 return autocvar_g_random_items_replace_weapon_porto;
526 case "weapon_fireball":
528 return autocvar_g_random_items_replace_weapon_fireball;
530 case "weapon_minelayer":
532 return autocvar_g_random_items_replace_weapon_minelayer;
536 return autocvar_g_random_items_replace_weapon_hlac;
539 case "weapon_campingrifle":
540 case "weapon_sniperrifle":
542 return autocvar_g_random_items_replace_weapon_rifle;
544 case "weapon_seeker":
546 return autocvar_g_random_items_replace_weapon_seeker;
548 case "weapon_vaporizer":
549 case "weapon_minstanex":
551 return autocvar_g_random_items_replace_weapon_vaporizer;
553 case "item_strength":
555 return autocvar_g_random_items_replace_item_strength;
557 case "item_invincible":
559 return autocvar_g_random_items_replace_item_shield;
561 case "item_fuel_regen":
563 return autocvar_g_random_items_replace_item_fuel_regen;
567 return autocvar_g_random_items_replace_item_jetpack;
569 case "item_vaporizer_cells":
571 return autocvar_g_random_items_replace_item_vaporizer_cells;
573 case "item_invisibility":
575 return autocvar_g_random_items_replace_item_invisibility;
577 case "item_extralife":
579 return autocvar_g_random_items_replace_item_extralife;
583 return autocvar_g_random_items_replace_item_speed;
585 case "replacedweapon":
589 case WEP_MINE_LAYER.m_id:
591 return autocvar_g_random_items_replace_weapon_minelayer;
595 return autocvar_g_random_items_replace_weapon_hlac;
599 return autocvar_g_random_items_replace_weapon_rifle;
601 case WEP_SEEKER.m_id:
603 return autocvar_g_random_items_replace_weapon_seeker;
618 /// \brief Returns a random instagib classname of the map item.
619 /// \return Random instagib classname of the map item.
620 string RandomItems_GetRandomInstagibMapItemClassName()
622 RandomSelection_Init();
623 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS,
624 autocvar_g_random_items_vaporizer_cells_probability, 1);
625 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY,
626 autocvar_g_random_items_invisibility_probability, 1);
627 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE,
628 autocvar_g_random_items_extralife_probability, 1);
629 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED,
630 autocvar_g_random_items_speed_probability, 1);
631 int item_type = RandomSelection_chosen_float;
634 case RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS:
636 return "item_vaporizer_cells";
638 case RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY:
640 return "item_invisibility";
642 case RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE:
644 return "item_extralife";
646 case RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED:
654 /// \brief Returns a random classname of the map item.
655 /// \return Random classname of the map item.
656 string RandomItems_GetRandomMapItemClassName()
658 if (autocvar_g_instagib)
660 return RandomItems_GetRandomInstagibMapItemClassName();
662 RandomSelection_Init();
663 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_HEALTH,
664 autocvar_g_random_items_health_probability, 1);
665 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_ARMOR,
666 autocvar_g_random_items_armor_probability, 1);
667 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_RESOURCE,
668 autocvar_g_random_items_resource_probability, 1);
669 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_WEAPON,
670 autocvar_g_random_items_weapon_probability, 1);
671 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_POWERUP,
672 autocvar_g_random_items_powerup_probability, 1);
673 int item_type = RandomSelection_chosen_float;
676 case RANDOM_ITEM_TYPE_HEALTH:
678 RandomSelection_Init();
679 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_HEALTH_SMALL,
680 autocvar_g_random_items_health_small_probability, 1);
681 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_HEALTH_MEDIUM,
682 autocvar_g_random_items_health_medium_probability, 1);
683 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_HEALTH_BIG,
684 autocvar_g_random_items_health_big_probability, 1);
685 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_HEALTH_MEGA,
686 autocvar_g_random_items_health_mega_probability, 1);
687 item_type = RandomSelection_chosen_float;
690 case RANDOM_ITEM_SUBTYPE_HEALTH_SMALL:
692 return "item_health_small";
694 case RANDOM_ITEM_SUBTYPE_HEALTH_MEDIUM:
696 return "item_health_medium";
698 case RANDOM_ITEM_SUBTYPE_HEALTH_BIG:
700 return "item_health_big";
702 case RANDOM_ITEM_SUBTYPE_HEALTH_MEGA:
704 return "item_health_mega";
709 case RANDOM_ITEM_TYPE_ARMOR:
711 RandomSelection_Init();
712 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_ARMOR_SMALL,
713 autocvar_g_random_items_armor_small_probability, 1);
714 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_ARMOR_MEDIUM,
715 autocvar_g_random_items_armor_medium_probability, 1);
716 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_ARMOR_BIG,
717 autocvar_g_random_items_armor_big_probability, 1);
718 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_ARMOR_MEGA,
719 autocvar_g_random_items_armor_mega_probability, 1);
720 item_type = RandomSelection_chosen_float;
723 case RANDOM_ITEM_SUBTYPE_ARMOR_SMALL:
725 return "item_armor_small";
727 case RANDOM_ITEM_SUBTYPE_ARMOR_MEDIUM:
729 return "item_armor_medium";
731 case RANDOM_ITEM_SUBTYPE_ARMOR_BIG:
733 return "item_armor_big";
735 case RANDOM_ITEM_SUBTYPE_ARMOR_MEGA:
737 return "item_armor_mega";
742 case RANDOM_ITEM_TYPE_RESOURCE:
744 RandomSelection_Init();
745 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_SHELLS,
746 autocvar_g_random_items_resource_shells_probability, 1);
747 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_BULLETS,
748 autocvar_g_random_items_resource_bullets_probability, 1);
749 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_ROCKETS,
750 autocvar_g_random_items_resource_rockets_probability, 1);
751 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_CELLS,
752 autocvar_g_random_items_resource_cells_probability, 1);
753 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_PLASMA,
754 autocvar_g_random_items_resource_plasma_probability, 1);
755 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_FUEL,
756 autocvar_g_random_items_resource_fuel_probability, 1);
757 item_type = RandomSelection_chosen_float;
760 case RANDOM_ITEM_SUBTYPE_RESOURCE_SHELLS:
762 return "item_shells";
764 case RANDOM_ITEM_SUBTYPE_RESOURCE_BULLETS:
766 return "item_bullets";
768 case RANDOM_ITEM_SUBTYPE_RESOURCE_ROCKETS:
770 return "item_rockets";
772 case RANDOM_ITEM_SUBTYPE_RESOURCE_CELLS:
776 case RANDOM_ITEM_SUBTYPE_RESOURCE_PLASMA:
778 return "item_plasma";
780 case RANDOM_ITEM_SUBTYPE_RESOURCE_FUEL:
787 case RANDOM_ITEM_TYPE_WEAPON:
789 RandomSelection_Init();
790 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_BLASTER,
791 autocvar_g_random_items_weapon_blaster_probability, 1);
792 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_SHOTGUN,
793 autocvar_g_random_items_weapon_shotgun_probability, 1);
794 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_MACHINEGUN,
795 autocvar_g_random_items_weapon_machinegun_probability, 1);
796 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_MORTAR,
797 autocvar_g_random_items_weapon_mortar_probability, 1);
798 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_ELECTRO,
799 autocvar_g_random_items_weapon_electro_probability, 1);
800 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_CRYLINK,
801 autocvar_g_random_items_weapon_crylink_probability, 1);
802 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_VORTEX,
803 autocvar_g_random_items_weapon_vortex_probability, 1);
804 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_HAGAR,
805 autocvar_g_random_items_weapon_hagar_probability, 1);
806 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_DEVASTATOR,
807 autocvar_g_random_items_weapon_devastator_probability, 1);
808 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_SHOCKWAVE,
809 autocvar_g_random_items_weapon_shockwave_probability, 1);
810 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_ARC,
811 autocvar_g_random_items_weapon_arc_probability, 1);
812 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_HOOK,
813 autocvar_g_random_items_weapon_hook_probability, 1);
814 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_TUBA,
815 autocvar_g_random_items_weapon_tuba_probability, 1);
816 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_PORTO,
817 autocvar_g_random_items_weapon_porto_probability, 1);
818 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_FIREBALL,
819 autocvar_g_random_items_weapon_fireball_probability, 1);
820 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_MINELAYER,
821 autocvar_g_random_items_weapon_minelayer_probability, 1);
822 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_HLAC,
823 autocvar_g_random_items_weapon_hlac_probability, 1);
824 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_RIFLE,
825 autocvar_g_random_items_weapon_rifle_probability, 1);
826 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_SEEKER,
827 autocvar_g_random_items_weapon_seeker_probability, 1);
828 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_VAPORIZER,
829 autocvar_g_random_items_weapon_vaporizer_probability, 1);
830 item_type = RandomSelection_chosen_float;
833 case RANDOM_ITEM_SUBTYPE_WEAPON_BLASTER:
835 return "weapon_blaster";
837 case RANDOM_ITEM_SUBTYPE_WEAPON_SHOTGUN:
839 return "weapon_shotgun";
841 case RANDOM_ITEM_SUBTYPE_WEAPON_MACHINEGUN:
843 return "weapon_machinegun";
845 case RANDOM_ITEM_SUBTYPE_WEAPON_MORTAR:
847 return "weapon_mortar";
849 case RANDOM_ITEM_SUBTYPE_WEAPON_ELECTRO:
851 return "weapon_electro";
853 case RANDOM_ITEM_SUBTYPE_WEAPON_CRYLINK:
855 return "weapon_crylink";
857 case RANDOM_ITEM_SUBTYPE_WEAPON_VORTEX:
859 return "weapon_vortex";
861 case RANDOM_ITEM_SUBTYPE_WEAPON_HAGAR:
863 return "weapon_hagar";
865 case RANDOM_ITEM_SUBTYPE_WEAPON_DEVASTATOR:
867 return "weapon_devastator";
869 case RANDOM_ITEM_SUBTYPE_WEAPON_SHOCKWAVE:
871 return "weapon_shockwave";
873 case RANDOM_ITEM_SUBTYPE_WEAPON_ARC:
877 case RANDOM_ITEM_SUBTYPE_WEAPON_HOOK:
879 return "weapon_hook";
881 case RANDOM_ITEM_SUBTYPE_WEAPON_TUBA:
883 return "weapon_tuba";
885 case RANDOM_ITEM_SUBTYPE_WEAPON_PORTO:
887 return "weapon_porto";
889 case RANDOM_ITEM_SUBTYPE_WEAPON_FIREBALL:
891 return "weapon_fireball";
893 case RANDOM_ITEM_SUBTYPE_WEAPON_MINELAYER:
895 return "weapon_minelayer";
897 case RANDOM_ITEM_SUBTYPE_WEAPON_HLAC:
899 return "weapon_hlac";
901 case RANDOM_ITEM_SUBTYPE_WEAPON_RIFLE:
903 return "weapon_rifle";
905 case RANDOM_ITEM_SUBTYPE_WEAPON_SEEKER:
907 return "weapon_seeker";
909 case RANDOM_ITEM_SUBTYPE_WEAPON_VAPORIZER:
911 return "weapon_vaporizer";
916 case RANDOM_ITEM_TYPE_POWERUP:
918 RandomSelection_Init();
919 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_POWERUP_STRENGTH,
920 autocvar_g_random_items_strength_probability, 1);
921 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_POWERUP_SHIELD,
922 autocvar_g_random_items_shield_probability, 1);
923 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_POWERUP_FUEL_REGEN,
924 autocvar_g_random_items_fuel_regen_probability, 1);
925 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_POWERUP_JETPACK,
926 autocvar_g_random_items_jetpack_probability, 1);
927 item_type = RandomSelection_chosen_float;
930 case RANDOM_ITEM_SUBTYPE_POWERUP_STRENGTH:
932 return "item_strength";
934 case RANDOM_ITEM_SUBTYPE_POWERUP_SHIELD:
936 return "item_invincible";
938 case RANDOM_ITEM_SUBTYPE_POWERUP_FUEL_REGEN:
940 return "item_fuel_regen";
942 case RANDOM_ITEM_SUBTYPE_POWERUP_JETPACK:
944 return "item_jetpack";
953 /// \brief Replaces a map item.
954 /// \param[in] item Item to replace.
955 /// \return Spawned item on success, NULL otherwise.
956 entity RandomItems_ReplaceMapItem(entity item)
958 //PrintToChatAll(strcat("Replacing ", item.classname));
959 string new_classnames = RandomItems_GetItemReplacementClassNames(item);
960 if (new_classnames == "")
964 string new_classname;
965 if (new_classnames == "random")
967 new_classname = RandomItems_GetRandomMapItemClassName();
968 if (new_classname == "")
975 int num_new_classnames = tokenize_console(new_classnames);
976 if (num_new_classnames == 1)
978 new_classname = new_classnames;
982 int classname_index = floor(random() * num_new_classnames);
983 new_classname = argv(classname_index);
986 //PrintToChatAll(strcat("Replacing with ", new_classname));
987 if (new_classname == item.classname)
991 random_items_is_spawning = true;
992 entity new_item = Item_Create(strzone(new_classname), item.origin);
993 random_items_is_spawning = false;
997 /// \brief Returns a random instagib classname of the loot item.
998 /// \return Random instagib classname of the loot item.
999 string RandomItems_GetRandomInstagibLootItemClassName()
1001 RandomSelection_Init();
1002 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS,
1003 autocvar_g_random_loot_vaporizer_cells_probability, 1);
1004 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY,
1005 autocvar_g_random_loot_invisibility_probability, 1);
1006 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE,
1007 autocvar_g_random_loot_extralife_probability, 1);
1008 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED,
1009 autocvar_g_random_loot_speed_probability, 1);
1010 int item_type = RandomSelection_chosen_float;
1013 case RANDOM_ITEM_SUBTYPE_INSTAGIB_VAPORIZER_CELLS:
1015 return "item_vaporizer_cells";
1017 case RANDOM_ITEM_SUBTYPE_INSTAGIB_INVISIBILITY:
1019 return "item_invisibility";
1021 case RANDOM_ITEM_SUBTYPE_INSTAGIB_EXTRA_LIFE:
1023 return "item_extralife";
1025 case RANDOM_ITEM_SUBTYPE_INSTAGIB_SPEED:
1027 return "item_speed";
1034 /// \brief Returns a random classname of the loot item.
1035 /// \return Random classname of the loot item.
1036 string RandomItems_GetRandomLootItemClassName()
1038 if (autocvar_g_instagib)
1040 return RandomItems_GetRandomInstagibLootItemClassName();
1042 RandomSelection_Init();
1043 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_HEALTH,
1044 autocvar_g_random_loot_health_probability, 1);
1045 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_ARMOR,
1046 autocvar_g_random_loot_armor_probability, 1);
1047 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_RESOURCE,
1048 autocvar_g_random_loot_resource_probability, 1);
1049 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_WEAPON,
1050 autocvar_g_random_loot_weapon_probability, 1);
1051 RandomSelection_AddFloat(RANDOM_ITEM_TYPE_POWERUP,
1052 autocvar_g_random_loot_powerup_probability, 1);
1053 int item_type = RandomSelection_chosen_float;
1056 case RANDOM_ITEM_TYPE_HEALTH:
1058 RandomSelection_Init();
1059 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_HEALTH_SMALL,
1060 autocvar_g_random_loot_health_small_probability, 1);
1061 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_HEALTH_MEDIUM,
1062 autocvar_g_random_loot_health_medium_probability, 1);
1063 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_HEALTH_BIG,
1064 autocvar_g_random_loot_health_big_probability, 1);
1065 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_HEALTH_MEGA,
1066 autocvar_g_random_loot_health_mega_probability, 1);
1067 item_type = RandomSelection_chosen_float;
1070 case RANDOM_ITEM_SUBTYPE_HEALTH_SMALL:
1072 return "item_health_small";
1074 case RANDOM_ITEM_SUBTYPE_HEALTH_MEDIUM:
1076 return "item_health_medium";
1078 case RANDOM_ITEM_SUBTYPE_HEALTH_BIG:
1080 return "item_health_big";
1082 case RANDOM_ITEM_SUBTYPE_HEALTH_MEGA:
1084 return "item_health_mega";
1089 case RANDOM_ITEM_TYPE_ARMOR:
1091 RandomSelection_Init();
1092 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_ARMOR_SMALL,
1093 autocvar_g_random_loot_armor_small_probability, 1);
1094 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_ARMOR_MEDIUM,
1095 autocvar_g_random_loot_armor_medium_probability, 1);
1096 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_ARMOR_BIG,
1097 autocvar_g_random_loot_armor_big_probability, 1);
1098 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_ARMOR_MEGA,
1099 autocvar_g_random_loot_armor_mega_probability, 1);
1100 item_type = RandomSelection_chosen_float;
1103 case RANDOM_ITEM_SUBTYPE_ARMOR_SMALL:
1105 return "item_armor_small";
1107 case RANDOM_ITEM_SUBTYPE_ARMOR_MEDIUM:
1109 return "item_armor_medium";
1111 case RANDOM_ITEM_SUBTYPE_ARMOR_BIG:
1113 return "item_armor_big";
1115 case RANDOM_ITEM_SUBTYPE_ARMOR_MEGA:
1117 return "item_armor_mega";
1122 case RANDOM_ITEM_TYPE_RESOURCE:
1124 RandomSelection_Init();
1125 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_SHELLS,
1126 autocvar_g_random_loot_resource_shells_probability, 1);
1127 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_BULLETS,
1128 autocvar_g_random_loot_resource_bullets_probability, 1);
1129 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_ROCKETS,
1130 autocvar_g_random_loot_resource_rockets_probability, 1);
1131 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_CELLS,
1132 autocvar_g_random_loot_resource_cells_probability, 1);
1133 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_PLASMA,
1134 autocvar_g_random_loot_resource_plasma_probability, 1);
1135 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_RESOURCE_FUEL,
1136 autocvar_g_random_loot_resource_fuel_probability, 1);
1137 item_type = RandomSelection_chosen_float;
1140 case RANDOM_ITEM_SUBTYPE_RESOURCE_SHELLS:
1142 return "item_shells";
1144 case RANDOM_ITEM_SUBTYPE_RESOURCE_BULLETS:
1146 return "item_bullets";
1148 case RANDOM_ITEM_SUBTYPE_RESOURCE_ROCKETS:
1150 return "item_rockets";
1152 case RANDOM_ITEM_SUBTYPE_RESOURCE_CELLS:
1154 return "item_cells";
1156 case RANDOM_ITEM_SUBTYPE_RESOURCE_PLASMA:
1158 return "item_plasma";
1160 case RANDOM_ITEM_SUBTYPE_RESOURCE_FUEL:
1167 case RANDOM_ITEM_TYPE_WEAPON:
1169 RandomSelection_Init();
1170 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_BLASTER,
1171 autocvar_g_random_loot_weapon_blaster_probability, 1);
1172 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_SHOTGUN,
1173 autocvar_g_random_loot_weapon_shotgun_probability, 1);
1174 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_MACHINEGUN,
1175 autocvar_g_random_loot_weapon_machinegun_probability, 1);
1176 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_MORTAR,
1177 autocvar_g_random_loot_weapon_mortar_probability, 1);
1178 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_ELECTRO,
1179 autocvar_g_random_loot_weapon_electro_probability, 1);
1180 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_CRYLINK,
1181 autocvar_g_random_loot_weapon_crylink_probability, 1);
1182 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_VORTEX,
1183 autocvar_g_random_loot_weapon_vortex_probability, 1);
1184 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_HAGAR,
1185 autocvar_g_random_loot_weapon_hagar_probability, 1);
1186 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_DEVASTATOR,
1187 autocvar_g_random_loot_weapon_devastator_probability, 1);
1188 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_SHOCKWAVE,
1189 autocvar_g_random_loot_weapon_shockwave_probability, 1);
1190 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_ARC,
1191 autocvar_g_random_loot_weapon_arc_probability, 1);
1192 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_HOOK,
1193 autocvar_g_random_loot_weapon_hook_probability, 1);
1194 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_TUBA,
1195 autocvar_g_random_loot_weapon_tuba_probability, 1);
1196 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_PORTO,
1197 autocvar_g_random_loot_weapon_porto_probability, 1);
1198 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_FIREBALL,
1199 autocvar_g_random_loot_weapon_fireball_probability, 1);
1200 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_MINELAYER,
1201 autocvar_g_random_loot_weapon_minelayer_probability, 1);
1202 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_HLAC,
1203 autocvar_g_random_loot_weapon_hlac_probability, 1);
1204 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_RIFLE,
1205 autocvar_g_random_loot_weapon_rifle_probability, 1);
1206 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_SEEKER,
1207 autocvar_g_random_loot_weapon_seeker_probability, 1);
1208 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_WEAPON_VAPORIZER,
1209 autocvar_g_random_loot_weapon_vaporizer_probability, 1);
1210 item_type = RandomSelection_chosen_float;
1213 case RANDOM_ITEM_SUBTYPE_WEAPON_BLASTER:
1215 return "weapon_blaster";
1217 case RANDOM_ITEM_SUBTYPE_WEAPON_SHOTGUN:
1219 return "weapon_shotgun";
1221 case RANDOM_ITEM_SUBTYPE_WEAPON_MACHINEGUN:
1223 return "weapon_machinegun";
1225 case RANDOM_ITEM_SUBTYPE_WEAPON_MORTAR:
1227 return "weapon_mortar";
1229 case RANDOM_ITEM_SUBTYPE_WEAPON_ELECTRO:
1231 return "weapon_electro";
1233 case RANDOM_ITEM_SUBTYPE_WEAPON_CRYLINK:
1235 return "weapon_crylink";
1237 case RANDOM_ITEM_SUBTYPE_WEAPON_VORTEX:
1239 return "weapon_vortex";
1241 case RANDOM_ITEM_SUBTYPE_WEAPON_HAGAR:
1243 return "weapon_hagar";
1245 case RANDOM_ITEM_SUBTYPE_WEAPON_DEVASTATOR:
1247 return "weapon_devastator";
1249 case RANDOM_ITEM_SUBTYPE_WEAPON_SHOCKWAVE:
1251 return "weapon_shockwave";
1253 case RANDOM_ITEM_SUBTYPE_WEAPON_ARC:
1255 return "weapon_arc";
1257 case RANDOM_ITEM_SUBTYPE_WEAPON_HOOK:
1259 return "weapon_hook";
1261 case RANDOM_ITEM_SUBTYPE_WEAPON_TUBA:
1263 return "weapon_tuba";
1265 case RANDOM_ITEM_SUBTYPE_WEAPON_PORTO:
1267 return "weapon_porto";
1269 case RANDOM_ITEM_SUBTYPE_WEAPON_FIREBALL:
1271 return "weapon_fireball";
1273 case RANDOM_ITEM_SUBTYPE_WEAPON_MINELAYER:
1275 return "weapon_minelayer";
1277 case RANDOM_ITEM_SUBTYPE_WEAPON_HLAC:
1279 return "weapon_hlac";
1281 case RANDOM_ITEM_SUBTYPE_WEAPON_RIFLE:
1283 return "weapon_rifle";
1285 case RANDOM_ITEM_SUBTYPE_WEAPON_SEEKER:
1287 return "weapon_seeker";
1289 case RANDOM_ITEM_SUBTYPE_WEAPON_VAPORIZER:
1291 return "weapon_vaporizer";
1296 case RANDOM_ITEM_TYPE_POWERUP:
1298 RandomSelection_Init();
1299 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_POWERUP_STRENGTH,
1300 autocvar_g_random_loot_strength_probability, 1);
1301 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_POWERUP_SHIELD,
1302 autocvar_g_random_loot_shield_probability, 1);
1303 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_POWERUP_FUEL_REGEN,
1304 autocvar_g_random_loot_fuel_regen_probability, 1);
1305 RandomSelection_AddFloat(RANDOM_ITEM_SUBTYPE_POWERUP_JETPACK,
1306 autocvar_g_random_loot_jetpack_probability, 1);
1307 item_type = RandomSelection_chosen_float;
1310 case RANDOM_ITEM_SUBTYPE_POWERUP_STRENGTH:
1312 return "item_strength";
1314 case RANDOM_ITEM_SUBTYPE_POWERUP_SHIELD:
1316 return "item_invincible";
1318 case RANDOM_ITEM_SUBTYPE_POWERUP_FUEL_REGEN:
1320 return "item_fuel_regen";
1322 case RANDOM_ITEM_SUBTYPE_POWERUP_JETPACK:
1324 return "item_jetpack";
1333 /// \brief Spawns a random loot item.
1334 /// \param[in] position Position of the item.
1335 /// \return No return.
1336 void RandomItems_SpawnLootItem(vector position)
1338 string class_name = RandomItems_GetRandomLootItemClassName();
1339 if (class_name == "")
1343 vector spread = '0 0 0';
1344 spread.z = autocvar_g_random_loot_spread / 2;
1345 spread += randomvec() * autocvar_g_random_loot_spread;
1346 random_items_is_spawning = true;
1347 Item_CreateLoot(class_name, position, spread, autocvar_g_random_loot_time);
1348 random_items_is_spawning = false;
1351 //============================= Hooks ========================================
1353 REGISTER_MUTATOR(random_items, (autocvar_g_random_items ||
1354 autocvar_g_random_loot));
1356 MUTATOR_HOOKFUNCTION(random_items, BuildMutatorsString)
1358 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":random_items");
1361 MUTATOR_HOOKFUNCTION(random_items, BuildMutatorsPrettyString)
1363 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Random items");
1366 /// \brief Hook that is called when an item is about to spawn.
1367 MUTATOR_HOOKFUNCTION(random_items, FilterItem, CBC_ORDER_LAST)
1369 //PrintToChatAll("FilterItem");
1370 if (!autocvar_g_random_items)
1374 if (random_items_is_spawning == true)
1378 entity item = M_ARGV(0, entity);
1379 if (Item_IsLoot(item))
1383 if (RandomItems_ReplaceMapItem(item) == NULL)
1390 /// \brief Hook that is called after the player has touched an item.
1391 MUTATOR_HOOKFUNCTION(random_items, ItemTouched, CBC_ORDER_LAST)
1393 //PrintToChatAll("ItemTouched");
1394 if (!autocvar_g_random_items)
1398 entity item = M_ARGV(0, entity);
1399 if (Item_IsLoot(item))
1403 entity new_item = RandomItems_ReplaceMapItem(item);
1404 if (new_item == NULL)
1408 Item_ScheduleRespawn(new_item);
1412 /// \brief Hook which is called when the player dies.
1413 MUTATOR_HOOKFUNCTION(random_items, PlayerDies)
1415 //PrintToChatAll("PlayerDies");
1416 if (!autocvar_g_random_loot)
1420 entity victim = M_ARGV(2, entity);
1421 vector loot_position = victim.origin + '0 0 32';
1422 int num_loot_items = floor(autocvar_g_random_loot_min + random() *
1423 autocvar_g_random_loot_max);
1424 for (int item_index = 0; item_index < num_loot_items; ++item_index)
1426 RandomItems_SpawnLootItem(loot_position);