randompercentage, randomelement (#4189)
'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.
This commit is contained in:
parent
eb7ddeb66c
commit
c21ab741f7
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user