#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA042_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA095_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_F20E_F20J_X30J
unsigned int16_t G0369_EventMaximumCount;
#endif
#ifdef MEDIA414_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t G0369_EventMaximumCount;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t G2009_i_LargestUsedEventOrdinal;
#endif
EVENT* G0370_ps_Events;
unsigned int16_t* G0371_pui_Timeline;
unsigned int16_t G0372_ui_EventCount;
unsigned int16_t G0373_ui_FirstUnusedEventIndex;
#ifdef MEDIA471_P20JB_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
BOOLEAN G3001_B_PreventSaveGame_CPSX;
#endif
#endif
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_05_FIX */
#ifndef NOCOPYPROTECTION
long G0374_l_WatchdogTime_CPSE = 0x00FFFFFF;
#endif
#endif
#ifdef MEDIA229_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE2_05_FIX */
#ifndef NOCOPYPROTECTION
long G0374_l_WatchdogTime_CPSE;
#endif
#endif

#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "timeline"
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
segment "timeline"
#endif

#ifdef MEDIA072_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_X31J
/*#ifdef MEDIA458_P20JA_P20JB*/
STATICFUNCTION void F0256_TIMELINE_ProcessEvent53_Watchdog_CPSE(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
);
#endif

void F0233_TIMELINE_Initialize_CPSE(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER EVENT* L0577_ps_Event;
#endif
        REGISTER unsigned int16_t L0576_ui_EventIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER EVENT* L0577_ps_Event;
#endif


        G0370_ps_Events = (EVENT*)M533_F0468_MEMORY_Allocate((long)(G0369_EventMaximumCount * sizeof(EVENT)), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
        G0371_pui_Timeline = (unsigned int16_t*)M533_F0468_MEMORY_Allocate((long)(G0369_EventMaximumCount * sizeof(unsigned int16_t)), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
        if (G0298_B_NewGame) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                for (L0576_ui_EventIndex = 0, L0577_ps_Event = G0370_ps_Events; L0576_ui_EventIndex < G0369_EventMaximumCount; L0576_ui_EventIndex++, L0577_ps_Event++) {
                        L0577_ps_Event->A.A.Type = C00_EVENT_NONE;
                }
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                L0577_ps_Event = G0370_ps_Events;
                for (L0576_ui_EventIndex = 0; L0576_ui_EventIndex < G0369_EventMaximumCount; L0576_ui_EventIndex++) {
                        L0577_ps_Event->A.A.Type = C00_EVENT_NONE;
                        L0577_ps_Event++;
                }
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                L0577_ps_Event = G0370_ps_Events;
                for (L0576_ui_EventIndex = 0; L0576_ui_EventIndex < G0369_EventMaximumCount; L0577_ps_Event++) {
                        L0577_ps_Event->A.A.Type = C00_EVENT_NONE;
                        ((UNUSED_EVENT*)L0577_ps_Event)->NextUnusedEventIndex = ++L0576_ui_EventIndex;
                }
                G2009_i_LargestUsedEventOrdinal = M000_INDEX_TO_ORDINAL(-1);
                ((UNUSED_EVENT*)(L0577_ps_Event - 1))->NextUnusedEventIndex = -1;
#endif
                G0372_ui_EventCount = 0;
                G0373_ui_FirstUnusedEventIndex = 0;
#ifdef MEDIA072_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
                F0256_TIMELINE_ProcessEvent53_Watchdog_CPSE();
#endif
#endif
        }
}

#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void F0651_TIMELINE_InitializeOptimizedManagement(
void
)
{
        REGISTER int16_t L3029_i_EventIndex;
        REGISTER int16_t L3030_i_UnusedEventIndex;


        G2009_i_LargestUsedEventOrdinal = M000_INDEX_TO_ORDINAL(-1);
        G0373_ui_FirstUnusedEventIndex = -1;
        for (L3029_i_EventIndex = 0; L3029_i_EventIndex < G0369_EventMaximumCount; L3029_i_EventIndex++) {
                if (G0370_ps_Events[L3029_i_EventIndex].A.A.Type == C00_EVENT_NONE) {
                        if ((int16_t)G0373_ui_FirstUnusedEventIndex == -1) {
                                G0373_ui_FirstUnusedEventIndex = L3029_i_EventIndex;
                        } else {
                                ((UNUSED_EVENT*)G0370_ps_Events)[L3030_i_UnusedEventIndex].NextUnusedEventIndex = L3029_i_EventIndex;
                        }
                        ((UNUSED_EVENT*)G0370_ps_Events)[L3029_i_EventIndex].NextUnusedEventIndex = -1;
                        L3030_i_UnusedEventIndex = L3029_i_EventIndex;
                        continue;
                }
                G2009_i_LargestUsedEventOrdinal = M000_INDEX_TO_ORDINAL(L3029_i_EventIndex);
        }
}
#endif

STATICFUNCTION BOOLEAN F0234_TIMELINE_IsEventABeforeEventB(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0509_ps_EventA, P0510_ps_EventB)
#endif
#ifdef MEDIA180_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE7_08_OPTIMIZATION Variable definition changed */
register EVENT* P0509_ps_EventA SEPARATOR
register EVENT* P0510_ps_EventB FINAL_SEPARATOR
#endif
#ifdef MEDIA328_S20E_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_08_OPTIMIZATION Variable definition changed */
EVENT*          P0509_ps_EventA SEPARATOR
EVENT*          P0510_ps_EventB FINAL_SEPARATOR
#endif
{
#ifdef MEDIA204_S10EA_S10EB_S11E_G14ED_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        REGISTER BOOLEAN L0578_B_Simultaneous;


        return (M030_TIME(P0509_ps_EventA->Map_Time) < M030_TIME(P0510_ps_EventB->Map_Time)) ||
#ifdef MEDIA203_S10EA_S10EB_S11E_G14ED_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_F31E_F31J_P31J
               ((L0578_B_Simultaneous = (M030_TIME(P0509_ps_EventA->Map_Time) == M030_TIME(P0510_ps_EventB->Map_Time))) && (P0509_ps_EventA->A.Type_Priority > P0510_ps_EventB->A.Type_Priority)) ||
               (L0578_B_Simultaneous && (P0509_ps_EventA->A.Type_Priority == P0510_ps_EventB->A.Type_Priority) && (P0509_ps_EventA <= P0510_ps_EventB));
#endif
#ifdef MEDIA707_I34E_I34M
               (((L0578_B_Simultaneous = (M030_TIME(P0509_ps_EventA->Map_Time) == M030_TIME(P0510_ps_EventB->Map_Time))) != C0_FALSE) && (P0509_ps_EventA->A.A.Type > P0510_ps_EventB->A.A.Type)) ||
               (L0578_B_Simultaneous && ((L0578_B_Simultaneous = (P0509_ps_EventA->A.A.Type == P0510_ps_EventB->A.A.Type)) != C0_FALSE) && (P0509_ps_EventA->A.A.Priority > P0510_ps_EventB->A.A.Priority)) ||
               (L0578_B_Simultaneous && (P0509_ps_EventA <= P0510_ps_EventB));
#endif
#endif
#ifdef MEDIA236_S12E_S12G_S13FA_S13FB /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                        moveq   #1,D0
                        move.l  #0x00FFFFFF,D1
                        move.l  (P0509_ps_EventA)+,D2
                        and.l   D1,D2                           /* D2 is the time of Event A */
                        and.l   (P0510_ps_EventB)+,D1           /* D1 is the time of Event B */
                        cmp.l   D1,D2
                        blt.s   T0234005_Return                 /* If Event A expires before Event B */
                        bne.s   T0234001                        /* If Event A and Event B do not expire at the same time (implies that Event B expires before Event A) */
                        move.w  (P0509_ps_EventA),D2
                        cmp.w   (P0510_ps_EventB),D2            /* Compare next word in Event (event type and priority) */
                        bhi.s   T0234005_Return
                        bne.s   T0234001
                        cmpa.l  P0509_ps_EventA,P0510_ps_EventB /* As a last resort, compare memory addresses of the events */
                        bcc.s   T0234005_Return
                T0234001:
                        moveq   #0,D0
                T0234005_Return:
        }
#endif
#ifdef MEDIA331_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE7_08_OPTIMIZATION Variable definition changed */
        asm {
                        movea.l P0509_ps_EventA(A6),A0
                        movea.l P0510_ps_EventB(A6),A1
                        moveq   #1,D0
                        move.l  #0x00FFFFFF,D1
                        move.l  (A0)+,D2
                        and.l   D1,D2                   /* D2 is the time of Event A */
                        and.l   (A1)+,D1                /* D1 is the time of Event B */
                        cmp.l   D1,D2
                        blt.s   @T0234005_Return        /* If Event A expires before Event B */
                        bne.s   @T0234001               /* If Event A and Event B do not expire at the same time (implies that Event B expires before Event A) */
                        cmpm.w  (A1)+,(A0)+             /* Compare next word in Event (event type and priority) */
                        bhi.s   @T0234005_Return
                        bne.s   @T0234001
                        cmpa.l  A0,A1                   /* As a last resort, compare memory addresses of the events */
                        bcc.s   @T0234005_Return
                @T0234001:
                        moveq   #0,D0
                @T0234005_Return:
        }
#endif
#ifdef MEDIA388_G20E_G21E
        BOOLEAN L6233_;


        asm {
                        LDY        #0x02
                        LDA        [P0510_ps_EventB],Y
                        AND        #0xff
                        STA        L6233_
                        LDA        [P0509_ps_EventA],Y
                        AND        #0xff
                        CMP        L6233_
                        BCC        L044AFC
                        BNE        L044B01
                        LDA        [P0509_ps_EventA]
                        CMP        [P0510_ps_EventB]
                        BCC        L044AFC
                        BNE        L044B01
                        LDY        #0x04
                        LDA        [P0509_ps_EventA],Y
                        CMP        [P0510_ps_EventB],Y
                        BCC        L044B01
                        BNE        L044AFC
                        LDA        P0509_ps_EventA+2
                        CMP        P0510_ps_EventB+2
                        BCC        L044AFC
                        BNE        L044B01
                        LDA        P0509_ps_EventA
                        CMP        P0510_ps_EventB
                        BCC        L044AFC
                        BNE        L044B01
                L044AFC:
                        LDA        #0x01
                        BRA        L044B04
                L044B01:
                        LDA        #0x00
                L044B04:
                        STA        L6233_
        }
        return L6233_;
#endif
}

unsigned int16_t F0235_TIMELINE_GetIndex(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0511_ui_EventIndex)
#endif
#ifdef MEDIA180_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE7_16_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
REGISTER unsigned int16_t P0511_ui_EventIndex FINAL_SEPARATOR
#endif
#ifdef MEDIA328_S20E_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_16_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
unsigned int16_t          P0511_ui_EventIndex FINAL_SEPARATOR
#endif
{
#ifdef MEDIA182_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE7_16_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        REGISTER unsigned int16_t* L0580_pui_TimelineEntry;
#endif
#ifdef MEDIA181_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB
        REGISTER unsigned int16_t L0579_TimelineIndex;
#endif
#ifdef MEDIA712_I34E_I34M_F31E_F31J_P31J
        REGISTER int16_t L0579_TimelineIndex;
#endif
#ifdef MEDIA180_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned int16_t* L0580_pui_TimelineEntry;
#endif


#ifdef MEDIA180_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        for (L0579_TimelineIndex = 0, L0580_pui_TimelineEntry = G0371_pui_Timeline; L0579_TimelineIndex < G0369_EventMaximumCount; L0579_TimelineIndex++) {
#endif
#ifdef MEDIA489_F20E_F20J_P20JA_P20JB
        L0580_pui_TimelineEntry = G0371_pui_Timeline;
        for (L0579_TimelineIndex = 0; L0579_TimelineIndex < G0369_EventMaximumCount; L0579_TimelineIndex++) {
#endif
#ifdef MEDIA712_I34E_I34M_F31E_F31J_P31J
        for (L0580_pui_TimelineEntry = G0371_pui_Timeline, L0579_TimelineIndex = 0; L0579_TimelineIndex < G2009_i_LargestUsedEventOrdinal; L0579_TimelineIndex++) {
#endif
                if (*L0580_pui_TimelineEntry++ == P0511_ui_EventIndex)
                        break;
        }
#ifdef MEDIA181_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB
        if (L0579_TimelineIndex >= G0369_EventMaximumCount) { /* BUG0_00 Useless code. The function is always called with event indices that are in the timeline */
#endif
#ifdef MEDIA712_I34E_I34M_F31E_F31J_P31J
        if (L0579_TimelineIndex >= G2009_i_LargestUsedEventOrdinal) { /* BUG0_00 Useless code. The function is always called with event indices that are in the timeline */
#endif
#ifdef MEDIA180_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                L0579_TimelineIndex = 0; /* BUG0_01 Coding error without consequence. Wrong return value. If the specified event index is not found in the timeline the function returns 0 which is the same value that is returned if the event index is found in the first timeline entry. No consequence because this code is never executed */
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                F0019_MAIN_DisplayErrorAndStop(C70_ERROR_REQUESTED_EVENT_NOT_IN_TIMELINE);
#endif
        }
        return L0579_TimelineIndex;
#endif
#ifdef MEDIA331_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE7_16_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
#ifdef MEDIA265_S20E_S21E
                        movea.l G0371_pui_Timeline(A4),A0
                        move.w  G0369_EventMaximumCount(A4),D1
#endif
#ifdef MEDIA613_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                        movea.l G0371_pui_Timeline(A5),A0
#endif
#ifdef MEDIA577_X30J
                        move.w  G0369_EventMaximumCount(A5),D1
#endif
#ifdef MEDIA749_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                        move.w  G2009_i_LargestUsedEventOrdinal(A5),D1
#endif
                        move.w  P0511_ui_EventIndex(A6),D2
                        moveq   #0,D0
                @T0235001_Loop:
                        cmp.w   (A0)+,D2
                        beq.s   @T0235005_Return
                        addq.w  #1,D0
                        cmp.w   D1,D0
                        bcs.s   @T0235001_Loop
#ifdef MEDIA265_S20E_S21E
                        moveq   #0,D0                            /* BUG0_01 Coding error without consequence. Wrong return value. If the specified event index is not found in the timeline the function returns 0 which is the same value that is returned if the event index is found in the first timeline entry. No consequence because this code is never executed */
#endif
        }
#ifdef MEDIA613_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
        F0019_MAIN_DisplayErrorAndStop(C70_ERROR_REQUESTED_EVENT_NOT_IN_TIMELINE);
#endif
        asm {
                @T0235005_Return:
        }
#endif
}

/* This function fixes the placement of the specified timeline entry. When this function returns the first event index in the timeline is the earliest event.
Timeline entries are sorted in a binary tree of nodes so that each parent node refers to an event that will occurs before (or at the same time) as both of its children nodes. The binary tree is stored in an array. Each node contains an event index.
First node is located at index 0 in the array
Each node located at index i in the array has one parent located at index (i - 1) / 2 and two children located at indices 2i + 1 and 2i + 2 */
void F0236_TIMELINE_FixPlacement(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0512_ui_TimelineIndex)
#endif
REGISTER unsigned int16_t P0512_ui_TimelineIndex FINAL_SEPARATOR
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER EVENT* L0584_ps_Event;
#endif
        REGISTER unsigned int16_t L0581_ui_TimelineIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned int16_t L0582_ui_EventIndex;
#endif
        REGISTER unsigned int16_t L0583_ui_Multiple;
#define AL0583_ui_EventCount        L0583_ui_Multiple
#define AL0583_ui_HalfTimelineIndex L0583_ui_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        BOOLEAN L0585_B_PlacementFixed;
        REGISTER EVENT* L0584_ps_Event;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER BOOLEAN L0585_B_PlacementFixed;
        REGISTER unsigned int16_t L0582_ui_EventIndex;
#endif


        if ((AL0583_ui_EventCount = G0372_ui_EventCount) == 1) /* No placement to fix if there is only one event in the timeline */
                return;
        L0584_ps_Event = &G0370_ps_Events[L0582_ui_EventIndex = G0371_pui_Timeline[P0512_ui_TimelineIndex]]; /* Event specified by the parameter */
        L0585_B_PlacementFixed = C0_FALSE;
        while (P0512_ui_TimelineIndex > 0) { /* Check if the event should be moved earlier in the timeline */
                L0581_ui_TimelineIndex = (P0512_ui_TimelineIndex - 1) >> 1; /* Index of parent node */
                if (F0234_TIMELINE_IsEventABeforeEventB(L0584_ps_Event, &G0370_ps_Events[G0371_pui_Timeline[L0581_ui_TimelineIndex]])) { /* If the specified event occurs before its parent in the tree */
                        G0371_pui_Timeline[P0512_ui_TimelineIndex] = G0371_pui_Timeline[L0581_ui_TimelineIndex];
                        P0512_ui_TimelineIndex = L0581_ui_TimelineIndex;
                        L0585_B_PlacementFixed = C1_TRUE;
                } else {
                        break;
                }
        }
        if (L0585_B_PlacementFixed)
                goto T0236011;
        AL0583_ui_HalfTimelineIndex = ((AL0583_ui_EventCount - 1) - 1) >> 1; /* Index of parent node of the last event */
        while (P0512_ui_TimelineIndex <= AL0583_ui_HalfTimelineIndex) { /* Check if the event should be moved later in the timeline */
                L0581_ui_TimelineIndex = (P0512_ui_TimelineIndex << 1) + 1; /* Index of first child of the node */
                if (((L0581_ui_TimelineIndex + 1) < G0372_ui_EventCount) && (F0234_TIMELINE_IsEventABeforeEventB(&G0370_ps_Events[G0371_pui_Timeline[L0581_ui_TimelineIndex + 1]], &G0370_ps_Events[G0371_pui_Timeline[L0581_ui_TimelineIndex]]))) {
                        L0581_ui_TimelineIndex++;
                }
                if (F0234_TIMELINE_IsEventABeforeEventB(&G0370_ps_Events[G0371_pui_Timeline[L0581_ui_TimelineIndex]], L0584_ps_Event)) {
                        G0371_pui_Timeline[P0512_ui_TimelineIndex] = G0371_pui_Timeline[L0581_ui_TimelineIndex];
                        P0512_ui_TimelineIndex = L0581_ui_TimelineIndex;
                } else {
                        break;
                }
        }
        T0236011:
        G0371_pui_Timeline[P0512_ui_TimelineIndex] = L0582_ui_EventIndex;
}

void F0237_TIMELINE_DeleteEvent(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0513_ui_EventIndex)
#endif
REGISTER unsigned int16_t P0513_ui_EventIndex FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0586_ui_TimelineIndex;
        REGISTER unsigned int16_t L0587_ui_EventCount;


        G0370_ps_Events[P0513_ui_EventIndex].A.A.Type = C00_EVENT_NONE;
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
        if (P0513_ui_EventIndex < G0373_ui_FirstUnusedEventIndex) {
                G0373_ui_FirstUnusedEventIndex = P0513_ui_EventIndex;
        }
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        ((UNUSED_EVENT*)G0370_ps_Events)[P0513_ui_EventIndex].NextUnusedEventIndex = G0373_ui_FirstUnusedEventIndex;
        G0373_ui_FirstUnusedEventIndex = P0513_ui_EventIndex;
#endif
        if ((L0587_ui_EventCount = --G0372_ui_EventCount) == 0)
                return;
        L0586_ui_TimelineIndex = F0235_TIMELINE_GetIndex(P0513_ui_EventIndex);
        if (L0586_ui_TimelineIndex == L0587_ui_EventCount) /* If the deleted event is the last in the timeline, no need to fix the timeline */
                return;
        G0371_pui_Timeline[L0586_ui_TimelineIndex] = G0371_pui_Timeline[L0587_ui_EventCount]; /* Replace the deleted event in the timeline by the last event in the timeline */
        F0236_TIMELINE_FixPlacement(L0586_ui_TimelineIndex);
}

#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t F0652_MergeEvent(
REGISTER EVENT* P2214_ps_Event FINAL_SEPARATOR
{
        REGISTER EVENT* L3031_ps_Event;
        REGISTER int16_t L3032_i_Multiple;
#define A3032_i_EventType  L3032_i_Multiple
#define A3032_i_EventIndex L3032_i_Multiple


        A3032_i_EventType = P2214_ps_Event->A.A.Type;
        if ((A3032_i_EventType >= C05_EVENT_CORRIDOR) && (A3032_i_EventType <= C10_EVENT_DOOR)) {
                L3031_ps_Event = G0370_ps_Events;
                for (A3032_i_EventIndex = 0; A3032_i_EventIndex < G2009_i_LargestUsedEventOrdinal; A3032_i_EventIndex++, L3031_ps_Event++) {
                        if ((L3031_ps_Event->A.A.Type >= C05_EVENT_CORRIDOR) && (L3031_ps_Event->A.A.Type <= C10_EVENT_DOOR)) {
                                if ((P2214_ps_Event->Map_Time == L3031_ps_Event->Map_Time) && (P2214_ps_Event->B.MapXY == L3031_ps_Event->B.MapXY) && ((L3031_ps_Event->A.A.Type != C06_EVENT_WALL) || (L3031_ps_Event->C.A.Cell == P2214_ps_Event->C.A.Cell))) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
                                        L3031_ps_Event->C.A.Effect = P2214_ps_Event->C.A.Effect;
                                        return A3032_i_EventIndex;
                                }
                                continue;
                        } else {
                                if ((L3031_ps_Event->A.A.Type == C01_EVENT_DOOR_ANIMATION) && (P2214_ps_Event->Map_Time == L3031_ps_Event->Map_Time) && (P2214_ps_Event->B.MapXY == L3031_ps_Event->B.MapXY)) {
                                        if (P2214_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                                                P2214_ps_Event->C.A.Effect = 1 - L3031_ps_Event->C.A.Effect;
                                        }
                                        F0237_TIMELINE_DeleteEvent(A3032_i_EventIndex);
                                        break;
                                }
                        }
                }
        } else {
                if (A3032_i_EventType == C01_EVENT_DOOR_ANIMATION) {
                        L3031_ps_Event = G0370_ps_Events;
                        for (A3032_i_EventIndex = 0; A3032_i_EventIndex < G2009_i_LargestUsedEventOrdinal; A3032_i_EventIndex++, L3031_ps_Event++) {
                                if ((P2214_ps_Event->Map_Time == L3031_ps_Event->Map_Time) && (P2214_ps_Event->B.MapXY == L3031_ps_Event->B.MapXY)) {
                                        if (L3031_ps_Event->A.A.Type == C10_EVENT_DOOR) {
                                                if (L3031_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                                                        L3031_ps_Event->C.A.Effect = 1 - P2214_ps_Event->C.A.Effect;
                                                }
                                                return A3032_i_EventIndex;
                                        }
                                        if (L3031_ps_Event->A.A.Type == C01_EVENT_DOOR_ANIMATION) {
                                                L3031_ps_Event->C.A.Effect = P2214_ps_Event->C.A.Effect;
                                                return A3032_i_EventIndex;
                                        }
                                }
                        }
                } else {
                        if (A3032_i_EventType == C02_EVENT_DOOR_DESTRUCTION) {
                                L3031_ps_Event = G0370_ps_Events;
                                for (A3032_i_EventIndex = 0; A3032_i_EventIndex < G2009_i_LargestUsedEventOrdinal; A3032_i_EventIndex++, L3031_ps_Event++) {
                                        if ((P2214_ps_Event->B.MapXY == L3031_ps_Event->B.MapXY) && (M029_MAP(P2214_ps_Event->Map_Time) == M029_MAP(L3031_ps_Event->Map_Time))) {
                                                if ((L3031_ps_Event->A.A.Type == C01_EVENT_DOOR_ANIMATION) || (L3031_ps_Event->A.A.Type == C10_EVENT_DOOR)) {
                                                        F0237_TIMELINE_DeleteEvent(A3032_i_EventIndex);
                                                }
                                        }
                                }
                        }
                }
        }
        return -1;
}
#endif

#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
unsigned int16_t F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0514_ps_Event)
#endif
REGISTER EVENT* P0514_ps_Event FINAL_SEPARATOR
{
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        REGISTER EVENT* L0591_ps_Event;
#endif
        REGISTER unsigned int16_t L0588_ui_EventIndex;
#ifdef MEDIA010_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB
        REGISTER int16_t L0589_i_Unreferenced; /* BUG0_00 Useless code */
#endif
        REGISTER unsigned int16_t L0590_ui_NewEventIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER EVENT* L0591_ps_Event;
#endif


        if (G0372_ui_EventCount == G0369_EventMaximumCount) {
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_05_FIX */
                T0238001:
                return 0; /* BUG0_18 When events are exhausted and the timeline is full, new events are not added to the timeline which can cause various issues: A projectile stays immobile in the air, an explosion remains forever on a square, a spell effect stays active forever (like Light, Shields, Footprints), a champion action icon remains disabled forever */
#endif
#ifdef MEDIA239_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB /* CHANGE3_05_FIX The game stops instead of not adding event to the timeline */
                F0019_MAIN_DisplayErrorAndStop(C45_ERROR_TIMELINE_FULL);
#endif
        }
#ifdef MEDIA064_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB
#ifndef NOCOPYPROTECTION
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_04_IMPROVEMENT */
        if (G0189_i_Graphic558_StopAddingEvents_CPSE != C03217_FALSE) {
#endif
#ifdef MEDIA281_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB /* CHANGE7_04_IMPROVEMENT Events are not added anymore if G0418_l_LastEvent22Time_CPSE is 0 (set by graphic #21 or by F0277_CPSE_IsFuzzySectorValid_FuzzyBits if there are no differences in fuzzy bits) */
        if ((G0189_i_Graphic558_StopAddingEvents_CPSE != C03217_FALSE) || G0418_l_LastEvent22Time_CPSE == 0) {
#endif
#ifdef MEDIA469_P20JB
                G3001_B_PreventSaveGame_CPSX = C1_TRUE;
#endif
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_05_FIX */
                goto T0238001;
#endif
#ifdef MEDIA241_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB /* CHANGE3_05_FIX The goto is not possible anymore as the first return 0 was removed */
                return 0;
#endif
        }
#endif
#endif
        if ((P0514_ps_Event->A.A.Type >= C05_EVENT_CORRIDOR) && (P0514_ps_Event->A.A.Type <= C10_EVENT_DOOR)) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                for (L0588_ui_EventIndex = 0, L0591_ps_Event = G0370_ps_Events; L0588_ui_EventIndex < G0369_EventMaximumCount; L0588_ui_EventIndex++, L0591_ps_Event++) {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                L0591_ps_Event = G0370_ps_Events;
                for (L0588_ui_EventIndex = 0; L0588_ui_EventIndex < G0369_EventMaximumCount; L0588_ui_EventIndex++, L0591_ps_Event++) {
#endif
                        if ((L0591_ps_Event->A.A.Type >= C05_EVENT_CORRIDOR) && (L0591_ps_Event->A.A.Type <= C10_EVENT_DOOR)) {
                                if ((P0514_ps_Event->Map_Time == L0591_ps_Event->Map_Time) && (P0514_ps_Event->B.MapXY == L0591_ps_Event->B.MapXY) && ((L0591_ps_Event->A.A.Type != C06_EVENT_WALL) || (L0591_ps_Event->C.A.Cell == P0514_ps_Event->C.A.Cell))) {
                                        L0591_ps_Event->C.A.Effect = P0514_ps_Event->C.A.Effect;
                                        return L0588_ui_EventIndex;
                                }
#ifdef MEDIA358_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB /* ANOMALY_ST_BRANCH */
                                else {
#endif
                                        continue;
#ifdef MEDIA358_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
                                }
#endif
                        } else {
                                if ((L0591_ps_Event->A.A.Type == C01_EVENT_DOOR_ANIMATION) && (P0514_ps_Event->Map_Time == L0591_ps_Event->Map_Time) && (P0514_ps_Event->B.MapXY == L0591_ps_Event->B.MapXY)) {
                                        if (P0514_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                                                P0514_ps_Event->C.A.Effect = 1 - L0591_ps_Event->C.A.Effect;
                                        }
                                        F0237_TIMELINE_DeleteEvent(L0588_ui_EventIndex);
                                        break;
                                }
                        }
                }
        } else {
                if (P0514_ps_Event->A.A.Type == C01_EVENT_DOOR_ANIMATION) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        for (L0588_ui_EventIndex = 0, L0591_ps_Event = G0370_ps_Events; L0588_ui_EventIndex < G0369_EventMaximumCount; L0588_ui_EventIndex++, L0591_ps_Event++) {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                        L0591_ps_Event = G0370_ps_Events;
                        for (L0588_ui_EventIndex = 0; L0588_ui_EventIndex < G0369_EventMaximumCount; L0588_ui_EventIndex++, L0591_ps_Event++) {
#endif
                                if ((P0514_ps_Event->Map_Time == L0591_ps_Event->Map_Time) && (P0514_ps_Event->B.MapXY == L0591_ps_Event->B.MapXY)) {
                                        if (L0591_ps_Event->A.A.Type == C10_EVENT_DOOR) {
                                                if (L0591_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                                                        L0591_ps_Event->C.A.Effect = 1 - P0514_ps_Event->C.A.Effect;
                                                }
                                                return L0588_ui_EventIndex;
                                        }
#ifdef MEDIA358_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB /* ANOMALY_ST_BRANCH */
                                        else {
#endif
                                                if (L0591_ps_Event->A.A.Type == C01_EVENT_DOOR_ANIMATION) {
                                                        L0591_ps_Event->C.A.Effect = P0514_ps_Event->C.A.Effect;
                                                        return L0588_ui_EventIndex;
                                                }
#ifdef MEDIA358_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
                                        }
#endif
                                }
                        }
                } else {
                        if (P0514_ps_Event->A.A.Type == C02_EVENT_DOOR_DESTRUCTION) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                for (L0588_ui_EventIndex = 0, L0591_ps_Event = G0370_ps_Events; L0588_ui_EventIndex < G0369_EventMaximumCount; L0588_ui_EventIndex++, L0591_ps_Event++) {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                                L0591_ps_Event = G0370_ps_Events;
                                for (L0588_ui_EventIndex = 0; L0588_ui_EventIndex < G0369_EventMaximumCount; L0588_ui_EventIndex++, L0591_ps_Event++) {
#endif
                                        if ((P0514_ps_Event->B.MapXY == L0591_ps_Event->B.MapXY) && (M029_MAP(P0514_ps_Event->Map_Time) == M029_MAP(L0591_ps_Event->Map_Time))) {
                                                if ((L0591_ps_Event->A.A.Type == C01_EVENT_DOOR_ANIMATION) || (L0591_ps_Event->A.A.Type == C10_EVENT_DOOR)) {
                                                        F0237_TIMELINE_DeleteEvent(L0588_ui_EventIndex);
                                                }
                                        }
                                }
                        }
                }
        }
        G0370_ps_Events[L0590_ui_NewEventIndex = G0373_ui_FirstUnusedEventIndex] = *P0514_ps_Event; /* Copy the event data (Megamax C can assign structures) */
        do {
                if (G0373_ui_FirstUnusedEventIndex == G0369_EventMaximumCount)
                        break;
        } while ((G0370_ps_Events[++G0373_ui_FirstUnusedEventIndex]).A.A.Type != C00_EVENT_NONE);
        G0371_pui_Timeline[G0372_ui_EventCount] = L0590_ui_NewEventIndex;
        F0236_TIMELINE_FixPlacement(G0372_ui_EventCount++);
        return L0590_ui_NewEventIndex;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0590_i_NewEventIndex;


#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        if (P0514_ps_Event->A.A.Type == C00_EVENT_NONE) {
                return -1;
        }
#endif
        if (G0372_ui_EventCount == G0369_EventMaximumCount) {
                F0019_MAIN_DisplayErrorAndStop(C45_ERROR_TIMELINE_FULL);
        }
#ifdef MEDIA630_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
        if ((G0189_i_Graphic558_StopAddingEvents_CPSE != C03217_FALSE) || G0418_l_LastEvent22Time_CPSE == 0) {
#ifdef MEDIA692_X31J
#ifndef NOCOPYPROTECTION
                G3001_B_PreventSaveGame_CPSX = C1_TRUE;
#endif
#endif
                return 0;
        }
#endif
#endif
        if ((L0590_i_NewEventIndex = F0652_MergeEvent(P0514_ps_Event)) >= 0) {
                return L0590_i_NewEventIndex;
        }
        L0590_i_NewEventIndex = G0373_ui_FirstUnusedEventIndex;
        G0373_ui_FirstUnusedEventIndex = ((UNUSED_EVENT*)G0370_ps_Events)[L0590_i_NewEventIndex].NextUnusedEventIndex;
        G0370_ps_Events[L0590_i_NewEventIndex] = *P0514_ps_Event; /* Copy the event data (structure assignment) */
        if (G2009_i_LargestUsedEventOrdinal <= L0590_i_NewEventIndex) {
                G2009_i_LargestUsedEventOrdinal = M000_INDEX_TO_ORDINAL(L0590_i_NewEventIndex);
        }
        G0371_pui_Timeline[G0372_ui_EventCount] = L0590_i_NewEventIndex;
        F0236_TIMELINE_FixPlacement(G0372_ui_EventCount++);
        return L0590_i_NewEventIndex;
#endif
}

STATICFUNCTION void F0239_TIMELINE_ExtractFirstEvent(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0515_ps_Event)
#endif
EVENT* P0515_ps_Event FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register unsigned int16_t L0592_ui_EventIndex;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        unsigned int16_t L0592_ui_EventIndex;
#endif


        *P0515_ps_Event = G0370_ps_Events[L0592_ui_EventIndex = G0371_pui_Timeline[0]]; /* Structure assignment */
        F0237_TIMELINE_DeleteEvent(L0592_ui_EventIndex);
}

STATICFUNCTION BOOLEAN F0240_TIMELINE_IsFirstEventExpired_CPSE(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA476_P20JB_X31J
#ifndef NOCOPYPROTECTION
        if (G0330_i_StopExpiringEvents_CPSE >= 2) {
                G3001_B_PreventSaveGame_CPSX = C1_TRUE;
        }
#endif
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
#ifndef NOCOPYPROTECTION
        if (G4093_B_CD_PROTECT_CPSX) {
                return C0_FALSE;
        }
#endif
#endif
        return (G0372_ui_EventCount && (M030_TIME(G0370_ps_Events[G0371_pui_Timeline[0]].Map_Time) <= G0313_ul_GameTime))
#ifdef MEDIA067_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
        && (G0330_i_StopExpiringEvents_CPSE < 2)
#endif
#endif
        ;
}

STATICFUNCTION void F0241_TIMELINE_ProcessEvent1_DoorAnimation(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0516_ps_Event)
#endif
REGISTER EVENT* P0516_ps_Event FINAL_SEPARATOR
{
        REGISTER unsigned char* L0597_puc_Square;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        REGISTER DOOR* L0598_ps_Door;
        REGISTER int16_t L0596_i_DoorState;
#endif
        REGISTER unsigned int16_t L0593_ui_MapX;
        REGISTER unsigned int16_t L0594_ui_MapY;
        REGISTER int16_t L0595_i_Effect;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L0596_i_DoorState;
#endif
#ifdef MEDIA224_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        DOOR* L0598_ps_Door;
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        THING L0599_T_GroupThing;
        unsigned int16_t L0600_ui_CreatureAttributes;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L0599_T_GroupThing;
#endif
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_06_FIX Useless code removed */
        char L0601_ac_Unreferenced[8]; /* BUG0_00 Useless code */
#endif
        unsigned int16_t L0602_ui_Multiple;
#define AL0602_ui_VerticalDoor L0602_ui_Multiple
#define AL0602_ui_Height       L0602_ui_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        unsigned int16_t L0600_ui_CreatureAttributes;
#endif


        L0597_puc_Square = &G0271_ppuc_CurrentMapData[L0593_ui_MapX = P0516_ps_Event->B.Location.MapX][L0594_ui_MapY = P0516_ps_Event->B.Location.MapY];
        if ((L0596_i_DoorState = M036_DOOR_STATE(*L0597_puc_Square)) == C5_DOOR_STATE_DESTROYED)
                return;
        P0516_ps_Event->Map_Time++;
        L0595_i_Effect = P0516_ps_Event->C.A.Effect;
        if (L0595_i_Effect == C01_EFFECT_CLEAR) {
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                L0598_ps_Door = (DOOR*)F0157_DUNGEON_GetSquareFirstThingData(L0593_ui_MapX, L0594_ui_MapY);
                AL0602_ui_VerticalDoor = L0598_ps_Door->Vertical;
#endif
                if ((G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (L0593_ui_MapX == G0306_i_PartyMapX) && (L0594_ui_MapY == G0307_i_PartyMapY) && (L0596_i_DoorState != C0_DOOR_STATE_OPEN)) {
                        if (G0305_ui_PartyChampionCount > 0) {
                                M037_SET_DOOR_STATE(*L0597_puc_Square, C0_DOOR_STATE_OPEN);
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                                if (F0324_CHAMPION_DamageAll_GetDamagedChampionCount(5, MASK0x0008_WOUND_TORSO | ((((DOOR*)G0284_apuc_ThingData[C00_THING_TYPE_DOOR])[M013_INDEX(F0161_DUNGEON_GetSquareFirstThing(L0593_ui_MapX, L0594_ui_MapY))].Vertical) ? MASK0x0004_WOUND_HEAD : MASK0x0001_WOUND_READY_HAND | MASK0x0002_WOUND_ACTION_HAND), C2_ATTACK_SELF)) { /* BUG0_78 */
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                                if (F0324_CHAMPION_DamageAll_GetDamagedChampionCount(5, MASK0x0008_WOUND_TORSO | AL0602_ui_VerticalDoor ? MASK0x0004_WOUND_HEAD : MASK0x0001_WOUND_READY_HAND | MASK0x0002_WOUND_ACTION_HAND, C2_ATTACK_SELF)) { /* BUG0_78 A closing horizontal door wounds champions to the head instead of to the hands. Missing parenthesis in the condition cause all doors to wound the head in addition to the torso because MASK0x0008_WOUND_TORSO | AL0602_ui_VerticalDoor is always non zero. The expected behavior would be for vertical doors to wound torso and head and for horizontal doors to wound hands and torso. The code should be:
                                F0324_CHAMPION_DamageAll_GetDamagedChampionCount(5, MASK0x0008_WOUND_TORSO | (AL0602_ui_VerticalDoor ? MASK0x0004_WOUND_HEAD : MASK0x0001_WOUND_READY_HAND | MASK0x0002_WOUND_ACTION_HAND), C2_ATTACK_SELF) */
#endif
                                        F0064_SOUND_RequestPlay_CPSD(M562_SOUND_PARTY_DAMAGED, L0593_ui_MapX, L0594_ui_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
                                }
                        }
                        P0516_ps_Event->Map_Time++;
                        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0516_ps_Event);
                        return;
                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                else {
#endif
                        if (((L0599_T_GroupThing = F0175_GROUP_GetThing(L0593_ui_MapX, L0594_ui_MapY)) != C0xFFFE_THING_ENDOFLIST) && !M007_GET(L0600_ui_CreatureAttributes = F0144_DUNGEON_GetCreatureAttributes(L0599_T_GroupThing), MASK0x0040_NON_MATERIAL)) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                                AL0602_ui_Height = (((DOOR*)G0284_apuc_ThingData[C00_THING_TYPE_DOOR])[M013_INDEX(F0161_DUNGEON_GetSquareFirstThing(L0593_ui_MapX, L0594_ui_MapY))].Vertical) ? M051_CREATURE_HEIGHT(L0600_ui_CreatureAttributes) : 1;
                                if (L0596_i_DoorState >= AL0602_ui_Height) { /* Creature height or 1 */
                                        if (F0191_GROUP_GetDamageAllCreaturesOutcome(&((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(L0599_T_GroupThing)], L0593_ui_MapX, L0594_ui_MapY, 5, C1_TRUE) != C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP) {
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                                if (L0596_i_DoorState >= (AL0602_ui_Height ? M051_CREATURE_HEIGHT(L0600_ui_CreatureAttributes) : 1)) { /* Creature height or 1 */
                                        if (F0191_GROUP_GetDamageAllCreaturesOutcome((GROUP*)F0156_DUNGEON_GetThingData(L0599_T_GroupThing), L0593_ui_MapX, L0594_ui_MapY, 5, C1_TRUE) != C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP) {
#endif
                                                F0209_GROUP_ProcessEvents29to41(L0593_ui_MapX, L0594_ui_MapY, CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE, 0);
                                        }
                                        L0596_i_DoorState = (L0596_i_DoorState == C0_DOOR_STATE_OPEN) ? C0_DOOR_STATE_OPEN : (L0596_i_DoorState - 1);
                                        M037_SET_DOOR_STATE(*L0597_puc_Square, L0596_i_DoorState);
                                        F0064_SOUND_RequestPlay_CPSD(C04_SOUND_WOODEN_THUD_ATTACK_TROLIN_ANTMAN_STONE_GOLEM, L0593_ui_MapX, L0594_ui_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
                                        P0516_ps_Event->Map_Time++;
                                        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0516_ps_Event);
                                        return;
                                }
                        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                }
#endif
        }
        if (((L0595_i_Effect == C00_EFFECT_SET) && (L0596_i_DoorState == C0_DOOR_STATE_OPEN)) || ((L0595_i_Effect == C01_EFFECT_CLEAR) && (L0596_i_DoorState == C4_DOOR_STATE_CLOSED))) {
                goto T0241020_Return;
        }
        L0596_i_DoorState += (L0595_i_Effect == C00_EFFECT_SET) ? -1 : 1;
        M037_SET_DOOR_STATE(*L0597_puc_Square, L0596_i_DoorState);
        F0064_SOUND_RequestPlay_CPSD(C02_SOUND_DOOR_RATTLE, L0593_ui_MapX, L0594_ui_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
        if (L0595_i_Effect == C00_EFFECT_SET) {
                if (L0596_i_DoorState == C0_DOOR_STATE_OPEN)
                        return;
        } else {
                if (L0596_i_DoorState == C4_DOOR_STATE_CLOSED)
                        return;
        }
        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0516_ps_Event);
        T0241020_Return: ;
}

STATICFUNCTION void F0242_TIMELINE_ProcessEvent7_Square_FakeWall(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0517_ps_Event)
#endif
REGISTER EVENT* P0517_ps_Event FINAL_SEPARATOR
{
        REGISTER unsigned char* L0607_puc_Square;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0605_i_Effect;
#endif
        REGISTER unsigned int16_t L0603_ui_MapX;
        REGISTER unsigned int16_t L0604_ui_MapY;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L0605_i_Effect;
#endif
        REGISTER THING L0606_T_Thing;


        L0607_puc_Square = &G0271_ppuc_CurrentMapData[L0603_ui_MapX = P0517_ps_Event->B.Location.MapX][L0604_ui_MapY = P0517_ps_Event->B.Location.MapY];
        L0605_i_Effect = P0517_ps_Event->C.A.Effect;
        if (L0605_i_Effect == C02_EFFECT_TOGGLE) {
                L0605_i_Effect = M007_GET(*L0607_puc_Square, MASK0x0004_FAKEWALL_OPEN) ? C01_EFFECT_CLEAR : C00_EFFECT_SET;
        }
        if (L0605_i_Effect == C01_EFFECT_CLEAR) {
                if ((G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (L0603_ui_MapX == G0306_i_PartyMapX) && (L0604_ui_MapY == G0307_i_PartyMapY)) {
                        P0517_ps_Event->Map_Time++;
                        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0517_ps_Event);
                } else {
#ifdef MEDIA047_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        if (((L0606_T_Thing = F0175_GROUP_GetThing(L0603_ui_MapX, L0604_ui_MapY)) != C0xFFFE_THING_ENDOFLIST) && !M007_GET(F0144_DUNGEON_GetCreatureAttributes(L0606_T_Thing), MASK0x0040_NON_MATERIAL)) {
                                P0517_ps_Event->Map_Time++;
                                F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0517_ps_Event);
#endif
#ifdef MEDIA707_I34E_I34M
#ifdef PC_FIX_CODE_SIZE
                        if (((L0606_T_Thing = F0175_GROUP_GetThing(L0603_ui_MapX, L0604_ui_MapY)) != C0xFFFE_THING_ENDOFLIST) && !M007_GET(F0144_DUNGEON_GetCreatureAttributes(L0606_T_Thing) + 2, MASK0x0040_NON_MATERIAL)) {
#endif
#ifndef PC_FIX_CODE_SIZE /* CODE COMMENTED TO DECREASE SIZE OF COMPILED CODE */
                        if (((L0606_T_Thing = F0175_GROUP_GetThing(L0603_ui_MapX, L0604_ui_MapY)) != C0xFFFE_THING_ENDOFLIST) && !M007_GET(F0144_DUNGEON_GetCreatureAttributes(L0606_T_Thing), MASK0x0040_NON_MATERIAL)) {
                                P0517_ps_Event->Map_Time++;
                                F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0517_ps_Event);
#endif
#endif
                        } else {
                                M009_CLEAR(*L0607_puc_Square, MASK0x0004_FAKEWALL_OPEN);
                        }
                }
        } else {
                M008_SET(*L0607_puc_Square, MASK0x0004_FAKEWALL_OPEN);
        }
}

STATICFUNCTION void F0243_TIMELINE_ProcessEvent2_DoorDestruction(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0518_ps_Event)
#endif
REGISTER EVENT* P0518_ps_Event FINAL_SEPARATOR
{
        REGISTER unsigned char* L0608_puc_Square;


        L0608_puc_Square = &G0271_ppuc_CurrentMapData[P0518_ps_Event->B.Location.MapX][P0518_ps_Event->B.Location.MapY];
        M037_SET_DOOR_STATE(*L0608_puc_Square, C5_DOOR_STATE_DESTROYED);
}

STATICFUNCTION void F0244_TIMELINE_ProcessEvent10_Square_Door(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0519_ps_Event)
#endif
REGISTER EVENT* P0519_ps_Event FINAL_SEPARATOR
{
        REGISTER int16_t L0609_i_DoorState;


        if ((L0609_i_DoorState = M036_DOOR_STATE(G0271_ppuc_CurrentMapData[P0519_ps_Event->B.Location.MapX][P0519_ps_Event->B.Location.MapY])) == C5_DOOR_STATE_DESTROYED) {
                return;
        }
        if (P0519_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                P0519_ps_Event->C.A.Effect = (L0609_i_DoorState == C0_DOOR_STATE_OPEN) ? C01_EFFECT_CLEAR : C00_EFFECT_SET;
        } else {
                if (P0519_ps_Event->C.A.Effect == C00_EFFECT_SET) {
                        if (L0609_i_DoorState == C0_DOOR_STATE_OPEN)
                                return;
                } else {
                        if (L0609_i_DoorState == C4_DOOR_STATE_CLOSED)
                                return;
                }
        }
        P0519_ps_Event->A.A.Type = C01_EVENT_DOOR_ANIMATION;
        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0519_ps_Event);
}

STATICFUNCTION void F0245_TIMELINE_ProcessEvent5_Square_Corridor(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0520_ps_Event)
#endif
REGISTER EVENT* P0520_ps_Event FINAL_SEPARATOR
{
        REGISTER SENSOR* L0614_ps_Sensor;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register int16_t L0610_i_ThingType;
        register BOOLEAN L0611_B_TextCurrentlyVisible;
        register unsigned int16_t L0612_ui_CreatureCount;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER TEXTSTRING* L0615_ps_TextString;
#endif
        REGISTER THING L0613_T_Thing;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        TEXTSTRING* L0615_ps_TextString;
        unsigned int16_t L0616_ui_MapX;
        unsigned int16_t L0617_ui_MapY;
        unsigned int16_t L0618_ui_Multiple;
#endif
#define AL0618_ui_HealthMultiplier L0618_ui_Multiple
#define AL0618_ui_Ticks            L0618_ui_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0618_ui_Multiple;
        REGISTER unsigned int16_t L0612_ui_CreatureCount;
        REGISTER unsigned int16_t L0616_ui_MapX;
        REGISTER unsigned int16_t L0617_ui_MapY;
        REGISTER BOOLEAN L0611_B_TextCurrentlyVisible;
        REGISTER int16_t L0610_i_ThingType;
#endif
        EVENT L0619_s_Event;


        L0613_T_Thing = F0161_DUNGEON_GetSquareFirstThing(L0616_ui_MapX = P0520_ps_Event->B.Location.MapX, L0617_ui_MapY = P0520_ps_Event->B.Location.MapY);
        while (L0613_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                if ((L0610_i_ThingType = M012_TYPE(L0613_T_Thing)) == C02_THING_TYPE_TEXTSTRING) {
                        L0615_ps_TextString = (TEXTSTRING*)F0156_DUNGEON_GetThingData(L0613_T_Thing);
                        L0611_B_TextCurrentlyVisible = L0615_ps_TextString->Visible;
                        if (P0520_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                                L0615_ps_TextString->Visible = !L0611_B_TextCurrentlyVisible;
                        } else {
                                L0615_ps_TextString->Visible = (P0520_ps_Event->C.A.Effect == C00_EFFECT_SET);
                        }
                        if (!L0611_B_TextCurrentlyVisible && L0615_ps_TextString->Visible && (G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (L0616_ui_MapX == G0306_i_PartyMapX) && (L0617_ui_MapY == G0307_i_PartyMapY)) {
                                F0168_DUNGEON_DecodeText(M774_CAST_PUC(G0353_ac_StringBuildBuffer), L0613_T_Thing, C1_TEXT_TYPE_MESSAGE);
                                F0047_TEXT_MESSAGEAREA_PrintMessage(C15_COLOR_WHITE, G0353_ac_StringBuildBuffer);
                        }
                } else {
                        if (L0610_i_ThingType == C03_THING_TYPE_SENSOR) {
                                L0614_ps_Sensor = (SENSOR*)F0156_DUNGEON_GetThingData(L0613_T_Thing);
                                if (M039_TYPE(L0614_ps_Sensor) == C006_SENSOR_FLOOR_GROUP_GENERATOR) {
                                        L0612_ui_CreatureCount = L0614_ps_Sensor->Remote.Value;
                                        if (M007_GET(L0612_ui_CreatureCount, MASK0x0008_RANDOMIZE_GENERATED_CREATURE_COUNT)) {
                                                L0612_ui_CreatureCount = M002_RANDOM(M007_GET(L0612_ui_CreatureCount, MASK0x0007_GENERATED_CREATURE_COUNT));
                                        } else {
                                                L0612_ui_CreatureCount--;
                                        }
                                        if ((AL0618_ui_HealthMultiplier = M045_HEALTH_MULTIPLIER(L0614_ps_Sensor)) == 0) {
                                                AL0618_ui_HealthMultiplier = G0269_ps_CurrentMap->C.Difficulty;
                                        }
                                        F0185_GROUP_GetGenerated(M040_DATA(L0614_ps_Sensor), AL0618_ui_HealthMultiplier, L0612_ui_CreatureCount, M004_RANDOM(4), L0616_ui_MapX, L0617_ui_MapY);
                                        if (L0614_ps_Sensor->Remote.Audible) {
                                                F0064_SOUND_RequestPlay_CPSD(M560_SOUND_BUZZ, L0616_ui_MapX, L0617_ui_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
                                        }
#ifdef MEDIA083_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                        if (L0614_ps_Sensor->Remote.OnceOnly) {
                                                M044_SET_TYPE_DISABLED(L0614_ps_Sensor);
                                        } else {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                                        M044_SET_TYPE_DISABLED(L0614_ps_Sensor);
                                        if (!L0614_ps_Sensor->Remote.OnceOnly) {
#endif
                                                if ((AL0618_ui_Ticks = M046_TICKS(L0614_ps_Sensor)) != 0) {
#ifdef MEDIA083_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                        M044_SET_TYPE_DISABLED(L0614_ps_Sensor);
#endif
                                                        if (AL0618_ui_Ticks > 127) {
                                                                AL0618_ui_Ticks = (AL0618_ui_Ticks - 126) << 6;
                                                        }
                                                        L0619_s_Event.A.A.Type = C65_EVENT_ENABLE_GROUP_GENERATOR;
                                                        M033_SET_MAP_AND_TIME(L0619_s_Event.Map_Time, G0272_i_CurrentMapIndex, G0313_ul_GameTime + AL0618_ui_Ticks);
                                                        L0619_s_Event.A.A.Priority = 0;
                                                        L0619_s_Event.B.Location.MapX = L0616_ui_MapX;
                                                        L0619_s_Event.B.Location.MapY = L0617_ui_MapY;
                                                        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0619_s_Event);
                                                }
                                        }
                                }
                        }
                }
                L0613_T_Thing = F0159_DUNGEON_GetNextThing(L0613_T_Thing);
        }
}

/* This function enables the first disabled sensor on the square by changing its type to C006_SENSOR_FLOOR_GROUP_GENERATOR */
STATICFUNCTION void F0246_TIMELINE_ProcessEvent65_EnableGroupGenerator(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0521_ps_Event)
#endif
REGISTER EVENT* P0521_ps_Event FINAL_SEPARATOR
{
        REGISTER SENSOR* L0621_ps_Sensor;
        REGISTER THING L0620_T_Thing;


        L0620_T_Thing = F0161_DUNGEON_GetSquareFirstThing(P0521_ps_Event->B.Location.MapX, P0521_ps_Event->B.Location.MapY);
        while (L0620_T_Thing != C0xFFFF_THING_NONE) {
                if (M012_TYPE(L0620_T_Thing) == C03_THING_TYPE_SENSOR) {
                        L0621_ps_Sensor = (SENSOR*)F0156_DUNGEON_GetThingData(L0620_T_Thing);
                        if (M039_TYPE(L0621_ps_Sensor) == C000_SENSOR_DISABLED) {
                                L0621_ps_Sensor->Remote.Type_Data |= C006_SENSOR_FLOOR_GROUP_GENERATOR;
                                return;
                        }
                }
                L0620_T_Thing = F0159_DUNGEON_GetNextThing(L0620_T_Thing);
        }
}

STATICFUNCTION void F0247_TIMELINE_TriggerProjectileLauncher(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0522_ps_Sensor, P0523_ps_Event)
#endif
REGISTER SENSOR* P0522_ps_Sensor SEPARATOR
REGISTER EVENT*  P0523_ps_Event  FINAL_SEPARATOR
{
        REGISTER THING L0622_T_FirstProjectileAssociatedThing;
        REGISTER THING L0623_T_SecondProjectileAssociatedThing;
        REGISTER unsigned int16_t L0624_ui_Cell;
        REGISTER int16_t L0625_i_SensorType;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0626_i_MapX;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0626_i_MapX;
#endif
        int16_t L0627_i_MapY;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        BOOLEAN L0632_B_LaunchSingleProjectile;
        unsigned int16_t L0633_ui_ThingCell;
#endif
        unsigned int16_t L0628_ui_ProjectileCell;
        int16_t L0629_i_SensorData;
        int16_t L0630_i_KineticEnergy;
        int16_t L0631_i_StepEnergy;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        BOOLEAN L0632_B_LaunchSingleProjectile;
        unsigned int16_t L0633_ui_ThingCell;
#endif


        L0626_i_MapX = P0523_ps_Event->B.Location.MapX;
        L0627_i_MapY = P0523_ps_Event->B.Location.MapY;
        L0624_ui_Cell = P0523_ps_Event->C.A.Cell;
        L0628_ui_ProjectileCell = M018_OPPOSITE(L0624_ui_Cell);
        L0625_i_SensorType = M039_TYPE(P0522_ps_Sensor);
        L0629_i_SensorData = M040_DATA(P0522_ps_Sensor);
        L0630_i_KineticEnergy = M047_KINETIC_ENERGY(P0522_ps_Sensor);
        L0631_i_StepEnergy = M048_STEP_ENERGY(P0522_ps_Sensor);
        L0632_B_LaunchSingleProjectile = (L0625_i_SensorType == C007_SENSOR_WALL_SINGLE_PROJECTILE_LAUNCHER_NEW_OBJECT) ||
                                         (L0625_i_SensorType == C008_SENSOR_WALL_SINGLE_PROJECTILE_LAUNCHER_EXPLOSION) ||
                                         (L0625_i_SensorType == C014_SENSOR_WALL_SINGLE_PROJECTILE_LAUNCHER_SQUARE_OBJECT);
        if ((L0625_i_SensorType == C008_SENSOR_WALL_SINGLE_PROJECTILE_LAUNCHER_EXPLOSION) || (L0625_i_SensorType == C010_SENSOR_WALL_DOUBLE_PROJECTILE_LAUNCHER_EXPLOSION)) {
                L0622_T_FirstProjectileAssociatedThing = L0623_T_SecondProjectileAssociatedThing = L0629_i_SensorData + C0xFF80_THING_FIRST_EXPLOSION;
        } else {
                if ((L0625_i_SensorType == C014_SENSOR_WALL_SINGLE_PROJECTILE_LAUNCHER_SQUARE_OBJECT) || (L0625_i_SensorType == C015_SENSOR_WALL_DOUBLE_PROJECTILE_LAUNCHER_SQUARE_OBJECT)) {
                        L0622_T_FirstProjectileAssociatedThing = F0161_DUNGEON_GetSquareFirstThing(L0626_i_MapX, L0627_i_MapY);
                        while (L0622_T_FirstProjectileAssociatedThing != C0xFFFF_THING_NONE) { /* BUG0_19 The game crashes when an object launcher sensor is triggered. C0xFFFF_THING_NONE should be C0xFFFE_THING_ENDOFLIST. If there are no more objects on the square then this loop may return an undefined value, this can crash the game. In the original DM and CSB dungeons, the number of times that these sensors are triggered is always controlled to be equal to the number of available objects (with a countdown sensor or a number of once only sensors) */
                                L0633_ui_ThingCell = M011_CELL(L0622_T_FirstProjectileAssociatedThing);
                                if ((M012_TYPE(L0622_T_FirstProjectileAssociatedThing) > C03_THING_TYPE_SENSOR) && ((L0633_ui_ThingCell == L0624_ui_Cell) || (L0633_ui_ThingCell == M017_NEXT(L0624_ui_Cell))))
                                        break;
                                L0622_T_FirstProjectileAssociatedThing = F0159_DUNGEON_GetNextThing(L0622_T_FirstProjectileAssociatedThing);
                        }
                        if (L0622_T_FirstProjectileAssociatedThing == C0xFFFF_THING_NONE) { /* BUG0_19 The game crashes when an object launcher sensor is triggered. C0xFFFF_THING_NONE should be C0xFFFE_THING_ENDOFLIST */
                                return;
                        }
                        F0164_DUNGEON_UnlinkThingFromList(L0622_T_FirstProjectileAssociatedThing, 0, L0626_i_MapX, L0627_i_MapY); /* The object is removed without triggering any sensor effects */
                        if (!L0632_B_LaunchSingleProjectile) {
                                L0623_T_SecondProjectileAssociatedThing = F0161_DUNGEON_GetSquareFirstThing(L0626_i_MapX, L0627_i_MapY);
                                while (L0623_T_SecondProjectileAssociatedThing != C0xFFFF_THING_NONE) { /* BUG0_19 The game crashes when an object launcher sensor is triggered. C0xFFFF_THING_NONE should be C0xFFFE_THING_ENDOFLIST. If there are no more objects on the square then this loop may return an undefined value, this can crash the game */
                                        L0633_ui_ThingCell = M011_CELL(L0623_T_SecondProjectileAssociatedThing);
                                        if ((M012_TYPE(L0623_T_SecondProjectileAssociatedThing) > C03_THING_TYPE_SENSOR) && ((L0633_ui_ThingCell == L0624_ui_Cell) || (L0633_ui_ThingCell == M017_NEXT(L0624_ui_Cell))))
                                                break;
                                        L0623_T_SecondProjectileAssociatedThing = F0159_DUNGEON_GetNextThing(L0623_T_SecondProjectileAssociatedThing);
                                }
                                if (L0623_T_SecondProjectileAssociatedThing == C0xFFFF_THING_NONE) { /* BUG0_19 The game crashes when an object launcher sensor is triggered. C0xFFFF_THING_NONE should be C0xFFFE_THING_ENDOFLIST */
                                        L0632_B_LaunchSingleProjectile = C1_TRUE;
                                } else {
                                        F0164_DUNGEON_UnlinkThingFromList(L0623_T_SecondProjectileAssociatedThing, 0, L0626_i_MapX, L0627_i_MapY); /* The object is removed without triggering any sensor effects */
                                }
                        }
                } else {
                        if ((L0622_T_FirstProjectileAssociatedThing = F0167_DUNGEON_GetObjectForProjectileLauncherOrObjectGenerator(L0629_i_SensorData)) == C0xFFFF_THING_NONE) {
                                return;
                        }
                        if (!L0632_B_LaunchSingleProjectile && ((L0623_T_SecondProjectileAssociatedThing = F0167_DUNGEON_GetObjectForProjectileLauncherOrObjectGenerator(L0629_i_SensorData)) == C0xFFFF_THING_NONE)) {
                                L0632_B_LaunchSingleProjectile = C1_TRUE;
                        }
                }
        }
        if (L0632_B_LaunchSingleProjectile) {
                L0628_ui_ProjectileCell = M021_NORMALIZE(L0628_ui_ProjectileCell + M005_RANDOM(2));
        }
        L0626_i_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[L0624_ui_Cell], L0627_i_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[L0624_ui_Cell]; /* BUG0_20 The game crashes if the launcher sensor is on a map boundary and shoots in a direction outside the map */
        G0365_B_CreateLauncherProjectile = C1_TRUE;
#ifdef MEDIA175_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE8_01_FIX */
        F0212_PROJECTILE_Create(L0622_T_FirstProjectileAssociatedThing, L0626_i_MapX, L0627_i_MapY, L0628_ui_ProjectileCell, L0624_ui_Cell, L0630_i_KineticEnergy, 100, 0); /* BUG0_21 Projectiles created by launcher sensors never run out of kinetic energy and move until they impact something. Projectile launcher sensors have a step energy value defining how much kinetic energy is consumed with each step of movement of the projectiles they create. This value is ignored and 0 is always used so that such projectiles always move until they impact something (wall, creature or party) */
#endif
#ifdef MEDIA345_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_01_FIX Projectiles created by launcher sensors use the step energy value stored in the sensor instead of 0 */
        F0212_PROJECTILE_Create(L0622_T_FirstProjectileAssociatedThing, L0626_i_MapX, L0627_i_MapY, L0628_ui_ProjectileCell, L0624_ui_Cell, L0630_i_KineticEnergy, 100, L0631_i_StepEnergy);
#endif
        if (!L0632_B_LaunchSingleProjectile) {
#ifdef MEDIA175_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE8_01_FIX */
                F0212_PROJECTILE_Create(L0623_T_SecondProjectileAssociatedThing, L0626_i_MapX, L0627_i_MapY, M017_NEXT(L0628_ui_ProjectileCell), L0624_ui_Cell, L0630_i_KineticEnergy, 100, 0); /* BUG0_21 */
#endif
#ifdef MEDIA345_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_01_FIX Projectiles created by launcher sensors use the step energy value stored in the sensor instead of 0 */
                F0212_PROJECTILE_Create(L0623_T_SecondProjectileAssociatedThing, L0626_i_MapX, L0627_i_MapY, M017_NEXT(L0628_ui_ProjectileCell), L0624_ui_Cell, L0630_i_KineticEnergy, 100, L0631_i_StepEnergy);
#endif
        }
        G0365_B_CreateLauncherProjectile = C0_FALSE;
}

STATICFUNCTION void F0248_TIMELINE_ProcessEvent6_Square_Wall(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0524_ps_Event)
#endif
REGISTER EVENT* P0524_ps_Event FINAL_SEPARATOR
{
        REGISTER SENSOR* L0638_ps_Sensor;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        TEXTSTRING* L0639_ps_TextString;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER TEXTSTRING* L0639_ps_TextString;
        REGISTER unsigned int16_t L0637_ui_SensorData;
        REGISTER int16_t L0636_i_Multiple;
#endif
#define AL0636_B_TriggerSetEffect L0636_i_Multiple
#define AL0636_i_BitMask          L0636_i_Multiple
        REGISTER THING L0634_T_Thing;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register int16_t L0635_i_ThingType;
        register int16_t L0636_i_Multiple;
        register unsigned int16_t L0637_ui_SensorData;
        unsigned int16_t L0640_ui_SensorType;
        int16_t L0641_i_MapX;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0640_ui_SensorType;
        REGISTER int16_t L0641_i_MapX;
#endif
        int16_t L0642_i_MapY;
        unsigned int16_t L0643_ui_Cell;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0635_i_ThingType;
#endif


        L0634_T_Thing = F0161_DUNGEON_GetSquareFirstThing(L0641_i_MapX = P0524_ps_Event->B.Location.MapX, L0642_i_MapY = P0524_ps_Event->B.Location.MapY);
        L0643_ui_Cell = P0524_ps_Event->C.A.Cell;
        while (L0634_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                if (((L0635_i_ThingType = M012_TYPE(L0634_T_Thing)) == C02_THING_TYPE_TEXTSTRING) && (M011_CELL(L0634_T_Thing) == P0524_ps_Event->C.A.Cell)) {
                        L0639_ps_TextString = (TEXTSTRING*)F0156_DUNGEON_GetThingData(L0634_T_Thing);
                        if (P0524_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                                L0639_ps_TextString->Visible = !L0639_ps_TextString->Visible;
                        } else {
#ifdef PC_FIX_CODE_SIZE
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
#endif
                                L0639_ps_TextString->Visible = (P0524_ps_Event->C.A.Effect == C00_EFFECT_SET);
                        }
                } else {
                        if (L0635_i_ThingType == C03_THING_TYPE_SENSOR) {
                                L0638_ps_Sensor = (SENSOR*)F0156_DUNGEON_GetThingData(L0634_T_Thing);
                                L0640_ui_SensorType = M039_TYPE(L0638_ps_Sensor);
                                L0637_ui_SensorData = M040_DATA(L0638_ps_Sensor);
                                if (L0640_ui_SensorType == C006_SENSOR_WALL_COUNTDOWN) {
                                        if (L0637_ui_SensorData > 0) {
                                                if (P0524_ps_Event->C.A.Effect == C00_EFFECT_SET) {
                                                        if (L0637_ui_SensorData < 511) {
                                                                L0637_ui_SensorData++;
                                                        }
                                                } else {
                                                        L0637_ui_SensorData--;
                                                }
                                                M041_SET_DATA(L0638_ps_Sensor, L0637_ui_SensorData);
                                                if (L0638_ps_Sensor->Remote.Effect == C03_EFFECT_HOLD) {
                                                        AL0636_B_TriggerSetEffect = ((L0637_ui_SensorData == 0) != L0638_ps_Sensor->Remote.RevertEffect);
#ifdef PC_FIX_CODE_SIZE
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
#endif
                                                        F0272_SENSOR_TriggerEffect(L0638_ps_Sensor, AL0636_B_TriggerSetEffect ? C00_EFFECT_SET : C01_EFFECT_CLEAR, L0641_i_MapX, L0642_i_MapY, L0643_ui_Cell);
                                                } else {
                                                        if (L0637_ui_SensorData == 0) {
#ifdef PC_FIX_CODE_SIZE
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
#endif
                                                                F0272_SENSOR_TriggerEffect(L0638_ps_Sensor, L0638_ps_Sensor->Remote.Effect, L0641_i_MapX, L0642_i_MapY, L0643_ui_Cell);
                                                        }
                                                }
                                        }
                                } else {
                                        if (L0640_ui_SensorType == C005_SENSOR_WALL_AND_OR_GATE) {
                                                AL0636_i_BitMask = 1 << (P0524_ps_Event->C.A.Cell);
                                                if (P0524_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                                                        if (M007_GET(L0637_ui_SensorData, AL0636_i_BitMask)) {
                                                                M009_CLEAR(L0637_ui_SensorData, AL0636_i_BitMask);
                                                        } else {
                                                                M008_SET(L0637_ui_SensorData, AL0636_i_BitMask);
                                                        }
                                                } else {
                                                        if (P0524_ps_Event->C.A.Effect) {
#ifdef PC_FIX_CODE_SIZE
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
#endif
                                                                M009_CLEAR(L0637_ui_SensorData, AL0636_i_BitMask);
                                                        } else {
                                                                M008_SET(L0637_ui_SensorData, AL0636_i_BitMask);
                                                        }
                                                }
                                                M041_SET_DATA(L0638_ps_Sensor, L0637_ui_SensorData);
                                                AL0636_B_TriggerSetEffect = (M042_MASK_CURRENT(L0637_ui_SensorData) == M043_MASK_REFERENCE(L0637_ui_SensorData)) != L0638_ps_Sensor->Remote.RevertEffect;
                                                if (L0638_ps_Sensor->Remote.Effect == C03_EFFECT_HOLD) {
#ifdef PC_FIX_CODE_SIZE
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
        L0637_ui_SensorData++;
#endif
                                                        F0272_SENSOR_TriggerEffect(L0638_ps_Sensor, AL0636_B_TriggerSetEffect ? C00_EFFECT_SET : C01_EFFECT_CLEAR, L0641_i_MapX, L0642_i_MapY, L0643_ui_Cell);
                                                } else {
                                                        if (AL0636_B_TriggerSetEffect) {
                                                                F0272_SENSOR_TriggerEffect(L0638_ps_Sensor, L0638_ps_Sensor->Remote.Effect, L0641_i_MapX, L0642_i_MapY, L0643_ui_Cell);
                                                        }
                                                }
                                        } else {
                                                if ((((L0640_ui_SensorType >= C007_SENSOR_WALL_SINGLE_PROJECTILE_LAUNCHER_NEW_OBJECT) && (L0640_ui_SensorType <= C010_SENSOR_WALL_DOUBLE_PROJECTILE_LAUNCHER_EXPLOSION)) || (L0640_ui_SensorType == C014_SENSOR_WALL_SINGLE_PROJECTILE_LAUNCHER_SQUARE_OBJECT) || (L0640_ui_SensorType == C015_SENSOR_WALL_DOUBLE_PROJECTILE_LAUNCHER_SQUARE_OBJECT)) && (M011_CELL(L0634_T_Thing) == P0524_ps_Event->C.A.Cell)) {
                                                        F0247_TIMELINE_TriggerProjectileLauncher(L0638_ps_Sensor, P0524_ps_Event);
                                                        if (L0638_ps_Sensor->Remote.OnceOnly) {
                                                                M044_SET_TYPE_DISABLED(L0638_ps_Sensor);
                                                        }
#ifdef MEDIA278_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_21_IMPROVEMENT New floor sensor type: end game. The game ends immediately when this sensor is triggered */
                                                } else {
                                                        if (L0640_ui_SensorType == C018_SENSOR_WALL_END_GAME) {
#ifdef MEDIA671_F31E_F31J_P31J
                                                                F1012_PALETTE_SetCurtain(C0_BLACK_PALETTE);
                                                                F0694_SetMultipleColorsInPalette(G2100_i_BlackPaletteIndex);
#endif
#ifdef MEDIA692_X31J
                                                                F0436_STARTEND_FadeToPalette(G3087_aui_Palette_Blank);
#endif
#ifdef MEDIA347_S21E_X30J_P20JB_I34E_I34M_A36M /* CHANGE8_02_IMPROVEMENT The end game sensor now includes an optional delay before drawing the end of the game (not used in the original dungeon) */
                                                                F0022_MAIN_Delay(60 * L0638_ps_Sensor->Remote.Value);
#endif
#ifdef MEDIA277_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M
                                                                G0524_B_RestartGameAllowed = C0_FALSE;
#endif
                                                                G0302_B_GameWon = C1_TRUE;
#ifdef MEDIA629_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                                F0666_endgame();
#endif
#ifdef MEDIA277_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M
                                                                F0444_STARTEND_Endgame(C1_TRUE);
#endif
                                                        }
#endif
                                                }
                                        }
                                }
                        }
                }
                L0634_T_Thing = F0159_DUNGEON_GetNextThing(L0634_T_Thing);
        }
        F0271_SENSOR_ProcessRotationEffect();
}

/* This function moves all things on the specified square to the same location in order to apply the square effects when a teleporter or pit is open */
STATICFUNCTION void F0249_TIMELINE_MoveTeleporterOrPitSquareThings(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0525_ui_MapX, P0526_ui_MapY)
#endif
REGISTER unsigned int16_t P0525_ui_MapX SEPARATOR
REGISTER unsigned int16_t P0526_ui_MapY FINAL_SEPARATOR
{
#ifdef MEDIA224_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        REGISTER PROJECTILE* L0646_ps_Projectile;
#endif
        REGISTER EVENT* L0647_ps_Event;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER PROJECTILE* L0646_ps_Projectile;
        REGISTER THING L0645_T_Thing;
#endif
        REGISTER unsigned int16_t L0644_ui_Multiple;
#define AL0644_ui_ThingType  L0644_ui_Multiple
#define AL0644_ui_EventIndex L0644_ui_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register THING L0645_T_Thing;
        THING L0648_T_NextThing;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L0648_T_NextThing;
#endif
#ifdef MEDIA278_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_22_FIX */
        int16_t L0649_i_ThingsToMoveCount;
#endif


        if ((G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (P0525_ui_MapX == G0306_i_PartyMapX) && (P0526_ui_MapY == G0307_i_PartyMapY)) {
                F0267_MOVE_GetMoveResult_CPSCE(C0xFFFF_THING_PARTY, P0525_ui_MapX, P0526_ui_MapY, P0525_ui_MapX, P0526_ui_MapY);
                F0296_CHAMPION_DrawChangedObjectIcons();
        }
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_22_FIX */
        L0645_T_Thing = F0161_DUNGEON_GetSquareFirstThing(P0525_ui_MapX, P0526_ui_MapY);
        while (L0645_T_Thing != C0xFFFE_THING_ENDOFLIST) { /* BUG0_22 When a teleporter or pit opens, the game hangs or some things are not moved correctly. The program enters an infinite loop if there are at least two things on a closed teleporter or closed pit square and these things end up on the same square when the teleporter or pit opens. This occurs in these cases:
- On a teleporter square targetting itself if there are at least two things on the square when the teleporter is opened.
- On a pit square if there are at least two things levitating over the pit (two projectiles or one group and one projectile) when the pit is opened

Some things are not moved correctly if the list of things on the square contains a group followed by a projectile that impacts the group and then other things. When the group is processed, the projectile is removed from the list of things on the square. The loop then proceeds with the projectile that is now out of the linked list of things on the square, which breaks the loop */
                L0648_T_NextThing = F0159_DUNGEON_GetNextThing(L0645_T_Thing);
                AL0644_ui_ThingType = M012_TYPE(L0645_T_Thing);
                if (AL0644_ui_ThingType >= C04_THING_TYPE_GROUP) {
#endif
#ifdef MEDIA278_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_22_FIX Process the group before all the other things on the square in order to process potential projectile impacts that would remove things from the square (projectiles or the group itself if killed). Count the remaining things on the square to make sure each one is processed only once and thus avoid infinite loops */
        if ((L0645_T_Thing = F0175_GROUP_GetThing(P0525_ui_MapX, P0526_ui_MapY)) != C0xFFFE_THING_ENDOFLIST) {
                F0267_MOVE_GetMoveResult_CPSCE(L0645_T_Thing, P0525_ui_MapX, P0526_ui_MapY, P0525_ui_MapX, P0526_ui_MapY);
        }
        L0645_T_Thing = F0162_DUNGEON_GetSquareFirstObject(P0525_ui_MapX, P0526_ui_MapY);
        L0648_T_NextThing = L0645_T_Thing;
        L0649_i_ThingsToMoveCount = 0;
        while (L0645_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                if (M012_TYPE(L0645_T_Thing) > C04_THING_TYPE_GROUP) {
                        L0649_i_ThingsToMoveCount++;
                }
                L0645_T_Thing = F0159_DUNGEON_GetNextThing(L0645_T_Thing);
        }
        L0645_T_Thing = L0648_T_NextThing;
        while ((L0645_T_Thing != C0xFFFE_THING_ENDOFLIST) && L0649_i_ThingsToMoveCount) {
                L0649_i_ThingsToMoveCount--;
                L0648_T_NextThing = F0159_DUNGEON_GetNextThing(L0645_T_Thing);
                AL0644_ui_ThingType = M012_TYPE(L0645_T_Thing);
                if (AL0644_ui_ThingType > C04_THING_TYPE_GROUP) {
#endif
                        F0267_MOVE_GetMoveResult_CPSCE(L0645_T_Thing, P0525_ui_MapX, P0526_ui_MapY, P0525_ui_MapX, P0526_ui_MapY);
                }
                if (AL0644_ui_ThingType == C14_THING_TYPE_PROJECTILE) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        L0647_ps_Event = &G0370_ps_Events[((PROJECTILE*)G0284_apuc_ThingData[C14_THING_TYPE_PROJECTILE])[M013_INDEX(L0645_T_Thing)].EventIndex];
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        L0646_ps_Projectile = (PROJECTILE*)F0156_DUNGEON_GetThingData(L0645_T_Thing);
                        L0647_ps_Event = &G0370_ps_Events[L0646_ps_Projectile->EventIndex];
#endif
                        L0647_ps_Event->C.Projectile.MapX = G0397_i_MoveResultMapX;
                        L0647_ps_Event->C.Projectile.MapY = G0398_i_MoveResultMapY;
                        L0647_ps_Event->C.Projectile.Direction = G0400_i_MoveResultDirection;
                        L0647_ps_Event->B.Slot = M015_THING_WITH_NEW_CELL(L0645_T_Thing, G0401_ui_MoveResultCell);
                        M031_SET_MAP(L0647_ps_Event->Map_Time, G0399_ui_MoveResultMapIndex);
                } else {
                        if (AL0644_ui_ThingType == C15_THING_TYPE_EXPLOSION) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                for (AL0644_ui_EventIndex = 0, L0647_ps_Event = G0370_ps_Events; AL0644_ui_EventIndex < G0369_EventMaximumCount; L0647_ps_Event++, AL0644_ui_EventIndex++) {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                                L0647_ps_Event = G0370_ps_Events;
                                for (AL0644_ui_EventIndex = 0; AL0644_ui_EventIndex < G0369_EventMaximumCount; L0647_ps_Event++, AL0644_ui_EventIndex++) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                L0647_ps_Event = G0370_ps_Events;
                                for (AL0644_ui_EventIndex = 0; AL0644_ui_EventIndex < G2009_i_LargestUsedEventOrdinal; L0647_ps_Event++, AL0644_ui_EventIndex++) {
#endif
                                        if ((L0647_ps_Event->A.A.Type == C25_EVENT_EXPLOSION) && (L0647_ps_Event->C.Slot == L0645_T_Thing)) { /* BUG0_23 A Fluxcage explosion remains on a square forever. If you open a pit or teleporter on a square where there is a Fluxcage explosion, the Fluxcage explosion is moved but the associated event is not updated (because Fluxcage explosions do not use C25_EVENT_EXPLOSION but rather C24_EVENT_REMOVE_FLUXCAGE) causing the Fluxcage explosion to remain in the dungeon forever on its destination square. When the C24_EVENT_REMOVE_FLUXCAGE expires the explosion thing is not removed, but it is marked as unused. Consequently, any objects placed on the Fluxcage square after it was moved but before it expires become orphans upon expiration. After expiration, any object placed on the fluxcage square is cloned when picked up */
                                                L0647_ps_Event->B.Location.MapX = G0397_i_MoveResultMapX;
                                                L0647_ps_Event->B.Location.MapY = G0398_i_MoveResultMapY;
                                                L0647_ps_Event->C.Slot = M015_THING_WITH_NEW_CELL(L0645_T_Thing, G0401_ui_MoveResultCell);
                                                M031_SET_MAP(L0647_ps_Event->Map_Time, G0399_ui_MoveResultMapIndex);
                                        }
                                }
                        }
                }
                L0645_T_Thing = L0648_T_NextThing;
        }
}

STATICFUNCTION void F0250_TIMELINE_ProcessEvent8_Square_Teleporter(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0527_ps_Event)
#endif
REGISTER EVENT* P0527_ps_Event FINAL_SEPARATOR
{
        REGISTER unsigned char* L0652_puc_Square;
        REGISTER unsigned int16_t L0650_ui_MapX;
        REGISTER unsigned int16_t L0651_ui_MapY;


        L0652_puc_Square = &G0271_ppuc_CurrentMapData[L0650_ui_MapX = P0527_ps_Event->B.Location.MapX][L0651_ui_MapY = P0527_ps_Event->B.Location.MapY];
        if (P0527_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                P0527_ps_Event->C.A.Effect = M007_GET(*L0652_puc_Square, MASK0x0008_TELEPORTER_OPEN) ? C01_EFFECT_CLEAR : C00_EFFECT_SET;
        }
        if (P0527_ps_Event->C.A.Effect == C00_EFFECT_SET) {
                M008_SET(*L0652_puc_Square, MASK0x0008_TELEPORTER_OPEN);
                F0249_TIMELINE_MoveTeleporterOrPitSquareThings(L0650_ui_MapX, L0651_ui_MapY);
        } else {
                M009_CLEAR(*L0652_puc_Square, MASK0x0008_TELEPORTER_OPEN);
        }
}

STATICFUNCTION void F0251_TIMELINE_ProcessEvent9_Square_Pit(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0528_ps_Event) /* This function is identical to F0250_TIMELINE_ProcessEvent8_Square_Teleporter */
#endif
REGISTER EVENT* P0528_ps_Event FINAL_SEPARATOR
{
        REGISTER unsigned char* L0655_puc_Square;
        REGISTER unsigned int16_t L0653_ui_MapX;
        REGISTER unsigned int16_t L0654_ui_MapY;


        L0655_puc_Square = &G0271_ppuc_CurrentMapData[L0653_ui_MapX = P0528_ps_Event->B.Location.MapX][L0654_ui_MapY = P0528_ps_Event->B.Location.MapY];
        if (P0528_ps_Event->C.A.Effect == C02_EFFECT_TOGGLE) {
                P0528_ps_Event->C.A.Effect = M007_GET(*L0655_puc_Square, MASK0x0008_PIT_OPEN) ? C01_EFFECT_CLEAR : C00_EFFECT_SET;
        }
        if (P0528_ps_Event->C.A.Effect == C00_EFFECT_SET) {
                M008_SET(*L0655_puc_Square, MASK0x0008_PIT_OPEN);
                F0249_TIMELINE_MoveTeleporterOrPitSquareThings(L0653_ui_MapX, L0654_ui_MapY);
        } else {
                M009_CLEAR(*L0655_puc_Square, MASK0x0008_PIT_OPEN);
        }
}

STATICFUNCTION void F0252_TIMELINE_ProcessEvents60to61_MoveGroup(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0529_ps_Event)
#endif
REGISTER EVENT* P0529_ps_Event FINAL_SEPARATOR
{
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_07_FIX */
        REGISTER GROUP* L0658_ps_Group;
#endif
        REGISTER unsigned int16_t L0656_ui_MapX;
        REGISTER unsigned int16_t L0657_ui_MapY;
#ifdef MEDIA224_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE2_07_FIX */
        BOOLEAN L0659_B_RandomDirectionMoveRetried;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_07_FIX */
        REGISTER BOOLEAN L0659_B_RandomDirectionMoveRetried;
#endif


#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_07_FIX */
        L0659_B_RandomDirectionMoveRetried = C0_FALSE;
#endif
        L0656_ui_MapX = P0529_ps_Event->B.Location.MapX;
        L0657_ui_MapY = P0529_ps_Event->B.Location.MapY;
        T0252001:
        if (!((G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (L0656_ui_MapX == G0306_i_PartyMapX) && (L0657_ui_MapY == G0307_i_PartyMapY)) && (F0175_GROUP_GetThing(L0656_ui_MapX, L0657_ui_MapY) == C0xFFFE_THING_ENDOFLIST)) { /* BUG0_24 Lord Chaos may teleport into one of the Black Flames and become invisible until the Black Flame is killed. In this case, F0175_GROUP_GetThing returns the Black Flame thing and the Lord Chaos thing is not moved into the dungeon until the Black Flame is killed */
                if (P0529_ps_Event->A.A.Type == C61_EVENT_MOVE_GROUP_AUDIBLE) {
                        F0064_SOUND_RequestPlay_CPSD(M560_SOUND_BUZZ, L0656_ui_MapX, L0657_ui_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
                }
                F0267_MOVE_GetMoveResult_CPSCE(P0529_ps_Event->C.Slot, CM1_MAPX_NOT_ON_A_SQUARE, 0, L0656_ui_MapX, L0657_ui_MapY);
        } else {
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_07_FIX If the group to move is Lord Chaos and 1/4 chance then try to move to a random adjacent destination square. This additional code makes sure Lord Chaos is soon moved to an adjacent square */
                if (!L0659_B_RandomDirectionMoveRetried) {
                        L0659_B_RandomDirectionMoveRetried = C1_TRUE;
                        L0658_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(P0529_ps_Event->C.Slot);
                        if ((L0658_ps_Group->Type == C23_CREATURE_LORD_CHAOS) && !M004_RANDOM(4)) {
                                switch (M004_RANDOM(4)) {
                                        case 0:
                                                L0656_ui_MapX--;
                                                break;
                                        case 1:
                                                L0656_ui_MapX++;
                                                break;
                                        case 2:
                                                L0657_ui_MapY--;
                                                break;
                                        case 3:
                                                L0657_ui_MapY++;
                                }
                                if (F0223_GROUP_IsLordChaosAllowed(L0656_ui_MapX, L0657_ui_MapY))
                                        goto T0252001;
                        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                        goto T0252002;
#endif
                }
#endif
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                else {
#endif
                        T0252002:
                        P0529_ps_Event->Map_Time += 5;
                        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0529_ps_Event);
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                }
#endif
        }
}

STATICFUNCTION void F0253_TIMELINE_ProcessEvent11Part1_EnableChampionAction(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0530_ui_ChampionIndex)
#endif
REGISTER unsigned int16_t P0530_ui_ChampionIndex FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0662_ps_Champion;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register int16_t L0660_i_SlotIndex;
#endif
        REGISTER int16_t L0661_i_QuiverSlotIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0660_i_SlotIndex;
#endif


        L0662_ps_Champion = &M516_CHAMPIONS[P0530_ui_ChampionIndex];
        L0662_ps_Champion->EnableActionEventIndex = -1;
        M009_CLEAR(L0662_ps_Champion->Attributes, MASK0x0008_DISABLE_ACTION);
        if (L0662_ps_Champion->ActionIndex != C0xFF_ACTION_NONE) {
                L0662_ps_Champion->ActionDefense -= G0495_ac_Graphic560_ActionDefense[L0662_ps_Champion->ActionIndex];
        }
        if (L0662_ps_Champion->CurrentHealth) {
                if ((L0662_ps_Champion->ActionIndex == C032_ACTION_SHOOT) && (L0662_ps_Champion->Slots[C00_SLOT_READY_HAND] == C0xFFFF_THING_NONE)) {
                        if (F0294_CHAMPION_IsAmmunitionCompatibleWithWeapon(P0530_ui_ChampionIndex, C01_SLOT_ACTION_HAND, L0660_i_SlotIndex = C12_SLOT_QUIVER_LINE1_1)) {
                                T0253002:
                                F0301_CHAMPION_AddObjectInSlot(P0530_ui_ChampionIndex, F0300_CHAMPION_GetObjectRemovedFromSlot(P0530_ui_ChampionIndex, L0660_i_SlotIndex), C00_SLOT_READY_HAND);
                        } else {
                                for (L0661_i_QuiverSlotIndex = 0; L0661_i_QuiverSlotIndex < 3; L0661_i_QuiverSlotIndex++) {
                                        if (F0294_CHAMPION_IsAmmunitionCompatibleWithWeapon(P0530_ui_ChampionIndex, C01_SLOT_ACTION_HAND, L0660_i_SlotIndex = L0661_i_QuiverSlotIndex + C07_SLOT_QUIVER_LINE2_1))
                                                goto T0253002;
                                }
                        }
                }
                M008_SET(L0662_ps_Champion->Attributes, MASK0x8000_ACTION_HAND);
                F0292_CHAMPION_DrawState(P0530_ui_ChampionIndex);
        }
        L0662_ps_Champion->ActionIndex = C0xFF_ACTION_NONE;
}

STATICFUNCTION void F0254_TIMELINE_ProcessEvent12_HideDamageReceived(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0531_ui_ChampionIndex)
#endif
REGISTER unsigned int16_t P0531_ui_ChampionIndex FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0663_ps_Champion;


        L0663_ps_Champion = &M516_CHAMPIONS[P0531_ui_ChampionIndex];
        L0663_ps_Champion->HideDamageReceivedEventIndex = -1;
        if (!L0663_ps_Champion->CurrentHealth) {
                return;
        }
        if (M000_INDEX_TO_ORDINAL(P0531_ui_ChampionIndex) == G0423_i_InventoryChampionOrdinal) {
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                F0354_INVENTORY_DrawStatusBoxPortrait(P0531_ui_ChampionIndex);
                F0078_MOUSE_DisableScreenUpdate();
        } else {
                M008_SET(L0663_ps_Champion->Attributes, MASK0x0080_NAME_TITLE);
                F0292_CHAMPION_DrawState(P0531_ui_ChampionIndex);
        }
}

STATICFUNCTION void F0255_TIMELINE_ProcessEvent13_ViAltarRebirth(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0532_ps_Event)
#endif
REGISTER EVENT* P0532_ps_Event FINAL_SEPARATOR
{
        REGISTER JUNK* L0668_ps_Junk;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L0667_T_Thing;
#endif
        REGISTER int16_t L0664_i_MapX;
        REGISTER int16_t L0665_i_MapY;
        REGISTER unsigned int16_t L0666_ui_Cell;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER THING L0667_T_Thing;
        int16_t L0669_i_IconIndex;
        unsigned int16_t L0670_ui_Step;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0669_i_IconIndex;
#endif
        unsigned int16_t L0671_ui_ChampionIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        unsigned int16_t L0670_ui_Step;
#endif


        L0664_i_MapX = P0532_ps_Event->B.Location.MapX;
        L0665_i_MapY = P0532_ps_Event->B.Location.MapY;
        L0666_ui_Cell = P0532_ps_Event->C.A.Cell;
        L0671_ui_ChampionIndex = P0532_ps_Event->A.A.Priority;
        switch (L0670_ui_Step = P0532_ps_Event->C.A.Effect) { /* Rebirth is a 3 steps process (Step 2 -> Step 1 -> Step 0). Step is stored in the Effect value of the event */
                case 2:
                        F0213_EXPLOSION_Create(C0xFFE4_THING_EXPLOSION_REBIRTH_STEP1, 0, L0664_i_MapX, L0665_i_MapY, L0666_ui_Cell);
                        P0532_ps_Event->Map_Time += 5;
                        T0255002:
                        P0532_ps_Event->C.A.Effect = --L0670_ui_Step;
                        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0532_ps_Event);
                        break;
                case 1:
                        L0667_T_Thing = F0161_DUNGEON_GetSquareFirstThing(L0664_i_MapX, L0665_i_MapY);
                        while (L0667_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                                if ((M011_CELL(L0667_T_Thing) == L0666_ui_Cell) && (M012_TYPE(L0667_T_Thing) == C10_THING_TYPE_JUNK)) {
                                        L0669_i_IconIndex = F0033_OBJECT_GetIconIndex(L0667_T_Thing);
                                        if (L0669_i_IconIndex == C147_ICON_JUNK_CHAMPION_BONES) {
                                                L0668_ps_Junk = (JUNK*)F0156_DUNGEON_GetThingData(L0667_T_Thing);
                                                if (L0668_ps_Junk->ChargeCount == L0671_ui_ChampionIndex) {
                                                        F0164_DUNGEON_UnlinkThingFromList(L0667_T_Thing, 0, L0664_i_MapX, L0665_i_MapY); /* BUG0_25 When a champion dies, no bones object is created so it is not possible to bring the champion back to life at an altar of Vi. Each time a champion is brought back to life, the bones object is removed from the dungeon but it is not marked as unused and thus becomes an orphan. After a large number of champion deaths, all JUNK things are exhausted and the game cannot create any more. This also affects the creation of JUNK things dropped by some creatures when they die (Screamer, Rockpile, Magenta Worm, Pain Rat, Red Dragon) */
#ifdef MEDIA346_S21E_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_03_FIX Mark the thing data as unused so it is not orphaned anymore */
                                                        L0668_ps_Junk->Next = C0xFFFF_THING_NONE;
#endif
                                                        P0532_ps_Event->Map_Time++;
                                                        goto T0255002;
                                                }
                                        }
                                }
                                L0667_T_Thing = F0159_DUNGEON_GetNextThing(L0667_T_Thing);
                        }
                        break;
                case 0:
                        F0283_CHAMPION_ViAltarRebirth(P0532_ps_Event->A.A.Priority);
        }
}

#ifdef MEDIA072_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
STATICFUNCTION void F0256_TIMELINE_ProcessEvent53_Watchdog_CPSE(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        EVENT L0672_s_Event;


        L0672_s_Event.A.A.Type = C53_EVENT_WATCHDOG;
        L0672_s_Event.Map_Time = G0374_l_WatchdogTime_CPSE = G0313_ul_GameTime + 300;
        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0672_s_Event);
}
#endif
#endif

STATICFUNCTION void F0257_TIMELINE_ProcessEvent70_Light(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0534_ps_Event)
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
REGISTER EVENT* P0534_ps_Event FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
EVENT*          P0534_ps_Event FINAL_SEPARATOR
#endif
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        EVENT L0676_s_Event;
        REGISTER int16_t L0673_i_WeakerLightPower;
#endif
        REGISTER int16_t L0674_i_Multiple;
#define AL0674_i_LightPower  L0674_i_Multiple
#define AL0674_i_LightAmount L0674_i_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0673_i_WeakerLightPower;
#endif
        REGISTER BOOLEAN L0675_B_NegativeLightPower;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        EVENT L0676_s_Event;
#endif


        if ((AL0674_i_LightPower = P0534_ps_Event->B.LightPower) == 0) {
                return;
        }
        if (L0675_B_NegativeLightPower = (AL0674_i_LightPower < 0)) {
                AL0674_i_LightPower = -AL0674_i_LightPower;
        }
        L0673_i_WeakerLightPower = AL0674_i_LightPower - 1;
        AL0674_i_LightAmount = G0039_ai_Graphic562_LightPowerToLightAmount[AL0674_i_LightPower] - G0039_ai_Graphic562_LightPowerToLightAmount[L0673_i_WeakerLightPower];
        if (L0675_B_NegativeLightPower) {
                AL0674_i_LightAmount = -AL0674_i_LightAmount;
                L0673_i_WeakerLightPower = -L0673_i_WeakerLightPower;
        }
        G0407_s_Party.MagicalLightAmount += AL0674_i_LightAmount;
        if (L0673_i_WeakerLightPower) {
                L0676_s_Event.A.A.Type = C70_EVENT_LIGHT;
                L0676_s_Event.B.LightPower = L0673_i_WeakerLightPower;
                M033_SET_MAP_AND_TIME(L0676_s_Event.Map_Time, G0309_i_PartyMapIndex, G0313_ul_GameTime + 4);
                L0676_s_Event.A.A.Priority = 0;
                F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0676_s_Event);
        }
}

STATICFUNCTION BOOLEAN F0258_TIMELINE_HasWeaponMovedToSlot(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0535_i_ChampionIndex, P0536_ps_Champion, P0537_ui_SourceSlotIndex, P0538_i_DestinationSlotIndex)
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
REGISTER int16_t          P0535_i_ChampionIndex        SEPARATOR
REGISTER CHAMPION*        P0536_ps_Champion            SEPARATOR
REGISTER unsigned int16_t P0537_ui_SourceSlotIndex     SEPARATOR
REGISTER int16_t          P0538_i_DestinationSlotIndex FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t                   P0535_i_ChampionIndex        SEPARATOR
CHAMPION*                 P0536_ps_Champion            SEPARATOR
unsigned int16_t          P0537_ui_SourceSlotIndex     SEPARATOR
int16_t                   P0538_i_DestinationSlotIndex FINAL_SEPARATOR
#endif
{
        if (M012_TYPE(P0536_ps_Champion->Slots[P0537_ui_SourceSlotIndex]) == C05_THING_TYPE_WEAPON) {
                F0301_CHAMPION_AddObjectInSlot(P0535_i_ChampionIndex, F0300_CHAMPION_GetObjectRemovedFromSlot(P0535_i_ChampionIndex, P0537_ui_SourceSlotIndex), P0538_i_DestinationSlotIndex);
                return C1_TRUE;
        }
        return C0_FALSE;
}

STATICFUNCTION void F0259_TIMELINE_ProcessEvent11Part2_MoveWeaponFromQuiverToSlot(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0539_ui_ChampionIndex, P0540_ui_SlotIndex)
#endif
REGISTER unsigned int16_t P0539_ui_ChampionIndex SEPARATOR
REGISTER unsigned int16_t P0540_ui_SlotIndex     FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0678_ps_Champion;
        REGISTER unsigned int16_t L0677_ui_SlotIndex;


        L0678_ps_Champion = &M516_CHAMPIONS[P0539_ui_ChampionIndex];
        if (L0678_ps_Champion->Slots[P0540_ui_SlotIndex] != C0xFFFF_THING_NONE)
                return;
        if (F0258_TIMELINE_HasWeaponMovedToSlot(P0539_ui_ChampionIndex, L0678_ps_Champion, C12_SLOT_QUIVER_LINE1_1, P0540_ui_SlotIndex)) {
                return;
        }
        for (L0677_ui_SlotIndex = C07_SLOT_QUIVER_LINE2_1; L0677_ui_SlotIndex <= C09_SLOT_QUIVER_LINE2_2; L0677_ui_SlotIndex++) {
                if (F0258_TIMELINE_HasWeaponMovedToSlot(P0539_ui_ChampionIndex, L0678_ps_Champion, L0677_ui_SlotIndex, P0540_ui_SlotIndex))
                        break;
        }
}

#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
void F0260_TIMELINE_RefreshAllChampionStatusBoxes(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER unsigned int16_t L0679_ui_ChampionIndex;


        for (L0679_ui_ChampionIndex = C00_CHAMPION_FIRST; L0679_ui_ChampionIndex < G0305_ui_PartyChampionCount; L0679_ui_ChampionIndex++) {
                M008_SET(M516_CHAMPIONS[L0679_ui_ChampionIndex].Attributes, MASK0x1000_STATUS_BOX);
        }
        F0293_CHAMPION_DrawAllChampionStates();
}
#endif

void F0261_TIMELINE_Process_CPSEF(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER EVENT* L0681_ps_Event;
        REGISTER unsigned int16_t L0680_ui_Multiple;
#define AL0680_ui_EventType     L0680_ui_Multiple
#define AL0680_ui_ChampionIndex L0680_ui_Multiple
        EVENT L0682_s_Event;


        while (F0240_TIMELINE_IsFirstEventExpired_CPSE()) {
                L0681_ps_Event = &L0682_s_Event;
                F0239_TIMELINE_ExtractFirstEvent(L0681_ps_Event);
                F0173_DUNGEON_SetCurrentMap(M029_MAP(L0682_s_Event.Map_Time));
#ifdef MEDIA153_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
                if (G0319_ul_LoadGameTime <= G0313_ul_GameTime) { /* This condition is always true */
#endif
#endif
                        AL0680_ui_EventType = L0682_s_Event.A.A.Type;
#ifdef MEDIA153_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
                }
#endif
#endif
                if ((AL0680_ui_EventType > (C29_EVENT_GROUP_REACTION_DANGER_ON_SQUARE - 1)) && (AL0680_ui_EventType < (C41_EVENT_UPDATE_BEHAVIOR_CREATURE_3 + 1))) {
                        F0209_GROUP_ProcessEvents29to41(L0682_s_Event.B.Location.MapX, L0682_s_Event.B.Location.MapY, AL0680_ui_EventType, L0682_s_Event.C.Ticks);
                } else {
                        switch (AL0680_ui_EventType) {
                                case C48_EVENT_MOVE_PROJECTILE_IGNORE_IMPACTS:
                                case C49_EVENT_MOVE_PROJECTILE:
                                        F0219_PROJECTILE_ProcessEvents48To49_Projectile(L0681_ps_Event);
                                        break;
                                case C01_EVENT_DOOR_ANIMATION:
                                        F0241_TIMELINE_ProcessEvent1_DoorAnimation(L0681_ps_Event);
                                        break;
                                case C25_EVENT_EXPLOSION:
                                        F0220_EXPLOSION_ProcessEvent25_Explosion(L0681_ps_Event);
                                        break;
                                case C07_EVENT_FAKEWALL:
                                        F0242_TIMELINE_ProcessEvent7_Square_FakeWall(L0681_ps_Event);
                                        break;
                                case C02_EVENT_DOOR_DESTRUCTION:
                                        F0243_TIMELINE_ProcessEvent2_DoorDestruction(L0681_ps_Event);
                                        break;
                                case C10_EVENT_DOOR:
                                        F0244_TIMELINE_ProcessEvent10_Square_Door(L0681_ps_Event);
                                        break;
                                case C09_EVENT_PIT:
                                        F0251_TIMELINE_ProcessEvent9_Square_Pit(L0681_ps_Event);
                                        break;
                                case C08_EVENT_TELEPORTER:
                                        F0250_TIMELINE_ProcessEvent8_Square_Teleporter(L0681_ps_Event);
                                        break;
                                case C06_EVENT_WALL:
                                        F0248_TIMELINE_ProcessEvent6_Square_Wall(L0681_ps_Event);
                                        break;
                                case C05_EVENT_CORRIDOR:
                                        F0245_TIMELINE_ProcessEvent5_Square_Corridor(L0681_ps_Event);
                                        break;
                                case C60_EVENT_MOVE_GROUP_SILENT:
                                case C61_EVENT_MOVE_GROUP_AUDIBLE:
                                        F0252_TIMELINE_ProcessEvents60to61_MoveGroup(L0681_ps_Event);
                                        break;
                                case C65_EVENT_ENABLE_GROUP_GENERATOR:
                                        F0246_TIMELINE_ProcessEvent65_EnableGroupGenerator(L0681_ps_Event);
                                        break;
                                case C20_EVENT_PLAY_SOUND:
                                        F0064_SOUND_RequestPlay_CPSD(L0682_s_Event.C.SoundIndex, L0682_s_Event.B.Location.MapX, L0682_s_Event.B.Location.MapY, C01_MODE_PLAY_IF_PRIORITIZED);
                                        break;
                                case C24_EVENT_REMOVE_FLUXCAGE:
                                        if (!G0302_B_GameWon) {
                                                F0164_DUNGEON_UnlinkThingFromList(L0682_s_Event.C.Slot, 0, L0682_s_Event.B.Location.MapX, L0682_s_Event.B.Location.MapY);
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_02_OPTIMIZATION Inline code replaced by function calls */
                                                ((EXPLOSION*)G0284_apuc_ThingData[C15_THING_TYPE_EXPLOSION])[M013_INDEX(L0682_s_Event.C.Slot)].Next = C0xFFFF_THING_NONE;
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_02_OPTIMIZATION Inline code replaced by function calls */
                                                L0681_ps_Event = (EVENT*)F0156_DUNGEON_GetThingData(L0682_s_Event.C.Slot);
                                                ((EXPLOSION*)L0681_ps_Event)->Next = C0xFFFF_THING_NONE;
#endif
                                        }
                                        break;
#ifdef MEDIA067_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
                                case C22_EVENT_CPSE:
                                        if (!F0210_CPSE_ProcessEvent22_IsFuzzySectorValid_NormalBytes(M517_FuzzySectorReadingBuffer_CPSE)) {
                                                G0022_i_Graphic562_IndirectStopExpiringEvent_CPSE = C00136_TRUE;
                                        }
                                        break;
#endif
#endif
                                case C11_EVENT_ENABLE_CHAMPION_ACTION:
                                        F0253_TIMELINE_ProcessEvent11Part1_EnableChampionAction(L0682_s_Event.A.A.Priority);
                                        if (L0682_s_Event.B.SlotOrdinal) {
                                                F0259_TIMELINE_ProcessEvent11Part2_MoveWeaponFromQuiverToSlot(L0682_s_Event.A.A.Priority, M001_ORDINAL_TO_INDEX(L0682_s_Event.B.SlotOrdinal));
                                        }
                                        goto T0261048;
                                case C12_EVENT_HIDE_DAMAGE_RECEIVED:
                                        F0254_TIMELINE_ProcessEvent12_HideDamageReceived(L0682_s_Event.A.A.Priority);
                                        break;
#ifdef MEDIA072_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
                                case C53_EVENT_WATCHDOG:
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                        F0256_TIMELINE_ProcessEvent53_Watchdog_CPSE(L0681_ps_Event); /* BUG0_01 Coding error without consequence. Function call with wrong number of parameters. It should be called with 0 parameters. No consequence because additional parameters are ignored */
#endif
#ifdef MEDIA596_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                                        F0256_TIMELINE_ProcessEvent53_Watchdog_CPSE();
#endif
                                        break;
#endif
#endif
                                case C70_EVENT_LIGHT:
                                        F0173_DUNGEON_SetCurrentMap(G0309_i_PartyMapIndex);
                                        F0257_TIMELINE_ProcessEvent70_Light(L0681_ps_Event);
                                        F0337_INVENTORY_SetDungeonViewPalette();
                                        break;
                                case C71_EVENT_INVISIBILITY:
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
                                        --G0407_s_Party.Event71Count_Invisibility;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                        if (!(--G0407_s_Party.Event71Count_Invisibility)) {
                                                if (G0423_i_InventoryChampionOrdinal) {
                                                        M008_SET(M516_CHAMPIONS[M001_ORDINAL_TO_INDEX(G0423_i_InventoryChampionOrdinal)].Attributes, MASK0x1000_STATUS_BOX);
                                                }
                                                F0293_CHAMPION_DrawAllChampionStates(MASK0x0400_ICON);
                                        }
#endif
                                        break;
                                case C72_EVENT_CHAMPION_SHIELD:
                                        M516_CHAMPIONS[L0682_s_Event.A.A.Priority].ShieldDefense -= L0682_s_Event.B.Defense;
                                        M008_SET(M516_CHAMPIONS[L0682_s_Event.A.A.Priority].Attributes, MASK0x1000_STATUS_BOX);
                                        T0261048:
                                        F0292_CHAMPION_DrawState(L0682_s_Event.A.A.Priority);
                                        break;
                                case C73_EVENT_THIEVES_EYE:
                                        --G0407_s_Party.Event73Count_ThievesEye;
                                        break;
                                case C74_EVENT_PARTY_SHIELD:
                                        G0407_s_Party.ShieldDefense -= L0682_s_Event.B.Defense;
                                        T0261053:
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
                                        F0260_TIMELINE_RefreshAllChampionStatusBoxes();
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                        F0293_CHAMPION_DrawAllChampionStates(MASK0x1000_STATUS_BOX);
#endif
                                        break;
                                case C77_EVENT_SPELLSHIELD:
                                        G0407_s_Party.SpellShieldDefense -= L0682_s_Event.B.Defense;
                                        goto T0261053;
                                case C78_EVENT_FIRESHIELD:
                                        G0407_s_Party.FireShieldDefense -= L0682_s_Event.B.Defense;
                                        goto T0261053;
                                case C75_EVENT_POISON_CHAMPION:
                                        M516_CHAMPIONS[AL0680_ui_ChampionIndex = L0682_s_Event.A.A.Priority].PoisonEventCount--;
                                        F0322_CHAMPION_Poison(AL0680_ui_ChampionIndex, L0682_s_Event.B.Attack);
                                        break;
                                case C13_EVENT_VI_ALTAR_REBIRTH:
                                        F0255_TIMELINE_ProcessEvent13_ViAltarRebirth(L0681_ps_Event);
                                        break;
                                case C79_EVENT_FOOTPRINTS:
                                        --G0407_s_Party.Event79Count_Footprints;
                                        break;
#ifdef MEDIA629_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                case C80_EVENT_MAGIC_MAP:
                                        M516_CHAMPIONS[L0682_s_Event.A.A.Priority].MagicMapWizardSpellCount--;
                                        break;
                                case C81_EVENT_MAGIC_MAP:
                                        M516_CHAMPIONS[L0682_s_Event.A.A.Priority].MagicMapNinjaSpellCount--;
                                        break;
                                case C82_EVENT_MAGIC_MAP:
                                        M516_CHAMPIONS[L0682_s_Event.A.A.Priority].MagicMapFighterSpellCount--;
                                        break;
                                case C83_EVENT_MAGIC_MAP:
                                        M516_CHAMPIONS[L0682_s_Event.A.A.Priority].MagicMapPriestSpellDirectionOrdinal = 0;
                                case  3:
                                case  4:
                                case 14:
                                case 15:
                                case 16:
                                case 17:
                                case 18:
                                case 19:
                                case 21:
                                case 23:
                                case 26:
                                case 27:
                                case 28:
                                case 29:
                                case 30:
                                case 31:
                                case 32:
                                case 33:
                                case 34:
                                case 35:
                                case 36:
                                case 37:
                                case 38:
                                case 39:
                                case 40:
                                case 41:
                                case 42:
                                case 43:
                                case 44:
                                case 45:
                                case 46:
                                case 47:
                                case 50:
                                case 51:
                                case 52:
                                case 54:
                                case 55:
                                case 56:
                                case 57:
                                case 58:
                                case 59:
                                case 62:
                                case 63:
                                case 64:
                                case 66:
                                case 67:
                                case 68:
                                case 69:
                                case 76:
                                        break;
#endif
                        }
                }
                F0173_DUNGEON_SetCurrentMap(G0309_i_PartyMapIndex);
        }
}

#ifdef MEDIA423_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#include "COPYPRO6.C"
#endif
#endif
