Prev: C4EB Up: Map Next: C556
C520: Move Player To Room
Used by the routine at ChangeRoom.
Moves the player to a new room. Before updating the current room, it updates all scenic events that were in the old room to be in the new room (so they follow the player). It then moves each item whose bit is set in Flag_CrabFollowing into the new room. Only bit 0, the giant crab, is ever set.
Input
A Destination room ID
Store the destination room ID and prepare to update scenic events.
MovePlayerToRoom C520 LD C,A Copy the destination room ID into C.
C521 LD A,($BD30) Load *Count_ScenicEvents into B for the loop counter.
C524 LD B,A
C525 LD A,($BCCB) Load CurrentRoom into A (the room we're leaving).
C528 LD HL,$BC78 Set a pointer to *Table_ScenicEventLocations in HL.
C52B JR FindScenicEvents Jump to FindScenicEvents.
Loop through all scenic events and move any that are in the current room to the destination room (so they follow the player).
FindScenicEvents_Loop C52D INC HL Move to the next scenic event in the table.
FindScenicEvents C52E CP (HL) Jump to FindScenicEvents_Next if this scenic event is not in the current room.
C52F JR NZ,FindScenicEvents_Next
C531 LD (HL),C Update this scenic event's location to the destination room.
FindScenicEvents_Next C532 DJNZ FindScenicEvents_Loop Decrease the scenic event counter by one and loop back to FindScenicEvents_Loop until all scenic events have been checked.
Update the current room ID to the destination room.
C534 LD A,C Write the destination room ID to CurrentRoom.
C535 LD ($BCCB),A
C538 LD A,($BC6F) Load *Flag_CrabFollowing into A.
C53B AND A Jump to MovePlayerToRoom_Return if no following item is active.
C53C JR Z,MovePlayerToRoom_Return
For each set bit, move the item at that position in Table_FollowingItems into the current room.
C53E LD B,$08 Set a counter in B for 08 bits.
C540 LD HL,$BC70 Set a pointer to Table_FollowingItems in HL.
C543 LD C,A Copy the following flags into C for bit testing.
C544 JR FollowingItems_CheckBit Jump to FollowingItems_CheckBit.
FollowingItems_Loop C546 INC HL Move to the next item ID.
FollowingItems_CheckBit C547 SRL C Shift the following flags right to check the next bit.
C549 JR NC,FollowingItems_Next Jump to FollowingItems_Next if this bit is not set.
This item is following, so move it to the current room.
C54B LD A,(HL) Get the item ID from the table.
C54C PUSH HL Stash the table pointer and counter on the stack.
C54D PUSH BC
C54E CALL Handler_UpdateItemEventCurrentRoom Call Handler_UpdateItemEventCurrentRoom to update the item's location to the current room.
C551 POP BC Restore the table pointer and counter from the stack.
C552 POP HL
FollowingItems_Next C553 DJNZ FollowingItems_Loop Decrease the bit counter by one and loop back to FollowingItems_Loop until all 08 bits have been tested.
MovePlayerToRoom_Return C555 RET Return.
Prev: C4EB Up: Map Next: C556