#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 MEDIA349_G14ED /* BUGX_XX: Compiler fails if this define is set in IIGS.H */
#define F0362_COMMAND_HighlightBoxEnable F0362_
#endif

#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
STATICFUNCTION void F0665_F0362_sub(
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
int16_t P2006_i_X1 SEPARATOR
int16_t P2007_i_X2 SEPARATOR
int16_t P2008_i_Y1 SEPARATOR
int16_t P2009_i_Y2 FINAL_SEPARATOR
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t* P2010_pi_XYZ FINAL_SEPARATOR
#endif
{
        F0077_MOUSE_EnableScreenUpdate_CPSE();
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        F0698_InvertBox(G0336_i_HighlightBoxX1 = P2006_i_X1, G0337_i_HighlightBoxX2 = P2007_i_X2, G0338_i_HighlightBoxY1 = P2008_i_Y1, G0339_i_HighlightBoxY2 = P2009_i_Y2);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0007_MAIN_CopyBytes((char*)P2010_pi_XYZ, (char*)G2012_HighlightedZone, (long)sizeof(G2012_HighlightedZone));
        F0698_InvertBox(P2010_pi_XYZ);
#endif
        G0341_B_HighlightBoxEnabled = C1_TRUE;
        F0078_MOUSE_DisableScreenUpdate();
        F0693_WaitVerticalBlank();
}
#endif

STATICFUNCTION void F0362_COMMAND_HighlightBoxEnable(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0729_i_X1, P0730_i_X2, P0731_i_Y1, P0732_i_Y2)
int16_t P0729_i_X1 SEPARATOR
int16_t P0730_i_X2 SEPARATOR
int16_t P0731_i_Y1 SEPARATOR
int16_t P0732_i_Y2 FINAL_SEPARATOR
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        while (G0340_B_HighlightBoxInversionRequested);
#endif
        G0336_i_HighlightBoxX1 = P0729_i_X1;
        G0337_i_HighlightBoxX2 = P0730_i_X2;
        G0338_i_HighlightBoxY1 = P0731_i_Y1;
        G0339_i_HighlightBoxY2 = P0732_i_Y2;
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        G0340_B_HighlightBoxInversionRequested = C1_TRUE;
        M526_WaitVerticalBlank();
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        M522_MOUSE_HidePointer();
#endif
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        F0006_MAIN_HighlightScreenBox(P0729_i_X1, P0730_i_X2, P0731_i_Y1, P0732_i_Y2);
        G0341_B_HighlightBoxEnabled = C1_TRUE;
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        M523_MOUSE_ShowPointer();
#endif
}
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t P2011_ZoneIndex FINAL_SEPARATOR
{
        int16_t L2280_ai_XYZ[4];


        if (F0638_GetZone(P2011_ZoneIndex, L2280_ai_XYZ)) {
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                F0665_F0362_sub(M704_ZONE_LEFT(L2280_ai_XYZ), M705_ZONE_RIGHT(L2280_ai_XYZ), M706_ZONE_TOP(L2280_ai_XYZ), M707_ZONE_BOTTOM(L2280_ai_XYZ));
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0665_F0362_sub(L2280_ai_XYZ);
#endif
        }
}
#endif

void F0363_COMMAND_HighlightBoxDisable(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        while (G0340_B_HighlightBoxInversionRequested);
        if (G0341_B_HighlightBoxEnabled) {
                G0340_B_HighlightBoxInversionRequested = C1_TRUE;
                M526_WaitVerticalBlank();
        }
#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
        if (G0341_B_HighlightBoxEnabled == C1_TRUE) {
#ifdef MEDIA351_G14ED_G20E_G21E
                M522_MOUSE_HidePointer();
#endif
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                F0006_MAIN_HighlightScreenBox(G0336_i_HighlightBoxX1, G0337_i_HighlightBoxX2, G0338_i_HighlightBoxY1, G0339_i_HighlightBoxY2);
#endif
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
                F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                F0698_InvertBox(G0336_i_HighlightBoxX1, G0337_i_HighlightBoxX2, G0338_i_HighlightBoxY1, G0339_i_HighlightBoxY2);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0698_InvertBox(G2012_HighlightedZone);
#endif
                G0341_B_HighlightBoxEnabled = C0_FALSE;
#ifdef MEDIA351_G14ED_G20E_G21E
                M523_MOUSE_ShowPointer();
#endif
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
                F0078_MOUSE_DisableScreenUpdate();
#endif
        }
#endif
}

STATICFUNCTION void F0364_COMMAND_TakeStairs(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0733_B_StairsGoDown)
#endif
BOOLEAN P0733_B_StairsGoDown FINAL_SEPARATOR
{
#ifdef MEDIA012_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB_I34E_I34M_P31J
        int16_t L1113_i_Unreferenced; /* BUG0_00 Useless code */
#endif


        F0267_MOVE_GetMoveResult_CPSCE(C0xFFFF_THING_PARTY, G0306_i_PartyMapX, G0307_i_PartyMapY, CM1_MAPX_NOT_ON_A_SQUARE, 0);
        G0327_i_NewPartyMapIndex = F0154_DUNGEON_GetLocationAfterLevelChange(G0309_i_PartyMapIndex, P0733_B_StairsGoDown ? -1 : 1, &G0306_i_PartyMapX, &G0307_i_PartyMapY);
        F0173_DUNGEON_SetCurrentMap(G0327_i_NewPartyMapIndex);
        F0284_CHAMPION_SetPartyDirection(F0155_DUNGEON_GetStairsExitDirection(G0306_i_PartyMapX, G0307_i_PartyMapY));
        F0173_DUNGEON_SetCurrentMap(G0309_i_PartyMapIndex);
}

void F0365_COMMAND_ProcessTypes1To2_TurnParty(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0734_i_Command)
#endif
int16_t P0734_i_Command 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 L1114_ui_Square;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        unsigned int16_t L1114_ui_Square;
#endif


        G0321_B_StopWaitingForPlayerInput = C1_TRUE;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        if (P0734_i_Command == C001_COMMAND_TURN_LEFT) {
                F0362_COMMAND_HighlightBoxEnable(234, 261, 125, 145);
        } else {
                F0362_COMMAND_HighlightBoxEnable(291, 318, 125, 145);
        }
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0362_COMMAND_HighlightBoxEnable((P0734_i_Command == C001_COMMAND_TURN_LEFT) ? C068_ZONE_TURN_LEFT : C069_ZONE_TURN_RIGHT);
#endif
        if (M034_SQUARE_TYPE(L1114_ui_Square = F0151_DUNGEON_GetSquare(G0306_i_PartyMapX, G0307_i_PartyMapY)) == C03_ELEMENT_STAIRS) {
                F0364_COMMAND_TakeStairs(M007_GET(L1114_ui_Square, MASK0x0004_STAIRS_UP));
                return;
        }
        F0276_SENSOR_ProcessThingAdditionOrRemoval(G0306_i_PartyMapX, G0307_i_PartyMapY, C0xFFFF_THING_PARTY, C1_TRUE, C0_FALSE);
        F0284_CHAMPION_SetPartyDirection(M021_NORMALIZE(G0308_i_PartyDirection + ((P0734_i_Command == C002_COMMAND_TURN_RIGHT) ? 1 : 3)));
        F0276_SENSOR_ProcessThingAdditionOrRemoval(G0306_i_PartyMapX, G0307_i_PartyMapY, C0xFFFF_THING_PARTY, C1_TRUE, C1_TRUE);
}

/* When the party moves from one square to another, sensors are processed on the source square to manage effects of the party departure and then on the destination square to manage effects of the party arrival.
Stairs are a special case: when the party moves from a non stairs square to a stairs square, sensors are processed on the source square to manage the party departure but sensors are not processed on the destination stairs square to manage the party arrival. Then sensors are processed on the stairs square to manage the party departure and sensors are processed on the corresponding stairs square on the destination map to process the party arrival.
When the party moves from a stairs square to a non stairs square, sensors are not processed on the stairs square to manage the party departure but sensors are processed on the destination square to manage the party arrival.
When the party moves from a stairs square to another stairs square (take the stairs by turning or moving backward while standing on a stairs square), sensors are processed normally to manage the party departure from the source stairs square and the party arrival on the destination stairs square */
void F0366_COMMAND_ProcessTypes3To6_MoveParty(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0735_ui_Command)
#endif
unsigned int16_t P0735_ui_Command FINAL_SEPARATOR
{
        REGISTER CHAMPION* L1119_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* L1120_pi_Box;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER char* L2281_pc_Unreferenced;
        REGISTER unsigned int16_t L1118_ui_Multiple;
        REGISTER BOOLEAN L1117_B_MovementBlocked;
#endif
        REGISTER unsigned int16_t L1115_ui_Multiple;
#define AL1115_ui_Square L1115_ui_Multiple
#define AL1115_ui_Ticks  L1115_ui_Multiple
        REGISTER int16_t L1116_i_SquareType;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER BOOLEAN L1117_B_MovementBlocked;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER BOOLEAN L1123_B_StairsSquare;
#endif
#define AL1118_ui_ChampionIndex      L1118_ui_Multiple
#define AL1118_ui_MovementArrowIndex L1118_ui_Multiple
#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 L1118_ui_Multiple;
        int16_t L1121_i_MapX;
        int16_t L1122_i_MapY;
        BOOLEAN L1123_B_StairsSquare;
#endif
        int16_t L1124_i_FirstDamagedChampionIndex;
        int16_t L1125_i_SecondDamagedChampionIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        int16_t L1121_i_MapX;
        int16_t L1122_i_MapY;
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        static int16_t G0465_ai_Graphic561_MovementArrowToStepForwardCount[4];
        static int16_t G0466_ai_Graphic561_MovementArrowToStepRightCount[4];
#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
        static int16_t G0465_ai_Graphic561_MovementArrowToStepForwardCount[4] = {
                1,   /* Forward */
                0,   /* Right */
                -1,  /* Backward */
                0 }; /* Left */
        static int16_t G0466_ai_Graphic561_MovementArrowToStepRightCount[4] = {
                0,    /* Forward */
                1,    /* Right */
                0,    /* Backward */
                -1 }; /* Left */
#endif


        G0321_B_StopWaitingForPlayerInput = C1_TRUE;
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED /* CHANGE7_11_OPTIMIZATION Comma removed */
        for (L1119_ps_Champion = M516_CHAMPIONS, AL1118_ui_ChampionIndex = C00_CHAMPION_FIRST; AL1118_ui_ChampionIndex < G0305_ui_PartyChampionCount; L1119_ps_Champion++, AL1118_ui_ChampionIndex++) {
#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_11_OPTIMIZATION Comma removed */
        L1119_ps_Champion = M516_CHAMPIONS;
        for (AL1118_ui_ChampionIndex = C00_CHAMPION_FIRST; AL1118_ui_ChampionIndex < G0305_ui_PartyChampionCount; AL1118_ui_ChampionIndex++) {
#endif
#ifdef MEDIA346_S21E_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_10_FIX Do not decrease stamina of dead champions when the party moves */
                if (L1119_ps_Champion->CurrentHealth) {
#endif
                        F0325_CHAMPION_DecrementStamina(AL1118_ui_ChampionIndex, ((L1119_ps_Champion->Load * 3) / F0309_CHAMPION_GetMaximumLoad(L1119_ps_Champion)) + 1); /* BUG0_50 When a champion is brought back to life at a Vi Altar, his current stamina is lower than what it was before dying. Each time the party moves the current stamina of all champions is decreased, including for dead champions, by an amount that depends on the current load of the champion. For a dead champion the load before he died is used */
#ifdef MEDIA346_S21E_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_10_FIX */
                }
#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_11_OPTIMIZATION Comma removed */
                L1119_ps_Champion++;
#endif
        }
        AL1118_ui_MovementArrowIndex = P0735_ui_Command - C003_COMMAND_MOVE_FORWARD;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L1120_pi_Box = G0463_aai_Graphic561_Box_MovementArrows[AL1118_ui_MovementArrowIndex];
        F0362_COMMAND_HighlightBoxEnable(M768_BOX_LEFT(L1120_pi_Box), M769_BOX_RIGHT(L1120_pi_Box), M770_BOX_TOP(L1120_pi_Box), M771_BOX_BOTTOM(L1120_pi_Box));
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0362_COMMAND_HighlightBoxEnable(C070_ZONE_MOVE_FORWARD + AL1118_ui_MovementArrowIndex);
#endif
        L1123_B_StairsSquare = (M034_SQUARE_TYPE(AL1115_ui_Square = F0151_DUNGEON_GetSquare(L1121_i_MapX = G0306_i_PartyMapX, L1122_i_MapY = G0307_i_PartyMapY)) == C03_ELEMENT_STAIRS);
        if (L1123_B_StairsSquare && (AL1118_ui_MovementArrowIndex == 2)) { /* If moving backward while in stairs */
                F0364_COMMAND_TakeStairs(M007_GET(AL1115_ui_Square, MASK0x0004_STAIRS_UP));
                return;
        }
        F0150_DUNGEON_UpdateMapCoordinatesAfterRelativeMovement(G0308_i_PartyDirection, G0465_ai_Graphic561_MovementArrowToStepForwardCount[AL1118_ui_MovementArrowIndex], G0466_ai_Graphic561_MovementArrowToStepRightCount[AL1118_ui_MovementArrowIndex], &L1121_i_MapX, &L1122_i_MapY);
        L1116_i_SquareType = M034_SQUARE_TYPE(AL1115_ui_Square = F0151_DUNGEON_GetSquare(L1121_i_MapX, L1122_i_MapY));
        if (L1116_i_SquareType == C03_ELEMENT_STAIRS) {
                F0267_MOVE_GetMoveResult_CPSCE(C0xFFFF_THING_PARTY, G0306_i_PartyMapX, G0307_i_PartyMapY, CM1_MAPX_NOT_ON_A_SQUARE, 0);
                G0306_i_PartyMapX = L1121_i_MapX;
                G0307_i_PartyMapY = L1122_i_MapY;
                F0364_COMMAND_TakeStairs(M007_GET(AL1115_ui_Square, MASK0x0004_STAIRS_UP));
                return;
        }
        L1117_B_MovementBlocked = C0_FALSE;
        if (L1116_i_SquareType == C00_ELEMENT_WALL) {
                L1117_B_MovementBlocked = C1_TRUE;
        } else {
                if (L1116_i_SquareType == C04_ELEMENT_DOOR) {
                        L1117_B_MovementBlocked = M036_DOOR_STATE(AL1115_ui_Square);
                        L1117_B_MovementBlocked = (L1117_B_MovementBlocked != C0_DOOR_STATE_OPEN) && (L1117_B_MovementBlocked != C1_DOOR_STATE_CLOSED_ONE_FOURTH) && (L1117_B_MovementBlocked != C5_DOOR_STATE_DESTROYED);
                } else {
                        if (L1116_i_SquareType == C06_ELEMENT_FAKEWALL) {
                                L1117_B_MovementBlocked = (!M007_GET(AL1115_ui_Square, MASK0x0004_FAKEWALL_OPEN) && !M007_GET(AL1115_ui_Square, MASK0x0001_FAKEWALL_IMAGINARY));
                        }
                }
        }
        if (G0305_ui_PartyChampionCount == 0) { /* BUG0_85 Movement over a group is not blocked if there are no champions in the party. The engine does not check for the presence of a group if the party is empty. Because the movement is allowed, the group on the target square is instantly killed. This issue only affects custom dungeons. It does not exist in the original dungeons because there are no creature types allowed on the maps containing champion mirrors */
        } else {
                if (L1117_B_MovementBlocked) {
                        L1117_B_MovementBlocked = F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage(L1124_i_FirstDamagedChampionIndex = F0286_CHAMPION_GetTargetChampionIndex(L1121_i_MapX, L1122_i_MapY, M021_NORMALIZE(AL1118_ui_MovementArrowIndex += (G0308_i_PartyDirection + 2))), 1, MASK0x0008_WOUND_TORSO | MASK0x0010_WOUND_LEGS, C2_ATTACK_SELF); /* BUG0_43 If the game did not end because the last living champion in the party was killed while looking at a candidate champion in a portrait then in versions Amiga 3.x, PC, PC-9801, X68000 and Chaos Strikes Back for FM-Towns F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage returns 0 (because F0286_CHAMPION_GetTargetChampionIndex returned CM1_CHAMPION_NONE) and then movement is not blocked anymore. This does not occurs in versions Atari ST, Apple IIGS, Amiga 2.x and Dungeon Master for FM-Towns because F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage incorrectly returns a non zero value */
                        if (L1124_i_FirstDamagedChampionIndex != (L1125_i_SecondDamagedChampionIndex = F0286_CHAMPION_GetTargetChampionIndex(L1121_i_MapX, L1122_i_MapY, M017_NEXT(AL1118_ui_MovementArrowIndex)))) {
                                L1117_B_MovementBlocked |= F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage(L1125_i_SecondDamagedChampionIndex, 1, MASK0x0008_WOUND_TORSO | MASK0x0010_WOUND_LEGS, C2_ATTACK_SELF);
                        }
                        if (L1117_B_MovementBlocked) {
#ifdef PC_FIX_CODE_SIZE
        L1118_ui_Multiple++;
        L1118_ui_Multiple++;
        L1118_ui_Multiple++;
#endif
#ifdef MEDIA161_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
                                F0064_SOUND_RequestPlay_CPSD(M562_SOUND_PARTY_DAMAGED, G0306_i_PartyMapX, G0307_i_PartyMapY, C00_MODE_PLAY_IMMEDIATELY);
#endif
#ifdef MEDIA371_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
                                F0064_SOUND_RequestPlay_CPSD(M562_SOUND_PARTY_DAMAGED, L1121_i_MapX, L1122_i_MapY, C00_MODE_PLAY_IMMEDIATELY);
#endif
                        }
                } else {
                        if (L1117_B_MovementBlocked = (F0175_GROUP_GetThing(L1121_i_MapX, L1122_i_MapY) != C0xFFFE_THING_ENDOFLIST)) {
                                F0209_GROUP_ProcessEvents29to41(L1121_i_MapX, L1122_i_MapY, CM1_EVENT_CREATE_REACTION_EVENT_31_PARTY_IS_ADJACENT, 0); /* Bumping into a creature makes it react faster */
                        }
                }
        }
        if (L1117_B_MovementBlocked) {
                F0357_COMMAND_DiscardAllInput();
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0693_WaitVerticalBlank();
#endif
                G0321_B_StopWaitingForPlayerInput = C0_FALSE;
                return;
        }
        if (L1123_B_StairsSquare) {
                F0267_MOVE_GetMoveResult_CPSCE(C0xFFFF_THING_PARTY, CM1_MAPX_NOT_ON_A_SQUARE, 0, L1121_i_MapX, L1122_i_MapY);
        } else {
                F0267_MOVE_GetMoveResult_CPSCE(C0xFFFF_THING_PARTY, G0306_i_PartyMapX, G0307_i_PartyMapY, L1121_i_MapX, L1122_i_MapY);
        }
        AL1115_ui_Ticks = 1;
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED /* CHANGE7_11_OPTIMIZATION Comma removed */
        for (L1119_ps_Champion = M516_CHAMPIONS, AL1118_ui_ChampionIndex = C00_CHAMPION_FIRST; AL1118_ui_ChampionIndex < G0305_ui_PartyChampionCount; AL1118_ui_ChampionIndex++, L1119_ps_Champion++) {
#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_11_OPTIMIZATION Comma removed */
        L1119_ps_Champion = M516_CHAMPIONS;
        for (AL1118_ui_ChampionIndex = C00_CHAMPION_FIRST; AL1118_ui_ChampionIndex < G0305_ui_PartyChampionCount; AL1118_ui_ChampionIndex++) {
#endif
                if (L1119_ps_Champion->CurrentHealth) {
                        AL1115_ui_Ticks = F0025_MAIN_GetMaximumValue(AL1115_ui_Ticks, F0310_CHAMPION_GetMovementTicks(L1119_ps_Champion));
                }
#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_11_OPTIMIZATION Comma removed */
                L1119_ps_Champion++;
#endif
        }
        G0310_i_DisabledMovementTicks = AL1115_ui_Ticks;
        G0311_i_ProjectileDisabledMovementTicks = 0;
}

#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#include "CLIKCHAM.C"

void F0369_COMMAND_ProcessTypes101To108_ClickInSpellSymbolsArea_CPSE(
P0740_i_Command)
int16_t P0740_i_Command FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L1130_ui_SymbolIndex;
        REGISTER int16_t* L1131_pi_Box;


        if (P0740_i_Command == C108_COMMAND_CLICK_IN_SPELL_AREA_CAST_SPELL) {
                if (M516_CHAMPIONS[G0514_i_MagicCasterChampionIndex].Symbols[0] == '\0') {
                        return;
                }
                F0362_COMMAND_HighlightBoxEnable(234, 303, 63, 73);
#ifndef NOCOPYPROTECTION
                if ((G0031_i_Graphic562_FuzzySectorAnalyzed_CPSE != C00136_TRUE) && !F0277_CPSE_IsFuzzySectorValid_FuzzyBits(M517_FuzzySectorReadingBuffer_CPSE)) {
                        G0189_i_Graphic558_StopAddingEvents_CPSE = C00136_TRUE;
                }
#endif
                G0321_B_StopWaitingForPlayerInput = F0408_MENUS_GetClickOnSpellCastResult(C0_USELESS); /* 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 */
                return;
        }
        L1130_ui_SymbolIndex = P0740_i_Command - C101_COMMAND_CLICK_IN_SPELL_AREA_SYMBOL_1;
        L1131_pi_Box = G0464_aai_Graphic561_Box_SpellSymbolsAndDelete[L1130_ui_SymbolIndex];
        F0362_COMMAND_HighlightBoxEnable(M768_BOX_LEFT(L1131_pi_Box), M769_BOX_RIGHT(L1131_pi_Box), M770_BOX_TOP(L1131_pi_Box), M771_BOX_BOTTOM(L1131_pi_Box));
        M526_WaitVerticalBlank();
        F0363_COMMAND_HighlightBoxDisable();
        if (L1130_ui_SymbolIndex < 6) {
                F0399_MENUS_AddChampionSymbol(L1130_ui_SymbolIndex);
        } else {
                F0400_MENUS_DeleteChampionSymbol();
        }
}
#endif

void F0370_COMMAND_ProcessType100_ClickInSpellArea_CPSE(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0741_ui_X, P0742_ui_Y)
#endif
unsigned int16_t P0741_ui_X SEPARATOR
unsigned int16_t P0742_ui_Y 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 L1132_ui_Command;
#endif
        REGISTER int16_t L1133_i_Multiple;
#define AL1133_i_ChampionIndex L1133_i_Multiple
#define AL1133_i_ZoneIndex     L1133_i_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L1132_ui_Command;
        REGISTER int16_t L2282_i_ZoneIndex;
#endif


#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        AL1133_i_ChampionIndex = CM1_CHAMPION_NONE;
        if (P0742_ui_Y <= 48) {
                switch (G0514_i_MagicCasterChampionIndex) {
                        case 0:
                                if ((P0741_ui_X >= 280) && (P0741_ui_X <= 291)) {
                                        AL1133_i_ChampionIndex = 1;
                                } else {
                                        if ((P0741_ui_X >= 294) && (P0741_ui_X <= 305)) {
                                                AL1133_i_ChampionIndex = 2;
                                        } else {
                                                if (P0741_ui_X >= 308) {
                                                        AL1133_i_ChampionIndex = 3;
                                                }
                                        }
                                }
                                break;
                        case 1:
                                if ((P0741_ui_X >= 233) && (P0741_ui_X <= 244)) {
                                        AL1133_i_ChampionIndex = 0;
                                } else {
                                        if ((P0741_ui_X >= 294) && (P0741_ui_X <= 305)) {
                                                AL1133_i_ChampionIndex = 2;
                                        } else {
                                                if (P0741_ui_X >= 308) {
                                                        AL1133_i_ChampionIndex = 3;
                                                }
                                        }
                                }
                                break;
                        case 2:
                                if ((P0741_ui_X >= 233) && (P0741_ui_X <= 244)) {
                                        AL1133_i_ChampionIndex = 0;
                                } else {
                                        if ((P0741_ui_X >= 247) && (P0741_ui_X <= 258)) {
                                                AL1133_i_ChampionIndex = 1;
                                        } else {
                                                if (P0741_ui_X >= 308) {
                                                        AL1133_i_ChampionIndex = 3;
                                                }
                                        }
                                }
                                break;
                        case 3:
                                if ((P0741_ui_X >= 247) && (P0741_ui_X <= 258)) {
                                        AL1133_i_ChampionIndex = 1;
                                } else {
                                        if ((P0741_ui_X >= 261) && (P0741_ui_X <= 272)) {
                                                AL1133_i_ChampionIndex = 2;
                                        } else {
                                                if (P0741_ui_X <= 244) {
                                                        AL1133_i_ChampionIndex = 0;
                                                }
                                        }
                                }
                                break;
                }
                if ((AL1133_i_ChampionIndex != CM1_CHAMPION_NONE) && (AL1133_i_ChampionIndex < G0305_ui_PartyChampionCount)) {
                        F0394_MENUS_SetMagicCasterAndDrawSpellArea(AL1133_i_ChampionIndex);
                }
                return;
        }
        L1132_ui_Command = F0358_COMMAND_GetCommandFromMouseInput_CPSC(G0454_as_Graphic561_MouseInput_SpellArea, P0741_ui_X, P0742_ui_Y, MASK0x0002_MOUSE_LEFT_BUTTON);
        if (L1132_ui_Command != C000_COMMAND_NONE) {
                F0369_COMMAND_ProcessTypes101To108_ClickInSpellSymbolsArea_CPSE(L1132_ui_Command);
        }
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L1132_ui_Command = F0358_COMMAND_GetCommandFromMouseInput_CPSC(G0454_as_Graphic561_MouseInput_SpellArea, P0741_ui_X, P0742_ui_Y, MASK0x0002_MOUSE_LEFT_BUTTON);
        if (L1132_ui_Command != C000_COMMAND_NONE) {
                if (L1132_ui_Command == C109_COMMAND_CLICK_IN_SPELL_AREA_SET_MAGIC_CASTER) {
                        L2282_i_ZoneIndex = C224_ZONE_SPELL_AREA_MAGIC_CASTER_TAB + 5 * G0514_i_MagicCasterChampionIndex;
                        for (AL1133_i_ChampionIndex = 0; AL1133_i_ChampionIndex < G0305_ui_PartyChampionCount; AL1133_i_ChampionIndex++) {
                                if (F0629_IsPointInZoneIndex(L2282_i_ZoneIndex++, P0741_ui_X, P0742_ui_Y)) {
                                        F0394_MENUS_SetMagicCasterAndDrawSpellArea(AL1133_i_ChampionIndex);
                                        break;
                                }
                        }
                } else {
                        if (L1132_ui_Command == C108_COMMAND_CLICK_IN_SPELL_AREA_CAST_SPELL) {
                                if (M516_CHAMPIONS[G0514_i_MagicCasterChampionIndex].Symbols[0] == '\0') {
                                        return;
                                }
                                F0362_COMMAND_HighlightBoxEnable(C252_ZONE_SPELL_AREA_CAST_SPELL);
#ifdef MEDIA581_X30J_P20JA_P20JB_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
                                if ((G0031_i_Graphic562_FuzzySectorAnalyzed_CPSE != C00136_TRUE) && !F0277_CPSE_IsFuzzySectorValid_FuzzyBits(M517_FuzzySectorReadingBuffer_CPSE)) {
                                        G0189_i_Graphic558_StopAddingEvents_CPSE = C00136_TRUE;
                                }
#endif
#endif
                                G0321_B_StopWaitingForPlayerInput = F0408_MENUS_GetClickOnSpellCastResult();
                                return;
                        }
                        AL1133_i_ZoneIndex = L1132_ui_Command - C101_COMMAND_CLICK_IN_SPELL_AREA_SYMBOL_1;
                        F0362_COMMAND_HighlightBoxEnable((AL1133_i_ZoneIndex < 6) ? (unsigned int16_t)AL1133_i_ZoneIndex + C245_ZONE_SPELL_AREA_SYMBOL_1 : C254_ZONE_SPELL_AREA_RECANT_SYMBOL);
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                        M526_WaitVerticalBlank();
                        M526_WaitVerticalBlank();
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        F0022_MAIN_Delay(2);
#endif
                        F0363_COMMAND_HighlightBoxDisable();
                        if (AL1133_i_ZoneIndex < 6) {
                                F0399_MENUS_AddChampionSymbol(AL1133_i_ZoneIndex);
                        } else {
                                F0400_MENUS_DeleteChampionSymbol();
                        }
                }
        }
#endif
}

void F0371_COMMAND_ProcessType111To115_ClickInActionArea_CPSE(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0743_i_X, P0744_i_Y)
#endif
int16_t P0743_i_X SEPARATOR
int16_t P0744_i_Y FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L1134_ui_Command;


        if (G0506_ui_ActingChampionOrdinal) {
                L1134_ui_Command = F0358_COMMAND_GetCommandFromMouseInput_CPSC(G0452_as_Graphic561_MouseInput_ActionAreaNames, P0743_i_X, P0744_i_Y, MASK0x0002_MOUSE_LEFT_BUTTON);
                if (L1134_ui_Command != C000_COMMAND_NONE) {
                        if (L1134_ui_Command == C112_COMMAND_CLICK_IN_ACTION_AREA_PASS) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                F0362_COMMAND_HighlightBoxEnable(285, 319, 77, 83);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                F0362_COMMAND_HighlightBoxEnable(C098_ZONE_ACTION_AREA_PASS);
#endif
                                F0391_MENUS_DidClickTriggerAction(-1);
                        } else {
                                if ((L1134_ui_Command - C112_COMMAND_CLICK_IN_ACTION_AREA_PASS) <= G0507_ui_ActionCount) {
                                        if (L1134_ui_Command == C113_COMMAND_CLICK_IN_ACTION_AREA_ACTION_0) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                                F0362_COMMAND_HighlightBoxEnable(234, 318, 86, 96);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                F0362_COMMAND_HighlightBoxEnable(C082_ZONE_ACTION_AREA_ACTION_0);
#endif
                                        } else {
                                                if (L1134_ui_Command == C114_COMMAND_CLICK_IN_ACTION_AREA_ACTION_1) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                                        F0362_COMMAND_HighlightBoxEnable(234, 318, 98, 108);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                        F0362_COMMAND_HighlightBoxEnable(C083_ZONE_ACTION_AREA_ACTION_1);
#endif
#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
                                                        if ((G0031_i_Graphic562_FuzzySectorAnalyzed_CPSE != C00136_TRUE) && !F0277_CPSE_IsFuzzySectorValid_FuzzyBits(M517_FuzzySectorReadingBuffer_CPSE)) {
                                                                G0189_i_Graphic558_StopAddingEvents_CPSE = C00136_TRUE;
                                                        }
#endif
#endif
                                                } else {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                                        F0362_COMMAND_HighlightBoxEnable(234, 318, 110, 120);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                        F0362_COMMAND_HighlightBoxEnable(C084_ZONE_ACTION_AREA_ACTION_2);
#endif
                                                }
                                        }
                                        G0321_B_StopWaitingForPlayerInput = F0391_MENUS_DidClickTriggerAction(L1134_ui_Command - C113_COMMAND_CLICK_IN_ACTION_AREA_ACTION_0);
                                }
                        }
                }
        } else {
                if (G0509_B_ActionAreaContainsIcons) {
                        L1134_ui_Command = F0358_COMMAND_GetCommandFromMouseInput_CPSC(G0453_as_Graphic561_MouseInput_ActionAreaIcons, P0743_i_X, P0744_i_Y, MASK0x0002_MOUSE_LEFT_BUTTON);
                        if (L1134_ui_Command != C000_COMMAND_NONE) {
                                if ((L1134_ui_Command -= C116_COMMAND_CLICK_IN_ACTION_AREA_CHAMPION_0_ACTION) < G0305_ui_PartyChampionCount) {
                                        F0389_MENUS_ProcessCommands116To119_SetActingChampion(L1134_ui_Command);
                                }
                        }
                }
        }
}
#endif
