From 5353e969311f53d3d78a664e621413c8e164db6c Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 20 May 2023 00:19:33 +0200 Subject: [PATCH] Instagib: select a random powerup to replace an item among the less spawned ones so that there can't be many powerups of one type and few of another type --- .../mutators/mutator/instagib/sv_instagib.qc | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc index 916ac06ba..740b48c4c 100644 --- a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc +++ b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc @@ -303,6 +303,29 @@ void instagib_replace_item_with(entity this, GameItem def) StartItem(new_item, def); } +const int INSTAGIB_POWERUP_COUNT = 3; +GameItem instagib_remaining_powerups[INSTAGIB_POWERUP_COUNT]; + +// replaces item with a random powerup selected among the less spawned ones +void instagib_replace_item_with_random_powerup(entity item) +{ + static int remaining_powerups_count = INSTAGIB_POWERUP_COUNT; + if (remaining_powerups_count == 0) + remaining_powerups_count = INSTAGIB_POWERUP_COUNT; + if (remaining_powerups_count == INSTAGIB_POWERUP_COUNT) + { + instagib_remaining_powerups[0] = ITEM_Invisibility; + instagib_remaining_powerups[1] = ITEM_ExtraLife; + instagib_remaining_powerups[2] = ITEM_Speed; + } + + float r = floor(random() * remaining_powerups_count); + instagib_replace_item_with(item, instagib_remaining_powerups[r]); + for(int i = r; i < INSTAGIB_POWERUP_COUNT - 1; ++i) + instagib_remaining_powerups[i] = instagib_remaining_powerups[i + 1]; + --remaining_powerups_count; +} + MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem) { entity item = M_ARGV(0, entity); @@ -310,15 +333,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem) if(def == ITEM_Strength || def == ITEM_Shield || def == ITEM_HealthMega || def == ITEM_ArmorMega) { if(autocvar_g_powerups) - { - float r = random(); - if (r < 0.3) - instagib_replace_item_with(item, ITEM_Invisibility); - else if (r < 0.6) - instagib_replace_item_with(item, ITEM_ExtraLife); - else - instagib_replace_item_with(item, ITEM_Speed); - } + instagib_replace_item_with_random_powerup(item); return true; } -- 2.39.2