#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 MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "start"
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
segment "start"
#endif

#ifdef MEDIA458_P20JA_P20JB
#ifndef NOCOPYPROTECTION
int16_t G0068_i_CheckLastEvent22Time_CPSE = C00512_FALSE;
#endif
#endif
#ifdef MEDIA707_I34E_I34M
int16_t G0587_i_HideMousePointerRequestCount = 1;
int16_t G0588_i_MouseButtonsStatus;
BOOLEAN G0592_B_BuildMousePointerScreenAreaRequested; /* Unused */
BOOLEAN G0597_B_IgnoreMouseMovements;
BOOLEAN G0598_B_MousePointerBitmapUpdated = C1_TRUE;
unsigned int16_t G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap; /* If non zero then the mouse pointer bitmap is a champion icon */
BOOLEAN G0600_B_UseObjectAsMousePointerBitmap; /* If true and G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap = 0 then the mouse pointer bitmap is an object icon */
BOOLEAN G0601_B_UseHandAsMousePointerBitmap; /* If true and G0600_B_UseObjectAsMousePointerBitmap = C0_FALSE and G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap = 0 then the mouse pointer bitmap is the hand else it is the arrow */
int16_t G2194_Unreferenced = 0;
/* String " " in F0444_STARTEND_Endgame */
char G2205_Unreferenced[8]; /* One of these two unreferenced variables probably corresponds to G0593_ to G0596_ which are unused in D34E_D34M */
char G2206_Unreferenced[8];
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
jmp_buf G2023_jmp_buf; /* 44 bytes on Amiga / X68000 (THINK C), 20 bytes on PC-98/PC (Turbo C/Turbo C++) */
#endif
#ifdef MEDIA709_I34E_I34M_P31J
char G2207_Unreferenced[24]; /* PC/PC-98 versions use the same buffer size of 44 but only the first 20 bytes are actually used. Can probably be replaced by: long G2023_jmp_buf[11]; */
#endif


#ifdef MEDIA129_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
STATICFUNCTION void F0443_STARTEND_EndgamePrintString(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0852_i_X, P0853_i_Y, P0854_i_TextColor, P0855_pc_String)
#endif
int16_t        P0852_i_X         SEPARATOR
int16_t        P0853_i_Y         SEPARATOR
int16_t        P0854_i_TextColor SEPARATOR
REGISTER char* P0855_pc_String   FINAL_SEPARATOR
{
        REGISTER char* L1407_pc_Character;
        char L1408_ac_ModifiedString[50];


        L1407_pc_Character = L1408_ac_ModifiedString;
        while (*L1407_pc_Character = *P0855_pc_String++) {
                if ((*L1407_pc_Character >= 'A') && (*L1407_pc_Character <= 'Z')) {
                        *L1407_pc_Character -= 64; /* Use the same font as the one used for scrolls */
                }
                L1407_pc_Character++;
        }
        F0053_TEXT_PrintToLogicalScreen(P0852_i_X, P0853_i_Y, P0854_i_TextColor, C12_COLOR_DARKEST_GRAY, M772_CAST_PC(L1408_ac_ModifiedString));
}
#endif

#ifdef MEDIA582_X30J_P20JA_P20JB_A31E_F31E_F31J_X31J_P31J
#include "DARKCOLR.C"
#endif

#ifdef MEDIA755_A36M_A31M_A33M_A35E_A35M
void F1011_(
int16_t           P2935_ZoneIndex SEPARATOR
char*             P2936_String    SEPARATOR
register int16_t* P2937_          FINAL_SEPARATOR
{
        int16_t L2559_i_Width;
        int16_t L2560_i_Height;
        int16_t L2561_ai_XYZ[4];


        if (F0645_GetStringPixelDimensions(P2936_String, &L2559_i_Width, &L2560_i_Height)) {
                F0635_(NULL, L2561_ai_XYZ, P2935_ZoneIndex, &L2559_i_Width, &L2560_i_Height);
                F0628_AddZoneMargin(L2561_ai_XYZ, G3043_ + G3045_, G3044_ + G3046_);
                F0732_FillScreenArea(L2561_ai_XYZ, C01_COLOR_DARK_GRAY);
                F0628_AddZoneMargin(L2561_ai_XYZ, -G3045_, -G3046_);
                F0732_FillScreenArea(L2561_ai_XYZ, C00_COLOR_BLACK);
                F0650_PrintCenteredTextToScreenZone(P2935_ZoneIndex, C04_COLOR_CYAN, C00_COLOR_BLACK, P2936_String);
                P2937_[1] = M704_ZONE_LEFT(L2561_ai_XYZ);
                P2937_[2] = M705_ZONE_RIGHT(L2561_ai_XYZ);
                P2937_[3] = M706_ZONE_TOP(L2561_ai_XYZ);
                P2937_[4] = M707_ZONE_BOTTOM(L2561_ai_XYZ);
        }
}
#endif

void F0444_STARTEND_Endgame(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0856_B_DoNotDrawCreditsOnly)
BOOLEAN P0856_B_DoNotDrawCreditsOnly FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER BOOLEAN P0856_B_DoNotDrawCreditsOnly FINAL_SEPARATOR
#endif
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned char* L1413_puc_TemporaryBuffer;
        REGISTER unsigned char* L1414_puc_Bitmap_TheEnd;
        REGISTER int16_t L1409_i_Multiple;
        REGISTER int16_t L1410_i_Multiple;
        REGISTER int16_t L1411_i_Multiple;
        REGISTER int16_t L1412_i_SkillLevel;
        char L1415_c_ChampionTitleFirstCharacter;
        CHAMPION* L1416_ps_Champion;
#endif
#ifdef MEDIA548_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        REGISTER unsigned char* L1413_puc_TemporaryBuffer;
#endif
#ifdef MEDIA528_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        REGISTER CHAMPION* L1416_ps_Champion;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned char* L1414_puc_Bitmap_TheEnd;
        REGISTER int16_t L1409_i_Multiple;
#endif
#define AL1409_i_Color              L1409_i_Multiple
#define AL1409_i_ChampionIndex      L1409_i_Multiple
#define AL1409_i_VerticalBlankCount L1409_i_Multiple
#ifdef MEDIA528_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        unsigned char* L1418_puc_Bitmap_ChampionMirror;
#endif
#ifdef MEDIA548_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        REGISTER int16_t L1411_i_Multiple;
#endif
#ifdef MEDIA528_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        REGISTER int16_t L1410_i_Multiple;
#endif
#define AL1410_i_Counter L1410_i_Multiple
#define AL1410_i_Y       L1410_i_Multiple
#ifdef MEDIA462_P20JA_P20JB_I34E_I34M
        REGISTER int16_t L1411_i_Multiple;
#endif
#define AL1411_i_X          L1411_i_Multiple
#define AL1411_i_SkillIndex L1411_i_Multiple
#ifdef MEDIA528_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        REGISTER char L1415_c_ChampionTitleFirstCharacter;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        BOOLEAN L1423_B_WaitBeforeDrawingRestart;
#endif
#ifdef MEDIA533_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
        REGISTER int16_t L1412_i_SkillLevel;
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        unsigned char* L1417_puc_Graphic_Credits;
#endif
#ifdef MEDIA458_P20JA_P20JB
        long L2562_l_TheEnd_BitmapByteCount;
#endif
#ifdef MEDIA630_A31E_A31M_A33M_A35E_A35M_X31J
        int16_t L2563_i_Unreferenced;
#endif
#ifdef MEDIA498_F20E_F20J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        long L2564_l_ByteCount;
#endif
#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
        unsigned char* L1417_puc_Graphic_Credits;
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned char* L1418_puc_Bitmap_ChampionMirror;
#endif
#ifdef MEDIA078_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
        unsigned int16_t L1419_aui_Palette[16];
#endif
#ifdef MEDIA085_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
        unsigned int16_t L1420_aui_Palette_TopAndBottomScreen[16];
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        char L1422_ac_String[20];
#endif
#ifdef MEDIA078_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
        unsigned int16_t L1421_aui_Palette_DarkBlue[16];
#endif
#ifdef MEDIA037_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_F31E_F31J_X31J
        char L1422_ac_String[20];
#endif
#ifdef MEDIA517_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J_X31J_P31J
        unsigned char* L2565_puc_;
#endif
#ifdef MEDIA516_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J_P31J
        unsigned int16_t L2566_;
#endif
#ifdef MEDIA692_X31J
        unsigned long L2566_;
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned char* L1651_puc_Bitmap_Portrait_ChipMemory;
#endif
#ifdef MEDIA287_S20E_S21E_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE7_37_IMPROVEMENT */
        BOOLEAN L1423_B_WaitBeforeDrawingRestart;
#endif


#ifdef MEDIA291_S20E_S21E_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_37_IMPROVEMENT */
        L1423_B_WaitBeforeDrawingRestart = C1_TRUE;
#endif
        F0067_MOUSE_SetPointerToNormal(C0_POINTER_ARROW);
#ifdef MEDIA410_A20ED
        F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
#ifdef MEDIA093_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        M522_MOUSE_HidePointer();
#endif
        G0441_ps_PrimaryMouseInput = NULL;
        G0442_ps_SecondaryMouseInput = NULL;
        G0443_ps_PrimaryKeyboardInput = NULL;
        G0444_ps_SecondaryKeyboardInput = NULL;
        if (P0856_B_DoNotDrawCreditsOnly && !G0302_B_GameWon) {
                F0064_SOUND_RequestPlay_CPSD(M561_SOUND_SCREAM, G0306_i_PartyMapX, G0307_i_PartyMapY, C00_MODE_PLAY_IMMEDIATELY);
                F0022_MAIN_Delay(240);
        }
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
        F0428_DIALOG_RequireGameDiskInDrive_NoDialogDrawn(C0_DO_NOT_FORCE_DIALOG_DM_CSB, C0_FALSE);
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0428_DIALOG_RequireGameDiskInDrive_NoDialogDrawn(C0_DO_NOT_FORCE_DIALOG_DM_CSB);
#endif
        F0477_MEMORY_OpenGraphicsDat_CPSDF();
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L1413_puc_TemporaryBuffer = G0700_puc_Bitmap_WallSet_Wall_D1LCR;
#endif
#ifdef MEDIA506_F20E_F20J_X30J
        L1413_puc_TemporaryBuffer = F0631_GetBitmapPointer(G3013_i_WallSet_Wall_D1C);
#endif
        if (P0856_B_DoNotDrawCreditsOnly) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                L1414_puc_Bitmap_TheEnd = L1413_puc_TemporaryBuffer;
                L1413_puc_TemporaryBuffer += M075_BITMAP_BYTE_COUNT(80, 14);
#endif
#ifdef MEDIA458_P20JA_P20JB
                L2562_l_TheEnd_BitmapByteCount = M103_BITMAP_BYTE_COUNT(G2005_GraphicWidthHeight[C006_GRAPHIC_THE_END].Width, G2005_GraphicWidthHeight[C006_GRAPHIC_THE_END].Height);
                L1414_puc_Bitmap_TheEnd = F0468_MEMORY_Allocate(L2562_l_TheEnd_BitmapByteCount, MASK0x8000_ALLOCATE_BITMAP | C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
#endif
#ifdef MEDIA506_F20E_F20J_X30J
                L1414_puc_Bitmap_TheEnd = L1413_puc_TemporaryBuffer + 4;
#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
                F0490_MEMORY_LoadDecompressAndExpandGraphic(C006_GRAPHIC_THE_END, L1414_puc_Bitmap_TheEnd, 0, 0);
#endif
#ifdef MEDIA506_F20E_F20J_X30J
                L1413_puc_TemporaryBuffer += F0653_GetBitmapByteCount(L1414_puc_Bitmap_TheEnd) + 4;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                L1414_puc_Bitmap_TheEnd = F0763_LoadEndgameBitmapExpanded(C006_GRAPHIC_THE_END);
#endif
#ifdef MEDIA129_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
                if (G0302_B_GameWon) {
#ifdef MEDIA117_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
                        L1418_puc_Bitmap_ChampionMirror = L1413_puc_TemporaryBuffer;
                        L1413_puc_TemporaryBuffer += M075_BITMAP_BYTE_COUNT(64, 43);
#endif
#ifdef MEDIA458_P20JA_P20JB
                        L1418_puc_Bitmap_ChampionMirror = F0468_MEMORY_Allocate(M103_BITMAP_BYTE_COUNT(G2005_GraphicWidthHeight[C208_GRAPHIC_WALL_ORNAMENT_43_CHAMPION_MIRROR].Width, G2005_GraphicWidthHeight[C208_GRAPHIC_WALL_ORNAMENT_43_CHAMPION_MIRROR].Height), MASK0x8000_ALLOCATE_BITMAP | C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
#endif
#ifdef MEDIA506_F20E_F20J_X30J
                        L1418_puc_Bitmap_ChampionMirror = L1413_puc_TemporaryBuffer + 4;
#endif
#ifdef MEDIA123_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
                        F0490_MEMORY_LoadDecompressAndExpandGraphic(C208_GRAPHIC_WALL_ORNAMENT_43_CHAMPION_MIRROR, L1418_puc_Bitmap_ChampionMirror, 0, 0);
#endif
#ifdef MEDIA506_F20E_F20J_X30J
                        L1413_puc_TemporaryBuffer += F0653_GetBitmapByteCount(L1418_puc_Bitmap_ChampionMirror) + 4;
#endif
#ifdef MEDIA726_I34E_I34M_A36M_F31E_F31J
                        L1418_puc_Bitmap_ChampionMirror = F0763_LoadEndgameBitmapExpanded(C346_GRAPHIC_WALL_ORNAMENT_43_CHAMPION_MIRROR);
#endif
                }
#endif
        }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        F0490_MEMORY_LoadDecompressAndExpandGraphic(MASK0x8000_NOT_EXPANDED | C005_GRAPHIC_CREDITS, L1417_puc_Graphic_Credits = L1413_puc_TemporaryBuffer, 0, 0);
#endif
#ifdef MEDIA458_P20JA_P20JB
        L1417_puc_Graphic_Credits = F0468_MEMORY_Allocate(L2564_l_ByteCount = F0494_MEMORY_GetGraphicDecompressedByteCount(C005_GRAPHIC_CREDITS), C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
        F0490_MEMORY_LoadDecompressAndExpandGraphic(C005_GRAPHIC_CREDITS | MASK0x8000_NOT_EXPANDED | MASK0x4000_DO_NOT_COPY_DIMENSIONS, L1417_puc_Graphic_Credits, 0, 0);
#endif
#ifdef MEDIA506_F20E_F20J_X30J
        F0490_MEMORY_LoadDecompressAndExpandGraphic(C005_GRAPHIC_CREDITS | MASK0x8000_NOT_EXPANDED | MASK0x4000_DO_NOT_COPY_DIMENSIONS, L1417_puc_Graphic_Credits = L1413_puc_TemporaryBuffer, 0, 0);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L2564_l_ByteCount = M536_F0440_STARTEND_GetTemporarilyLoadedGraphicByteCount(C005_GRAPHIC_CREDITS, &L1417_puc_Graphic_Credits, MASK0x0400_MEMREQ);
#endif
        F0478_MEMORY_CloseGraphicsDat_CPSDF();
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        if (G0322_B_PaletteSwitchingEnabled) {
                F0007_MAIN_CopyBytes(G0347_aui_Palette_TopAndBottomScreen, L1420_aui_Palette_TopAndBottomScreen, sizeof(G0347_aui_Palette_TopAndBottomScreen));
                for (AL1410_i_Counter = 0; AL1410_i_Counter <= 7; AL1410_i_Counter++) {
                        M526_WaitVerticalBlank();
                        for (AL1409_i_Color = 0; AL1409_i_Color < 16; AL1409_i_Color++) {
                                G0346_aui_Palette_MiddleScreen[AL1409_i_Color] = F0431_STARTEND_GetDarkenedColor(G0346_aui_Palette_MiddleScreen[AL1409_i_Color]);
                                G0347_aui_Palette_TopAndBottomScreen[AL1409_i_Color] = F0431_STARTEND_GetDarkenedColor(G0347_aui_Palette_TopAndBottomScreen[AL1409_i_Color]);
                        }
                }
                G0322_B_PaletteSwitchingEnabled = C0_FALSE;
                M526_WaitVerticalBlank();
                F0007_MAIN_CopyBytes(L1420_aui_Palette_TopAndBottomScreen, G0347_aui_Palette_TopAndBottomScreen, sizeof(L1420_aui_Palette_TopAndBottomScreen));
        } else {
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                F0436_STARTEND_FadeToPalette(G0345_aui_BlankBuffer);
#endif
#ifdef MEDIA607_X30J_X31J
                F0436_STARTEND_FadeToPalette(G3087_aui_Palette_Blank);
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        }
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        F1012_PALETTE_SetCurtain(C0_BLACK_PALETTE);
        F0694_SetMultipleColorsInPalette(G2100_i_BlackPaletteIndex);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        F0436_STARTEND_FadeToPalette(G3161_ac_Buffer724Bytes->_aui_Palette_0x188);
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        G2062_DialogSetIndex = C1_DIALOG_SET_SCREEN;
#endif
        if (P0856_B_DoNotDrawCreditsOnly) {
#ifdef MEDIA129_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
                if (G0302_B_GameWon) {
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
                        L1651_puc_Bitmap_Portrait_ChipMemory = F0468_MEMORY_Allocate((long)M075_BITMAP_BYTE_COUNT(32, 29), C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
#endif
#ifdef MEDIA113_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E
                        F0134_VIDEO_FillBitmap(G0348_Bitmap_Screen, C12_COLOR_DARKEST_GRAY, M076_BITMAP_UNIT_COUNT(320, 200));
#endif
#ifdef MEDIA439_A20E_A20F_A20G_A21E_A22E_A22G_A36M
                        F0509_AMIGA_FillScreen(C12_COLOR_DARKEST_GRAY);
#endif
#ifdef MEDIA495_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J
                        F0694_SetMultipleColorsInPalette(G2099_i_InterfacePaletteIndex);
#endif
#ifdef MEDIA523_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J
                        F0733_FillZoneByIndex(C002_ZONE_SCREEN, C12_COLOR_DARKEST_GRAY);
#endif
                        for (AL1409_i_ChampionIndex = C00_CHAMPION_FIRST; AL1409_i_ChampionIndex < G0305_ui_PartyChampionCount; AL1409_i_ChampionIndex++) {
                                AL1410_i_Y = AL1409_i_ChampionIndex * 48;
                                L1416_ps_Champion = &M516_CHAMPIONS[AL1409_i_ChampionIndex];
#ifdef MEDIA117_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
                                M520_F0021_MAIN_BlitToScreen(L1418_puc_Bitmap_ChampionMirror, G0015_ai_Graphic562_Box_Endgame_ChampionMirror, C032_BYTE_WIDTH, C10_COLOR_FLESH, 43);
#endif
#ifdef MEDIA533_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
                                F0021_MAIN_BlitToScreen(L1418_puc_Bitmap_ChampionMirror, C412_ZONE_ENDGAME_CHAMPION_MIRROR_0 + AL1409_i_ChampionIndex, C10_COLOR_FLESH);
#endif
#ifdef MEDIA113_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E
                                F0021_MAIN_BlitToScreen(L1416_ps_Champion->Portrait, G0016_ai_Graphic562_Box_Endgame_ChampionPortrait, C016_BYTE_WIDTH, C01_COLOR_DARK_GRAY);
#endif
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
                                F0007_MAIN_CopyBytes(L1416_ps_Champion->Portrait, L1651_puc_Bitmap_Portrait_ChipMemory, M075_BITMAP_BYTE_COUNT(32, 29));
                                F0021_MAIN_BlitToScreen(L1651_puc_Bitmap_Portrait_ChipMemory, G0016_ai_Graphic562_Box_Endgame_ChampionPortrait, C016_BYTE_WIDTH, C01_COLOR_DARK_GRAY, 29);
#endif
#ifdef MEDIA533_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
                                F0021_MAIN_BlitToScreen(M774_CAST_PUC(L1416_ps_Champion->Portrait), C416_ZONE_ENDGAME_CHAMPION_PORTRAIT_0 + AL1409_i_ChampionIndex, C01_COLOR_DARK_GRAY);
#endif
                                F0443_STARTEND_EndgamePrintString(87, AL1410_i_Y += 14, C09_COLOR_GOLD, L1416_ps_Champion->Name);
                                AL1411_i_X = (6 * M544_STRLEN(L1416_ps_Champion->Name)) + 87;
                                L1415_c_ChampionTitleFirstCharacter = L1416_ps_Champion->Title[0];
                                if ((L1415_c_ChampionTitleFirstCharacter != ',') && (L1415_c_ChampionTitleFirstCharacter != ';') && (L1415_c_ChampionTitleFirstCharacter != '-')) {
                                        AL1411_i_X += 6;
                                }
                                F0443_STARTEND_EndgamePrintString(AL1411_i_X, AL1410_i_Y++, C09_COLOR_GOLD, L1416_ps_Champion->Title);
                                for (AL1411_i_SkillIndex = C00_SKILL_FIGHTER; AL1411_i_SkillIndex <= C03_SKILL_WIZARD; AL1411_i_SkillIndex++) {
                                        L1412_i_SkillLevel = F0024_MAIN_GetMinimumValue(16, F0303_CHAMPION_GetSkillLevel(AL1409_i_ChampionIndex, AL1411_i_SkillIndex | (MASK0x4000_IGNORE_OBJECT_MODIFIERS | MASK0x8000_IGNORE_TEMPORARY_EXPERIENCE)));
                                        if (L1412_i_SkillLevel == 1)
                                                continue;
#ifdef MEDIA127_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_F31E_F31J
                                        M547_STRCPY(L1422_ac_String, G0428_apc_SkillLevelNames[L1412_i_SkillLevel - 2]);
#endif
#ifdef MEDIA734_I34M_A36M
                                        M547_STRCPY(L1422_ac_String, F0758_TranslateLanguage(G2014_ai_SkillLevelNames[L1412_i_SkillLevel - 2]));
#endif
                                        M545_STRCAT(L1422_ac_String, " ");
#ifdef MEDIA127_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_F31E_F31J
                                        M545_STRCAT(L1422_ac_String, G0417_apc_BaseSkillNames[AL1411_i_SkillIndex]);
#endif
#ifdef MEDIA734_I34M_A36M
                                        M545_STRCAT(L1422_ac_String, F0758_TranslateLanguage(G2015_ai_BaseSkillNames[AL1411_i_SkillIndex]));
#endif
                                        F0443_STARTEND_EndgamePrintString(105, AL1410_i_Y += 8, C13_COLOR_LIGHTEST_GRAY, L1422_ac_String);
                                }
#ifdef MEDIA117_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
                                M706_ZONE_TOP(G0015_ai_Graphic562_Box_Endgame_ChampionMirror) += 48;
                                M707_ZONE_BOTTOM(G0015_ai_Graphic562_Box_Endgame_ChampionMirror) += 48;
                                M706_ZONE_TOP(G0016_ai_Graphic562_Box_Endgame_ChampionPortrait) += 48;
                                M707_ZONE_BOTTOM(G0016_ai_Graphic562_Box_Endgame_ChampionPortrait) += 48;
#endif
                        }
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        F0436_STARTEND_FadeToPalette(L1420_aui_Palette_TopAndBottomScreen); /* BUG0_84 The ending screen with champion portraits is displayed with an incorrect color palette that may render skill levels unreadable. The color palette used to draw the ending screen in L1420_aui_Palette_TopAndBottomScreen is not initialized if the dungeon view was not visible on screen right before. This bug does not affect Dungeon Master because the end is triggered by the Fuse action (which cannot be performed while sleeping) and the inventory is automatically closed before the Fuse animation sequence so that the dungeon view is visible */
                        for (;;); /*_Infinite loop_*/
#endif
#ifdef MEDIA393_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
                        F0436_STARTEND_FadeToPalette(G0347_aui_Palette_TopAndBottomScreen);
#endif
#ifdef MEDIA610_X30J_A36M
                        F0436_STARTEND_FadeToPalette(G3088_aui_Palette_TopAndBottomScreen);
#endif
#ifdef MEDIA495_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J
                        F1012_PALETTE_SetCurtain(C1_NORMAL_PALETTE);
#endif
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
                        F0469_MEMORY_FreeAtHeapTop((long)M075_BITMAP_BYTE_COUNT(32, 29));
                        F0507_AMIGA_DeinitializeAndInfiniteLoop(); /*_Infinite loop_*/
#endif
#ifdef MEDIA406_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
                        F0357_COMMAND_DiscardAllInput();
#endif
#ifdef MEDIA577_X30J
                        while (G0588_i_MouseButtonsStatus || M527_IsCharacterInKeyboardBuffer()) {
                                if (M527_IsCharacterInKeyboardBuffer()) {
                                        M528_GetCharacterInKeyboardBuffer();
                                }
                        }
#endif
#ifdef MEDIA406_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
                        while (!F0712_AnyKeyboardOrMouseInput());
#endif
#ifdef MEDIA388_G20E_G21E
                        F0436_STARTEND_FadeToPalette(G0345_aui_BlankBuffer);
#endif
#ifdef MEDIA495_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J
                        F1012_PALETTE_SetCurtain(C0_BLACK_PALETTE);
                        F0694_SetMultipleColorsInPalette(G2100_i_BlackPaletteIndex);
#endif
#ifdef MEDIA577_X30J
                        F0436_STARTEND_FadeToPalette(G3087_aui_Palette_Blank);
#endif
#ifdef MEDIA744_A36M
                        F0436_STARTEND_FadeToPalette(G3161_ac_Buffer724Bytes->_aui_Palette_0x188);
#endif
                }
#endif
                T0444017:
                M518_FillScreenBlack();
#ifdef MEDIA505_F20E_F20J_P20JB_I34E_I34M_F31E_F31J_P31J
                F0741_MUSIC_PlayGameMusic(C3_MUSIC_THE_END);
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                F1012_PALETTE_SetCurtain(C0_BLACK_PALETTE);
                F0694_SetMultipleColorsInPalette(C12_PRESENTS);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0021_MAIN_BlitToScreen(L1414_puc_Bitmap_TheEnd, C005_ZONE_SCREEN_CENTERED_DIALOG, CM1_COLOR_NO_TRANSPARENCY);
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                F1012_PALETTE_SetCurtain(C1_NORMAL_PALETTE);
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                M520_F0021_MAIN_BlitToScreen(L1414_puc_Bitmap_TheEnd, G0012_ai_Graphic562_Box_Endgame_TheEnd, C040_BYTE_WIDTH, CM1_COLOR_NO_TRANSPARENCY, 14);
#endif
#ifdef MEDIA085_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
                F0010_MAIN_WriteSpacedWords(L1421_aui_Palette_DarkBlue, 16, M501_RGB_DARK_BLUE, (int16_t)sizeof(int16_t));
                F0007_MAIN_CopyBytes(L1421_aui_Palette_DarkBlue, L1419_aui_Palette, M543_BYTE_COUNT_INT(sizeof(L1419_aui_Palette)));
#endif
#ifdef MEDIA607_X30J_X31J
                F0007_MAIN_CopyBytes(G3075_aui_Palette_DarkBlue, L1419_aui_Palette, M543_BYTE_COUNT_INT(sizeof(L1419_aui_Palette)));
#endif
#ifdef MEDIA078_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                L1419_aui_Palette[15] = M509_RGB_WHITE;
                F0436_STARTEND_FadeToPalette(L1419_aui_Palette);
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
                F2163_SetBorderColor(C02_BORDER_COLOR_DARK_BLUE);
#endif
#ifdef MEDIA291_S20E_S21E_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_37_IMPROVEMENT */
                if (L1423_B_WaitBeforeDrawingRestart) {
#endif
                        F0022_MAIN_Delay(300);
#ifdef MEDIA291_S20E_S21E_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_37_IMPROVEMENT */
                } /* BUG0_00 Useless code */
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                F1012_PALETTE_SetCurtain(C0_BLACK_PALETTE);
                F0694_SetMultipleColorsInPalette(G2100_i_BlackPaletteIndex);
                F0694_SetMultipleColorsInPalette(C09_ICON);
#endif
#ifdef MEDIA128_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                if (G0524_B_RestartGameAllowed) {
#ifdef MEDIA117_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
                        G0578_B_UseByteBoxCoordinates = C0_FALSE;
                        M524_FillScreenBox(G0013_ai_Graphic562_Box_Endgame_Restart_Outer, C01_COLOR_DARK_GRAY);
                        M524_FillScreenBox(G0014_ai_Graphic562_Box_Endgame_Restart_Inner, C00_COLOR_BLACK);
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                        F0732_FillScreenArea(G0013_ai_Graphic562_Box_Endgame_Restart_Outer, C01_COLOR_DARK_GRAY);
                        F0732_FillScreenArea(G0014_ai_Graphic562_Box_Endgame_Restart_Inner, C00_COLOR_BLACK);
#endif
#ifdef MEDIA708_I34E_I34M_A31E_F31E_F31J_X31J_P31J
                        F0732_FillScreenArea(G2019_ai_XYZ_Endgame_Restart_Outer, C01_COLOR_DARK_GRAY);
                        F0732_FillScreenArea(G2020_ai_XYZ_Endgame_Restart_Inner, C00_COLOR_BLACK);
#endif
#ifdef MEDIA197_S10EA_S10EB_S11E_S12E_S20E_S21E_G20E_G21E_A20E_A21E_A22E_F20E_A31E /* CHANGE4_00_LOCALIZATION Translation to German language */
                        F0053_TEXT_PrintToLogicalScreen(110, 154, C04_COLOR_CYAN, C00_COLOR_BLACK, "RESTART THIS GAME");
#endif
#ifdef MEDIA255_S12G_A20G_A22G /* CHANGE4_00_LOCALIZATION Translation to German language */
                        F0053_TEXT_PrintToLogicalScreen(89, 154, C04_COLOR_CYAN, C00_COLOR_BLACK, "DIESES SPIEL NEU STARTEN");
#endif
#ifdef MEDIA261_S13FA_S13FB_A20F /* CHANGE5_00_LOCALIZATION Translation to French language */
                        F0053_TEXT_PrintToLogicalScreen(107, 154, C04_COLOR_CYAN, C00_COLOR_BLACK, "RECOMMENCER CE JEU");
#endif
#ifdef MEDIA569_F20J_X30J_P20JA_P20JB
                        F0053_TEXT_PrintToLogicalScreen(130, 159, C04_COLOR_CYAN, C00_COLOR_BLACK, "받겉띋둎");
#endif
#ifdef MEDIA689_F31J_X31J_P31J
                        F0053_TEXT_PrintToLogicalScreen(130, 154, C04_COLOR_CYAN, C00_COLOR_BLACK, "받겉띋둎");
#endif
#ifdef MEDIA705_I34E_F31E
                        F0053_TEXT_PrintToLogicalScreen(110, 149, C04_COLOR_CYAN, C00_COLOR_BLACK, "RESTART THIS GAME");
#endif
#ifdef MEDIA733_I34M
                        F0053_TEXT_PrintToLogicalScreen(110, 149, C04_COLOR_CYAN, C00_COLOR_BLACK, F0758_TranslateLanguage(C77_RESTART_THIS_GAME));
#endif
#ifdef MEDIA739_A35E
                        F1011_(C437_ZONE_ENDGAME_RESTART_THIS_GAME, "RESTART THIS GAME", G0446_as_Graphic561_PrimaryMouseInput_RestartGame);
#endif
#ifdef MEDIA757_A36M_A31M_A33M_A35M
                        F1011_(C437_ZONE_ENDGAME_RESTART_THIS_GAME, F0758_TranslateLanguage(C77_RESTART_THIS_GAME), G0446_as_Graphic561_PrimaryMouseInput_RestartGame);
#endif
#ifdef MEDIA713_I34E_I34M_F31E_F31J_X31J_P31J
                        F0732_FillScreenArea(G2021_ai_XYZ_Endgame_Quit_Outer, C01_COLOR_DARK_GRAY);
                        F0732_FillScreenArea(G2022_ai_XYZ_Endgame_Quit_Inner, C00_COLOR_BLACK);
#endif
#ifdef MEDIA689_F31J_X31J_P31J
                        F0053_TEXT_PrintToLogicalScreen(146, 189, C04_COLOR_CYAN, C00_COLOR_BLACK, G0558_pc_SAVEANDQUIT);
#endif
#ifdef MEDIA669_F31E
                        F0053_TEXT_PrintToLogicalScreen(149, 174, C04_COLOR_CYAN, C00_COLOR_BLACK, G0558_pc_SAVEANDQUIT);
#endif
#ifdef MEDIA701_I34E
                        F0053_TEXT_PrintToLogicalScreen(134, 174, C04_COLOR_CYAN, C00_COLOR_BLACK, G0558_pc_SAVEANDQUIT);
#endif
#ifdef MEDIA733_I34M
                        F0053_TEXT_PrintToLogicalScreen(134, 174, C04_COLOR_CYAN, C00_COLOR_BLACK, F0758_TranslateLanguage(C103_QUIT));
#endif
#ifdef MEDIA760_A36M_A35M
                        F1011_(C438_ZONE_ENDGAME_QUIT, F0758_TranslateLanguage(C103_QUIT), &G0446_as_Graphic561_PrimaryMouseInput_RestartGame[1]);
#endif
#ifdef MEDIA133_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                        L1419_aui_Palette[1] = M503_RGB_PINK;
                        L1419_aui_Palette[4] = M509_RGB_WHITE;
#endif
                        G0441_ps_PrimaryMouseInput = G0446_as_Graphic561_PrimaryMouseInput_RestartGame;
                        F0357_COMMAND_DiscardAllInput();
                        M523_MOUSE_ShowPointer();
#ifdef MEDIA133_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                        F0436_STARTEND_FadeToPalette(L1419_aui_Palette);
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                        F1012_PALETTE_SetCurtain(C1_NORMAL_PALETTE);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        G0523_B_RestartGameRequested = C0_FALSE;
#endif
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_37_IMPROVEMENT */
                        for (AL1409_i_VerticalBlankCount = 600; --AL1409_i_VerticalBlankCount && !G0523_B_RestartGameRequested; M526_WaitVerticalBlank()) {
#endif
#ifdef MEDIA295_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB /* CHANGE7_37_IMPROVEMENT Restart experience improved: the game waits a longer time for the player to click on the 'Restart this game' button before drawing the credits */
                        for (AL1409_i_VerticalBlankCount = 900; --AL1409_i_VerticalBlankCount && !G0523_B_RestartGameRequested; M526_WaitVerticalBlank()) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        for (AL1409_i_VerticalBlankCount = 900; --AL1409_i_VerticalBlankCount && !G0523_B_RestartGameRequested; F0022_MAIN_Delay(1)) {
#endif
                                F0380_COMMAND_ProcessQueue_CPSC();
                        }
                        M522_MOUSE_HidePointer();
                        if (G0523_B_RestartGameRequested) {
#ifdef MEDIA134_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
                                F0436_STARTEND_FadeToPalette(L1421_aui_Palette_DarkBlue);
#endif
#ifdef MEDIA607_X30J_X31J
                                F0436_STARTEND_FadeToPalette(G3075_aui_Palette_DarkBlue);
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                                F0694_SetMultipleColorsInPalette(G2101_i_BluePaletteIndex);
#endif
#ifdef MEDIA122_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_P31J
                                M518_FillScreenBlack();
#endif
#ifdef MEDIA577_X30J
                                F0732_FillScreenArea(G3000_ai_Box_Screen, C00_COLOR_BLACK);
#endif
#ifdef MEDIA692_X31J
                                F0733_FillZoneByIndex(C002_ZONE_SCREEN, C00_COLOR_BLACK);
#endif
#ifdef MEDIA133_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                                F0436_STARTEND_FadeToPalette(G0021_aaui_Graphic562_Palette_DungeonView[0]);
#endif
#ifdef MEDIA388_G20E_G21E
                                F2163_SetBorderColor(C00_BORDER_COLOR_BLACK);
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                                F0694_SetMultipleColorsInPalette(C00_LIGHT0);
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                                F0007_MAIN_CopyBytes(G0021_aaui_Graphic562_Palette_DungeonView[0], G0346_aui_Palette_MiddleScreen, sizeof(G0346_aui_Palette_MiddleScreen));
#endif
#ifdef MEDIA388_G20E_G21E
                                F0007_MAIN_CopyBytes(G0021_aaui_Graphic562_Palette_DungeonView[0], G3949_pui_Palette_MiddleScreen, sizeof(G0021_aaui_Graphic562_Palette_DungeonView[0]));
#endif
                                G0298_B_NewGame = C000_MODE_LOAD_SAVED_GAME;
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                F0469_MEMORY_FreeAtHeapTop(L2564_l_ByteCount);
                                if (P0856_B_DoNotDrawCreditsOnly) {
                                        F0607_FreeMemForGraphic(L1414_puc_Bitmap_TheEnd);
                                }
#endif
                                if (F0435_STARTEND_LoadGame() != CM1_LOAD_GAME_FAILURE) {
#ifdef MEDIA458_P20JA_P20JB
                                        F0469_MEMORY_FreeAtHeapTop(L2564_l_ByteCount);
                                        if (P0856_B_DoNotDrawCreditsOnly) {
                                                F0469_MEMORY_FreeAtHeapTop(L2562_l_TheEnd_BitmapByteCount + 4);
                                        }
#endif
                                        F0462_START_StartGame_CPSEF();
                                        G0523_B_RestartGameRequested = C0_FALSE;
                                        M523_MOUSE_ShowPointer();
                                        F0357_COMMAND_DiscardAllInput();
                                        return;
                                }
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                F0428_DIALOG_RequireGameDiskInDrive_NoDialogDrawn(C0_DO_NOT_FORCE_DIALOG_DM_CSB);
                                F0477_MEMORY_OpenGraphicsDat_CPSDF();
                                if (P0856_B_DoNotDrawCreditsOnly) {
                                        L1414_puc_Bitmap_TheEnd = F0763_LoadEndgameBitmapExpanded(C006_GRAPHIC_THE_END);
                                }
                                L2564_l_ByteCount = M536_F0440_STARTEND_GetTemporarilyLoadedGraphicByteCount(C005_GRAPHIC_CREDITS, &L1417_puc_Graphic_Credits, MASK0x0400_MEMREQ);
                                F0478_MEMORY_CloseGraphicsDat_CPSDF();
#endif
                        }
                }
#endif
#ifdef MEDIA085_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
                F0436_STARTEND_FadeToPalette(L1421_aui_Palette_DarkBlue);
#endif
#ifdef MEDIA607_X30J_X31J
                F0436_STARTEND_FadeToPalette(G3075_aui_Palette_DarkBlue);
#endif
        }
#ifdef MEDIA692_X31J
        if (G3076_B_) {
                F1028_FillX68000LargeScreenBlack();
        }
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        F0466_EXPAND_GraphicToBitmap(L1417_puc_Graphic_Credits, G0348_Bitmap_Screen, 0, 0);
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        F1012_PALETTE_SetCurtain(C0_BLACK_PALETTE);
        F0694_SetMultipleColorsInPalette(G2100_i_BlackPaletteIndex);
        F0694_SetMultipleColorsInPalette(G2098_i_CreditsPaletteIndex);
#endif
#ifdef MEDIA517_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J_X31J_P31J
        L2566_ = G0639_DerivedBitmapByteCount[C000_DERIVED_BITMAP_VIEWPORT];
        G0639_DerivedBitmapByteCount[C000_DERIVED_BITMAP_VIEWPORT] = G2183_CreditsBitmapByteCount;
        F0491_CACHE_IsDerivedBitmapInCache(C000_DERIVED_BITMAP_VIEWPORT);
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        F0466_EXPAND_GraphicToBitmap(L1417_puc_Graphic_Credits, L2565_puc_ = F0492_CACHE_GetDerivedBitmap(C000_DERIVED_BITMAP_VIEWPORT), 0, 0);
#endif
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        F0466_EXPAND_GraphicToBitmap(L1417_puc_Graphic_Credits, L2565_puc_ = F0492_CACHE_GetDerivedBitmap(C000_DERIVED_BITMAP_VIEWPORT));
#endif
        M100_PIXEL_WIDTH(L2565_puc_) = G2071_C320_ScreenPixelWidth;
        M101_PIXEL_HEIGHT(L2565_puc_) = G2072_C200_ScreenPixelHeight;
        F0021_MAIN_BlitToScreen(L2565_puc_, C002_ZONE_SCREEN, CM1_COLOR_NO_TRANSPARENCY);
        F0493_CACHE_AddDerivedBitmap(C000_DERIVED_BITMAP_VIEWPORT);
        F0480_CACHE_ReleaseBlock(C000_DERIVED_BITMAP_VIEWPORT | MASK0x8000_DERIVED_BITMAP);
        G0639_DerivedBitmapByteCount[C000_DERIVED_BITMAP_VIEWPORT] = L2566_;
#endif
#ifdef MEDIA717_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M
        F0466_EXPAND_GraphicToBitmap(L1417_puc_Graphic_Credits, G0348_Bitmap_Screen);
#endif
#ifdef MEDIA078_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
        F0436_STARTEND_FadeToPalette(G0019_aui_Graphic562_Palette_Credits);
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        F2163_SetBorderColor(C02_BORDER_COLOR_DARK_BLUE);
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        F1012_PALETTE_SetCurtain(C1_NORMAL_PALETTE);
#endif
#ifdef MEDIA329_S20E_S21E_X30J /* CHANGE7_37_IMPROVEMENT Restart experience improved: restart is now possible even after the credits have been drawn by pressing a key or clicking a mouse button */
        while (!G0588_i_MouseButtonsStatus && !M527_IsCharacterInKeyboardBuffer());
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        F0541_INPUT_WaitForMouseOrKeyboardActivity();
#endif
#ifdef MEDIA407_G20E_G21E_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0357_COMMAND_DiscardAllInput();
#endif
#ifdef MEDIA403_G20E_G21E_F20E_F20J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        while (!F0712_AnyKeyboardOrMouseInput());
#endif
#ifdef MEDIA388_G20E_G21E
        F0357_COMMAND_DiscardAllInput();
        F0010_MAIN_WriteSpacedWords(L1421_aui_Palette_DarkBlue, 16, M501_RGB_DARK_BLUE, (int16_t)sizeof(int16_t));
        F0436_STARTEND_FadeToPalette(L1421_aui_Palette_DarkBlue);
        M518_FillScreenBlack();
        F2162_ShutDown();
#endif
#ifdef MEDIA319_S20E_S21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_37_IMPROVEMENT Restart experience improved: restart is now possible even after the credits have been drawn by pressing a key or clicking a mouse button */
        if (G0524_B_RestartGameAllowed && P0856_B_DoNotDrawCreditsOnly) {
                L1423_B_WaitBeforeDrawingRestart = C0_FALSE;
#ifdef MEDIA323_S20E_S21E_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
                F0436_STARTEND_FadeToPalette(L1421_aui_Palette_DarkBlue);
#endif
#ifdef MEDIA607_X30J_X31J
                F0436_STARTEND_FadeToPalette(G3075_aui_Palette_DarkBlue);
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                F1012_PALETTE_SetCurtain(C0_BLACK_PALETTE);
#endif
                goto T0444017;
        }
#endif
#ifdef MEDIA110_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_F20E_F20J_X30J
        for (;;); /*_Infinite loop_*/
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        F0507_AMIGA_DeinitializeAndInfiniteLoop(); /*_Infinite loop_*/
#endif
#ifdef MEDIA469_P20JB
        F1012_PALETTE_SetCurtain(C0_BLACK_PALETTE);
        M518_FillScreenBlack();
        F1012_PALETTE_SetCurtain(C1_NORMAL_PALETTE);
#endif
#ifdef MEDIA458_P20JA_P20JB
        exit(0);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0666_endgame();
#endif
}

#ifdef MEDIA129_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
STATICFUNCTION void F0445_STARTEND_FuseSequenceUpdate(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA707_I34E_I34M
        G0317_i_WaitForInputVerticalBlankCount = 0;
        G0321_B_StopWaitingForPlayerInput = C0_FALSE;
#endif
        F0261_TIMELINE_Process_CPSEF();
        F0128_DUNGEONVIEW_Draw_CPSF(G0308_i_PartyDirection, G0306_i_PartyMapX, G0307_i_PartyMapY);
        F0065_SOUND_PlayPendingSound_CPSD();
#ifdef MEDIA707_I34E_I34M
        while (!G0321_B_StopWaitingForPlayerInput);
#endif
        G0313_ul_GameTime++; /* BUG0_71 Some timings are too short on fast computers. The ending animation when Lord Chaos is fused plays too quickly because the execution speed is not limited */
}

void F0446_STARTEND_FuseSequence(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER GROUP* L1428_ps_Group;
        REGISTER EXPLOSION* L1429_ps_Explosion;
        REGISTER int16_t L1424_i_Multiple;
#define AL1424_B_RemoveFluxcagesFromLoadChaosSquare L1424_i_Multiple
#define AL1424_i_Attack                             L1424_i_Multiple
#define AL1424_i_CreatureTypeSwitchCount            L1424_i_Multiple
#define AL1424_i_MapX                               L1424_i_Multiple
#define AL1424_i_TextStringThingCount               L1424_i_Multiple
        REGISTER int16_t L1425_i_Multiple;
#define AL1425_i_FluxcageMapX         L1425_i_Multiple
#define AL1425_i_MapY                 L1425_i_Multiple
#define AL1425_i_CycleCount           L1425_i_Multiple
#define AL1425_i_TextStringThingIndex L1425_i_Multiple
#ifdef MEDIA533_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
        REGISTER THING L1427_T_Thing;
        REGISTER unsigned int16_t L1431_ui_LordChaosMapX;
        REGISTER unsigned int16_t L1432_ui_LordChaosMapY;
#endif
        REGISTER int16_t L1426_i_Multiple;
#define AL1426_i_FluxcageMapY            L1426_i_Multiple
#define AL1426_i_FuseSequenceUpdateCount L1426_i_Multiple
#define AL1426_i_TextStringThingCount    L1426_i_Multiple
#ifdef MEDIA117_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER THING L1427_T_Thing;
        THING L1430_T_NextThing;
        unsigned int16_t L1431_ui_LordChaosMapX;
        unsigned int16_t L1432_ui_LordChaosMapY;
#endif
#ifdef MEDIA118_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB
        THING L1433_T_LordChaosThing;
#endif
#ifdef MEDIA130_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A36M_F31E_F31J
        char L1434_c_TextFirstCharacter;
        THING L1435_aT_TextStringThings[8];
        char L1436_ac_String[200];
#endif


        G0302_B_GameWon = C1_TRUE;
        if (G0423_i_InventoryChampionOrdinal) {
                F0355_INVENTORY_Toggle_CPSE(C04_CHAMPION_CLOSE_INVENTORY);
        }
        F0363_COMMAND_HighlightBoxDisable();
        G0407_s_Party.MagicalLightAmount = 200;
        F0337_INVENTORY_SetDungeonViewPalette();
        G0407_s_Party.FireShieldDefense = G0407_s_Party.SpellShieldDefense = G0407_s_Party.ShieldDefense = 100;
#ifdef MEDIA123_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
        F0260_TIMELINE_RefreshAllChampionStatusBoxes();
#endif
#ifdef MEDIA726_I34E_I34M_A36M_F31E_F31J
        F0293_CHAMPION_DrawAllChampionStates(MASK0x1000_STATUS_BOX);
#endif
        F0445_STARTEND_FuseSequenceUpdate();
        L1431_ui_LordChaosMapX = G0306_i_PartyMapX;
        L1432_ui_LordChaosMapY = G0307_i_PartyMapY;
        L1431_ui_LordChaosMapX += G0233_ai_Graphic559_DirectionToStepEastCount[G0308_i_PartyDirection], L1432_ui_LordChaosMapY += G0234_ai_Graphic559_DirectionToStepNorthCount[G0308_i_PartyDirection];
#ifdef MEDIA117_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
        L1428_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L1433_T_LordChaosThing = F0175_GROUP_GetThing(L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY));
#endif
#ifdef MEDIA533_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
        L1428_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(F0175_GROUP_GetThing(L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY));
#endif
        L1428_ps_Group->Health[0] = 10000;
        F0146_DUNGEON_SetGroupCells(L1428_ps_Group, C0xFF_SINGLE_CENTERED_CREATURE, G0309_i_PartyMapIndex);
        F0148_DUNGEON_SetGroupDirections(L1428_ps_Group, M018_OPPOSITE(G0308_i_PartyDirection), G0309_i_PartyMapIndex);
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_20_FIX This code removes Fluxcages from the party square but fails to remove them from the Lord Chaos square */
        L1427_T_Thing = F0162_DUNGEON_GetSquareFirstObject(G0306_i_PartyMapX, G0307_i_PartyMapY);
        AL1424_B_RemoveFluxcagesFromLoadChaosSquare = C1_TRUE;
        T0446002:
        while (L1427_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                L1430_T_NextThing = F0159_DUNGEON_GetNextThing(L1427_T_Thing);
                if (M012_TYPE(L1427_T_Thing) == C15_THING_TYPE_EXPLOSION) {
                        L1429_ps_Explosion = (EXPLOSION*)F0156_DUNGEON_GetThingData(L1427_T_Thing);
                        if (L1429_ps_Explosion->Type == C050_EXPLOSION_FLUXCAGE) {
                                F0164_DUNGEON_UnlinkThingFromList(L1427_T_Thing, 0, G0306_i_PartyMapX, G0307_i_PartyMapY); /* BUG0_59 The game hangs when using the Fuse action on Lord Chaos. If there is a Fluxcage on the square where Lord Chaos stands then it is not removed as it should and this hangs the game while processing the end sequence. In the second pass, this call still removes explosion things from the party square instead of the Lord Chaos square. Here is the process leading to the game hanging: The game finds a Fluxcage explosion on the square where Lord Chaos is standing but it tries to remove it from the party square with this call to F0164_DUNGEON_UnlinkThingFromList, which fails. The explosion is then marked as unused, but it is still part of the linked list of things on Lord Chaos' square. The first call to F0213_EXPLOSION_Create below calls F0166_DUNGEON_GetUnusedThing to get an unused explosion thing, which initializes and returns the same thing that is still part of the linked list. F0213_EXPLOSION_Create then calls F0163_DUNGEON_LinkThingToList to add the explosion at the end of the list. The last thing in the list being the same as the thing being added, this results in an explosion thing linked to itself. This causes an infinite loop the next time that all things on the square are processed in a loop */
                                L1429_ps_Explosion->Next = C0xFFFF_THING_NONE;
                        }
                }
                L1427_T_Thing = L1430_T_NextThing;
        }
        if (AL1424_B_RemoveFluxcagesFromLoadChaosSquare) {
                AL1424_B_RemoveFluxcagesFromLoadChaosSquare = C0_FALSE;
                L1427_T_Thing = F0162_DUNGEON_GetSquareFirstObject(L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY);
                goto T0446002;
        }
#endif
#ifdef MEDIA233_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J /* CHANGE2_20_FIX Fluxcages are removed correctly from both the party square and the Lord Chaos square */
        AL1424_B_RemoveFluxcagesFromLoadChaosSquare = C1_TRUE;
        AL1425_i_FluxcageMapX = G0306_i_PartyMapX;
        AL1426_i_FluxcageMapY = G0307_i_PartyMapY;
        T0446002:
        L1427_T_Thing = F0162_DUNGEON_GetSquareFirstObject(AL1425_i_FluxcageMapX, AL1426_i_FluxcageMapY);
        while (L1427_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                if (M012_TYPE(L1427_T_Thing) == C15_THING_TYPE_EXPLOSION) {
                        L1429_ps_Explosion = (EXPLOSION*)F0156_DUNGEON_GetThingData(L1427_T_Thing);
                        if (L1429_ps_Explosion->Type == C050_EXPLOSION_FLUXCAGE) {
                                F0164_DUNGEON_UnlinkThingFromList(L1427_T_Thing, 0, AL1425_i_FluxcageMapX, AL1426_i_FluxcageMapY);
                                L1429_ps_Explosion->Next = C0xFFFF_THING_NONE;
                                goto T0446002;
                        }
                }
                L1427_T_Thing = F0159_DUNGEON_GetNextThing(L1427_T_Thing);
        }
        if (AL1424_B_RemoveFluxcagesFromLoadChaosSquare) {
                AL1424_B_RemoveFluxcagesFromLoadChaosSquare = C0_FALSE;
                AL1425_i_FluxcageMapX = L1431_ui_LordChaosMapX;
                AL1426_i_FluxcageMapY = L1432_ui_LordChaosMapY;
                goto T0446002;
        }
#endif
#ifdef MEDIA388_G20E_G21E
        G0077_B_DoNotDrawFluxcagesDuringEndgame = C1_TRUE;
        F0445_STARTEND_FuseSequenceUpdate();
        for (AL1424_i_MapX = 0; AL1424_i_MapX < G0273_i_CurrentMapWidth; AL1424_i_MapX++) {
                for (AL1425_i_MapY = 0; AL1425_i_MapY < G0274_i_CurrentMapHeight; AL1425_i_MapY++) {
                        if (((L1427_T_Thing = F0175_GROUP_GetThing(AL1424_i_MapX, AL1425_i_MapY)) != C0xFFFE_THING_ENDOFLIST) && ((AL1424_i_MapX != L1431_ui_LordChaosMapX) || (AL1425_i_MapY != L1432_ui_LordChaosMapY))) {
                                F0189_GROUP_Delete(AL1424_i_MapX, AL1425_i_MapY);
                        }
                }
        }
#endif
        F0445_STARTEND_FuseSequenceUpdate();
        for (AL1424_i_Attack = 55; AL1424_i_Attack <= 255; AL1424_i_Attack += 40) {
                F0213_EXPLOSION_Create(C0xFF80_THING_EXPLOSION_FIREBALL, AL1424_i_Attack, L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY, C0xFF_SINGLE_CENTERED_CREATURE);
                F0445_STARTEND_FuseSequenceUpdate();
        }
        F0064_SOUND_RequestPlay_CPSD(M560_SOUND_BUZZ, L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY, C01_MODE_PLAY_IF_PRIORITIZED);
        L1428_ps_Group->Type = C25_CREATURE_LORD_ORDER;
        F0445_STARTEND_FuseSequenceUpdate();
        for (AL1424_i_Attack = 55; AL1424_i_Attack <= 255; AL1424_i_Attack += 40) {
                F0213_EXPLOSION_Create(C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL, AL1424_i_Attack, L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY, C0xFF_SINGLE_CENTERED_CREATURE);
                F0445_STARTEND_FuseSequenceUpdate();
        }
        for (AL1425_i_CycleCount = 4; --AL1425_i_CycleCount; ) {
                for (AL1424_i_CreatureTypeSwitchCount = 5; --AL1424_i_CreatureTypeSwitchCount; ) {
                        F0064_SOUND_RequestPlay_CPSD(M560_SOUND_BUZZ, L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY, C01_MODE_PLAY_IF_PRIORITIZED);
                        L1428_ps_Group->Type = (AL1424_i_CreatureTypeSwitchCount & 0x0001) ? C25_CREATURE_LORD_ORDER : C23_CREATURE_LORD_CHAOS;
                        for (AL1426_i_FuseSequenceUpdateCount = AL1425_i_CycleCount; AL1426_i_FuseSequenceUpdateCount--; F0445_STARTEND_FuseSequenceUpdate());
                }
        }
        F0213_EXPLOSION_Create(C0xFF80_THING_EXPLOSION_FIREBALL, 255, L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY, C0xFF_SINGLE_CENTERED_CREATURE);
        F0213_EXPLOSION_Create(C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL, 255, L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY, C0xFF_SINGLE_CENTERED_CREATURE);
        F0445_STARTEND_FuseSequenceUpdate();
        L1428_ps_Group->Type = C26_CREATURE_GREY_LORD;
        F0445_STARTEND_FuseSequenceUpdate();
#ifdef MEDIA141_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        G0077_B_DoNotDrawFluxcagesDuringEndgame = C1_TRUE;
        F0445_STARTEND_FuseSequenceUpdate();
        for (AL1424_i_MapX = 0; AL1424_i_MapX < G0273_i_CurrentMapWidth; AL1424_i_MapX++) {
                for (AL1425_i_MapY = 0; AL1425_i_MapY < G0274_i_CurrentMapHeight; AL1425_i_MapY++) {
                        if (((L1427_T_Thing = F0175_GROUP_GetThing(AL1424_i_MapX, AL1425_i_MapY)) != C0xFFFE_THING_ENDOFLIST) && ((AL1424_i_MapX != L1431_ui_LordChaosMapX) || (AL1425_i_MapY != L1432_ui_LordChaosMapY))) {
                                F0189_GROUP_Delete(AL1424_i_MapX, AL1425_i_MapY);
                        }
                }
        }
        F0445_STARTEND_FuseSequenceUpdate();
#endif
#ifdef MEDIA503_F20E_F20J_P20JB_F31E_F31J
        F0741_MUSIC_PlayGameMusic(C2_MUSIC_GAME_WON);
#endif
#ifdef MEDIA130_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A36M_F31E_F31J
        /* Count and get list of text things located at 0, 0 in the current map. Their text is then printed as messages in the order specified by their first letter (which is not printed) */
        L1427_T_Thing = F0161_DUNGEON_GetSquareFirstThing(0, 0);
        AL1424_i_TextStringThingCount = 0;
        while (L1427_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                if (M012_TYPE(L1427_T_Thing) == C02_THING_TYPE_TEXTSTRING) {
                        L1435_aT_TextStringThings[AL1424_i_TextStringThingCount++] = L1427_T_Thing;
                }
                L1427_T_Thing = F0159_DUNGEON_GetNextThing(L1427_T_Thing);
        }
        L1434_c_TextFirstCharacter = 'A';
        AL1426_i_TextStringThingCount = AL1424_i_TextStringThingCount;
        while (AL1424_i_TextStringThingCount--) {
                for (AL1425_i_TextStringThingIndex = 0; AL1425_i_TextStringThingIndex < AL1426_i_TextStringThingCount; AL1425_i_TextStringThingIndex++) {
                        F0168_DUNGEON_DecodeText(M774_CAST_PUC(L1436_ac_String), L1435_aT_TextStringThings[AL1425_i_TextStringThingIndex], C1_TEXT_TYPE_MESSAGE | MASK0x8000_DECODE_EVEN_IF_INVISIBLE);
                        if (L1436_ac_String[1] == L1434_c_TextFirstCharacter) {
                                F0043_TEXT_MESSAGEAREA_ClearAllRows();
                                L1436_ac_String[1] = '\n'; /* New line */
                                F0047_TEXT_MESSAGEAREA_PrintMessage(C15_COLOR_WHITE, &L1436_ac_String[1]);
                                F0445_STARTEND_FuseSequenceUpdate();
                                F0022_MAIN_Delay(780);
                                L1434_c_TextFirstCharacter++;
                                break;
                        }
                }
        }
#ifdef MEDIA439_A20E_A20F_A20G_A21E_A22E_A22G_A36M
        for (AL1424_i_Attack = 55; AL1424_i_Attack <= 255; AL1424_i_Attack += 40) {
                F0213_EXPLOSION_Create(C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL, AL1424_i_Attack, L1431_ui_LordChaosMapX, L1432_ui_LordChaosMapY, C0xFF_SINGLE_CENTERED_CREATURE);
                F0445_STARTEND_FuseSequenceUpdate();
        }
#endif
        F0022_MAIN_Delay(600);
        G0524_B_RestartGameAllowed = C0_FALSE;
        F0444_STARTEND_Endgame(C1_TRUE);
#endif
#ifdef MEDIA707_I34E_I34M
        G0302_B_GameWon = C1_TRUE;
        F0666_endgame();
#endif
}
#endif

#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
#ifndef NOCOPYPROTECTION
void F0447_STARTEND_HangIfFalse_CPSA(
P0857_B_CommandLineParameterIsAUTO)
BOOLEAN P0857_B_CommandLineParameterIsAUTO FINAL_SEPARATOR
{
        if (!P0857_B_CommandLineParameterIsAUTO) {
                for (;;); /*_Infinite loop_*/
        }
}
#endif
#endif

#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void F0666_endgame(
void
)
{
        while (G0587_i_HideMousePointerRequestCount <= 0) {
                M522_MOUSE_HidePointer();
        }
        F0478_MEMORY_CloseGraphicsDat_CPSDF();
        F0478_MEMORY_CloseGraphicsDat_CPSDF();
#ifdef MEDIA625_A31E_A31M_A33M_A35E
        if (!G0302_B_GameWon) {
                for (;;);
        }
#endif
#ifdef MEDIA693_X31J_P31J
        F0815_StopMIDIMusic();
#endif
#ifdef MEDIA743_A35M_F31E_F31J_X31J_P31J
        if (G0302_B_GameWon) {
#endif
#ifdef MEDIA674_F31E_F31J_X31J_P31J
                M518_FillScreenBlack();
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                F0733_FillZoneByIndex(C401_ZONE_SCREEN_TOP, C00_COLOR_BLACK);
                F0035_OBJECT_ClearLeaderHandObjectName();
                F0733_FillZoneByIndex(C013_ZONE_SPELL_AREA, C00_COLOR_BLACK);
                F0733_FillZoneByIndex(C011_ZONE_ACTION_AREA, C00_COLOR_BLACK);
                F0733_FillZoneByIndex(C009_ZONE_MOVEMENT_ARROWS, C00_COLOR_BLACK);
#endif
#ifdef MEDIA630_A31E_A31M_A33M_A35E_A35M_X31J
                G3134_PRIM_Executable->Parameter = FTL_ENDA;
#endif
#ifdef MEDIA743_A35M_F31E_F31J_X31J_P31J
        }
#endif
        F0750_CPSX();
        longjmp(G2023_jmp_buf, C1_UNKNOWN);
}
#endif
#endif
