Prev: AFEB Up: Map Next: B05E
B01F: Move Player To Room
Used by the routine at 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_EventStates into the new room (see Table_TurnBasedEventItems).
Input
A Destination room ID
Store the destination room ID and prepare to update scenic events.
MovePlayerToRoom B01F LD C,A Copy the destination room ID into C.
B020 LD A,($A7EE) Jump to MovePlayerToRoom_SetRoom if *Count_ScenicEvents is zero.
B023 AND A
B024 JR Z,MovePlayerToRoom_SetRoom
B026 LD B,A Load *Count_ScenicEvents into B for the loop counter.
B027 LD HL,($A7E2) Set a pointer to *Pointer_ScenicEventItems in HL.
B02A 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 B02C INC HL Move to the next scenic event item ID.
ScenicItem_Next B02D LD A,(HL) Load this scenic event item ID into A.
B02E CALL ValidateItemPresent Call ValidateItemPresent to test whether it is here or carried.
B031 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.
B033 PUSH HL Stash the table pointer and counter on the stack.
B034 PUSH BC
B035 LD B,(HL) Load the scenic event item ID into B.
B036 CALL Handler_UpdateItemLocation Call Handler_UpdateItemLocation to update the item's location to the destination room.
B039 POP BC Restore the table pointer and counter from the stack.
B03A POP HL
ScenicItem_Count B03B 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 B03D LD A,C Write the destination room ID to CurrentRoom.
B03E LD ($A7C3),A
B041 LD A,($A787) Return if no following event flag is set in Flag_EventStates.
B044 AND A
B045 RET Z
For each set bit, move the item at that position in Table_TurnBasedEventItems into the current room.
B046 LD B,$08 Set a counter in B for 08 bits.
B048 LD HL,$A788 Set a pointer to Table_TurnBasedEventItems in HL.
B04B LD C,A Copy the event flags into C for bit testing.
B04C JR EventFlag_Next Jump to EventFlag_Next.
EventFlag_Advance B04E INC HL Move to the next item ID.
EventFlag_Next B04F SRL C Shift the event flags right to check the next bit.
B051 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.
B053 LD A,(HL) Get the item ID from the table.
B054 PUSH HL Stash the table pointer and counter on the stack.
B055 PUSH BC
B056 CALL Handler_UpdateItemEventCurrentRoom Call Handler_UpdateItemEventCurrentRoom to update the item's location to the current room.
B059 POP BC Restore the table pointer and counter from the stack.
B05A POP HL
EventFlag_Count B05B DJNZ EventFlag_Advance Decrease the bit counter by one and loop back to EventFlag_Advance until all 08 bits have been tested.
MovePlayerToRoom_Return B05D RET Return.
Prev: AFEB Up: Map Next: B05E