Prev: AC88 Up: Map Next: ACFC
ACBD: Move Player To Room
Used by the routine at ChangeRoom.
Moves the player to a new room. Before updating the current room, it moves every scenic-event item from Table_ScenicEventItems that is present into the destination room (so those events follow the player). It then writes the destination to CurrentRoom and, for each set bit in Flags_EventStates, brings the matching byte from Data_PhraseTokens into the new room via Handler_UpdateItemEventCurrentRoom.
Input
A Destination room ID
Store the destination room ID and prepare to update scenic events.
MovePlayerToRoom ACBD LD C,A Copy the destination room ID into C.
ACBE LD A,($BBCF) Jump to MovePlayerToRoom_SetRoom if *Count_ScenicEvents is zero.
ACC1 AND A
ACC2 JR Z,MovePlayerToRoom_SetRoom
Loop through the scenic items at Table_ScenicEventItems and move any that are present into the destination room.
ACC4 LD B,A Copy the scenic-event count from A into B as the loop counter.
ACC5 LD HL,$B6BA Point HL at the scenic event items table at Table_ScenicEventItems.
ACC8 JR ScenicItem_Next Jump to ScenicItem_Next.
ScenicItem_Advance ACCA INC HL Move HL on to the next scenic event item ID.
ScenicItem_Next ACCB LD A,(HL) Fetch this scenic event's item ID from Table_ScenicEventItems into A.
ACCC CALL ValidateItemPresent Call ValidateItemPresent to test whether that item is present.
ACCF JR NZ,ScenicItem_Count Jump to ScenicItem_Count if the item is not present.
This scenic item is present, so move it to the destination room.
ACD1 PUSH HL Stash the scenic table pointer and loop counter on the stack.
ACD2 PUSH BC
ACD3 LD B,(HL) Copy the scenic item ID into B.
ACD4 CALL Handler_UpdateItemLocation Call Handler_UpdateItemLocation to place that item in the destination room held in C.
ACD7 POP BC Restore the loop counter and scenic table pointer from the stack.
ACD8 POP HL
ScenicItem_Count ACD9 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 ACDB LD A,C Write the destination room ID from C to CurrentRoom.
ACDC LD ($A106),A
ACDF LD A,($A0D1) Fetch *Flags_EventStates into A and return if no event flag is set.
ACE2 AND A
ACE3 RET Z
For each set bit in Flags_EventStates, bring the corresponding byte from Data_PhraseTokens into the current room.
ACE4 LD B,$08 Set a counter in B for 08 bits.
ACE6 LD HL,$B6F4 Point HL at Data_PhraseTokens.
ACE9 LD C,A Copy the event flags into C for bit testing.
ACEA JR EventFlag_Next Jump to EventFlag_Next.
EventFlag_Advance ACEC INC HL Move HL on to the next event item ID.
EventFlag_Next ACED SRL C Shift the event flags right to test the next bit.
ACEF JR NC,EventFlag_Count Jump to EventFlag_Count if this bit is not set.
This event bit is set, so bring its item into the current room.
ACF1 LD A,(HL) Fetch the item ID from Data_PhraseTokens into A.
ACF2 PUSH HL Stash the table pointer and bit counter on the stack.
ACF3 PUSH BC
ACF4 CALL Handler_UpdateItemEventCurrentRoom Call Handler_UpdateItemEventCurrentRoom to move that item into the current room.
ACF7 POP BC Restore the bit counter and table pointer from the stack.
ACF8 POP HL
EventFlag_Count ACF9 DJNZ EventFlag_Advance Decrease the bit counter by one and loop back to EventFlag_Advance until all 08 bits have been tested.
MovePlayerToRoom_Return ACFB RET Return.
Prev: AC88 Up: Map Next: ACFC