| Routines

27820: Check whether any characters have been hit by a fist, pellet or conker

Used by the routines at 27804, 29896 and 30380. Returns with the carry flag reset if someone is in the same location as the fist, pellet or conker, and with D holding that person's character number.
Input
B | Number of potential victims to check
D | Character number of the first potential victim to check
H | Puncher's, pellet's or conker's character number
27820 | EX DE,HL |
27821 | LD L,1 | Point HL at byte 1 of the next potential target's character buffer
27823 | LD E,L | Point DE at byte 1 of the puncher's, pellet's or conker's character buffer
27824 | LD A,(DE) | A=x-coordinate of the fist/pellet/conker
27825 | CP (HL) | Does this match the target character's x-coordinate?
27826 | JR Z,27834 | Jump if so
27828 | INC H | Move to the next potential target
27829 | DJNZ 27821 | Jump back until all potential targets have been checked
27831 | EX DE,HL |
27832 | SCF | Signal: no character was hit
27833 | RET |
A potential victim of the fist, pellet or conker was found at the right x-coordinate. What about the y-coordinate?
27834 | INC L | Point HL at byte 2 of the next potential target's character buffer
27835 | INC E | Point DE at byte 2 of the puncher's, pellet's, or conker's character buffer
27836 | LD A,(DE) | A=y-coordinate of the fist/pellet/conker
27837 | CP (HL) | Does this match the target character's y-coordinate?
27838 | JR NZ,27828 | Jump back to consider the next character if not
The potential victim's coordinates are a perfect match.
27840 | LD A,H | A=number of the stricken character
27841 | CP 210 | Was ERIC hit?
27843 | JR Z,27853 | Jump if so
27845 | LD L,18 | Bytes 17 and 18 of the character's buffer may hold the address of an uninterruptible subcommand routine (which would prevent him from being knocked over); pick up the MSB in A
27847 | LD A,(HL)
27848 | AND A | Can this character be knocked over at the moment?
27849 | JR NZ,27828 | Jump back to consider the next character if not
27851 | EX DE,HL | Transfer the stricken character's number to D
27852 | RET |
ERIC was the potential victim.
27853 | LD A,(32763) | Collect ERIC's status flags from 32763; now A=0 unless ERIC is engaged in some activity other than walking
27856 | JR 27848 |