Prev: C3FA Up: Map Next: C463
C42F: Move Player To Room
Used by the routines at Handler_InjuryCheck and Action_Blow.
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_PrincessFollowing into the new room. Only bit 0, Princess Mara, is ever set.
Input
A Destination room ID
Store the destination room ID and prepare to update scenic events.
MovePlayerToRoom C42F LD C,A Copy the destination room ID into C.
C430 LD A,($BB00) Load *Count_ScenicEvents into B for the loop counter.
C433 LD B,A
C434 LD A,($BA9B) Load *CurrentRoom into A (the room we're leaving).
C437 LD HL,$BA48 Set a pointer to Table_ScenicEventLocations in HL.
C43A 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 C43C INC HL Move to the next scenic event in the table.
ScenicItem_Next C43D CP (HL) Jump to ScenicItem_Count if this scenic event is not in the current room.
C43E JR NZ,ScenicItem_Count
C440 LD (HL),C Update this scenic event's location to the destination room.
ScenicItem_Count C441 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 C443 LD A,C Write the destination room ID to CurrentRoom.
C444 LD ($BA9B),A
C447 LD A,($BA3F) Load *Flag_PrincessFollowing into A.
C44A AND A Jump to MovePlayerToRoom_Return if no following item is active.
C44B JR Z,MovePlayerToRoom_Return
For each set bit, move the item at that position in Table_FollowingItems into the current room.
C44D LD B,$08 Set a counter in B for 08 bits.
C44F LD HL,$BA40 Set a pointer to Table_FollowingItems in HL.
C452 LD C,A Copy the following flags into C for bit testing.
C453 JR EventFlag_Next Jump to EventFlag_Next.
EventFlag_Advance C455 INC HL Move to the next item ID.
EventFlag_Next C456 SRL C Shift the following flags right to check the next bit.
C458 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.
C45A LD A,(HL) Get the item ID from the table.
C45B EXX Switch to the alternate register set to preserve the scan.
C45C CALL Handler_UpdateItemForTheCurrentRoom Call Handler_UpdateItemForTheCurrentRoom to update the item's location to the current room.
C45F EXX Switch back to the event scan registers.
EventFlag_Count C460 DJNZ EventFlag_Advance Decrease the bit counter by one and loop back to EventFlag_Advance until all 08 bits have been tested.
MovePlayerToRoom_Return C462 RET Return.
Prev: C3FA Up: Map Next: C463