Prev: 41589 Up: Map Next: 41733
41600: Handler: Process Game Events
Used by the routine at GameStart.
Counts down the turn-based events in Flags_TurnEvents and, when a counter reaches zero, runs the handler from JumpTable_TurnEvents.
Then relocates any scenic event that is not already in the current room, picking the new room from the group at 46783.
A turn-based event runs only while its bit in Flags_TurnEvents is set.
Handler_GameEvents 41600 LD A,(41160) Leave the events alone when none are armed.
41603 OR A
41604 JR Z,Handler_GameEvents_1
Eight turn-based events share the flag byte.
41606 LD C,A Start with the first turn-based event.
41607 LD B,8
This event is not running.
TurnEvent_NextBit 41609 SRL C Skip an event that is not armed.
41611 JR NC,Handler_GameEvents_0
Count down this event. It fires when the counter at TurnEventCounters reaches zero.
41613 LD DE,0 Leave the event for a later turn when the counter is still running.
41616 LD HL,41161
41619 LD A,8
41621 SUB B
41622 LD E,A
41623 ADD HL,DE
41624 DEC (HL)
41625 JR NZ,Handler_GameEvents_0
The counter has expired, so run this event's script from JumpTable_TurnEvents.
41627 PUSH IX The scripts are listed at JumpTable_TurnEvents.
41629 PUSH BC
41630 LD IX,48057
41634 SLA E This is the event whose counter expired.
41636 ADD IX,DE
41638 LD L,(IX+0) Read that script's address.
41641 LD H,(IX+1)
41644 PUSH HL Copy the script address from HL into IX.
41645 POP IX
41647 CALL Handler_RunScript Run that script.
41650 POP BC Restore the event counter and event pointer from the stack.
41651 POP IX
Test the next turn-based event.
Handler_GameEvents_0 41653 DJNZ TurnEvent_NextBit Every armed event is considered once per turn.
Scenic events live in Table_ScenicEventLocations2.
Handler_GameEvents_1 41655 LD HL,46778 There is nothing to move when no scenic event is active.
41658 LD A,(48079)
41661 OR A
41662 JR Z,Handler_GameEvents_5
41664 LD B,A Visit each scenic event in turn.
41665 JR ScenicEvent_Item
Room 0 means this scenic item is inactive.
ScenicEvent_Next 41667 INC HL The next scenic item.
ScenicEvent_Item 41668 LD A,(HL) Its item id.
41669 PUSH HL
41670 CALL ItemLocator Call ItemLocator to read where this item is.
41673 POP HL Restore the event-list pointer from the stack.
41674 AND A An inactive item is left where it is.
41675 JR Z,Handler_GameEvents_4
An event that is already in the player's room stays there.
41677 LD C,A Skip an event whose room is CurrentRoom.
41678 LD A,(41222)
41681 CP C
41682 JR Z,Handler_GameEvents_4
Each scenic event has a room group in 46783.
41684 PUSH IX The scenic scan waits while a room is chosen.
41686 PUSH BC
41687 PUSH HL
41688 LD A,(48079) Which event's group this is.
41691 SUB B
41692 LD E,A
41693 LD IX,46783 The room groups are listed at 46783.
41697 CALL GetTableEntry This event's room group.
The refresh register picks how far to walk into the room group. 255 ends the group and the walk wraps.
41700 LD A,R Choose a room from this event's group.
41702 LD B,A
41703 LD A,255
Handler_GameEvents_2 41705 LD L,(IX+0)
41708 LD H,(IX+1)
41711 JR Handler_GameEvents_3
Walk the room group. 255 restarts it, and the refresh count chooses where to stop. Then move the scenic item there.
ScenicRoom_Next 41713 INC HL 255 restarts the group. Otherwise step to the next room.
Handler_GameEvents_3 41714 CP (HL)
41715 JR Z,Handler_GameEvents_2
41717 DJNZ ScenicRoom_Next
41719 LD C,(HL) Fetch the destination room into C.
41720 POP HL Restore the scenic-event pointer from the stack.
41721 LD B,(HL) Fetch the item ID into B and stash the pointer again.
41722 PUSH HL
41723 CALL Handler_UpdateItemLocation Call Handler_UpdateItemLocation.
41726 POP HL Restore the scenic scan from the stack.
41727 POP BC
41728 POP IX
Move on to the next scenic event.
Handler_GameEvents_4 41730 DJNZ ScenicEvent_Next Every scenic event is considered once.
Handler_GameEvents_5 41732 RET Return.
View the equivalent code in;
Prev: 41589 Up: Map Next: 41733