Prev: B6E0 Up: Map Next: B753
B714: Move Player To Room
Used by the routine at Handler_ChangeRoom.
Moves the player to a new room. Before updating the current room, it brings every scenic-event item that is here or carried along to the destination. It then moves each item whose bit is set in Flag_FollowingHeroes into the new room (see Table_FollowingItems).
Input
A Destination room ID
Store the destination room ID and prepare to update scenic events.
MovePlayerToRoom B714 LD C,A Copy the destination room ID into C.
B715 LD A,($AEF8) Load *Count_ScenicEvents into A.
B718 AND A Jump to MovePlayerToRoom_SetRoom if no scenic events are defined.
B719 JR Z,MovePlayerToRoom_SetRoom
B71B LD B,A Load *Count_ScenicEvents into B for the loop counter.
B71C LD HL,($AEEC) Set a pointer to *Pointer_Spare in HL.
B71F JR ScenicItem_Next Jump to ScenicItem_Next.
Loop through all scenic event items and move any that are here or carried to the destination room (so they follow the player).
ScenicItem_Advance B721 INC HL Move to the next scenic event item ID.
ScenicItem_Next B722 LD A,(HL) Load this scenic event item ID into A.
B723 CALL ValidateItemPresent Call ValidateItemPresent to test whether it is here or carried.
B726 JR NZ,ScenicItem_Count Jump to ScenicItem_Count if it is neither here nor carried.
This scenic event item is here or carried, so move it with the player.
B728 PUSH HL Stash the table pointer and counter on the stack.
B729 PUSH BC
B72A LD B,(HL) Load the scenic event item ID into B.
B72B CALL SetItemRoom Call SetItemRoom to update the item's location to the destination room.
B72E POP BC Restore the table pointer and counter from the stack.
B72F POP HL
ScenicItem_Count B730 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 B732 LD A,C Copy the destination room ID into A.
B733 LD ($AECD),A Write the destination room ID to CurrentRoom.
B736 LD A,($AE91) Load *Flag_FollowingHeroes into A.
B739 AND A Return if no following item is active.
B73A RET Z
For each set bit, move the item at that position in Table_FollowingItems into the current room.
B73B LD B,$08 Set a counter in B for 08 bits.
B73D LD HL,$AE92 Set a pointer to Table_FollowingItems in HL.
B740 LD C,A Copy the following flags into C for bit testing.
B741 JR EventFlag_Next Jump to EventFlag_Next.
EventFlag_Advance B743 INC HL Move to the next item ID.
EventFlag_Next B744 SRL C Shift the following flags right to check the next bit.
B746 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.
B748 LD A,(HL) Get the item ID from the table.
B749 PUSH HL Stash the table pointer and counter on the stack.
B74A PUSH BC
B74B CALL HandlerUpdateItemEventForTheCurrentRoom Call HandlerUpdateItemEventForTheCurrentRoom to update the item's location to the current room.
B74E POP BC Restore the table pointer and counter from the stack.
B74F POP HL
EventFlag_Count B750 DJNZ EventFlag_Advance Decrease the bit counter by one and loop back to EventFlag_Advance until all 08 bits have been tested.
MovePlayerToRoom_Return B752 RET Return.
Prev: B6E0 Up: Map Next: B753