Fixes more errors
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#define reverseList(L) reverseRange(L.Copy())
|
||||
#define LAZYADDASSOC(L, K, V) if(!L) { L = list(); } L[K] += list(V);
|
||||
#define LAZYREMOVEASSOC(L, K, V) if(L) { if(L[K]) { L[K] -= V; if(!length(L[K])) L -= K; } if(!length(L)) L = null; }
|
||||
#define LAZYACCESSASSOC(L, I, K) L ? L[I] ? L[I][K] ? L[I][K] : null : null : null
|
||||
|
||||
/// Passed into BINARY_INSERT to compare keys
|
||||
#define COMPARE_KEY __BIN_LIST[__BIN_MID]
|
||||
@@ -294,6 +295,22 @@
|
||||
if (total <= 0)
|
||||
return item
|
||||
|
||||
/proc/pickweightAllowZero(list/L) //The original pickweight proc will sometimes pick entries with zero weight. I'm not sure if changing the original will break anything, so I left it be.
|
||||
var/total = 0
|
||||
var/item
|
||||
for (item in L)
|
||||
if (!L[item])
|
||||
L[item] = 0
|
||||
total += L[item]
|
||||
|
||||
total = rand(0, total)
|
||||
for (item in L)
|
||||
total -=L [item]
|
||||
if (total <= 0 && L[item])
|
||||
return item
|
||||
|
||||
return null
|
||||
|
||||
//Picks a number of elements from a list based on weight.
|
||||
//This is highly optimised and good for things like grabbing 200 items from a list of 40,000
|
||||
//Much more efficient than many pickweight calls
|
||||
|
||||
Reference in New Issue
Block a user