Prev: CDDF Up: Map Next: CE79
CDE8: Bring a monster into a cell next to the knight's
Used by the routine at NEW_GAME.
Called by NEW_GAME every turn but during the ending. Once the knight has finished appearing, every fourth turn (bits 0-1 of TURNS both set), the first empty monster record (MONSTERS) gets MONSTER_RECORD, a monster appearing (graphic 128). Its cell is the knight's or one of the eight round it, a column and a row each chosen from a third of the random number's range. It goes at a random place in that cell, at least 32 from each edge; one that appears in the first half of every 256 turns gets bit 5 of its flags, which makes a monster of 112-127 turn towards the knight when it chooses a way to go (STEER). After four turns APPEARING_UPDATE makes it a monster of 64-79 or 112-127.
If the cell chosen is solid (types 1 and 2) the routine returns there -- but the record has already been filled, so it keeps its monster, in the corner of the town, cell 0,0, which is solid. Measured: a spawn with the knight's cell set to the corner, where every cell round it is solid, left graphic 128 at U 0 and V 0. Away from the corner it does no harm: after its four turns of appearing its own update finds it more than two cells from the knight and empties the record (WANDERING_MONSTER, MONSTER112_UPDATE), so it only keeps the record from a real monster for those turns. Near the top-left corner it lives: with the knight in cell 1,1 the strays walk off the map to column or row 255, which the byte subtraction of the nearness test counts as close, and for 1463 of 1500 turns three or four of the six monster records held them (measured for the bugs page). Only types 1 and 2 are refused, so a monster is often put inside a building's cell, where it is never drawn and walks on the spot; with the knight standing still the six records fill with these and no new monster appears (measured for the animations page).
SPAWN_MONSTER CDE8 LD A,(ARRIVING) the knight still appearing: none
CDEB CP $70
CDED RET NZ
CDEE LD A,(TURNS) only when bits 0-1 of TURNS are both set
CDF1 CPL
CDF2 AND $03
CDF4 RET NZ
CDF5 LD IY,MONSTERS the first empty monster record; none, none
CDF9 LD DE,$0010
CDFC LD B,$06
SPAWN_MONSTER_0 CDFE LD A,(IY+$00)
CE01 AND A
CE02 JR Z,SPAWN_MONSTER_1
CE04 ADD IY,DE
CE06 DJNZ SPAWN_MONSTER_0
CE08 RET
SPAWN_MONSTER_1 CE09 LD HL,MONSTER_RECORD a monster appearing, in it
CE0C PUSH IY
CE0E POP DE
CE0F LD BC,$0010
CE12 LDIR
CE14 LD A,(KNIGHT_COLUMN) HL = the knight's column and row
CE17 LD L,A
CE18 LD A,(KNIGHT_ROW)
CE1B LD H,A
CE1C LD A,(RANDOM) the random number's low byte: below $55 the same column, below $AA the next, else the one before
CE1F CP $55
CE21 JR C,SPAWN_MONSTER_3
CE23 CP $AA
CE25 JR C,SPAWN_MONSTER_2
CE27 DEC L
CE28 DEC L
SPAWN_MONSTER_2 CE29 INC L
SPAWN_MONSTER_3 CE2A LD A,($BBAB) its high byte chooses the row the same way
CE2D CP $55
CE2F JR C,SPAWN_MONSTER_5
CE31 CP $AA
CE33 JR C,SPAWN_MONSTER_4
CE35 DEC H
CE36 DEC H
SPAWN_MONSTER_4 CE37 INC H
SPAWN_MONSTER_5 CE38 LD A,L in the town, 0-31
CE39 AND $1F
CE3B LD L,A
CE3C LD A,H
CE3D AND $1F
CE3F LD H,A
CE40 PUSH HL a solid cell: leave it (the record keeps its monster, at the corner)
CE41 CALL TOWN_CELL
CE44 POP HL
CE45 DEC A
CE46 CP $02
CE48 RET C
CE49 LD (IY+$02),L its cell
CE4C LD (IY+$04),H
CE4F CALL STIR_RANDOM stir the random number
CE52 LD A,(RANDOM) U within the cell: 32-223
CE55 CP $C0
CE57 JR C,SPAWN_MONSTER_6
CE59 SUB $40
SPAWN_MONSTER_6 CE5B ADD A,$20
CE5D LD (IY+$01),A
CE60 LD A,($BBAB) V the same, from the high byte
CE63 CP $C0
CE65 JR C,SPAWN_MONSTER_7
CE67 SUB $40
SPAWN_MONSTER_7 CE69 ADD A,$20
CE6B LD (IY+$03),A
CE6E LD A,(TURNS) born in the first half of 256 turns: bit 5, heading for the knight
CE71 CP $80
CE73 RET NC
CE74 SET 5,(IY+$07)
CE78 RET
Prev: CDDF Up: Map Next: CE79