Prev: 27542 Up: Map Next: 27621
27543: Check whether a chair is occupied and unseat any occupant
Used by the routine at 27517. Returns with the carry flag reset if the chair next to the character looking for a seat is not occupied by any of the potential occupants being checked. Otherwise knocks the occupant out of the chair and returns with the carry flag set.
Input
B Number of potential occupants to check (11, 3, or 1)
D Number of the first potential occupant to check (152, 167, or 172)
H Number of the character looking for a seat (152-169)
27543 LD L,98 Byte 98 of a character's buffer holds his x-coordinate
27545 LD E,L
27546 LD A,(DE) A=x-coordinate of the potential dethronee
27547 CP (HL) Do the x-coordinates match?
27548 JR NZ,27564 Jump ahead to consider the next character if not
27550 DEC E E=L=97 (which byte holds the character's y-coordinate)
27551 DEC L
27552 LD A,(DE) A=y-coordinate of the potential dethronee
27553 CP (HL) Do the y-coordinates match?
27554 JR NZ,27564 Jump ahead to consider the next character if not
27556 DEC E E=96
27557 LD A,(DE) A=animatory state of the potential dethronee
27558 AND 15
27560 CP 5 Is this character sitting in the chair?
27562 JR Z,27569 Dethrone him if so
27564 INC D Next character to check
27565 DJNZ 27543 Jump back until all potential dethronees have been checked
27567 AND A Return with the carry flag reset to indicate that no one was knocked out of the chair
27568 RET
27569 LD A,D A=number of the character sitting in the chair
27570 CP 172 Is ERIC sitting here?
27572 JR NZ,27601 Jump if not
27574 LD DE,32763 32763 holds ERIC's status flags
27577 EX DE,HL
27578 SET 4,(HL) Signal: ERIC has been knocked out of his chair
27580 EX DE,HL
This entry point is used by the routine at 27517 to make the chair-seeking character sit down after having found a vacant seat.
27581 LD L,112 Remove the uninterruptible subcommand routine address from bytes 111 and 112 of the buffer of the character who is going to sit down
27583 LD (HL),0
27585 LD L,96 A=this character's current animatory state
27587 LD A,(HL)
27588 AND 248 Set A to the animatory state of this character sitting in a chair
27590 ADD A,5
27592 INC L Pick up the character's coordinates in DE
27593 LD D,(HL)
27594 INC L
27595 LD E,(HL)
27596 CALL 25008 Update the character's animatory state and update the SRB
27599 SCF Return with the carry flag set to indicate that a character was pushed out of his chair
27600 RET
Someone is sitting in the chair, but it isn't ERIC.
27601 LD E,112 Is there an uninterruptible subcommand routine address in bytes 111 and 112 of the seated character's buffer?
27603 LD A,(DE)
27604 AND A
27605 JR Z,27613 Jump if not
The current occupant of the chair must be in the process of being dethroned by someone else at the moment (i.e. bytes 111 and 112 of his buffer hold the address of the uninterruptible subcommand routine at 27733). In that case, the chair-seeking character will give way to the dethroner and look for another chair.
27607 LD L,96 A=current animatory state of the character who wants to sit down
27609 LD A,(HL)
27610 INC A Put this character midstride; this has the effect of making him walk to the next chair
27611 JR 27592
The current occupant of the chair can be dethroned. Make it so.
27613 EX DE,HL
27614 LD (HL),108 Place the address of the uninterruptible subcommand routine at 27733 into bytes 111 and 112 of the seated character's buffer
27616 DEC L
27617 LD (HL),85
27619 JR 27580
Prev: 27542 Up: Map Next: 27621