Routines

25581: Guide character to (intermediate) destination


The address of this routine is placed into the character's buffer by the routines at 25700, 27904, 31915 and 61696. It is used to make a character go straight to a destination (or intermediate destination) that is reachable without negotiating any staircases.

H Character number (183-214)

25581 2E0C LD L,12 Point to byte 12 of the character's buffer
25583 3608 LD (HL),8
25585 00 NOP
25586 00 NOP
25587 2E09 LD L,9 Point to byte 9 of the character's buffer
25589 36F7 LD (HL),247 Replace the address there (25581) with 25591 (the address of the next instruction)
25591 2E00 LD L,0 Point to byte 0 of the character's buffer
25593 CB46 BIT 0,(HL) Is the character midstride (bit 0 of animatory state set)?
25595 2815 JR Z,25618 Jump if not

If we get here then the character is midstride. He'll have to finish his stride before we set him off on the road to his new destination.
25597 CDB461 CALL 25012 Update SRB for current animatory state and location of character

This entry point is used by the routines at 25677 and 25944:
25600 1C INC E E=1 + character's x-coordinate
25601 CB7F BIT 7,A A=character's animatory state
25603 2002 JR NZ,25607 Jump if the character is facing right
25605 1D DEC E
25606 1D DEC E E=character's x-coordinate – 1
25607 E6FC AND 252
25609 47 LD B,A
25610 7B LD A,E A=x-coordinate of character after he's finished his stride
25611 E601 AND 1
25613 87 ADD A,A
25614 B0 OR B Now A=animatory state of character after he's finished his stride
25615 C33061 JP 24880 Update SRB for this new animatory state and location of character

The character is not midstride, so we can now get him on the way to his destination.
25618 2E0C LD L,12 Point to byte 12 of the character's buffer
25620 35 DEC (HL)
25621 CA9063 JP Z,25488 Jump to blank out the routine address at bytes 9 & 10 of the character's buffer
25624 2D DEC L
25625 7E LD A,(HL) Pick up x-coordinate of character's (intermediate) destination
25626 2E01 LD L,1
25628 BE CP (HL) Is the character already there?
25629 CA9063 JP Z,25488 Jump if so

This entry point is used by the routine at 63801:
25632 2B DEC HL
25633 CB7E BIT 7,(HL) Is the character facing left?
25635 2809 JR Z,25646 Jump if so
25637 3809 JR C,25648 Jump if character will have to turn round first

This entry point is used by the routine at 25677:
25639 CD8E70 CALL 28814 Check for doors
25642 3C INC A A=new (midstride) animatory state for character
25643 C33061 JP 24880 Update SRB for this new animatory state of character

This entry point is used by the routine at 26263:
25646 38F7 JR C,25639 Jump if the character is facing the right way

This entry point is used by several routines to turn a character round:
25648 CDB461 CALL 25012 Update SRB for current animatory state and location of character
25651 EE80 XOR 128 Flip bit 7 of the character's animatory state, thus turning him round
25653 C33061 JP 24880 Update SRB for this new animatory state of character