/** 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