[MIRROR] Adds a config that skews random spawners weights. (#28696)

* 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

🆑
admin: Added a config that regulares random spawners weights.
/🆑

* Adds a config that skews random spawners weights.

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-07-08 14:50:31 +05:30
committed by GitHub
co-authored by Ghom
parent eb9f43d7ba
commit 595b6b4cd9
3 changed files with 33 additions and 0 deletions
@@ -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.
*