Prev: 45035 Up: Map Next: 45150
45087: 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 45087 LD C,A Copy the destination room ID into C.
45088 LD A,(42990) Jump to MovePlayerToRoom_SetRoom if *Count_ScenicEvents is zero.
45091 AND A
45092 JR Z,MovePlayerToRoom_SetRoom
45094 LD B,A Load *Count_ScenicEvents into B for the loop counter.
45095 LD HL,(42978) Set a pointer to *Pointer_ScenicEventItems in HL.
45098 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 45100 INC HL Move to the next scenic event item ID.
ScenicItem_Next 45101 LD A,(HL) Load this scenic event item ID into A.
45102 CALL ValidateItemPresent Call ValidateItemPresent to test whether it is here or carried.
45105 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.
45107 PUSH HL Stash the table pointer and counter on the stack.
45108 PUSH BC
45109 LD B,(HL) Load the scenic event item ID into B.
45110 CALL Handler_UpdateItemLocation Call Handler_UpdateItemLocation to update the item's location to the destination room.
45113 POP BC Restore the table pointer and counter from the stack.
45114 POP HL
ScenicItem_Count 45115 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 45117 LD A,C Write the destination room ID to CurrentRoom.
45118 LD (42947),A
45121 LD A,(42887) Return if no following event flag is set in Flag_EventStates.
45124 AND A
45125 RET Z
For each set bit, move the item at that position in Table_TurnBasedEventItems into the current room.
45126 LD B,8 Set a counter in B for 8 bits.
45128 LD HL,42888 Set a pointer to Table_TurnBasedEventItems in HL.
45131 LD C,A Copy the event flags into C for bit testing.
45132 JR EventFlag_Next Jump to EventFlag_Next.
EventFlag_Advance 45134 INC HL Move to the next item ID.
EventFlag_Next 45135 SRL C Shift the event flags right to check the next bit.
45137 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.
45139 LD A,(HL) Get the item ID from the table.
45140 PUSH HL Stash the table pointer and counter on the stack.
45141 PUSH BC
45142 CALL Handler_UpdateItemEventCurrentRoom Call Handler_UpdateItemEventCurrentRoom to update the item's location to the current room.
45145 POP BC Restore the table pointer and counter from the stack.
45146 POP HL
EventFlag_Count 45147 DJNZ EventFlag_Advance Decrease the bit counter by one and loop back to EventFlag_Advance until all 8 bits have been tested.
MovePlayerToRoom_Return 45149 RET Return.
Prev: 45035 Up: Map Next: 45150