Prev: 50170 Up: Map Next: 50275
50223: 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 50223 LD C,A Copy the destination room ID into C.
50224 LD A,(47872) Load *Count_ScenicEvents into B for the loop counter.
50227 LD B,A
50228 LD A,(47771) Load *CurrentRoom into A (the room we're leaving).
50231 LD HL,47688 Set a pointer to Table_ScenicEventLocations in HL.
50234 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 50236 INC HL Move to the next scenic event in the table.
ScenicItem_Next 50237 CP (HL) Jump to ScenicItem_Count if this scenic event is not in the current room.
50238 JR NZ,ScenicItem_Count
50240 LD (HL),C Update this scenic event's location to the destination room.
ScenicItem_Count 50241 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 50243 LD A,C Write the destination room ID to CurrentRoom.
50244 LD (47771),A
50247 LD A,(47679) Load *Flag_PrincessFollowing into A.
50250 AND A Jump to MovePlayerToRoom_Return if no following item is active.
50251 JR Z,MovePlayerToRoom_Return
For each set bit, move the item at that position in Table_FollowingItems into the current room.
50253 LD B,8 Set a counter in B for 8 bits.
50255 LD HL,47680 Set a pointer to Table_FollowingItems in HL.
50258 LD C,A Copy the following flags into C for bit testing.
50259 JR EventFlag_Next Jump to EventFlag_Next.
EventFlag_Advance 50261 INC HL Move to the next item ID.
EventFlag_Next 50262 SRL C Shift the following flags right to check the next bit.
50264 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.
50266 LD A,(HL) Get the item ID from the table.
50267 EXX Switch to the alternate register set to preserve the scan.
50268 CALL Handler_UpdateItemForTheCurrentRoom Call Handler_UpdateItemForTheCurrentRoom to update the item's location to the current room.
50271 EXX Switch back to the event scan registers.
EventFlag_Count 50272 DJNZ EventFlag_Advance Decrease the bit counter by one and loop back to EventFlag_Advance until all 8 bits have been tested.
MovePlayerToRoom_Return 50274 RET Return.
Prev: 50170 Up: Map Next: 50275