@tel #456=me
@edit #456
1 10000 del
i
(Header, 23 lines -- Deadlandroll.muf
Jordan Greywolf, 11 May 2001 - http://greywolf.critter.net
This is a modified online die-roller program, intended to simulate the "open-ended" die-roll system of the Deadlands role-playing game. The basic method is such:
:
A number of dice are rolled of a specified die type. If any die comes up the maximum possible value, another die of the same type is added to that result. If it too comes up maximum, it continues to build. Repeat this process for each of the initial die to be rolled, and pick the best result. If more than half of the dice rolled come up a "1" on the initial roll this counts as a "botch", and is indicated as such - the result may still be a success, but it may have an undesired side effect.
:
The player uses the command 'deadlandroll' or 'dlroll' in the format of - for example - dlroll 3d12 to roll 3 12-sided dice. Optionally, a modifier may be tacked onto the end, such as:
. dlroll 3d12+2
:
The Marshal {GM} may use the command 'marshalroll' or 'mroll' to
produce a private result that is not seen by anyone else.
)
lvar dietype
lvar bonus
lvar numdice
lvar botchcount
lvar qflag
()
: tell ( s -- : sends message to user )
me @ swap notify
;
()
: tell-all ( s -- : sends message to room )
loc @ #-1 rot notify_except
;
()
: rollmessage ( i : shows result i of roll )
qflag @ 1 = if
"You Mroll "
else
"
" me @ name " DLrolls " strcat strcat
then
numdice @ intostr "d" dietype @ intostr
strcat strcat strcat
bonus @ 0 > if
"+" bonus @ intostr strcat strcat
then
bonus @ 0 < if
"-" bonus @ -1 * intostr strcat strcat
then
", giving a result of " strcat
swap intostr strcat
numdice @ 2 / botchcount @ < if
" ***BOTCH***" strcat
then
qflag @ 1 = if
tell
else
" " strcat
tell-all
then
;
()
: help
"-=-+-=-+-=-+-=-+- Dead Lands Die Roller -+-=-+-=-+-=-+-=-"
tell
"- Dead Lands is (c) Pinnacle Games / www.peginc.com -"
tell
"-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-"
tell
"- To roll dice for an Aptitude or Trait check, indicate -"
tell
"- the number and type of dice in the following format: -"
tell
"- -"
tell
"- dlroll 3d6+2 <- roll 3 6-sided dice, and add 2 -"
tell
"- -"
tell
"- The modifier at the end (+2) is optional. The Marshal -"
tell
"- can secretly roll a die result by using the following: -"
tell
"- -"
tell
"- mroll 4d12 <- roll 4 12-sided dice, no modifier -"
tell
"- -"
tell
"-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-"
tell
;
()
: die-roll ( -- i : returns random value from 1 to dietype )
random 1003 / ( divides "random" number by 1003 )
( to avoid low-digit bug )
dietype @ % ( then divide by dietype, take remainder )
1 + ( and add 1 )
dup dietype @ = if ( if equal to maximum value...)
die-roll + ( ... recurse )
then
;
()
: roll-dice ( -- i : returns result )
0 botchcount ! ( reset botch counter )
0 ( put best result of 0 on stack )
1 ( put loop counter on stack )
begin
dup numdice @ > if
pop break
then
die-roll dup 1 = if
botchcount @ 1 + botchcount ! ( keep track of ones )
then
dup 4 pick > if
rot pop swap
else
pop
then
1 +
repeat
bonus @ + ( add bonus - or penalty - to end result )
;
()
: format-error ( generates proper usage format message )
"Use in the format of '" command @
" 3d8+2', for example to roll 3 8-sided dice and add 2."
strcat strcat tell
;
()
: parse-command ( s -- 0|1 : splits up input into local vars )
"" " " subst
dup "d" instring dup not if
"Error: no 'd' found to indicate die type." tell
pop pop 0 exit
then
dup 1 if ( if no number of dice given, assume 1 )
pop 1 numdice !
else ( get number before 'd' and store )
1 - strcut swap atoi dup 1 < if
"Error: number before 'd' must be from 1 to 12."
tell pop pop 0 exit
then
dup 12 > ( arbitrary maximum of 12 to limit recursion )
"Error: number before 'd' must be from 1 to 12."
tell pop pop 0 exit
numdice !
then
1 - strcut 1 strcut swap pop ( remove the 'd' )
0 bonus !
dup "+" instring dup if
1 - strcut 1 strcut swap pop ( split and remove '+' )
atoi bonus !
else
pop
then
dup "-" instring dup if
1 - strcut 1 strcut swap pop ( split and remove '-' )
atoi -1 * bonus !
else
pop
then
atoi dup 4 < if
"Error: die type must be d4 or greater." tell
pop 0 exit
then
dietype !
atoi dup 1 < if
pop 1
then
numdice !
command @ "mroll" stringcmp not
command @ "marshalroll" stringcmp not or if
1 qflag !
else
0 qflag !
then
1
;
()
: main
dup not if
pop help exit
then
dup 1 strcut pop "#" stringcmp not if
pop help exit
then
dup 4 strcut pop "help" stringcmp not if
pop help exit
then
parse-command not if
format-error exit
then
roll-dice
rollmessage
;
.
compile
quit