Skip to content

Commit

Permalink
randompercentage, randomelement (#4189)
Browse files Browse the repository at this point in the history
'randompercentage X' sets VAR_RESULT to TRUE X% of the time, or FALSE
100-X% of the time.

'randomelement X, Y, ...' sets VAR_RESULT to one of X, Y, ... with equal
probability.
  • Loading branch information
mrgriffin authored Feb 15, 2024
1 parent eb7ddeb commit c21ab74
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions asm/macros/event.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2133,3 +2133,34 @@
callnative ToggleGigantamaxFactor
.2byte \slot
.endm

@ Sets VAR_RESULT to one of the arguments (via setorcopyvar).
.macro randomelement element:req, elements:vararg
.set _randomelement_n, 0
.irp el, \element, \elements
.set _randomelement_n, _randomelement_n + 1
.endr
random _randomelement_n

.set _randomelement_n, 0
.irp el, \element, \elements
goto_if_ne VAR_RESULT, _randomelement_n, 1f
setorcopyvar VAR_RESULT, \el
goto 2f
1:
.set _randomelement_n, _randomelement_n + 1
.endr
2:
.endm

@ Sets VAR_RESULT to TRUE with probability 'percent', and FALSE
@ with probability '100% - percent'.
.macro randompercentage percent:req
random 100
goto_if_lt VAR_RESULT, \percent, 1f
setvar VAR_RESULT, FALSE
goto 2f
1:
setvar VAR_RESULT, TRUE
2:
.endm

0 comments on commit c21ab74

Please sign in to comment.