| Routines

25700: Make a character go to a location

Used by command lists 0, 2, 4, 6, 8, 10, 12, 14, 16, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 70, 72, 74, 76, 78, 80, 82, 84, 86 and 88 to make a character go to a specified place.
Input
H | Character number (183-209)
25700 | LD L,5 | Copy the destination coordinates from the command list into bytes 5 and 6 of the character's buffer
25702 | CALL 25188
This entry point is used by the routine at 25815.
25705 | LD L,3 | Replace the address of this routine in bytes 3 and 4 of the character's buffer with 25726 (below)
25707 | LD (HL),126
25709 | LD L,0 | Point HL at byte 0 of the character's buffer
25711 | LD A,(HL) | A=character's animatory state
25712 | AND 7 | Is the character sitting on a chair (kids only)?
25714 | CP 4
25716 | JR NZ,25726 | Jump if not
The character is sitting on a chair. He'll have to stand up first.
25718 | CALL 25012 | Update the SRB for the character's current animatory state
25721 | AND 248 | A=animatory state of the character standing up
25723 | JP 24880 | Update the character's animatory state and update the SRB
The second and subsequent calls to this routine (from 25296) enter here:
25726 | LD L,6 | Collect the destination coordinates into DE
25728 | LD D,(HL)
25729 | DEC L
25730 | LD E,(HL)
25731 | LD L,1 | Point HL at byte 1 of the character's buffer
25733 | LD A,E | A=destination x-coordinate
25734 | CP (HL) | Compare it with the character's current x-coordinate
25735 | INC HL | L=2
25736 | JR NZ,25743 | Jump forward unless the character's current x-coordinate matches that of the destination
25738 | LD A,D | A=destination y-coordinate
25739 | CP (HL) | Is the character already at his destination?
25740 | JP Z,25484 | Move to the next command in the command list if so
The character hasn't reached his destination yet.
25743 | CALL 25554 | Get the region identifier for the character's destination
Now A holds a region ID (189-196) corresponding to the character's destination:
ID | Region
--- | ---
189 | Top floor, left of the left study door in the boys' skool
190 | Middle floor, left of the far wall of the Science Lab storeroom
191 | Bottom floor (anywhere)
192 | Assembly hall stage
193 | Near the middle-floor window in the boys' skool
194 | Top floor, right of the left study door in the boys' skool
195 | Middle floor, girls' skool
196 | Top floor, girls' skool
25746 | LD D,(HL) | Collect the character's current coordinates into DE
25747 | DEC L
25748 | LD E,(HL)
25749 | LD L,A | L=destination region ID (189-196)
25750 | CALL 25554 | A=region ID (189-196) for the character's current location
25753 | CP L | Will the character have to negotiate any staircases in order to reach his destination?
25754 | JR Z,25800 | Jump if not (he's in the same region as his destination)
25756 | LD D,A | D=region ID of the character's current location (189-196)
25757 | LD A,L | A=destination region ID (189-196)
25758 | SUB 129 | E=destination region ID minus 129 (60-67)
25760 | LD E,A
25761 | LD A,(DE) | Collect the appropriate staircase endpoint identifier
The staircase endpoint identifiers are arranged in bytes 60-67 (corresponding to the destination) of pages 189-196 (corresponding to the current location) as follows:
| 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196
48444 | 189 |  | 189 | 189 | 189 | 189 | 189 | 189 | 189
48700 | 190 | 190 |  | 191 | 191 | 191 | 191 | 191 | 191
48956 | 191 | 192 | 192 |  | 193 | 193 | 193 | 194 | 194
49212 | 192 | 195 | 195 | 195 |  | 196 | 196 | 195 | 195
49468 | 193 | 197 | 197 | 197 | 197 |  | 198 | 197 | 197
49724 | 194 | 199 | 199 | 199 | 199 | 199 |  | 199 | 199
49980 | 195 | 200 | 200 | 200 | 200 | 200 | 200 |  | 206
50236 | 196 | 207 | 207 | 207 | 207 | 207 | 207 | 207 |
The staircase endpoint indentifier now in A (189-200, 206 or 207) corresponds to the top or bottom of the first staircase the character will have to negotiate in order to reach his destination. The x-coordinate (x), direction indicator (d), appropriate routine address LSB (56 for 25656, 77 for 25677) and number of steps (n) for the staircase can be found in bytes 68-71 of pages 189-200 and 206-207, as follows:
ID | x | d | LSB | n | Staircase endpoint
--- | --- | --- | --- | --- | ---
189 | 26 | 0 | 77 | 8 | Top of the staircase leading down from the Revision Library
190 | 19 | 128 | 56 | 8 | Bottom of the staircase leading up to the Revision Library
191 | 15 | 128 | 77 | 8 | Top of the staircase leading down to the bottom floor on the far left of the boys' skool
192 | 22 | 0 | 56 | 8 | Bottom of the staircase leading up to the middle floor on the far left of the boys' skool
193 | 83 | 0 | 56 | 4 | Bottom of the staircase leading up to the assembly hall stage
194 | 176 | 128 | 56 | 8 | Bottom of the staircase leading up to the middle floor in the girls' skool
195 | 80 | 128 | 77 | 4 | Top of the staircase leading down from the assembly hall stage
196 | 81 | 128 | 56 | 5 | Bottom of the staircase leading up from the assembly hall stage
197 | 85 | 0 | 77 | 5 | Top of the staircase leading down to the assembly hall stage
198 | 91 | 0 | 56 | 8 | Bottom of the staircase leading up to the head's study
199 | 84 | 128 | 77 | 8 | Top of the staircase leading down from the head's study
200 | 183 | 0 | 77 | 8 | Top of the staircase leading down to the bottom floor in the girls' skool
206 | 186 | 0 | 56 | 8 | Bottom of the staircase leading up to the top floor in the girls' skool
207 | 179 | 128 | 77 | 8 | Top of the staircase leading down to middle floor in the girls' skool
25762 | LD D,A | Place the staircase endpoint identifier in D
25763 | LD E,68 | Byte 68 holds the x-coordinate of the top or bottom of the staircase identified by D
25765 | LD L,1 | Point DE at byte 1 of the character's buffer, and HL at the staircase endpoint x-coordinate
25767 | EX DE,HL
25768 | LD A,(DE) | A=character's current x-coordinate
25769 | CP (HL) | Is the character already at the top or bottom of the appropriate staircase?
25770 | JR NZ,25796 | Jump forward if not
At this stage the character is standing at the top or bottom of the first staircase he will have to negotiate in order to reach his destination.
25772 | INC L | (HL)=0 if the character has to face left to ascend or descend the stairs, 128 otherwise
25773 | DEC E | E=0
25774 | LD A,(DE) | A=character's animatory state
25775 | XOR (HL) | Set the carry flag if the character has to turn round to negotiate the staircase
25776 | RLCA
25777 | EX DE,HL | Swap DE and HL so that H holds the character number
25778 | JP C,25648 | Turn the character round if he's facing the wrong way
25781 | EX DE,HL | Swap DE and HL back again
25782 | LD E,11 | Point DE at byte 11 of the character's buffer
25784 | INC L | L=70
25785 | LD C,(HL) | BC=25656 if the stairs are to be ascended, 25677 if descended
25786 | LD B,100
25788 | NOP |
25789 | INC L | L=71
25790 | LD A,(HL) | A=1 + number of steps in the staircase
25791 | LD (DE),A | Place this number of steps in byte 11 of the character's buffer
25792 | EX DE,HL | Swap DE and HL so that H holds the character number
25793 | JP 25520 | Copy the interruptible subcommand routine address from BC into bytes 9 and 10 of the character's buffer and jump to it
The character is not yet at the top or bottom of the appropriate staircase.
25796 | LD A,(HL) | A=x-coordinate of the top or bottom of the staircase
25797 | EX DE,HL | H=character number
25798 | JR 25803 | Send the character towards the staircase
The character can reach his destination without negotiating any staircases.
25800 | LD L,5 | Point HL at byte 5 of the character's buffer
25802 | LD A,(HL) | A=x-coordinate of the character's destination
25803 | LD L,11 | Place the x-coordinate of the top or bottom of the staircase, or the destination, into byte 11 of the character's buffer
25805 | LD (HL),A
25806 | LD BC,25581 | Place the address of the interruptible subcommand routine at 25581 into bytes 9 and 10 of the character's buffer and jump to it, thus guiding the character to this x-coordinate
25809 | JP 25520