Skool Daze Routines
25404: Guide character to intermediate destination
Used by the routine at 31854 (and indirectly by the routines at 25303, 25534 and 32048) to guide a character to a location that doesn't require going up or down any staircases.
H Character number (152-169)
25404 LD L,108 The counter at byte 108 of the character's buffer is initialised by the calling routine to limit the amount of time that this routine has control; hand control back to the calling routine (via 25172) if this counter is now zero
25406 DEC (HL)
25407 JP Z,25252
25410 DEC L Collect the x-coordinate of the intermediate destination from byte 107 of the character's buffer
25411 LD A,(HL)
25412 LD L,98 Byte 98 of the character's buffer holds his x-coordinate
25414 CP (HL) Has the character reached the intermediate destination?
25415 JR NZ,25423 Jump if not
25417 LD L,96 Byte 96 of the character's buffer holds his animatory state
25419 BIT 0,(HL) Is the character midstride?
25421 JR Z,25407 Jump if not (nothing left to do)
25423 CALL 25108 Update SRB for the character's current location
25426 LD C,A Store the character's animatory state in C
25427 LD L,107 Collect the x-coordinate of the intermediate destination from byte 107 of the character's buffer
25429 LD A,(HL)
25430 CP E E holds the character's x-coordinate
25431 LD A,C A=character's animatory state
25432 JR NZ,25440 Jump unless the character has reached the destination
The character has reached the destination, but he is midstride. To complete the journey, he must finish his stride. This entry point is also used by the routine at 27772.
25434 BIT 7,A Is the character facing left?
25436 JR Z,25449 Jump if so
25438 JR 25471
The character has not yet reached the destination. Figure out his next move.
25440 BIT 7,A Now the zero flag indicates which way the character is facing: set=left, reset=right
25442 JR NC,25466 Jump if the character is to the left of his destination
The character is to the right of his destination, and so must proceed leftwards.
25444 RES 7,A Make sure the character is facing left
25446 JP NZ,25008 Update the character's animatory state and update SRB if he was facing right
25449 INC A A=character's next animatory state
25450 BIT 0,A Will the character be midstride?
25452 JP NZ,25008 Update the character's animatory state and update SRB if so
25455 DEC E E=character's next x-coordinate (one to the left)
25456 AND 3 Calculate the character's next animatory state in A
25458 LD B,A
25459 LD A,C
25460 AND 252
25462 ADD A,B
25463 JP 25008 Update the character's animatory state and location and update SRB
The character is to the left of his destination, and so must proceed rightwards.
25466 SET 7,A Make sure the character is facing right
25468 JP Z,25008 Update the character's animatory state and update SRB if the character was facing left
25471 INC A A=character's next animatory state
25472 BIT 0,A Will the character be midstride?
25474 JP NZ,25008 Update the character's animatory state and update SRB if so
25477 INC E E=character's next x-coordinate (one to the right)
25478 JR 25456 Jump back to update the character's animatory state and location and update SRB