Prev: 52081 Up: Map Next: 52140
52091: Choose Start Position
Used by the routine at StartGame.
Chooses a random cell of the village for the player to start in, avoiding cells that are solid (tiles 1 and 2), and stores its column and row in the template for the player at PlayerTemplate.
Pick a random cell that is not solid.
ChooseStartPosition 52091 CALL RandomNumber Update the random number generator.
52094 LD DE,(48042) Fetch the random number.
ChooseStartPosition_Cell 52098 LD A,D Turn the random number into a place in the map of the village.
52099 AND 3
52101 LD D,A
52102 LD HL,24068 Find the tile in the map.
52105 ADD HL,DE
52106 LD A,(HL) Jump to ChooseStartPosition_Found to use this cell unless the tile is solid (1 or 2).
52107 DEC A
52108 CP 2
52110 JR NC,ChooseStartPosition_Found
52112 INC DE Otherwise move on to the next cell and try again.
52113 JR ChooseStartPosition_Cell
Store the column and the row in the template.
ChooseStartPosition_Found 52115 LD A,E Store the column of the cell in the template for the player.
52116 AND 31
52118 LD (52280),A
52121 RL E Shift the place in the map left three times, which moves the row of the cell into the lowest five bits of D.
52123 RL D
52125 RL E
52127 RL D
52129 RL E
52131 RL D
52133 LD A,D Store the row of the cell in the template for the player.
52134 AND 31
52136 LD (52282),A
52139 RET Return.
Prev: 52081 Up: Map Next: 52140