Prev: 34150 Up: Map Next: 34226
34200: Get Random Coordinate
Used by the routine at SpawnCreature.
Chooses a random position along one axis of the room. A random number is reduced to less than the size of the room less 8 and then it is either added to or taken away from 96. This is used by SpawnCreature to place a new creature.
Input
B The size of the room along the axis
HL The address of the previous byte of the position in the entity
Output
A The coordinate
HL The address of the next byte of the entity
GetRandomCoordinate 34200 LD A,B Fetch the size of the room along the axis.
34201 SUB 8 Take 8 off the size of the room.
34203 LD B,A Keep the result in B as the limit for the random number.
34204 LD A,R Fetch a random number (from the refresh register).
34206 INC HL Move HL on to the next byte.
GetRandomCoordinate_Reduce 34207 CP B Jump to GetRandomCoordinate_Offset if the random number is less than the limit.
34208 JR C,GetRandomCoordinate_Offset
34210 SUB B Subtract the limit from the random number.
34211 JR GetRandomCoordinate_Reduce Jump back to GetRandomCoordinate_Reduce to keep reducing the number.
GetRandomCoordinate_Offset 34213 LD C,A Keep the random offset in C.
34214 LD A,R Fetch a random number (from the refresh register).
34216 BIT 1,A Test bit 1 of the random number, to choose which side of 96 to use.
34218 LD A,96 A=96.
34220 JR Z,GetRandomCoordinate_Negative Jump to GetRandomCoordinate_Negative if bit 1 was not set.
34222 ADD A,C Add the offset to 96.
34223 RET Return.
GetRandomCoordinate_Negative 34224 SUB C Take the offset away from 96.
34225 RET Return.
Prev: 34150 Up: Map Next: 34226