Routines

25944: Make teacher find ERIC


Used by routines at 32379, 61595, 62794 and 62815

H Character number of teacher (200-204)

25944 2E00 LD L,0
25946 CB46 BIT 0,(HL) Is the teacher midstride?
25948 280D JR Z,25963 Jump if not

This entry point is used by the routines at 32379, 61595 and 62794:
25950 CDB461 CALL 25012 Update SRB for teacher's current animatory state and location
25953 47 LD B,A Save animatory state temporarily
25954 2E0F LD L,15 Now A=1 if the teacher is descending a staircase, 0 otherwise
25956 7E LD A,(HL)
25957 82 ADD A,D If the teacher's descending a staircase, he will drop a level at the same time as finishing his stride
25958 57 LD D,A
25959 78 LD A,B Restore the animatory state to A
25960 C30064 JP 25600 Make teacher finish his stride

The teacher is not midstride.
25963 CD526E CALL 28242 Is the teacher on a staircase?
25966 3827 JR C,26007 Jump if so
25968 ED5B01D2 LD DE,(53761) Pick up ERIC's coordinates in DE
25972 2E00 LD L,0
25974 CB7E BIT 7,(HL) Is the teacher facing left?
25976 2E01 LD L,1
25978 2804 JR Z,25984 Jump if so
25980 7B LD A,E A=ERIC's x-coordinate
25981 96 SUB (HL) Subtract that of the teacher
25982 1802 JR 25986
25984 7E LD A,(HL) A=teacher's x-coordinate
25985 93 SUB E Subtract that of ERIC
25986 FE04 CP 4 Is ERIC less than 4 spaces in front of the teacher?
25988 300E JR NC,26004 Jump if not
25990 2C INC L
25991 7E LD A,(HL) A=teacher's y-coordinate
25992 D604 SUB 4
25994 3803 JR C,25999 Jump if the teacher's on the top floor
25996 BA CP D IS ERIC too far above the teacher to be seen?
25997 3005 JR NC,26004 Jump if so
25999 C607 ADD A,7
26001 BA CP D
26002 3F CCF
26003 D8 RET C Return if ERIC is too far below the teacher to be seen
26004 CDBE63 CALL 25534 Now D=3, 10, 14, or 17 (floor ERIC's closest to)
26007 CDF364 CALL 25843 Work out how teacher can reach ERIC from here
26010 CB5F BIT 3,A Is there a closed door in the way?
26012 C2A270 JP NZ,28834 Open it if so
26015 010000 LD BC,0
26018 FE02 CP 2 Is the teacher descending a staircase?
26020 2001 JR NZ,26023 Jump if not
26022 04 INC B B=1
26023 3001 JR NC,26026 Jump if the teacher is not ascending a staircase
26025 0D DEC C C=255
26026 FE03 CP 3 Is the teacher on a staircase?
26028 380F JR C,26045 Jump if so
26030 2E00 LD L,0
26032 FE04 CP 4
26034 CB7E BIT 7,(HL)
26036 3805 JR C,26043 Jump if the teacher must go left to reach ERIC
26038 2005 JR NZ,26045 Jump if the teacher is facing right
26040 C33064 JP 25648 Turn the teacher round
26043 20FB JR NZ,26040 Turn the teacher round if he's facing right
26045 2E0F LD L,15 Set byte 15 of teacher's buffer to 1 if the teacher is descending a staircase, 0 if ascending a staircase or not on one
26047 70 LD (HL),B
26048 C5 PUSH BC
26049 CDB461 CALL 25012 Update SRB for teacher's current animatory state and location
26052 C1 POP BC
26053 CB41 BIT 0,C Is the teacher ascending a staircase?
26055 2801 JR Z,26058 Jump if not
26057 15 DEC D Up a stair
26058 3C INC A One foot forward (midstride)
26059 C33061 JP 24880 Update SRB for teacher's new animatory state and location