| Routines

62976: Make a character go to a location

Used by many command lists to make a character go to a specified place.
Input
H | Character number (215-229)
62976 | CALL 31944 | Collect the destination coordinates from the command list
62979 | JR 62998 |
This entry point is used by the command lists at 25066, 64756, 64790, 64816, 64846, 64878 and 64902 to make a character carry Sam to a location.
62981 | CALL 31944 | Collect the destination coordinates from the command list
62984 | LD (HL),10 | Change the address of the primary command routine in bytes 8 and 9 of the character's buffer to 62986 (below)
62986 | CALL 63128 | Exit now if the character is midstride
62989 | CALL 60812 | Determine the next move the character should make to reach his destination
62992 | AND A | Has the character reached his destination?
62993 | JR Z,63007 | Move to the next command in the command list if so
62995 | JP 29479 | Move the character one step towards his destination
The character is not carrying Sam.
62998 | LD (HL),24 | Change the address of the primary command routine in bytes 8 and 9 of the character's buffer to 63000 (below)
63000 | CALL 63128 | Exit now if the character is midstride
63003 | CALL 60812 | Determine the next move the character should make to reach his destination
63006 | AND A | Has the character reached his destination?
63007 | JP Z,62080 | Move to the next command in the command list if so
63010 | CP 5 | Is the character standing next to a closed door?
63012 | JR NC,63100 | Jump if so
63014 | PUSH AF | Save the direction indicator
63015 | LD BC,62926 | Point BC at the interruptible subcommand routine at 62926
63018 | LD L,13 | Pick up the location/destination indicator from byte 13 of the character's buffer
63020 | LD A,(HL)
63021 | AND A | Is the character on the sidewalk or the road (or on the front steps of the hotel but heading somewhere other than the hotel)?
63022 | JR NZ,63051 | Jump if not
63024 | LD BC,62971 | Point BC at the interruptible subcommand routine at 62971
63027 | LD L,16 | Place the x- or y-coordinate of the character's intermediate destination into byte 16 of his buffer
63029 | LD (HL),E
63030 | LD L,15 | Copy the interruptible subcommand routine address in BC (62892, 62926 or 62971) into bytes 14 and 15 of the character's buffer
63032 | LD (HL),B
63033 | DEC L
63034 | LD (HL),C
63035 | POP AF | Restore the direction indicator (1-4) to A
This entry point is used by the routines at 29361 and 31362.
63036 | DEC A | Does the character need to move right next to reach his destination?
63037 | JP Z,60334 | Jump if so
63040 | DEC A | Does the character need to move left?
63041 | JP Z,60347 | Jump if so
63044 | DEC A | Does the character need to move up?
63045 | JP Z,60315 | Jump if so
63048 | JP 60320 | Make the character move down
The character is not on the sidewalk or road.
63051 | DEC A | Is the character's destination in a region other than the one he's in at the moment?
63052 | JR NZ,63083 | Jump if so
63054 | LD L,2 | Collect the character's y-coordinate from byte 2 of his buffer
63056 | LD A,(HL)
63057 | CP 31 | Is the character on or below the level of the first floor?
63059 | JR NC,63074 | Jump if so
63061 | LD L,10 | Point HL at byte 10 of the character's buffer
63063 | LD E,(HL) | E=character's destination x-coordinate
63064 | INC L | L=11
63065 | CP (HL) | Is the character's y-coordinate the same as that of his destination?
63066 | JR Z,63027 | If so, send the character to his destination x-coordinate (on the same floor)
63068 | LD E,(HL) | E=character's destination y-coordinate
63069 | LD BC,62892 | Point BC at the interruptible subcommand routine at 62892
63072 | JR 63027 | Send the character up or down the stairs towards his destination
The character is in the same region as his destination, and on or below the level of the first floor.
63074 | LD L,4 | Byte 4 of the character's buffer holds his z-coordinate
63076 | BIT 0,(HL) | Is the character indoors (z=1)?
63078 | CALL NZ,62597 | If so, make him consider flipping a light switch
63081 | JR 63035 | Move the character one step closer to his destination
The character's destination is in a region other than the one he's in at the moment.
63083 | LD L,2 | Collect the character's y-coordinate from byte 2 of his buffer
63085 | LD A,(HL)
63086 | LD E,31 | This is the y-coordinate of the first floor
63088 | CP E | Is the character above the first floor?
63089 | JR C,63069 | Jump if so to send him down to the first floor
63091 | LD L,4 | Byte 4 of the character's buffer holds his z-coordinate
63093 | BIT 0,(HL) | Is the character indoors (z=1)?
63095 | CALL NZ,62880 | If so, make him consider flipping a light switch off before leaving
63098 | JR 63035 | Move the character one step closer to his destination
The character is standing next to a closed door. This entry point is used by the routines at 29361 and 31362.
63100 | JP Z,62252 | Jump if the character is standing behind a closed door
63103 | LD L,15 | Prepare the MSB of the address of the interruptible subcommand routine at 62278 in byte 15 of the character's buffer
63105 | LD (HL),243
63107 | JP 62264 | Prepare the LSB and raise the character's arm