I thought some architects out there might be interested in seeing this -
Now that we have wonderful variables to work with, it's easier than ever to add random-looking behavior to a hold. In fact, there's no reason we can't implement a pseudo-random number generator.
Of course nothing will ever be truly random in DROD, but it can get pretty damn close. This is an implementation of the
game of Chomp, and every time you leave and reenter the main room, it generates a new starting setup for you. (Chomp is a two player game, so grab a friend and take turns controlling Beethro, or play against yourself.)
WORD OF CAUTION: Use ctrl-f7 to see how the variables are changing at your own risk. For me, that's a recipe for a DROD crash. If someone can confirm that happening in 3.1, I'll post something in the Bugs forum.
Here's how the randomness is handled: One NPC, off in the corner, is scripted as follows:
Label "Waiting"
Wait until var RandomRequest = 1
Set var RandomSeed * 1664525
Set var RandomSeed + 1013904223
If ...
Wait until var RandomSeed < 0
Set var RandomSeed + 2147483647
Set var RandomSeed + 1
If End
Set var RandomResult = RandomSeed
Set var RandomResult / 1024
Set var RandomResult % RandomRange
Set var RandomRequest = 0
Go to "Waiting"
This guy implements the RNG, which is a standard
Linear Congruential Generator. The numbers I'm using are usually meant to generate numbers across the full range of unsigned 32 bit integers, but DROD uses signed integers so I'm only generating in the 0 to 2^31 range. (Hence the addition of 2^31 in the middle.) If I understand the math, the randomness is just as strong.
Whenever any other script wants to generate a random number, let's say 0,1,...20, it does it like so:
Set var RandomRange = 21
Set var RandomRequest = 1
Wait until var RandomRequest = 0
Set var MyResult = RandomResult
MyResult then stores the needed number.
But how do we generate the initial RandomSeed value? Computers usually use some randomish physical phenomenon, like the system time in milliseconds, and you can use randomish DROD phenomenon in the same way. For example, count the total number of moves the player took in some room x. That's what Chomp does - it uses the number of moves spent in the entrance. The end result is that anyone playing your hold will probably get different seed every time they play through.
Remember kids! Use randomness for good, and not for evil.
[Last edited by Remlin at 08-21-2007 05:11 AM]