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). After moving, it also updates any active turn-based events to appear in the new room.
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_EventState into A (bits indicate which turn-based events are active).
C53B AND A Jump to MovePlayerToRoom_Return if no turn-based events are active (all bits are zero).
C53C JR Z,MovePlayerToRoom_Return
Process each turn-based event. For each active event (bit set), move its associated item to the current room.
C53E LD B,$08 Set a counter in B for 08 events (one per bit).
C540 LD HL,$BC70 Set a pointer to Table_TurnBasedEventItems in HL.
C543 LD C,A Copy the event state flags into C for bit testing.
C544 JR ProcessTurnBasedEvents_CheckBit Jump to ProcessTurnBasedEvents_CheckBit to start processing events.
ProcessTurnBasedEvents_Loop C546 INC HL Move to the next event's item ID in the table.
ProcessTurnBasedEvents_CheckBit C547 SRL C Shift the event state flags right to check the next bit.
C549 JR NC,ProcessTurnBasedEvents_Next Jump to ProcessTurnBasedEvents_Next if this bit is not set (event is not active).
This event is active, so move its associated item to the current room.
C54B LD A,(HL) Get the item ID for this event 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
ProcessTurnBasedEvents_Next C553 DJNZ ProcessTurnBasedEvents_Loop Decrease the event counter by one and loop back to ProcessTurnBasedEvents_Loop until all 08 events have been processed.
MovePlayerToRoom_Return C555 RET Return.
View the equivalent code in Warlord.
Prev: C4EB Up: Map Next: C556