Prev: 49240 Up: Map Next: 49648
49533: Process Game Events
Used by the routine at GameLoop.
This routine manages two types of in-game events:
1. Turn-Based Events
These are timer-based hazards that count down with each game turn. When a turn counter reaches zero, the associated event handler is called via a jump table.
2. Scenic Events
Mostly atmospheric events that randomly appear in different locations to add flavor to the game world (like seagulls appearing at the beach).
The routine maintains a table of current locations for each scenic event. On each turn, it checks if any scenic event is NOT in the current room, then randomly relocates it to one of its valid rooms.
Each scenic event has a predefined group of rooms where the event can appear.
The routine ensures that:
  • Multiple turn-based dangers can threaten the player simultaneously
  • Scenic events don't repeatedly trigger in the same room
  • The game world feels dynamic with events occurring in different locations
First process the turn-based events (if any are active).
GameEventsProcessor 49533 LD A,(48230) Load *Flag_TurnBasedEventState into A.
49536 OR A Jump to GameScenicEventsProcessor if no turn-based events are currently active.
49537 JR Z,GameScenicEventsProcessor
Eight turn-based events share the flag byte.
49539 LD C,A Copy the turn-based event flags into C.
49540 LD B,8 Set a counter in B for the number of possible turn-based events (8).
Keep shifting the event flags one-by-one to find which bits are set.
GameEventChecker_Loop 49542 SRL C Shift C one position left to check the next event flag bit.
49544 JR NC,GameEventChecker_Next Jump to GameEventChecker_Next if this event bit is not set.
Count down this event's timer.
49546 LD DE,0 Initialise DE to 0.
49549 LD HL,48231 HL=Counter_Crab.
49552 LD A,8 Calculate the event index (8-B) and store it in E.
49554 SUB B
49555 LD E,A
49556 ADD HL,DE Point HL at this event's countdown timer.
49557 DEC (HL) Decrease this event's countdown timer by one.
49558 JR NZ,GameEventChecker_Next Jump to GameEventChecker_Next if this event's countdown timer is still running.
The timer has expired, so run this event's handler.
49560 LD IX,(48398) IX=*Pointer_TurnBasedEvents_Jump.
49564 SLA E Double the event index, as each entry in the table is two bytes.
49566 ADD IX,DE Point IX at this event's entry in the table.
49568 LD L,(IX+0) Read that handler's address into HL.
49571 LD H,(IX+1)
49574 PUSH BC Stash BC on the stack.
49575 LD DE,49580 Stash GameEventChecker_Return on the stack so the next return resumes event processing.
49578 PUSH DE
49579 JP (HL) Jump to the routine pointed to by *HL to action the current event.
Once the event handler has run, this is where the routine will resume.
GameEventChecker_Return 49580 POP BC Restore BC from the stack.
Test the next turn-based event.
GameEventChecker_Next 49581 DJNZ GameEventChecker_Loop Decrease the event bit counter by one and loop back to GameEventChecker_Loop until all eight events have been considered.
Now handle the scenic events.
GameScenicEventsProcessor 49583 NOP No operation.
49584 LD HL,48248 HL=Table_ScenicEventLocations.
49587 LD A,(48432) Fetch the number of active scenic events from Count_ScenicEvents.
49590 OR A
49591 JR Z,GameEventsProcessor_Return Jump to GameEventsProcessor_Return if there are no active scenic events.
49593 LD B,A Set a counter in B for the number of scenic events.
49594 JR GameScenicEventChecker Jump to GameScenicEventChecker to process the first scenic event without advancing the table pointer.
This is the main scenic event loop.
GameScenicEventChecker_Loop 49596 INC HL Move on to the next scenic item.
GameScenicEventChecker 49597 LD A,(HL) Jump to GameScenicEventChecker_Next if the event room is 0 (deactivated).
49598 OR A
49599 JR Z,GameScenicEventChecker_Next
49601 LD A,(48331) Jump to GameScenicEventChecker_Next if *CurrentRoom is equal to the event room.
49604 CP (HL)
49605 JR Z,GameScenicEventChecker_Next
Pick a room for this scenic event.
49607 PUSH HL Stash HL and BC on the stack.
49608 PUSH BC
Calculate which scenic event's room group this is.
49609 LD A,(48432) Calculate the index of the currently processed event.
49612 SUB B
49613 LD E,A
Point at this event's room list.
49614 LD IX,48332 IX=Table_ScenicEventRooms.
The routine at GetTableEntry is usually used to fetch an address from the given table, but here it's used to move IX to point to the index of the currently processed event (and this routine will fetch the address itself).
49618 CALL GetTableEntry Call GetTableEntry.
49621 CALL FetchFrames Call FetchFrames to pick a random step count and store it in B.
49624 LD B,A
49625 LD A,255 A=the room group terminator (255).
The table at Table_ScenicEventRooms is indexed by event (there are 8 entries), but each address points to a "group" of room IDs where this event could occur. Each set of room IDs for the event is terminated using 255.
GameScenicEvent_FetchRoomGroup 49627 LD L,(IX+0) Point HL at the start of this room group.
49630 LD H,(IX+1)
49633 JR GameScenicEvent_CountRoomsInGroup Jump to GameScenicEvent_CountRoomsInGroup.
Use the random number to select a room from the group - this loops through the rooms using B as a counter.
GameScenicEvent_CountRooms_Loop 49635 INC HL Move to the next room ID in the group.
GameScenicEvent_CountRoomsInGroup 49636 CP (HL) Jump back to GameScenicEvent_FetchRoomGroup when the terminator matches.
49637 JR Z,GameScenicEvent_FetchRoomGroup
49639 DJNZ GameScenicEvent_CountRooms_Loop Decrease the random counter by one and loop back to GameScenicEvent_CountRooms_Loop until the counter is zero.
49641 LD A,(HL) Fetch the destination room into A.
49642 POP BC Restore BC and HL from the stack.
49643 POP HL
49644 LD (HL),A Update the scenic event location with the newly selected room.
GameScenicEventChecker_Next 49645 DJNZ GameScenicEventChecker_Loop Decrease the scenic event counter by one and loop back to GameScenicEventChecker_Loop until all scenic events have been processed.
All done, now return.
GameEventsProcessor_Return 49647 RET Return.
View the equivalent code in;
Prev: 49240 Up: Map Next: 49648