Files
Citadel-Station-13-RP/code/__HELPERS/lists/counter.dm
Zandario ed05e01a95 __HELPERS Cleaning and other things I decided to do. (#4584)
* Schizoposting

* The Crungly

* Tabbin' the JSON y'all

* Strings
2022-10-21 01:56:59 -07:00

31 lines
602 B
Plaintext

/** Definining a counter as a series of key -> numeric value entries
*
* All these procs modify in place.
*/
/proc/counterlist_scale(list/L, scalar)
var/list/out = list()
for(var/key in L)
out[key] = L[key] * scalar
. = out
/proc/counterlist_sum(list/L)
. = 0
for(var/key in L)
. += L[key]
/proc/counterlist_normalise(list/L)
var/avg = counterlist_sum(L)
if(avg != 0)
. = counterlist_scale(L, 1 / avg)
else
. = L
/proc/counterlist_combine(list/L1, list/L2)
for(var/key in L2)
var/other_value = L2[key]
if(key in L1)
L1[key] += other_value
else
L1[key] = other_value