Skip to content

Commit

Permalink
Port superior pick_weight implementation (#2144)
Browse files Browse the repository at this point in the history
* Port superior pick_weight implementation

* Fix broken weights
  • Loading branch information
Absolucy authored Jun 24, 2024
1 parent f59fd2a commit c6c3796
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
**/
/proc/list_clear_nulls(list/list_to_clear)
return (list_to_clear.RemoveAll(null) > 0)


/*
* Returns list containing all the entries from first list that are not present in second.
Expand Down Expand Up @@ -434,22 +434,19 @@
* B would have a 30% chance of being picked,
* C would have a 10% chance of being picked,
* and D would have a 0% chance of being picked.
* You should only pass integers in.
*/
/proc/pick_weight(list/list_to_pick)
/proc/pick_weight(list/list_to_pick) // monkestation edit: port superior pick_weight impl
var/total = 0
var/item
for(item in list_to_pick)
if(!list_to_pick[item])
list_to_pick[item] = 0
if(isnull(list_to_pick[item]))
stack_trace("weighted_pick given null weight: [json_encode(list_to_pick)]")
total += list_to_pick[item]

total = rand(1, total)
total = rand() * total
for(item in list_to_pick)
total -= list_to_pick[item]
if(total <= 0 && list_to_pick[item])
if(total <= 0)
return item

return null

/**
Expand Down
4 changes: 2 additions & 2 deletions monkestation/code/modules/clothing/shoes/clown.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
desc = "A court jester's shoes, updated with modern squeaking technology."
icon_state = "jester_shoes"
icon = 'icons/obj/clothing/shoes.dmi'
squeak_sound = list('monkestation/sound/effects/clown_jingle1.ogg'=1, 'monkestation/sound/effects/clown_jingle2.ogg') //jingHONK jinglHONK jHONKgle jiHONKgle
squeak_sound = list('monkestation/sound/effects/clown_jingle1.ogg'=1, 'monkestation/sound/effects/clown_jingle2.ogg'=1) //jingHONK jinglHONK jHONKgle jiHONKgle

/obj/item/clothing/shoes/clown_shoes/harlequin_boots
name = "harlequin boots"
Expand All @@ -29,4 +29,4 @@
icon_state = "harlequin_boots"
worn_icon = 'monkestation/icons/mob/clothing/feet.dmi'
worn_icon_state = "harlequin_boots"
squeak_sound = list('monkestation/sound/effects/clown_jingle1.ogg'=1, 'monkestation/sound/effects/clown_jingle2.ogg')
squeak_sound = list('monkestation/sound/effects/clown_jingle1.ogg'=1, 'monkestation/sound/effects/clown_jingle2.ogg'=1)

0 comments on commit c6c3796

Please sign in to comment.