Prev: 50411 Up: Map Next: 50518
50464: 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 50464 LD C,A Copy the destination room ID into C.
50465 LD A,(48432) Load *Count_ScenicEvents into B for the loop counter.
50468 LD B,A
50469 LD A,(48331) Load CurrentRoom into A (the room we're leaving).
50472 LD HL,48248 Set a pointer to *Table_ScenicEventLocations in HL.
50475 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 50477 INC HL Move to the next scenic event in the table.
FindScenicEvents 50478 CP (HL) Jump to FindScenicEvents_Next if this scenic event is not in the current room.
50479 JR NZ,FindScenicEvents_Next
50481 LD (HL),C Update this scenic event's location to the destination room.
FindScenicEvents_Next 50482 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.
50484 LD A,C Write the destination room ID to CurrentRoom.
50485 LD (48331),A
50488 LD A,(48239) Load *Flag_EventState into A (bits indicate which turn-based events are active).
50491 AND A Jump to MovePlayerToRoom_Return if no turn-based events are active (all bits are zero).
50492 JR Z,MovePlayerToRoom_Return
Process each turn-based event. For each active event (bit set), move its associated item to the current room.
50494 LD B,8 Set a counter in B for 8 events (one per bit).
50496 LD HL,48240 Set a pointer to Table_TurnBasedEventItems in HL.
50499 LD C,A Copy the event state flags into C for bit testing.
50500 JR ProcessTurnBasedEvents_CheckBit Jump to ProcessTurnBasedEvents_CheckBit to start processing events.
ProcessTurnBasedEvents_Loop 50502 INC HL Move to the next event's item ID in the table.
ProcessTurnBasedEvents_CheckBit 50503 SRL C Shift the event state flags right to check the next bit.
50505 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.
50507 LD A,(HL) Get the item ID for this event from the table.
50508 PUSH HL Stash the table pointer and counter on the stack.
50509 PUSH BC
50510 CALL Handler_UpdateItemEventCurrentRoom Call Handler_UpdateItemEventCurrentRoom to update the item's location to the current room.
50513 POP BC Restore the table pointer and counter from the stack.
50514 POP HL
ProcessTurnBasedEvents_Next 50515 DJNZ ProcessTurnBasedEvents_Loop Decrease the event counter by one and loop back to ProcessTurnBasedEvents_Loop until all 8 events have been processed.
MovePlayerToRoom_Return 50517 RET Return.
View the equivalent code in Warlord.
Prev: 50411 Up: Map Next: 50518