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). 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 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_CrabFollowing into A.
50491 AND A Jump to MovePlayerToRoom_Return if no following item is active.
50492 JR Z,MovePlayerToRoom_Return
For each set bit, move the item at that position in Table_FollowingItems into the current room.
50494 LD B,8 Set a counter in B for 8 bits.
50496 LD HL,48240 Set a pointer to Table_FollowingItems in HL.
50499 LD C,A Copy the following flags into C for bit testing.
50500 JR FollowingItems_CheckBit Jump to FollowingItems_CheckBit.
FollowingItems_Loop 50502 INC HL Move to the next item ID.
FollowingItems_CheckBit 50503 SRL C Shift the following flags right to check the next bit.
50505 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.
50507 LD A,(HL) Get the item ID 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
FollowingItems_Next 50515 DJNZ FollowingItems_Loop Decrease the bit counter by one and loop back to FollowingItems_Loop until all 8 bits have been tested.
MovePlayerToRoom_Return 50517 RET Return.
Prev: 50411 Up: Map Next: 50518