Prev: C164 Up: Map Next: C1B9
C19C: Which villain is nearest the thing at IX?
Used by the routine at APPEARING_UPDATE.
Nearest by the columns and the rows apart added together (VILLAIN_DISTANCE); the first found wins a tie. Returns 3 for the villain in the first record down to 0 for the last: the kind of the monsters that villain brings (APPEARING_UPDATE). With no villain left, 3.
Input
IX the record
Output
A 3 - the nearest villain's record number
NEAREST_VILLAIN C19C LD IY,VILLAINS IY = the first villain; the nearest so far none, at 255
C1A0 LD B,$04
C1A2 LD DE,$04FF
NEAREST_VILLAIN_0 C1A5 CALL VILLAIN_DISTANCE nearer? keep its distance, and B
C1A8 CP E
C1A9 JR NC,NEAREST_VILLAIN_1
C1AB LD E,A
C1AC LD D,B
NEAREST_VILLAIN_1 C1AD PUSH DE the next villain
C1AE LD DE,$0010
C1B1 ADD IY,DE
C1B3 POP DE
C1B4 DJNZ NEAREST_VILLAIN_0
C1B6 LD A,D 3 for the first record, 0 for the last
C1B7 DEC A
C1B8 RET
Prev: C164 Up: Map Next: C1B9