Skip to content

Commit

Permalink
Abno queue null entry fix (vlggms#1966)
Browse files Browse the repository at this point in the history
new fixed picked weight proc
  • Loading branch information
Halonexus authored Feb 14, 2024
1 parent d561994 commit 9af7eec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,23 @@

return null

/proc/PickWeightRealNumber(list/L)
var/total = 0.0
var/item
for (item in L)
if (!L[item])
L[item] = 1.0
total += L[item]
var/generator/G = generator("num", 0.0, total, UNIFORM_RAND)
total = G.Rand()
for (item in L)
total -= L[item]
if (total <= 0.000001)
return item
if(LAZYLEN(L))
log_runtime("PickWeightRealNumber failed with leftover total = [total]")
return null

/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
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/abnormality_queue.dm
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ SUBSYSTEM_DEF(abnormality_queue)
picked_levs |= lev
if(!LAZYLEN(possible_abnormalities[lev] - picking_abnormalities))
continue
var/chosen_abno = pickweight(possible_abnormalities[lev] - picking_abnormalities)
var/chosen_abno = PickWeightRealNumber(possible_abnormalities[lev] - picking_abnormalities)
picking_abnormalities += chosen_abno
if(!LAZYLEN(picking_abnormalities))
return FALSE
Expand Down

0 comments on commit 9af7eec

Please sign in to comment.