From: terencehill Date: Fri, 19 May 2023 22:19:33 +0000 (+0200) Subject: Instagib: select a random powerup to replace an item among the less spawned ones... X-Git-Tag: xonotic-v0.8.6~96^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5353e969311f53d3d78a664e621413c8e164db6c;p=xonotic%2Fxonotic-data.pk3dir.git 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 --- 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; }