#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
STATICFUNCTION void F0372_COMMAND_ProcessType80_ClickInDungeonView_TouchFrontWallSensor(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned int16_t L1135_ui_MapX;
        unsigned int16_t L1136_ui_MapY;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L1135_ui_MapX;
        REGISTER unsigned int16_t L1136_ui_MapY;
#endif


        L1135_ui_MapX = G0306_i_PartyMapX;
        L1136_ui_MapY = G0307_i_PartyMapY;
        L1135_ui_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[G0308_i_PartyDirection], L1136_ui_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[G0308_i_PartyDirection];
        if ((L1135_ui_MapX >= 0) && (L1135_ui_MapX < G0273_i_CurrentMapWidth) && (L1136_ui_MapY >= 0) && (L1136_ui_MapY < G0274_i_CurrentMapHeight)) {
                G0321_B_StopWaitingForPlayerInput = F0275_SENSOR_IsTriggeredByClickOnWall(L1135_ui_MapX, L1136_ui_MapY, M018_OPPOSITE(G0308_i_PartyDirection));
        }
}

#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void F0664_COMMAND_ProcessType80_ClickInDungeonView_KnockOnFrontWall(
BOOLEAN          P2012_B_ClosedImaginaryFakeWall SEPARATOR
unsigned int16_t P2013_ui_MapX                   SEPARATOR
unsigned int16_t P2014_ui_MapY                   FINAL_SEPARATOR
{
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M /* BUGX_XX FIX: In earlier versions, you can knock on the wall even if there is no champion in the party */
        if (G0305_ui_PartyChampionCount) {
#endif
                if (P2012_B_ClosedImaginaryFakeWall) {
#ifdef MEDIA725_I34E_I34M_A36M_A33M_A35E_A35M
                        if (G2152_B_PressingClosedImaginaryFakeWall) {
                                return;
                        }
#endif
                        G0597_B_IgnoreMouseMovements = C1_TRUE;
                        G2152_B_PressingClosedImaginaryFakeWall = C1_TRUE;
#ifdef MEDIA712_I34E_I34M_F31E_F31J_P31J
                        F0706_GetMouseState(&G2010_, &G2011_, &G0588_i_MouseButtonsStatus);
#endif
                        if (!M007_GET(G0588_i_MouseButtonsStatus, MASK0x0002_MOUSE_LEFT_BUTTON)) {
                                G0597_B_IgnoreMouseMovements = C0_FALSE;
                                G2152_B_PressingClosedImaginaryFakeWall = C0_FALSE;
#ifdef MEDIA622_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                                G2229_B_StopPressingClosedImaginaryFakeWall = C0_FALSE;
#endif
                        } else {
#ifdef MEDIA665_A33M
                                if (!G2229_B_StopPressingClosedImaginaryFakeWall) {
#endif
                                        M522_MOUSE_HidePointer();
#ifdef MEDIA665_A33M
                                } else {
                                        G2229_B_StopPressingClosedImaginaryFakeWall = C0_FALSE;
                                }
#endif
                        }
                } else {
                        F0064_SOUND_RequestPlay_CPSD(C04_SOUND_WOODEN_THUD_ATTACK_TROLIN_ANTMAN_STONE_GOLEM, P2013_ui_MapX, P2014_ui_MapY, C00_MODE_PLAY_IMMEDIATELY);
                }
#ifdef MEDIA725_I34E_I34M_A36M_A33M_A35E_A35M
                G0321_B_StopWaitingForPlayerInput = C1_TRUE;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        }
#endif
}
#endif

STATICFUNCTION void F0373_COMMAND_ProcessType80_ClickInDungeonView_GrabLeaderHandObject(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0745_ui_ViewCell)
#endif
REGISTER unsigned int16_t P0745_ui_ViewCell FINAL_SEPARATOR /* Cells 0 and 1 are on the party square, cells 2 and 3 are on the square in front of the party */
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L1139_T_Thing;
#endif
        REGISTER int16_t L1137_i_MapX;
        REGISTER int16_t L1138_i_MapY;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER THING L1139_T_Thing;
#endif


        if (G0411_i_LeaderIndex == CM1_CHAMPION_NONE) {
                return;
        }
        L1137_i_MapX = G0306_i_PartyMapX;
        L1138_i_MapY = G0307_i_PartyMapY;
        if (P0745_ui_ViewCell >= C02_VIEW_CELL_BACK_RIGHT) {
                L1137_i_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[G0308_i_PartyDirection], L1138_i_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[G0308_i_PartyDirection];
                if (((L1139_T_Thing = F0175_GROUP_GetThing(L1137_i_MapX, L1138_i_MapY)) != C0xFFFE_THING_ENDOFLIST) &&
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                    !F0264_MOVE_IsLevitating(L1139_T_Thing, C04_THING_TYPE_GROUP) && /* BUG0_01 Coding error without consequence. Function call with wrong number of parameters. It should be called with 1 parameter. No consequence because additional parameters are ignored */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                    !F0264_MOVE_IsLevitating(L1139_T_Thing) &&
#endif
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                    F0176_GROUP_GetCreatureOrdinalInCell(&(((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(L1139_T_Thing)]), M021_NORMALIZE(P0745_ui_ViewCell + G0308_i_PartyDirection))) {
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                    F0176_GROUP_GetCreatureOrdinalInCell((GROUP*)F0156_DUNGEON_GetThingData(L1139_T_Thing), M021_NORMALIZE(P0745_ui_ViewCell + G0308_i_PartyDirection))) {
#endif
                        return; /* It is not possible to grab an object on floor if there is a non levitating creature on its cell */
                }
        }
        L1139_T_Thing = G0292_aT_PileTopObject[P0745_ui_ViewCell];
#ifdef MEDIA045_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_X31J_P31J
        if (F0033_OBJECT_GetIconIndex(L1139_T_Thing) != C0xFFFF_ICON_NONE) {
#endif
#ifdef MEDIA670_F31E_F31J
        if (F0033_OBJECT_GetIconIndex(L1139_T_Thing) != -1) {
#endif
                F0267_MOVE_GetMoveResult_CPSCE(L1139_T_Thing, L1137_i_MapX, L1138_i_MapY, CM1_MAPX_NOT_ON_A_SQUARE, 0);
                G0416_i_DelayMouse_Useless = 1; /* BUG0_00 Useless code */
                F0297_CHAMPION_PutObjectInLeaderHand(L1139_T_Thing, C1_TRUE);
        }
        G0321_B_StopWaitingForPlayerInput = C1_TRUE;
}

STATICFUNCTION void F0374_COMMAND_ProcessType80_ClickInDungeonView_DropLeaderHandObject(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0746_ui_ViewCell)
#endif
REGISTER unsigned int16_t P0746_ui_ViewCell FINAL_SEPARATOR /* Cells 0 and 1 are on the party square, cells 2 and 3 are on the square in front of the party */
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER JUNK* L1143_ps_Junk;
        REGISTER THING L1142_T_Thing;
#endif
        REGISTER int16_t L1140_i_MapX;
        REGISTER int16_t L1141_i_MapY;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER THING L1142_T_Thing;
        int16_t L1144_i_IconIndex;
        unsigned int16_t L1145_ui_Cell;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L1145_ui_Cell;
#endif
        BOOLEAN L1146_B_DroppingIntoAnAlcove;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER JUNK* L1143_ps_Junk;
#endif
        EVENT L1147_s_Event;


        if (G0411_i_LeaderIndex == CM1_CHAMPION_NONE) {
                return;
        }
        L1140_i_MapX = G0306_i_PartyMapX;
        L1141_i_MapY = G0307_i_PartyMapY;
        if (L1146_B_DroppingIntoAnAlcove = (P0746_ui_ViewCell == C04_VIEW_CELL_ALCOVE)) {
                P0746_ui_ViewCell = C02_VIEW_CELL_BACK_RIGHT;
        }
        if (P0746_ui_ViewCell > C01_VIEW_CELL_FRONT_RIGHT) {
                L1140_i_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[G0308_i_PartyDirection], L1141_i_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[G0308_i_PartyDirection];
        }
        L1145_ui_Cell = M021_NORMALIZE(G0308_i_PartyDirection + P0746_ui_ViewCell);
        L1142_T_Thing = F0298_CHAMPION_GetObjectRemovedFromLeaderHand();
        F0267_MOVE_GetMoveResult_CPSCE(M015_THING_WITH_NEW_CELL(L1142_T_Thing, L1145_ui_Cell), CM1_MAPX_NOT_ON_A_SQUARE, 0, L1140_i_MapX, L1141_i_MapY);
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        if (L1146_B_DroppingIntoAnAlcove && G0287_B_FacingViAltar && ((L1144_i_IconIndex = F0033_OBJECT_GetIconIndex(L1142_T_Thing)) == C147_ICON_JUNK_CHAMPION_BONES)) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (L1146_B_DroppingIntoAnAlcove && G0287_B_FacingViAltar && (F0033_OBJECT_GetIconIndex(L1142_T_Thing) == C147_ICON_JUNK_CHAMPION_BONES)) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
#endif
                L1143_ps_Junk = (JUNK*)F0156_DUNGEON_GetThingData(L1142_T_Thing);
                M033_SET_MAP_AND_TIME(L1147_s_Event.Map_Time, G0309_i_PartyMapIndex, G0313_ul_GameTime + 1);
                L1147_s_Event.A.A.Type = C13_EVENT_VI_ALTAR_REBIRTH;
                L1147_s_Event.A.A.Priority = L1143_ps_Junk->ChargeCount;
                L1147_s_Event.B.Location.MapX = L1140_i_MapX;
                L1147_s_Event.B.Location.MapY = L1141_i_MapY;
                L1147_s_Event.C.A.Cell = L1145_ui_Cell;
                L1147_s_Event.C.A.Effect = C02_EFFECT_TOGGLE;
                F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L1147_s_Event);
        }
        G0321_B_StopWaitingForPlayerInput = C1_TRUE;
}

STATICFUNCTION BOOLEAN F0375_COMMAND_ProcessType80_ClickInDungeonView_IsLeaderHandObjectThrown(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0747_i_X, P0748_i_Y)
#endif
int16_t P0747_i_X SEPARATOR
int16_t P0748_i_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 int16_t L1148_i_Unreferenced; /* BUG0_00 Useless code */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L2278_i_ZoneIndex;
#endif
#ifdef MEDIA346_S21E_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_11_FIX */
        REGISTER BOOLEAN L1149_B_ObjectThrown;
#endif


#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        if ((P0748_i_Y < 47) || (P0748_i_Y > 102)) {
                return C0_FALSE;
        }
        if (P0747_i_X <= 111) {
                if (G0285_i_SquareAheadElement == C17_ELEMENT_DOOR_FRONT) {
                        if (P0747_i_X < 64) {
                                return C0_FALSE;
                        }
                } else {
                        if (P0747_i_X < 32) {
                                return C0_FALSE;
                        }
                }
#endif
#ifdef MEDIA175_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE8_11_FIX */
                return F0329_CHAMPION_IsLeaderHandObjectThrown(C0_SIDE_LEFT); /* BUG0_51 Throwing the object in the leader hand does not stop the wait for player input in the main loop. Each time player input with the mouse or keyboard causes some meaningful activity in the game (like moving, performing an action, casting a spell, etc.) the main game loop stops waiting for more player input and proceeds with advancing the game time by one tick and managing everything else. Throwing the object in the leader hand is the only such activity inconsistent with all others */
        }
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L1149_B_ObjectThrown = C0_FALSE;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (G0285_i_SquareAheadElement == C17_ELEMENT_DOOR_FRONT) {
                L2278_i_ZoneIndex = M640_ZONE;
        } else {
                L2278_i_ZoneIndex = M641_ZONE;
        }
        if (F0629_IsPointInZoneIndex(L2278_i_ZoneIndex, P0747_i_X, P0748_i_Y)) {
#endif
#ifdef MEDIA488_F20E_F20J
                return F0329_CHAMPION_IsLeaderHandObjectThrown(C0_SIDE_LEFT);
        }
#endif
#ifdef MEDIA346_S21E_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_11_FIX Throwing the object in the leader hand stops the wait for player input in the main loop */
                L1149_B_ObjectThrown = F0329_CHAMPION_IsLeaderHandObjectThrown(C0_SIDE_LEFT);
        } else {
#endif
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* ANOMALY_ST_BRANCH */
        else {
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                if (G0285_i_SquareAheadElement == C17_ELEMENT_DOOR_FRONT) {
                        if (P0747_i_X > 163) {
                                return C0_FALSE;
                        }
                } else {
                        if (P0747_i_X > 191) {
                                return C0_FALSE;
                        }
                }
#endif
#ifdef MEDIA175_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE8_11_FIX */
                return F0329_CHAMPION_IsLeaderHandObjectThrown(C1_SIDE_RIGHT); /* BUG0_51 */
#endif
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        }
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                if (F0629_IsPointInZoneIndex(L2278_i_ZoneIndex + 1, P0747_i_X, P0748_i_Y)) {
#endif
#ifdef MEDIA488_F20E_F20J
                        return F0329_CHAMPION_IsLeaderHandObjectThrown(C1_SIDE_RIGHT);
                } else {
                        return C0_FALSE;
                }
#endif
#ifdef MEDIA346_S21E_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_11_FIX Throwing the object in the leader hand stops the wait for player input in the main loop */
                        L1149_B_ObjectThrown = F0329_CHAMPION_IsLeaderHandObjectThrown(C1_SIDE_RIGHT);
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                }
#endif
        }
        if (L1149_B_ObjectThrown) {
                G0321_B_StopWaitingForPlayerInput = C1_TRUE;
        }
        return L1149_B_ObjectThrown;
#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
STATICFUNCTION BOOLEAN F0376_COMMAND_IsPointInBox(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0749_p_Box, P0750_i_X, P0751_i_Y)
REGISTER unsigned char* P0749_p_Box SEPARATOR
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
REGISTER int16_t*       P0749_p_Box SEPARATOR
#endif
#ifdef MEDIA010_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB
REGISTER int16_t        P0750_i_X   SEPARATOR
REGISTER int16_t        P0751_i_Y   FINAL_SEPARATOR
#endif
#ifdef MEDIA506_F20E_F20J_X30J
int16_t                 P0750_i_X   SEPARATOR
int16_t                 P0751_i_Y   FINAL_SEPARATOR
#endif
{
        return ((P0750_i_X <= M769_BOX_RIGHT(P0749_p_Box)) && (P0750_i_X >= M768_BOX_LEFT(P0749_p_Box)) && (P0751_i_Y <= M771_BOX_BOTTOM(P0749_p_Box)) && (P0751_i_Y >= M770_BOX_TOP(P0749_p_Box)));
}
#endif

void F0377_COMMAND_ProcessType80_ClickInDungeonView(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0752_i_X, P0753_i_Y)
#endif
REGISTER int16_t P0752_i_X SEPARATOR
REGISTER int16_t P0753_i_Y FINAL_SEPARATOR
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER JUNK* L1151_ps_Junk;
#endif
        REGISTER unsigned int16_t L1150_ui_Multiple;
#define AL1150_ui_ViewCell L1150_ui_Multiple
#define AL1150_ui_Square   L1150_ui_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        THING L1152_T_Thing;
        unsigned int16_t L1153_ui_IconIndex;
        unsigned int16_t L1154_ui_Weight;
        int16_t L1155_i_MapX;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L1152_T_Thing;
        REGISTER int16_t L1155_i_MapX;
#endif
        int16_t L1156_i_MapY;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER JUNK* L1151_ps_Junk;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        unsigned int16_t L1153_ui_IconIndex;
        unsigned int16_t L1154_ui_Weight;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        BOOLEAN L2279_B_ClosedImaginaryFakeWall;
#endif


#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        P0752_i_X -= G2067_i_ViewportScreenX;
        P0753_i_Y -= G2068_i_ViewportScreenY;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L1155_i_MapX = G0306_i_PartyMapX;
        L1156_i_MapY = G0307_i_PartyMapY;
        L1155_i_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[G0308_i_PartyDirection], L1156_i_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[G0308_i_PartyDirection];
#endif
        if (G0285_i_SquareAheadElement == C17_ELEMENT_DOOR_FRONT) {
                if (G0411_i_LeaderIndex == CM1_CHAMPION_NONE) {
                        return;
                }
#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
                L1155_i_MapX = G0306_i_PartyMapX;
                L1156_i_MapY = G0307_i_PartyMapY;
                L1155_i_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[G0308_i_PartyDirection], L1156_i_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[G0308_i_PartyDirection];
#endif
                if (G0415_ui_LeaderEmptyHanded) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        if ((((DOOR*)G0284_apuc_ThingData[C00_THING_TYPE_DOOR])[M013_INDEX(F0161_DUNGEON_GetSquareFirstThing(L1155_i_MapX, L1156_i_MapY))].Button) && (F0376_COMMAND_IsPointInBox(G0291_aauc_DungeonViewClickableBoxes[C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT], P0752_i_X, P0753_i_Y - 33))) {
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        L1151_ps_Junk = (JUNK*)F0157_DUNGEON_GetSquareFirstThingData(L1155_i_MapX, L1156_i_MapY);
#endif
#ifdef MEDIA224_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        if ((((DOOR*)L1151_ps_Junk)->Button) && (F0376_COMMAND_IsPointInBox(G0291_aauc_DungeonViewClickableBoxes[C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT], P0752_i_X, P0753_i_Y - 33))) {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        if ((((DOOR*)L1151_ps_Junk)->Button) && (F0376_COMMAND_IsPointInBox(G2210_aai_XYZ_DungeonViewClickable[C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT], P0752_i_X, P0753_i_Y))) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        if ((((DOOR*)L1151_ps_Junk)->Button) && (F0798_COMMAND_IsPointInZone(G2210_aai_XYZ_DungeonViewClickable[C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT], P0752_i_X, P0753_i_Y))) {
#endif
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
                                G0321_B_StopWaitingForPlayerInput = C1_TRUE;
#endif
                                F0064_SOUND_RequestPlay_CPSD(C01_SOUND_SWITCH, G0306_i_PartyMapX, G0307_i_PartyMapY, C01_MODE_PLAY_IF_PRIORITIZED);
                                F0268_SENSOR_AddEvent(C10_EVENT_DOOR, L1155_i_MapX, L1156_i_MapY, 0, C02_EFFECT_TOGGLE, G0313_ul_GameTime + 1);
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                G0321_B_StopWaitingForPlayerInput = C1_TRUE;
#endif
                                return;
                        }
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_09_OPTIMIZATION */
                }
                if (!G0415_ui_LeaderEmptyHanded) {
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_09_OPTIMIZATION Code deduplication */
                } else {
#endif
                        if (F0375_COMMAND_ProcessType80_ClickInDungeonView_IsLeaderHandObjectThrown(P0752_i_X, P0753_i_Y)) {
                                return;
                        }
                }
        }
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L2279_B_ClosedImaginaryFakeWall = (M034_SQUARE_TYPE(AL1150_ui_Square = F0151_DUNGEON_GetSquare(L1155_i_MapX, L1156_i_MapY)) == C06_ELEMENT_FAKEWALL) && M007_GET(MASK0x0001_FAKEWALL_IMAGINARY, AL1150_ui_Square) && !M007_GET(MASK0x0004_FAKEWALL_OPEN, AL1150_ui_Square);
#endif
        if (G0415_ui_LeaderEmptyHanded) {
                for (AL1150_ui_ViewCell = C00_VIEW_CELL_FRONT_LEFT; AL1150_ui_ViewCell < C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT + 1; AL1150_ui_ViewCell++) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        if (F0376_COMMAND_IsPointInBox(G0291_aauc_DungeonViewClickableBoxes[AL1150_ui_ViewCell], P0752_i_X, P0753_i_Y - 33)) {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                        if (F0376_COMMAND_IsPointInBox(G2210_aai_XYZ_DungeonViewClickable[AL1150_ui_ViewCell], P0752_i_X, P0753_i_Y)) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        if (F0798_COMMAND_IsPointInZone(G2210_aai_XYZ_DungeonViewClickable[AL1150_ui_ViewCell], P0752_i_X, P0753_i_Y)) {
#endif
                                if (AL1150_ui_ViewCell == C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT) {
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                        if (G0288_B_FacingFountain && (G0411_i_LeaderIndex != CM1_CHAMPION_NONE)) {
                                                M516_CHAMPIONS[G0411_i_LeaderIndex].Water = 2048;
                                                F0064_SOUND_RequestPlay_CPSD(C08_SOUND_SWALLOW, G0306_i_PartyMapX, G0307_i_PartyMapY, C00_MODE_PLAY_IMMEDIATELY);
                                        }
#endif
                                        if (!G0286_B_FacingAlcove) {
#ifdef PC_FIX_CODE_SIZE
        L1150_ui_Multiple++;
        L1150_ui_Multiple++;
        L1150_ui_Multiple++;
        L1150_ui_Multiple++;
#endif
                                                F0372_COMMAND_ProcessType80_ClickInDungeonView_TouchFrontWallSensor();
                                        }
                                } else {
#ifdef PC_FIX_CODE_SIZE
        L1150_ui_Multiple++;
#endif
                                        F0373_COMMAND_ProcessType80_ClickInDungeonView_GrabLeaderHandObject(AL1150_ui_ViewCell);
                                }
                                return;
                        }
                }
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                if (G0285_i_SquareAheadElement == C00_ELEMENT_WALL) {
                        if (F0629_IsPointInZoneIndex(M641_ZONE, P0752_i_X, P0753_i_Y) || F0629_IsPointInZoneIndex(C746_ZONE, P0752_i_X, P0753_i_Y)) {
                                F0664_COMMAND_ProcessType80_ClickInDungeonView_KnockOnFrontWall(L2279_B_ClosedImaginaryFakeWall, L1155_i_MapX, L1156_i_MapY);
                        }
                }
#endif
        } else {
                L1152_T_Thing = G4055_s_LeaderHandObject.Thing;
                L1151_ps_Junk = (JUNK*)F0156_DUNGEON_GetThingData(L1152_T_Thing);
                if ((G0285_i_SquareAheadElement == C00_ELEMENT_WALL)
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                   && !L2279_B_ClosedImaginaryFakeWall
#endif
                   ) {
                        for (AL1150_ui_ViewCell = C00_VIEW_CELL_FRONT_LEFT; AL1150_ui_ViewCell < C01_VIEW_CELL_FRONT_RIGHT + 1; AL1150_ui_ViewCell++) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                if (F0376_COMMAND_IsPointInBox(G0462_aauc_Graphic561_Box_ObjectPiles[AL1150_ui_ViewCell], P0752_i_X, P0753_i_Y)) {
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                if (F0629_IsPointInZoneIndex(M642_ZONE_OBJECT_PILES + AL1150_ui_ViewCell, P0752_i_X, P0753_i_Y)) {
#endif
                                        F0374_COMMAND_ProcessType80_ClickInDungeonView_DropLeaderHandObject(AL1150_ui_ViewCell);
                                        return;
                                }
                        }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        if (F0376_COMMAND_IsPointInBox(G0291_aauc_DungeonViewClickableBoxes[C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT], P0752_i_X, P0753_i_Y - 33)) {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                        if (F0376_COMMAND_IsPointInBox(G2210_aai_XYZ_DungeonViewClickable[C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT], P0752_i_X, P0753_i_Y)) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        if (F0798_COMMAND_IsPointInZone(G2210_aai_XYZ_DungeonViewClickable[C05_VIEW_CELL_DOOR_BUTTON_OR_WALL_ORNAMENT], P0752_i_X, P0753_i_Y)) {
#endif
                                if (G0286_B_FacingAlcove) {
                                        F0374_COMMAND_ProcessType80_ClickInDungeonView_DropLeaderHandObject(C04_VIEW_CELL_ALCOVE);
                                } else {
                                        if (G0288_B_FacingFountain) {
                                                L1153_ui_IconIndex = F0033_OBJECT_GetIconIndex(L1152_T_Thing);
                                                L1154_ui_Weight = F0140_DUNGEON_GetObjectWeight(L1152_T_Thing);
                                                if ((L1153_ui_IconIndex >= C008_ICON_JUNK_WATER) && (L1153_ui_IconIndex <= C009_ICON_JUNK_WATERSKIN)) {
                                                        L1151_ps_Junk->ChargeCount = 3; /* Full */
                                                } else {
                                                        if (L1153_ui_IconIndex == C195_ICON_POTION_EMPTY_FLASK) {
                                                                ((POTION*)L1151_ps_Junk)->Type = C15_POTION_WATER_FLASK;
                                                        } else {
                                                                goto T0377019;
                                                        }
                                                }
                                                F0296_CHAMPION_DrawChangedObjectIcons();
                                                M516_CHAMPIONS[G0411_i_LeaderIndex].Load += F0140_DUNGEON_GetObjectWeight(L1152_T_Thing) - L1154_ui_Weight;
                                        }
                                        T0377019:
                                        F0372_COMMAND_ProcessType80_ClickInDungeonView_TouchFrontWallSensor();
                                }
                        }
                } else {
                        if (F0375_COMMAND_ProcessType80_ClickInDungeonView_IsLeaderHandObjectThrown(P0752_i_X, P0753_i_Y)) {
                                return;
                        }
                        for (AL1150_ui_ViewCell = C00_VIEW_CELL_FRONT_LEFT; AL1150_ui_ViewCell < C03_VIEW_CELL_BACK_LEFT + 1; AL1150_ui_ViewCell++) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                if (F0376_COMMAND_IsPointInBox(G0462_aauc_Graphic561_Box_ObjectPiles[AL1150_ui_ViewCell], P0752_i_X, P0753_i_Y)) {
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                if (F0629_IsPointInZoneIndex(M642_ZONE_OBJECT_PILES + AL1150_ui_ViewCell, P0752_i_X, P0753_i_Y)) {
#endif
                                        F0374_COMMAND_ProcessType80_ClickInDungeonView_DropLeaderHandObject(AL1150_ui_ViewCell);
                                        return;
                                }
                        }
                }
        }
}
#endif
