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 ScenicItem_Next Jump to ScenicItem_Next.
Loop through all scenic events and move any that are in the current room to the destination room (so they follow the player).
ScenicItem_Advance 50477 INC HL Move to the next scenic event in the table.
ScenicItem_Next 50478 CP (HL) Jump to ScenicItem_Count if this scenic event is not in the current room.
50479 JR NZ,ScenicItem_Count
50481 LD (HL),C Update this scenic event's location to the destination room.
ScenicItem_Count 50482 DJNZ ScenicItem_Advance Decrease the scenic event counter by one and loop back to ScenicItem_Advance until all scenic events have been checked.
Update the current room ID to the destination room.
MovePlayerToRoom_SetRoom 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 EventFlag_Next Jump to EventFlag_Next.
EventFlag_Advance 50502 INC HL Move to the next item ID.
EventFlag_Next 50503 SRL C Shift the following flags right to check the next bit.
50505 JR NC,EventFlag_Count Jump to EventFlag_Count 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
EventFlag_Count 50515 DJNZ EventFlag_Advance Decrease the bit counter by one and loop back to EventFlag_Advance until all 8 bits have been tested.
MovePlayerToRoom_Return 50517 RET Return.
Prev: 50411 Up: Map Next: 50518