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
One of the events has triggered, find which one.
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 isn't set.
The currently processed turn-based event is active, so process it.
This is: Counter_Crab+(8-the current event counter).
49546 LD DE,0 Calculate the turn-based event index and store it in HL.
49549 LD HL,48231
49552 LD A,8
49554 SUB B
49555 LD E,A
49556 ADD HL,DE
49557 DEC (HL) Decrease the turn-based event counter at *HL by one.
49558 JR NZ,GameEventChecker_Next Jump to GameEventChecker_Next if the event turn counter at *HL was still more than zero.
The event turn counter is zero, so activate the event itself.
49560 LD IX,(48398) Load *Pointer_TurnBasedEvents_Jump into IX.
49564 SLA E Double the index as this table contains addresses.
49566 ADD IX,DE Add this offset to IX to point to the current handler.
49568 LD L,(IX+0) Get the handler address and store it in HL.
49571 LD H,(IX+1)
49574 PUSH BC Stash the bit index and event flag byte on the stack.
49575 LD DE,49580 Push GameEventChecker_Return onto the stack so that the next return will go on to continue processing events.
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 the event bit index counter and event flag byte from the stack.
GameEventChecker_Next 49581 DJNZ GameEventChecker_Loop Decrease the event bit counter by one and loop back to GameEventChecker_Loop until all the event status bits have been processed.
Process scenic events.
GameScenicEventsProcessor 49583 NOP No operation.
49584 LD HL,48248 Load HL with Table_ScenicEventLocations.
49587 LD A,(48432) Load *Count_ScenicEvents into A.
49590 OR A Jump to GameEventsProcessor_Return if there are no more scenic events to run (the count is zero).
49591 JR Z,GameEventsProcessor_Return
49593 LD B,A Copy *Count_ScenicEvents into B as an event counter for the loop.
49594 JR GameScenicEventChecker Jump to GameScenicEventChecker.
This is the main scenic event loop.
GameScenicEventChecker_Loop 49596 INC HL Increment the scenic event pointer location by one.
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
49607 PUSH HL Stash the scenic event location pointer and event counter on the stack.
49608 PUSH BC
This is: E=*Count_ScenicEvents-B.
49609 LD A,(48432) Calculate the index of the currently processed event.
49612 SUB B
49613 LD E,A
49614 LD IX,48332 Load Table_ScenicEventRooms into IX.
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 Load a random number from FetchFrames into B.
49624 LD B,A
49625 LD A,255 Set A to 255 (the room group terminator) for the comparison.
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) Get the room group address pointer and store it in HL.
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 to GameScenicEvent_FetchRoomGroup if the terminator is read from *HL.
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) Load the current room ID into A.
49642 POP BC Restore the event counter and scenic event location pointer 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.
Prev: 49240 Up: Map Next: 49648