Prev: E9D3 Up: Map Next: EA70
E9E1: Change Room
Used by the routines at Handler_ShowNewRoom, MovePlayer, Action_Pour and GameStart.
Commits a move into the destination room held in A. It handles the Hall of the Phoenix and the ruined cottage, calls MovePlayerToRoom to update the current room, then jumps to Handler_ShowNewRoom to describe the new room.
Input
A Destination room ID
Entering the Hall of the Phoenix is fatal. Bit 0 of *Flags_RoomChange, when set, means the firegate does not incinerate the player.
ChangeRoom E9E1 CP $37 Jump to ChangeRoom_LeavePhoenix if the destination is not room 37: " The Hall of the Phoenix".
E9E3 JR NZ,ChangeRoom_LeavePhoenix
E9E5 LD HL,$AE76 Jump to ChangeRoom_LeavePhoenix if bit 0 of *Flags_RoomChange is set.
E9E8 BIT 0,(HL)
E9EA JR NZ,ChangeRoom_LeavePhoenix
The player is dead, so do not resume the movement handler.
E9EC POP HL Discard the calling address of ChangeRoom.
E9ED LD HL,$E9B5 Switch GameOver onto the stack so the next return actions a "game over".
E9F0 EX (SP),HL
Print "The scorching flames of the firegate have incinerated you.".
E9F1 LD HL,$D04C Point HL at Messaging_TheScorchingFlamesOfTheFiregateHave and print it and start a new line.
E9F4 CALL PrintStringAndNewline
E9F7 RET Return.
Leaving the Hall of the Phoenix.
ChangeRoom_LeavePhoenix E9F8 LD C,A Copy the destination room ID into C.
E9F9 LD A,($AECD) Fetch *CurrentRoom into A.
E9FC CP $37 Jump to ChangeRoom_EnterRoom if the current room is not 37: " The Hall of the Phoenix".
E9FE JR NZ,ChangeRoom_EnterRoom
EA00 LD HL,$AE76 Jump to ChangeRoom_EnterRoom if bit 1 of *Flags_RoomChange is set.
EA03 BIT 1,(HL)
EA05 JR NZ,ChangeRoom_EnterRoom
South into the Hall of Black Magic turns the ashes into a phoenix.
EA07 LD A,$3F Jump to ChangeRoom_PhoenixToAshes if the destination is not room 3F: " The Hall of Black Magic".
EA09 CP C
EA0A JR NZ,ChangeRoom_PhoenixToAshes
EA0C LD BC,$8182 Call TransformItem to transform "Some hot ashes." into "A phoenix.".
EA0F CALL TransformItem
This action changes the map:
EA12 XOR A Write 00 to close southbound access to The Hall of Black Magic from The Hall of the Phoenix.
EA13 LD ($E931),A
Print "Suddenly,the ashes burst into flames....".
ChangeRoom_AshesBurst EA16 LD HL,$D087 Point HL at Messaging_SuddenlyTheAshesBurstIntoFlames and print it and start a new line.
EA19 CALL PrintStringAndNewline
Print "A phoenix emerges from the fire and blocks your path.".
ChangeRoom_PhoenixAppears EA1C LD HL,$D0B0 Point HL at Messaging_APhoenixEmergesFromTheFireAndBlocks and pause, print it and scroll.
EA1F CALL PausePrintStringAndScroll
EA22 RET Return.
Any other exit from the Hall of the Phoenix turns the phoenix back into ashes and opens the south.
ChangeRoom_PhoenixToAshes EA23 LD A,C Copy the destination room ID into A.
EA24 PUSH AF Stash the destination room ID on the stack.
EA25 LD A,$82 Call HandlerDestroyItemEvent with item 82: "A phoenix.".
EA27 CALL HandlerDestroyItemEvent
EA2A LD A,$81 Call HandlerUpdateItemEventForTheCurrentRoom with item 81: "Some hot ashes.".
EA2C CALL HandlerUpdateItemEventForTheCurrentRoom
This action changes the map:
EA2F LD A,$3F Write 3F to open southbound access to The Hall of Black Magic from The Hall of the Phoenix.
EA31 LD ($E931),A
EA34 POP AF Restore the destination room ID from the stack.
EA35 LD C,A Copy it into C.
Move into the destination room.
ChangeRoom_EnterRoom EA36 LD A,C Copy the destination room ID into A.
EA37 CALL MovePlayerToRoom Call MovePlayerToRoom to move the player into the room.
Winning in the ruined cottage.
EA3A LD A,($AECD) Fetch *CurrentRoom into A.
EA3D CP $02 Jump to Handler_ShowNewRoom if it is not room 02: " Inside the Ruined Cottage".
EA3F JR NZ,Handler_ShowNewRoom
EA41 LD A,($AE91) Fetch *Flag_FollowingHeroes into A.
EA44 CP $0F Jump to Handler_ShowNewRoom if it is not 0F (all four heroes following).
EA46 JR NZ,Handler_ShowNewRoom
EA48 LD HL,$EA70 Count how many of the five gems at Table_Gems are here.
EA4B LD B,$05
EA4D LD C,$00
Count each gem that is here.
Cottage_CountGem EA4F LD A,(HL) Fetch the next gem item ID.
EA50 CALL ValidateItemPresent Call ValidateItemPresent to test whether it is here.
EA53 JR NZ,Cottage_CountGem_Next Jump to Cottage_CountGem_Next if it is not here.
EA55 INC C Count a gem that is here.
Continue the gem count.
Cottage_CountGem_Next EA56 INC HL Advance to the next gem.
EA57 DJNZ Cottage_CountGem Decrease the gem counter by one and loop back to Cottage_CountGem until it is zero.
EA59 LD A,$05 Jump to Handler_ShowNewRoom if fewer than five gems are here.
EA5B CP C
EA5C JR NZ,Handler_ShowNewRoom
EA5E LD HL,$E504 Call CheckActiveScenicEvents with the jade-flower group at Data_ItemGroup_Flower.
EA61 CALL CheckActiveScenicEvents
EA64 JR NZ,Handler_ShowNewRoom Jump to Handler_ShowNewRoom if the jade flower is neither here nor carried.
The game is won, so do not resume the movement handler or the command loop.
EA66 POP HL Discard the return address of ChangeRoom and of its caller.
EA67 POP HL
EA68 LD A,$04 Call AddToScore to score four points.
EA6A CALL AddToScore
EA6D JP GameComplete Jump to GameComplete.
Prev: E9D3 Up: Map Next: EA70