From 7be649a7f6f73bddeaebe4811daf6b06fdd755f8 Mon Sep 17 00:00:00 2001 From: Ghom <42542238+Ghommie@users.noreply.github.com> Date: Sun, 7 Jul 2024 21:16:59 +0200 Subject: [PATCH] Adds a config that skews random spawners weights. (#84616) ## About The Pull Request Title. It's an exponent that multiplies weights of random spawners. For example, if the exponent were 0.8, and the spawner has a natural 99.9% chance to spawn a donk-pocket and a 0.01% of a vial of adminodrazine, after calculations it'd be roughly 99.6% vs 0.4%. ## Why It's Good For The Game This can give admins/keyholders more control over random spawners. ~~However, most of the random spawners are maploaded things so an admin would've to get to edit the config quite fast before SSatoms initializes to witness the most out of it, but I'm just ranting.~~ ## Changelog :cl: admin: Added a config that regulares random spawners weights. /:cl: --- .../configuration/entries/game_options.dm | 9 +++++++++ .../objects/effects/spawners/random/random.dm | 19 +++++++++++++++++++ config/game_options.txt | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/code/controllers/configuration/entries/game_options.dm b/code/controllers/configuration/entries/game_options.dm index 068f857c8cb..8297085dbcf 100644 --- a/code/controllers/configuration/entries/game_options.dm +++ b/code/controllers/configuration/entries/game_options.dm @@ -464,3 +464,12 @@ /datum/config_entry/number/max_positive_quirks default = 6 min_val = -1 + +/** + * A config that skews with the random spawners weights + * If the value is lower than 1, it'll tend to even out the odds + * If higher than 1, it'll lean toward common spawns even more. + */ +/datum/config_entry/number/random_loot_weight_modifier + default = 1 + min_val = 0.05 diff --git a/code/game/objects/effects/spawners/random/random.dm b/code/game/objects/effects/spawners/random/random.dm index 2c98ba72a4e..ed77f671191 100644 --- a/code/game/objects/effects/spawners/random/random.dm +++ b/code/game/objects/effects/spawners/random/random.dm @@ -52,6 +52,9 @@ if(loot_subtype_path) loot += subtypesof(loot_subtype_path) + if(CONFIG_GET(number/random_loot_weight_modifier) != 1) + skew_loot_weights(CONFIG_GET(number/random_loot_weight_modifier)) + if(loot?.len) var/loot_spawned = 0 var/pixel_divider = FLOOR(16 / spawn_loot_split_pixel_offsets, 1) // 16 pixels offsets is max that should be allowed in any direction @@ -85,6 +88,22 @@ spawned_loot.pixel_y = spawn_loot_split_pixel_offsets * (loot_spawned % pixel_divider) loot_spawned++ +///Levels out the weights of loot if lower than 1, or makes rarer spawns even more rare. +/obj/effect/spawner/random/proc/skew_loot_weights(list/loot_list, exponent) + ///This helps keeping the modified weights more or less correct, since pick_weight doesn't appreciate decimals. + var/precision = 1 + if(exponent < 1) + precision = round((1 - exponent) * 10) + 1 + for(var/loot_type in loot_list) + if(islist(loot_type)) + skew_loot_weights(loot_type, exponent) + var/loot_weight = loot_list[loot_type] + if(loot_weight <= 1) + if(exponent < 1) + loot_list[loot_type] *= precision + continue + loot_list[loot_type] = round(loot_weight ** exponent * precision, 1) + /** * Makes the actual item related to our spawner. * diff --git a/config/game_options.txt b/config/game_options.txt index 2979648126d..ef15cbeb123 100644 --- a/config/game_options.txt +++ b/config/game_options.txt @@ -539,3 +539,8 @@ NEGATIVE_STATION_TRAITS 3 1 # If set to 0, then players won't be able to select any positive quirks. # If commented-out or undefined, the maximum default is 6. MAX_POSITIVE_QUIRKS 6 + +# A config that skews with the random spawners weights +# If the value is lower than 1, it'll tend to even out the odds +# If higher than 1, it'll lean toward common spawns even more. +RANDOM_LOOT_WEIGHT_MODIFIER 1 \ No newline at end of file