Routines
 Prev: 27953 Up: Map Next: 28002
27954: Check whether a target character can be seen by another character
Used by the routines at 28002 and 28029. This routine checks through B' 'spotter' characters starting with character H'. If any spotter is close enough to the target to be able to see it, the routine returns with A holding a non-zero value, H holding the spotter's character number, and the carry flag set if the spotter is facing the right way to see it (reset otherwise). If no spotters are close enough to the target to be able to see it, the routine returns with A holding 0 and the carry flag reset.
Input
B Upper x-coordinate of the target range
C Lower x-coordinate of the target range
D Target character's y-coordinate
E Target character's x-coordinate
B' Number of spotters to check
H' Character number of the first spotter to check
27954 EXX
27955 LD L,2 Pick up the spotter's coordinates in DE'; we are going to check whether this character can see the target
27957 LD D,(HL)
27958 DEC L
27959 LD E,(HL)
27960 LD A,D Transfer the spotter's y-coordinate to A
27961 EXX
27962 SUB D Subtract the target's y-coordinate
27963 JR NC,27967 Jump if the spotter is below or level with the target
27965 NEG
27967 CP 4 Is the spotter within 3 y-coordinates of the target?
27969 JR NC,27980 Jump if not
27971 EXX
27972 LD A,E A=spotter's x-coordinate
27973 EXX
27974 CP C Compare this with the lower and upper limits of the range within which the target can be seen, and jump to 27987 if the spotter is within seeing range
27975 JR C,27980
27977 CP B
27978 JR C,27987
This entry point is used by the routine at 28002.
27980 EXX
This entry point is used by the routine at 28029.
27981 INC H The last spotter was not within seeing range of the target; try the next spotter
27982 DJNZ 27955
27984 EXX
27985 XOR A Signal: none of the spotters was within range
27986 RET
We've found a spotter within seeing range of the target. But is he facing the right way?
27987 CP E Does the spotter's x-coordinate match the target's?
27988 JR Z,27999 Jump if so
27990 LD A,0 The carry flag is now set if the spotter is to the left of the target
27992 RRA A=128 if the spotter is to the left of the target, 0 if to the right
27993 EXX
27994 LD L,0 Point HL' at the spotter's animatory state
27996 XOR (HL) Compare this orientation with the direction in which the spotter is facing
27997 EXX
27998 RLCA
27999 CCF Set the carry flag if the spotter's facing the right way to see the target
28000 LD A,B Set A to something non-zero to indicate that the spotter was within range
28001 RET
 Prev: 27953 Up: Map Next: 28002