#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 MEDIA351_G14ED_G20E_G21E
#ifndef NOCOPYPROTECTION
int16_t G0068_i_CheckLastEvent22Time_CPSE = C00512_FALSE;
#endif
#endif
ACTIVE_GROUP* G0375_ps_ActiveGroups;
unsigned int16_t G0376_ui_MaximumActiveGroupCount;
unsigned int16_t G0377_ui_CurrentActiveGroupCount = 0;
int16_t G0378_i_CurrentGroupMapX;
int16_t G0379_i_CurrentGroupMapY;
THING G0380_T_CurrentGroupThing;
unsigned int16_t G0381_ui_CurrentGroupDistanceToParty;
int16_t G0382_i_CurrentGroupPrimaryDirectionToParty;
int16_t G0383_i_CurrentGroupSecondaryDirectionToParty;
unsigned char G0384_auc_GroupMovementTestedDirections[4];
char G0385_ac_FluxCages[4];
unsigned int16_t G0386_ui_FluxCageCount;
BOOLEAN G0387_B_GroupMovementBlockedByWallStairsPitFakeWallFluxcageTeleporter;
THING G0388_T_GroupMovementBlockedByGroupThing;
BOOLEAN G0389_B_GroupMovementBlockedByDoor;
BOOLEAN G0390_B_GroupMovementBlockedByParty;
unsigned int16_t G0391_ui_DropMovingCreatureFixedPossessionsCellCount;
unsigned char G0392_auc_DropMovingCreatureFixedPossessionsCells[4];
#ifdef MEDIA153_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
int16_t G0393_ai_CodePatch4_CPSE[34];
#endif
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
#ifndef NOCOPYPROTECTION
char G0393_ai_CodePatch4_CPSE[289];
#endif
#endif

#ifdef MEDIA707_I34E_I34M
extern BOOLEAN F0197_GROUP_IsViewPartyBlocked();
extern BOOLEAN F0198_GROUP_IsSmellPartyBlocked();
#endif


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

THING F0175_GROUP_GetThing(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0323_i_MapX, P0324_i_MapY)
#endif
int16_t P0323_i_MapX SEPARATOR
int16_t P0324_i_MapY FINAL_SEPARATOR
{
        REGISTER THING L0317_T_Thing;


        L0317_T_Thing = F0161_DUNGEON_GetSquareFirstThing(P0323_i_MapX, P0324_i_MapY);
        while ((L0317_T_Thing != C0xFFFE_THING_ENDOFLIST) && (M012_TYPE(L0317_T_Thing) != C04_THING_TYPE_GROUP)) {
                L0317_T_Thing = F0159_DUNGEON_GetNextThing(L0317_T_Thing);
        }
        return L0317_T_Thing;
}

int16_t F0176_GROUP_GetCreatureOrdinalInCell(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0325_ps_Group, P0326_ui_Cell)
#endif
REGISTER GROUP*           P0325_ps_Group SEPARATOR
REGISTER unsigned int16_t P0326_ui_Cell  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 char L0318_uc_GroupCells;
#endif
        REGISTER unsigned char L0319_uc_CreatureIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned char L0318_uc_GroupCells;
#endif
        REGISTER unsigned char L0320_uc_CreatureCell;


        if ((L0318_uc_GroupCells = F0145_DUNGEON_GetGroupCells(P0325_ps_Group, G0272_i_CurrentMapIndex)) == C0xFF_SINGLE_CENTERED_CREATURE) { /* A single centered creature in the group is present on all cells */
                return M000_INDEX_TO_ORDINAL(0);
        }
        L0319_uc_CreatureIndex = P0325_ps_Group->Count;
        if (M007_GET(G0243_as_Graphic559_CreatureInfo[P0325_ps_Group->Type].Attributes, MASK0x0003_SIZE) == C1_SIZE_HALF_SQUARE) {
                if ((F0147_DUNGEON_GetGroupDirections(P0325_ps_Group, G0272_i_CurrentMapIndex) & 0x0001) == (P0326_ui_Cell & 0x0001)) {
                        P0326_ui_Cell = M020_PREVIOUS(P0326_ui_Cell);
                }
                do {
                        if (((L0320_uc_CreatureCell = M050_CREATURE_VALUE(L0318_uc_GroupCells, L0319_uc_CreatureIndex)) == P0326_ui_Cell) || (L0320_uc_CreatureCell == M017_NEXT(P0326_ui_Cell))) {
                                return M000_INDEX_TO_ORDINAL(L0319_uc_CreatureIndex);
                        }
                } while (L0319_uc_CreatureIndex--);
        } else {
                do {
                        if (M050_CREATURE_VALUE(L0318_uc_GroupCells, L0319_uc_CreatureIndex) == P0326_ui_Cell) {
                                return M000_INDEX_TO_ORDINAL(L0319_uc_CreatureIndex);
                        }
                } while (L0319_uc_CreatureIndex--);
        }
        return 0;
}

int16_t F0177_GROUP_GetMeleeTargetCreatureOrdinal(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0327_i_GroupMapX, P0328_i_GroupMapY, P0329_i_PartyMapX, P0330_i_PartyMapY, P0331_ui_ChampionCell)
#endif
int16_t          P0327_i_GroupMapX     SEPARATOR
int16_t          P0328_i_GroupMapY     SEPARATOR
int16_t          P0329_i_PartyMapX     SEPARATOR
int16_t          P0330_i_PartyMapY     SEPARATOR
unsigned int16_t P0331_ui_ChampionCell FINAL_SEPARATOR
{
        REGISTER GROUP* L0324_ps_Group;
        REGISTER unsigned int16_t L0321_ui_Counter;
        REGISTER int16_t L0322_i_CreatureOrdinal;
        REGISTER THING L0323_T_GroupThing;
        unsigned char L0325_auc_OrderedCellsToAttack[4];


#ifdef MEDIA070_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        if ((L0323_T_GroupThing = F0175_GROUP_GetThing(P0327_i_GroupMapX, P0328_i_GroupMapY)) == C0xFFFE_THING_ENDOFLIST) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                return 0;
#endif
        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
        else {
#endif
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
        if ((L0323_T_GroupThing = F0175_GROUP_GetThing(P0327_i_GroupMapX, P0328_i_GroupMapY)) != C0xFFFE_THING_ENDOFLIST) {
#endif
                L0324_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L0323_T_GroupThing);
                F0229_GROUP_SetOrderedCellsToAttack(M772_CAST_PC(L0325_auc_OrderedCellsToAttack), P0327_i_GroupMapX, P0328_i_GroupMapY, P0329_i_PartyMapX, P0330_i_PartyMapY, P0331_ui_ChampionCell);
                L0321_ui_Counter = 0;
                for (;;) { /*_Infinite loop_*/
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        if (L0321_ui_Counter == 4) {
                                return 0;
                        }
#endif
                        if (L0322_i_CreatureOrdinal = F0176_GROUP_GetCreatureOrdinalInCell(L0324_ps_Group, L0325_auc_OrderedCellsToAttack[L0321_ui_Counter])) {
                                return L0322_i_CreatureOrdinal;
                        }
                        L0321_ui_Counter++;
                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        }
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        return 0;
#endif
}

#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
BOOLEAN F0223_GROUP_IsLordChaosAllowed(
int16_t P0468_i_MapX SEPARATOR
int16_t P0469_i_MapY FINAL_SEPARATOR
{
        REGISTER int16_t L0544_i_SquareType;


        return (((L0544_i_SquareType = M034_SQUARE_TYPE(F0151_DUNGEON_GetSquare(P0468_i_MapX, P0469_i_MapY))) == C01_ELEMENT_CORRIDOR)
                || (L0544_i_SquareType == C05_ELEMENT_TELEPORTER) || (L0544_i_SquareType == C02_ELEMENT_PIT) || (L0544_i_SquareType == C04_ELEMENT_DOOR));
}
#endif

unsigned int16_t F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0332_ui_GroupValue, P0333_ui_CreatureIndex, P0334_ui_CreatureValue)
#endif
unsigned int16_t          P0332_ui_GroupValue    SEPARATOR
REGISTER unsigned int16_t P0333_ui_CreatureIndex SEPARATOR
REGISTER unsigned int16_t P0334_ui_CreatureValue FINAL_SEPARATOR
{
        P0334_ui_CreatureValue &= 0x0003;
        P0334_ui_CreatureValue <<= (P0333_ui_CreatureIndex <<= 1);
        return P0334_ui_CreatureValue | (P0332_ui_GroupValue & ~(3 << P0333_ui_CreatureIndex));
}

STATICFUNCTION long F0179_GROUP_GetCreatureAspectUpdateTime(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0335_ps_ActiveGroup, P0336_i_CreatureIndex, P0337_B_IsAttacking)
#endif
REGISTER ACTIVE_GROUP* P0335_ps_ActiveGroup  SEPARATOR
REGISTER int16_t       P0336_i_CreatureIndex SEPARATOR
BOOLEAN                P0337_B_IsAttacking   FINAL_SEPARATOR
{
        REGISTER GROUP* L0329_ps_Group;
        REGISTER unsigned int16_t L0326_ui_Multiple;
#define AL0326_ui_Aspect         L0326_ui_Multiple
#define AL0326_ui_AnimationTicks L0326_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 L0327_ui_CreatureGraphicInfo;
#endif
        REGISTER int16_t L0328_i_Offset;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0327_ui_CreatureGraphicInfo;
        REGISTER unsigned int16_t L0331_ui_CreatureType;
#endif
        BOOLEAN L0330_B_ProcessGroup;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned int16_t L0331_ui_CreatureType;
#endif
#ifdef MEDIA400_G20E_G21E_A21E_A22E
        unsigned int16_t L1635_ui_SoundIndex;
#endif


        L0329_ps_Group = &(((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[P0335_ps_ActiveGroup->GroupThingIndex]);
        L0327_ui_CreatureGraphicInfo = G0243_as_Graphic559_CreatureInfo[L0331_ui_CreatureType = L0329_ps_Group->Type].GraphicInfo;
        if (L0330_B_ProcessGroup = (P0336_i_CreatureIndex < 0)) { /* If the creature index is negative then all creatures in the group are processed */
                P0336_i_CreatureIndex = L0329_ps_Group->Count;
        }
        do {
                AL0326_ui_Aspect = P0335_ps_ActiveGroup->Aspect[P0336_i_CreatureIndex] & (MASK0x0080_IS_ATTACKING | MASK0x0040_FLIP_BITMAP);
                if (L0328_i_Offset = M052_MAXIMUM_HORIZONTAL_OFFSET(L0327_ui_CreatureGraphicInfo)) {
                        L0328_i_Offset = M002_RANDOM(L0328_i_Offset);
                        if (M005_RANDOM(2)) {
                                L0328_i_Offset = (-L0328_i_Offset) & 0x0007;
                        }
                        M024_SET_HORIZONTAL_OFFSET(AL0326_ui_Aspect, L0328_i_Offset);
                }
                if (L0328_i_Offset = M053_MAXIMUM_VERTICAL_OFFSET(L0327_ui_CreatureGraphicInfo)) {
                        L0328_i_Offset = M002_RANDOM(L0328_i_Offset);
                        if (M005_RANDOM(2)) {
                                L0328_i_Offset = (-L0328_i_Offset) & 0x0007;
                        }
                        M025_SET_VERTICAL_OFFSET(AL0326_ui_Aspect, L0328_i_Offset);
                }
                if (P0337_B_IsAttacking) {
                        if (M007_GET(L0327_ui_CreatureGraphicInfo, MASK0x0200_FLIP_ATTACK)) {
                                if (M007_GET(AL0326_ui_Aspect, MASK0x0080_IS_ATTACKING) && (L0331_ui_CreatureType == C18_CREATURE_ANIMATED_ARMOUR_DETH_KNIGHT)) {
                                        if (M005_RANDOM(2)) {
                                                M010_TOGGLE(AL0326_ui_Aspect, MASK0x0040_FLIP_BITMAP);
                                                F0064_SOUND_RequestPlay_CPSD(M563_SOUND_COMBAT_ATTACK_SKELETON_ANIMATED_ARMOUR_DETH_KNIGHT, G0378_i_CurrentGroupMapX, G0379_i_CurrentGroupMapY, C01_MODE_PLAY_IF_PRIORITIZED);
                                        }
                                } else {
                                        if (!M007_GET(AL0326_ui_Aspect, MASK0x0080_IS_ATTACKING) || !M007_GET(L0327_ui_CreatureGraphicInfo, MASK0x0400_FLIP_DURING_ATTACK)) {
                                                if (M005_RANDOM(2)) {
                                                        M008_SET(AL0326_ui_Aspect, MASK0x0040_FLIP_BITMAP);
                                                } else {
#ifdef PC_FIX_CODE_SIZE
        L0328_i_Offset++;
        L0328_i_Offset++;
        L0328_i_Offset++;
        L0328_i_Offset++;
        L0328_i_Offset++;
#endif
                                                        M009_CLEAR(AL0326_ui_Aspect, MASK0x0040_FLIP_BITMAP);
                                                }
                                        }
                                }
                        } else {
                                M009_CLEAR(AL0326_ui_Aspect, MASK0x0040_FLIP_BITMAP);
                        }
                        M008_SET(AL0326_ui_Aspect, MASK0x0080_IS_ATTACKING);
                } else {
                        if (M007_GET(L0327_ui_CreatureGraphicInfo, MASK0x0004_FLIP_NON_ATTACK)) {
#ifdef MEDIA355_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                if (L0331_ui_CreatureType == C13_CREATURE_COUATL) {
                                        if (M005_RANDOM(2)) {
                                                M010_TOGGLE(AL0326_ui_Aspect, MASK0x0040_FLIP_BITMAP);
#ifdef MEDIA383_G14ED_A20ED_A20E_A20F_A20G_A22G
                                                F0064_SOUND_RequestPlay_CPSD(C23_SOUND_MOVE_COUATL_GIANT_WASP_MUNCHER, G0378_i_CurrentGroupMapX, G0379_i_CurrentGroupMapY, C01_MODE_PLAY_IF_PRIORITIZED);
#endif
#ifdef MEDIA400_G20E_G21E_A21E_A22E
                                                L1635_ui_SoundIndex = F0514_MOVE_GetSound(C13_CREATURE_COUATL);
                                                if (L1635_ui_SoundIndex <= M513_SOUND_COUNT) {
                                                        F0064_SOUND_RequestPlay_CPSD(L1635_ui_SoundIndex, G0378_i_CurrentGroupMapX, G0379_i_CurrentGroupMapY, C01_MODE_PLAY_IF_PRIORITIZED);
                                                }
#endif
#ifdef MEDIA485_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                F0064_SOUND_RequestPlay_CPSD(F0514_MOVE_GetSound(C13_CREATURE_COUATL), G0378_i_CurrentGroupMapX, G0379_i_CurrentGroupMapY, C01_MODE_PLAY_IF_PRIORITIZED);
#endif
                                        }
                                } else {
#endif
                                        if (M005_RANDOM(2)) {
                                                M008_SET(AL0326_ui_Aspect, MASK0x0040_FLIP_BITMAP);
                                        } else {
#ifdef PC_FIX_CODE_SIZE
        L0328_i_Offset++;
        L0328_i_Offset++;
        L0328_i_Offset++;
        L0328_i_Offset++;
        L0328_i_Offset++;
#endif
                                                M009_CLEAR(AL0326_ui_Aspect, MASK0x0040_FLIP_BITMAP);
                                        }
#ifdef MEDIA355_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                }
#endif
                        } else {
                                M009_CLEAR(AL0326_ui_Aspect, MASK0x0040_FLIP_BITMAP);
                        }
                        M009_CLEAR(AL0326_ui_Aspect, MASK0x0080_IS_ATTACKING);
                }
                P0335_ps_ActiveGroup->Aspect[P0336_i_CreatureIndex] = AL0326_ui_Aspect;
        } while (L0330_B_ProcessGroup && (P0336_i_CreatureIndex--));
        AL0326_ui_AnimationTicks = G0243_as_Graphic559_CreatureInfo[L0329_ps_Group->Type].AnimationTicks;
        return G0313_ul_GameTime + (P0337_B_IsAttacking ? M064_NEXT_ATTACK_ASPECT_UPDATE_TICKS(AL0326_ui_AnimationTicks) : M063_NEXT_NON_ATTACK_ASPECT_UPDATE_TICKS(AL0326_ui_AnimationTicks)) + M005_RANDOM(2);
}

void F0180_GROUP_StartWandering(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0338_i_MapX, P0339_i_MapY)
#endif
int16_t P0338_i_MapX SEPARATOR
int16_t P0339_i_MapY FINAL_SEPARATOR
{
        REGISTER GROUP* L0332_ps_Group;
        EVENT L0333_s_Event;


#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0332_ps_Group = &((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(F0175_GROUP_GetThing(P0338_i_MapX, P0339_i_MapY))];
#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 */
        L0332_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(F0175_GROUP_GetThing(P0338_i_MapX, P0339_i_MapY));
#endif
        if (L0332_ps_Group->Behavior >= C4_BEHAVIOR_USELESS) {
                L0332_ps_Group->Behavior = C0_BEHAVIOR_WANDER;
        }
        M033_SET_MAP_AND_TIME(L0333_s_Event.Map_Time, G0272_i_CurrentMapIndex, (G0313_ul_GameTime + 1));
        L0333_s_Event.A.A.Type = C37_EVENT_UPDATE_BEHAVIOR_GROUP;
        L0333_s_Event.A.A.Priority = 255 - G0243_as_Graphic559_CreatureInfo[L0332_ps_Group->Type].MovementTicks; /* The fastest creatures (with small MovementTicks value) get higher event priority */
        L0333_s_Event.C.Ticks = 0;
        L0333_s_Event.B.Location.MapX = P0338_i_MapX;
        L0333_s_Event.B.Location.MapY = P0339_i_MapY;
        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0333_s_Event);
}

void F0181_GROUP_DeleteEvents(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0340_i_MapX, P0341_i_MapY)
#endif
REGISTER unsigned int16_t P0340_i_MapX SEPARATOR
REGISTER unsigned int16_t P0341_i_MapY FINAL_SEPARATOR
{
        REGISTER EVENT* L0336_ps_Event;
        REGISTER unsigned int16_t L0334_ui_EventIndex;
        REGISTER unsigned int16_t L0335_ui_EventType;


#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED /* CHANGE7_11_OPTIMIZATION Comma removed */
        for (L0334_ui_EventIndex = 0, L0336_ps_Event = G0370_ps_Events; L0334_ui_EventIndex < G0369_EventMaximumCount; L0336_ps_Event++, L0334_ui_EventIndex++) {
#endif
#ifdef MEDIA289_S20E_S21E_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB /* CHANGE7_11_OPTIMIZATION Comma removed */
        L0336_ps_Event = G0370_ps_Events;
        for (L0334_ui_EventIndex = 0; L0334_ui_EventIndex < G0369_EventMaximumCount; L0334_ui_EventIndex++) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L0336_ps_Event = G0370_ps_Events;
        for (L0334_ui_EventIndex = 0; L0334_ui_EventIndex < G2009_i_LargestUsedEventOrdinal; L0334_ui_EventIndex++) {
#endif
                if ((M029_MAP(L0336_ps_Event->Map_Time) == G0272_i_CurrentMapIndex) &&
                    ((L0335_ui_EventType = L0336_ps_Event->A.A.Type) > C29_EVENT_GROUP_REACTION_DANGER_ON_SQUARE - 1) && (L0335_ui_EventType < C41_EVENT_UPDATE_BEHAVIOR_CREATURE_3 + 1) &&
                    (L0336_ps_Event->B.Location.MapX == P0340_i_MapX) && (L0336_ps_Event->B.Location.MapY == P0341_i_MapY)) {
                        F0237_TIMELINE_DeleteEvent(L0334_ui_EventIndex);
                }
#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 */
                L0336_ps_Event++;
#endif
        }
}

void F0182_GROUP_StopAttacking(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0342_ps_ActiveGroup, P0343_i_MapX, P0344_i_MapY)
#endif
ACTIVE_GROUP* P0342_ps_ActiveGroup SEPARATOR
int16_t       P0343_i_MapX         SEPARATOR
int16_t       P0344_i_MapY         FINAL_SEPARATOR
{
        REGISTER int16_t L0337_i_CreatureIndex;


        for (L0337_i_CreatureIndex = 0; L0337_i_CreatureIndex < 4; M009_CLEAR(P0342_ps_ActiveGroup->Aspect[L0337_i_CreatureIndex++], MASK0x0080_IS_ATTACKING));
        F0181_GROUP_DeleteEvents(P0343_i_MapX, P0344_i_MapY);
}

void F0183_GROUP_AddActiveGroup(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0345_T_GroupThing, P0346_i_MapX, P0347_i_MapY)
#endif
THING   P0345_T_GroupThing SEPARATOR
int16_t P0346_i_MapX       SEPARATOR
int16_t P0347_i_MapY       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 L0338_i_Unreferenced; /* BUG0_00 Useless code */
        REGISTER unsigned int16_t L0339_ui_CreatureIndex;
        REGISTER GROUP* L0340_ps_Group;
        register ACTIVE_GROUP* L0341_ps_ActiveGroup;
        long L0342_l_Unreferenced; /* BUG0_00 Useless code */
        BOOLEAN L0343_B_HalfSquareSizedCreature_Useless; /* BUG0_00 Useless code */
        unsigned int16_t L0344_ui_ActiveGroupIndex;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER ACTIVE_GROUP* L0341_ps_ActiveGroup;
        REGISTER GROUP* L0340_ps_Group;
        REGISTER unsigned int16_t L0339_ui_CreatureIndex;
        REGISTER unsigned int16_t L0344_ui_ActiveGroupIndex;
#endif


        L0341_ps_ActiveGroup = G0375_ps_ActiveGroups;
        L0344_ui_ActiveGroupIndex = 0;
        while (L0341_ps_ActiveGroup->GroupThingIndex >= 0) {
                if (++L0344_ui_ActiveGroupIndex >= G0376_ui_MaximumActiveGroupCount) {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        return; /* BUG0_11 Data corruption in memory. Each group located on the same map as the party has additional associated data but there is only provision for 60 instances (G0376_ui_MaximumActiveGroupCount). If there are more groups at the same time then some of them do not get their instance and when the game accesses this information it will corrupt other data in memory (either the instance of another group, parts of the timeline or events). This situation cannot occur in the original Dungeon Master and Chaos Strikes Back dungeons for the following reasons (but it may occur in custom dungeons if they are not designed carefully): there is no map with already more than 60 groups in the original dungeons and none of the following 3 possible ways to move a group into a map can increase the number of instances above the maximum of 60:
                        - A group generator sensor is triggered: the game never generates a group on the party map if there are less than 5 instances available. This limits the actual number of groups on a map to 55 in most cases.
                        - A group falls through a pit from the map above (the creature type must be allowed on the target map): a group will never willingly move to an open pit square. It may move to a closed pit square and fall if the pit is then open (either automatically or triggered by the party on the map below). There are no such pits in the original dungeons.
                        - A group is teleported from another map (the creature type must be allowed on the target map): in the original dungeons, all teleporters whose scope include groups and target another map are either inaccessible to groups or the groups are not allowed on the target map. The only exception is for some Gigglers in the Chaos Strikes Back dungeon but there are not enough to use the 5 reserved instances.

                        This code returns immediately if all ACTIVE_GROUP entries are already in use, which avoids an out of bounds access into G0375_ps_ActiveGroups below (through L0341_ps_ActiveGroup). However in this case the specified group ends up without an associated ACTIVE_GROUP structure which is assumed everywhere in the code to be present for groups on the same map as the party. If there are more than 60 groups on the party map at any given time then this will corrupt memory (in G0370_ps_Events and G0371_pui_Timeline allocated in F0233_TIMELINE_Initialize_CPSE before G0375_ps_ActiveGroups) because of read and write operations at incorrect memory addresses (the 'Cells' value of the GROUP will be used as an index in G0375_ps_ActiveGroups even though that value was not replaced by the index of an ACTIVE_GROUP in this function) */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        F0019_MAIN_DisplayErrorAndStop(C71_ERROR_TOO_MANY_ACTIVE_GROUPS);
#endif
                }
                L0341_ps_ActiveGroup++;
        }
        G0377_ui_CurrentActiveGroupCount++;
        L0340_ps_Group = ((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP]) + (L0341_ps_ActiveGroup->GroupThingIndex = M013_INDEX(P0345_T_GroupThing));
        L0341_ps_ActiveGroup->Cells = L0340_ps_Group->Cells;
        L0340_ps_Group->ActiveGroupIndex = L0344_ui_ActiveGroupIndex;
        L0341_ps_ActiveGroup->PriorMapX = L0341_ps_ActiveGroup->HomeMapX = P0346_i_MapX;
        L0341_ps_ActiveGroup->PriorMapY = L0341_ps_ActiveGroup->HomeMapY = P0347_i_MapY;
        L0341_ps_ActiveGroup->LastMoveTime = G0313_ul_GameTime - 127;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L0343_B_HalfSquareSizedCreature_Useless = (M007_GET(G0243_as_Graphic559_CreatureInfo[L0340_ps_Group->Type].Attributes, MASK0x0003_SIZE) == C1_SIZE_HALF_SQUARE); /* BUG0_00 Useless code */
#endif
        L0339_ui_CreatureIndex = L0340_ps_Group->Count;
        do {
                L0341_ps_ActiveGroup->Directions = F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(L0341_ps_ActiveGroup->Directions, L0339_ui_CreatureIndex, L0340_ps_Group->Direction);
                L0341_ps_ActiveGroup->Aspect[L0339_ui_CreatureIndex] = 0;
        } while (L0339_ui_CreatureIndex--);
        F0179_GROUP_GetCreatureAspectUpdateTime(L0341_ps_ActiveGroup, CM1_WHOLE_CREATURE_GROUP, C0_FALSE);
}

void F0184_GROUP_RemoveActiveGroup(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0348_ui_ActiveGroupIndex)
unsigned int16_t P0348_ui_ActiveGroupIndex FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0348_ui_ActiveGroupIndex FINAL_SEPARATOR
#endif
{
        REGISTER ACTIVE_GROUP* L0347_ps_ActiveGroup;
        REGISTER GROUP* L0348_ps_Group;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L0345_i_Unreferenced; /* BUG0_00 Useless code */
        REGISTER int16_t L0346_i_Unreferenced; /* BUG0_00 Useless code */
#endif


        if ((P0348_ui_ActiveGroupIndex > G0376_ui_MaximumActiveGroupCount) || (G0375_ps_ActiveGroups[P0348_ui_ActiveGroupIndex].GroupThingIndex < 0)) {
                return;
        }
        L0347_ps_ActiveGroup = &G0375_ps_ActiveGroups[P0348_ui_ActiveGroupIndex];
        L0348_ps_Group = &((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[L0347_ps_ActiveGroup->GroupThingIndex];
        G0377_ui_CurrentActiveGroupCount--;
        L0348_ps_Group->Cells = L0347_ps_ActiveGroup->Cells;
        L0348_ps_Group->Direction = M021_NORMALIZE(L0347_ps_ActiveGroup->Directions);
        if (L0348_ps_Group->Behavior >= C4_BEHAVIOR_USELESS) {
                L0348_ps_Group->Behavior = C0_BEHAVIOR_WANDER;
        }
        L0347_ps_ActiveGroup->GroupThingIndex = -1;
}

THING F0185_GROUP_GetGenerated(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0349_i_CreatureType, P0350_i_HealthMultiplier, P0351_ui_CreatureCount, P0352_i_Direction, P0353_i_MapX, P0354_i_MapY)
#endif
int16_t                   P0349_i_CreatureType     SEPARATOR
int16_t                   P0350_i_HealthMultiplier SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
unsigned int16_t          P0351_ui_CreatureCount   SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0351_ui_CreatureCount   SEPARATOR
#endif
unsigned int16_t          P0352_i_Direction        SEPARATOR
int16_t                   P0353_i_MapX             SEPARATOR
int16_t                   P0354_i_MapY             FINAL_SEPARATOR
{
        REGISTER GROUP* L0353_ps_Group;
        REGISTER CREATURE_INFO* L0354_ps_CreatureInfo;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0352_ui_GroupCells;
        REGISTER unsigned int16_t L0351_ui_Cell;
#endif
        REGISTER THING L0349_T_GroupThing;
        REGISTER unsigned int16_t L0350_ui_BaseHealth;
#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 L0351_ui_Cell;
        REGISTER unsigned int16_t L0352_ui_GroupCells;
#endif
        BOOLEAN L0355_B_SeveralCreaturesInGroup;


        if (((G0377_ui_CurrentActiveGroupCount >= (G0376_ui_MaximumActiveGroupCount - 5)) && (G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex)) || ((L0349_T_GroupThing = F0166_DUNGEON_GetUnusedThing(C04_THING_TYPE_GROUP)) == C0xFFFF_THING_NONE)) {
                return C0xFFFF_THING_NONE;
        }
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0353_ps_Group = &((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(L0349_T_GroupThing)];
#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 */
        L0353_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L0349_T_GroupThing);
#endif
        L0353_ps_Group->Slot = C0xFFFE_THING_ENDOFLIST;
        L0353_ps_Group->DoNotDiscard = C0_FALSE;
        L0353_ps_Group->Direction = P0352_i_Direction;
        L0353_ps_Group->Count = P0351_ui_CreatureCount;
        if (L0355_B_SeveralCreaturesInGroup = P0351_ui_CreatureCount) {
                L0351_ui_Cell = M004_RANDOM(4);
        } else {
                L0352_ui_GroupCells = C0xFF_SINGLE_CENTERED_CREATURE;
        }
        L0354_ps_CreatureInfo = &G0243_as_Graphic559_CreatureInfo[L0353_ps_Group->Type = P0349_i_CreatureType];
        L0350_ui_BaseHealth = L0354_ps_CreatureInfo->BaseHealth;
        do {
                L0353_ps_Group->Health[P0351_ui_CreatureCount] = (L0350_ui_BaseHealth * P0350_i_HealthMultiplier) + M002_RANDOM((L0350_ui_BaseHealth >> 2) + 1);
                if (L0355_B_SeveralCreaturesInGroup) {
                        L0352_ui_GroupCells = F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(L0352_ui_GroupCells, P0351_ui_CreatureCount, L0351_ui_Cell++);
                        if (M007_GET(L0354_ps_CreatureInfo->Attributes, MASK0x0003_SIZE) == C1_SIZE_HALF_SQUARE) {
                                L0351_ui_Cell++;
                        }
                        L0351_ui_Cell &= 0x0003;
                }
        } while (P0351_ui_CreatureCount--);
        L0353_ps_Group->Cells = L0352_ui_GroupCells;
        if (F0267_MOVE_GetMoveResult_CPSCE(L0349_T_GroupThing, CM1_MAPX_NOT_ON_A_SQUARE, 0, P0353_i_MapX, P0354_i_MapY)) { /* If F0267_MOVE_GetMoveResult_CPSCE returns C1_TRUE then the group was either killed by a projectile impact (in which case the thing data was marked as unused) or the party is on the destination square and an event is created to move the creature into the dungeon later (in which case the thing is referenced in the event) */
                return C0xFFFF_THING_NONE;
        }
        F0064_SOUND_RequestPlay_CPSD(M560_SOUND_BUZZ, P0353_i_MapX, P0354_i_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
        return L0349_T_GroupThing;
}

STATICFUNCTION void F0186_GROUP_DropCreatureFixedPossessions(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0355_ui_CreatureType, P0356_i_MapX, P0357_i_MapY, P0358_ui_Cell, P0359_i_Mode) /* Drop fixed possessions for a single creature in a group */
#endif
unsigned int16_t P0355_ui_CreatureType SEPARATOR
int16_t          P0356_i_MapX          SEPARATOR
int16_t          P0357_i_MapY          SEPARATOR
unsigned int16_t P0358_ui_Cell         SEPARATOR
int16_t          P0359_i_Mode          FINAL_SEPARATOR
{
        REGISTER unsigned int16_t* L0359_pui_FixedPossessions;
        REGISTER WEAPON* L0360_ps_Weapon;
        REGISTER unsigned int16_t L0356_ui_FixedPossession;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register int16_t L0357_i_ThingType;
        register THING L0358_T_Thing;
        BOOLEAN L0361_B_Cursed;
        BOOLEAN L0362_B_WeaponDropped;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L0358_T_Thing;
        REGISTER int16_t L0357_i_ThingType;
        REGISTER unsigned int16_t L0361_B_Cursed;
        REGISTER BOOLEAN L0362_B_WeaponDropped;
#endif


        L0361_B_Cursed = C0_FALSE;
        L0362_B_WeaponDropped = C0_FALSE;
        switch (P0355_ui_CreatureType) {
                default:
                        return;
                case C12_CREATURE_SKELETON:
                        L0359_pui_FixedPossessions = G0245_aui_Graphic559_FixedPossessionsCreature12Skeleton;
                        break;
                case C09_CREATURE_STONE_GOLEM:
                        L0359_pui_FixedPossessions = G0246_aui_Graphic559_FixedPossessionsCreature09StoneGolem;
                        break;
                case C16_CREATURE_TROLIN_ANTMAN:
                        L0359_pui_FixedPossessions = G0247_aui_Graphic559_FixedPossessionsCreature16Trolin_Antman;
                        break;
                case C18_CREATURE_ANIMATED_ARMOUR_DETH_KNIGHT:
                        L0361_B_Cursed = C1_TRUE;
                        L0359_pui_FixedPossessions = G0248_aui_Graphic559_FixedPossessionsCreature18AnimatedArmour_DethKnight;
                        break;
                case C07_CREATURE_ROCK_ROCKPILE:
                        L0359_pui_FixedPossessions = G0249_aui_Graphic559_FixedPossessionsCreature07Rock_RockPile;
                        break;
                case C04_CREATURE_PAIN_RAT_HELLHOUND:
                        L0359_pui_FixedPossessions = G0250_aui_Graphic559_FixedPossessionsCreature04PainRat_Hellhound;
                        break;
                case C06_CREATURE_SCREAMER:
                        L0359_pui_FixedPossessions = G0251_aui_Graphic559_FixedPossessionsCreature06Screamer;
                        break;
                case C15_CREATURE_MAGENTA_WORM_WORM:
                        L0359_pui_FixedPossessions = G0252_aui_Graphic559_FixedPossessionsCreature15MagentaWorm_Worm;
                        break;
                case C24_CREATURE_RED_DRAGON:
                        L0359_pui_FixedPossessions = G0253_aui_Graphic559_FixedPossessionsCreature24RedDragon;
        }
        while (L0356_ui_FixedPossession = *L0359_pui_FixedPossessions++) {
                if (M007_GET(L0356_ui_FixedPossession, MASK0x8000_RANDOM_DROP) && M005_RANDOM(2))
                        continue;
                if (M009_CLEAR(L0356_ui_FixedPossession, MASK0x8000_RANDOM_DROP) >= C127_OBJECT_INFO_INDEX_FIRST_JUNK) {
                        L0357_i_ThingType = C10_THING_TYPE_JUNK;
                        L0356_ui_FixedPossession -= C127_OBJECT_INFO_INDEX_FIRST_JUNK;
                } else {
                        if (L0356_ui_FixedPossession >= C069_OBJECT_INFO_INDEX_FIRST_ARMOUR) {
                                L0357_i_ThingType = C06_THING_TYPE_ARMOUR;
                                L0356_ui_FixedPossession -= C069_OBJECT_INFO_INDEX_FIRST_ARMOUR;
                        } else {
                                L0362_B_WeaponDropped = C1_TRUE;
                                L0357_i_ThingType = C05_THING_TYPE_WEAPON;
                                L0356_ui_FixedPossession -= C023_OBJECT_INFO_INDEX_FIRST_WEAPON;
                        }
                }
                if ((L0358_T_Thing = F0166_DUNGEON_GetUnusedThing(L0357_i_ThingType)) == C0xFFFF_THING_NONE) {
                        continue;
                }
                L0360_ps_Weapon = (WEAPON*)F0156_DUNGEON_GetThingData(L0358_T_Thing);
                L0360_ps_Weapon->Type = L0356_ui_FixedPossession; /* The same pointer type is used no matter the actual type C05_THING_TYPE_WEAPON, C06_THING_TYPE_ARMOUR or C10_THING_TYPE_JUNK */
                L0360_ps_Weapon->Cursed = L0361_B_Cursed;
#ifdef MEDIA016_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
                L0358_T_Thing = M015_THING_WITH_NEW_CELL(L0358_T_Thing, ((P0358_ui_Cell == C0xFF_SINGLE_CENTERED_CREATURE) || !M004_RANDOM(4)) ? M004_RANDOM(4) : P0358_ui_Cell);
#endif
#ifdef MEDIA613_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                if ((P0358_ui_Cell == C0xFF_SINGLE_CENTERED_CREATURE) || !M004_RANDOM(4)) {
                        L0356_ui_FixedPossession = M004_RANDOM(4);
                } else {
                        L0356_ui_FixedPossession = P0358_ui_Cell;
                }
                L0358_T_Thing = M015_THING_WITH_NEW_CELL(L0358_T_Thing, L0356_ui_FixedPossession);
#endif
                F0267_MOVE_GetMoveResult_CPSCE(L0358_T_Thing, CM1_MAPX_NOT_ON_A_SQUARE, 0, P0356_i_MapX, P0357_i_MapY);
        }
        F0064_SOUND_RequestPlay_CPSD(L0362_B_WeaponDropped ? C00_SOUND_METALLIC_THUD : C04_SOUND_WOODEN_THUD_ATTACK_TROLIN_ANTMAN_STONE_GOLEM, P0356_i_MapX, P0357_i_MapY, P0359_i_Mode);
}

void F0187_GROUP_DropMovingCreatureFixedPossessions(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0360_T_Thing, P0361_i_MapX, P0362_i_MapY)
#endif
THING   P0360_T_Thing SEPARATOR
int16_t P0361_i_MapX  SEPARATOR
int16_t P0362_i_MapY  FINAL_SEPARATOR
{
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        GROUP* L0363_ps_Group;
#endif
        int16_t L0364_i_CreatureType;


        if (G0391_ui_DropMovingCreatureFixedPossessionsCellCount) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                L0364_i_CreatureType = ((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(P0360_T_Thing)].Type;
#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 */
                L0363_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(P0360_T_Thing);
                L0364_i_CreatureType = L0363_ps_Group->Type;
#endif
                while (G0391_ui_DropMovingCreatureFixedPossessionsCellCount) {
                        F0186_GROUP_DropCreatureFixedPossessions(L0364_i_CreatureType, P0361_i_MapX, P0362_i_MapY, G0392_auc_DropMovingCreatureFixedPossessionsCells[--G0391_ui_DropMovingCreatureFixedPossessionsCellCount], C02_MODE_PLAY_ONE_TICK_LATER);
                }
        }
}

void F0188_GROUP_DropGroupPossessions(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0363_i_MapX, P0364_i_MapY, P0365_T_GroupThing, P0366_i_Mode) /* Drop fixed possessions for each creature in the group and also the group possessions */
REGISTER int16_t P0363_i_MapX       SEPARATOR
REGISTER int16_t P0364_i_MapY       SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t          P0363_i_MapX       SEPARATOR
int16_t          P0364_i_MapY       SEPARATOR
#endif
THING            P0365_T_GroupThing SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t          P0366_i_Mode       FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t P0366_i_Mode       FINAL_SEPARATOR
#endif
{
        REGISTER GROUP* L0367_ps_Group;
        REGISTER THING L0365_T_CurrentThing;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0369_i_CreatureIndex;
        REGISTER unsigned int16_t L0370_ui_GroupCells;
        REGISTER BOOLEAN L0371_B_WeaponDropped;
#endif
        REGISTER THING L0366_T_NextThing;
        unsigned int16_t L0368_ui_CreatureType;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned int16_t L0369_i_CreatureIndex;
        unsigned int16_t L0370_ui_GroupCells;
        BOOLEAN L0371_B_WeaponDropped;
#endif


#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0367_ps_Group = &((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(P0365_T_GroupThing)];
#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 */
        L0367_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(P0365_T_GroupThing);
#endif
        if ((P0366_i_Mode >= C00_MODE_PLAY_IMMEDIATELY) && M007_GET(G0243_as_Graphic559_CreatureInfo[L0368_ui_CreatureType = L0367_ps_Group->Type].Attributes, MASK0x0200_DROP_FIXED_POSSESSIONS)) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
                L0369_i_CreatureIndex = L0367_ps_Group->Count;
                L0370_ui_GroupCells = F0145_DUNGEON_GetGroupCells(L0367_ps_Group, G0272_i_CurrentMapIndex);
                do {
                        F0186_GROUP_DropCreatureFixedPossessions(L0368_ui_CreatureType, P0363_i_MapX, P0364_i_MapY, (L0370_ui_GroupCells == C0xFF_SINGLE_CENTERED_CREATURE) ? C0xFF_SINGLE_CENTERED_CREATURE : M050_CREATURE_VALUE(L0370_ui_GroupCells, L0369_i_CreatureIndex), P0366_i_Mode);
                } while (L0369_i_CreatureIndex--);
        }
        if ((L0365_T_CurrentThing = L0367_ps_Group->Slot) != C0xFFFE_THING_ENDOFLIST) {
                L0371_B_WeaponDropped = C0_FALSE;
                do {
                        L0366_T_NextThing = F0159_DUNGEON_GetNextThing(L0365_T_CurrentThing);
                        L0365_T_CurrentThing = M015_THING_WITH_NEW_CELL(L0365_T_CurrentThing, M004_RANDOM(4));
                        if (M012_TYPE(L0365_T_CurrentThing) == C05_THING_TYPE_WEAPON) {
                                L0371_B_WeaponDropped = C1_TRUE;
                        }
                        F0267_MOVE_GetMoveResult_CPSCE(L0365_T_CurrentThing, CM1_MAPX_NOT_ON_A_SQUARE, 0, P0363_i_MapX, P0364_i_MapY);
                } while ((L0365_T_CurrentThing = L0366_T_NextThing) != C0xFFFE_THING_ENDOFLIST);
                if (P0366_i_Mode >= C00_MODE_PLAY_IMMEDIATELY) {
                        F0064_SOUND_RequestPlay_CPSD(L0371_B_WeaponDropped ? C00_SOUND_METALLIC_THUD : C04_SOUND_WOODEN_THUD_ATTACK_TROLIN_ANTMAN_STONE_GOLEM, P0363_i_MapX, P0364_i_MapY, P0366_i_Mode);
                }
        }
}

void F0189_GROUP_Delete(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0367_i_MapX, P0368_i_MapY)
#endif
int16_t P0367_i_MapX SEPARATOR
int16_t P0368_i_MapY FINAL_SEPARATOR
{
        REGISTER GROUP* L0373_ps_Group;
        REGISTER THING L0372_T_GroupThing;


        if ((L0372_T_GroupThing = F0175_GROUP_GetThing(P0367_i_MapX, P0368_i_MapY)) == C0xFFFE_THING_ENDOFLIST) {
                return;
        }
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0373_ps_Group = &((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(L0372_T_GroupThing)];
#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 */
        L0373_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L0372_T_GroupThing);
#endif
        F0008_MAIN_ClearBytes(M772_CAST_PC(L0373_ps_Group->Health), M543_BYTE_COUNT_INT(sizeof(L0373_ps_Group->Health)));
        F0267_MOVE_GetMoveResult_CPSCE(L0372_T_GroupThing, P0367_i_MapX, P0368_i_MapY, CM1_MAPX_NOT_ON_A_SQUARE, 0);
        L0373_ps_Group->Next = C0xFFFF_THING_NONE;
        if (G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) {
                G0375_ps_ActiveGroups[L0373_ps_Group->ActiveGroupIndex].GroupThingIndex = -1;
                G0377_ui_CurrentActiveGroupCount--;
        }
        F0181_GROUP_DeleteEvents(P0367_i_MapX, P0368_i_MapY);
}

int16_t F0190_GROUP_GetDamageCreatureOutcome(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0369_ps_Group, P0370_ui_CreatureIndex, P0371_i_MapX, P0372_i_MapY, P0373_i_Damage, P0374_B_NotMoving)
#endif
REGISTER GROUP*  P0369_ps_Group         SEPARATOR
unsigned int16_t P0370_ui_CreatureIndex 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 P0371_i_MapX  SEPARATOR
register unsigned int16_t P0372_i_MapY  SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
unsigned int16_t          P0371_i_MapX  SEPARATOR
unsigned int16_t          P0372_i_MapY  SEPARATOR
#endif
int16_t          P0373_i_Damage         SEPARATOR
BOOLEAN          P0374_B_NotMoving      FINAL_SEPARATOR /* When a creature is killed while not moving then possessions are dropped in this function on the current map. When a creature is killed while moving (like falling in a pit) then possessions are not dropped in this function but rather in F0267_MOVE_GetMoveResult_CPSCE on the destination map which may be different from the current (source) map */
{
        REGISTER CREATURE_INFO* L0376_ps_CreatureInfo;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER EVENT* L0377_ps_Event;
        ACTIVE_GROUP* L0378_ps_ActiveGroup;
#endif
        REGISTER unsigned int16_t L0374_ui_Multiple;
#define AL0374_ui_EventIndex    L0374_ui_Multiple
#define AL0374_ui_CreatureIndex L0374_ui_Multiple
#define AL0374_ui_CreatureSize  L0374_ui_Multiple
#define AL0374_ui_Attack        L0374_ui_Multiple
        REGISTER unsigned int16_t L0375_ui_Multiple;
#define AL0375_ui_Outcome           L0375_ui_Multiple
#define AL0375_ui_EventType         L0375_ui_Multiple
#define AL0375_ui_NextCreatureIndex L0375_ui_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        EVENT* L0377_ps_Event;
        ACTIVE_GROUP* L0378_ps_ActiveGroup;
        unsigned int16_t L0379_ui_CreatureCount;
        unsigned int16_t L0380_ui_Multiple;
        unsigned int16_t L0381_ui_GroupCells;
        unsigned int16_t L0382_ui_GroupDirections;
        BOOLEAN L0383_B_CurrentMapIsPartyMap;
#endif
#define AL0380_ui_CreatureType   L0380_ui_Multiple
#define AL0380_ui_FearResistance L0380_ui_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0381_ui_GroupCells;
        REGISTER unsigned int16_t L0382_ui_GroupDirections;
        REGISTER unsigned int16_t L0380_ui_Multiple;
        unsigned int16_t L0379_ui_CreatureCount;
#endif
        unsigned int16_t L0384_ui_Cell;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        BOOLEAN L0383_B_CurrentMapIsPartyMap;
#endif


        L0376_ps_CreatureInfo = &G0243_as_Graphic559_CreatureInfo[AL0380_ui_CreatureType = P0369_ps_Group->Type];
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
        if (M007_GET(L0376_ps_CreatureInfo->Attributes, MASK0x2000_ARCHENEMY)) /* Lord Chaos cannot be damaged */
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (L0376_ps_CreatureInfo->Defense == C255_IMMUNE_TO_DAMAGE) /* Lord Chaos cannot be damaged */
#endif
                goto T0190024;
        if (P0369_ps_Group->Health[P0370_ui_CreatureIndex] <= P0373_i_Damage) {
                L0381_ui_GroupCells = F0145_DUNGEON_GetGroupCells(P0369_ps_Group, G0272_i_CurrentMapIndex);
                L0384_ui_Cell = (L0381_ui_GroupCells == C0xFF_SINGLE_CENTERED_CREATURE) ? C0xFF_SINGLE_CENTERED_CREATURE : M050_CREATURE_VALUE(L0381_ui_GroupCells, P0370_ui_CreatureIndex);
                if (!(L0379_ui_CreatureCount = P0369_ps_Group->Count)) { /* If there is a single creature in the group */
                        if (P0374_B_NotMoving) {
                                F0188_GROUP_DropGroupPossessions(P0371_i_MapX, P0372_i_MapY, F0175_GROUP_GetThing(P0371_i_MapX, P0372_i_MapY), C02_MODE_PLAY_ONE_TICK_LATER);
                                F0189_GROUP_Delete(P0371_i_MapX, P0372_i_MapY);
                        }
                        AL0375_ui_Outcome = C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP;
                } else { /* If there are several creatures in the group */
                        L0382_ui_GroupDirections = F0147_DUNGEON_GetGroupDirections(P0369_ps_Group, G0272_i_CurrentMapIndex);
                        if (M007_GET(L0376_ps_CreatureInfo->Attributes, MASK0x0200_DROP_FIXED_POSSESSIONS)) {
                                if (P0374_B_NotMoving) {
                                        F0186_GROUP_DropCreatureFixedPossessions(AL0380_ui_CreatureType, P0371_i_MapX, P0372_i_MapY, L0384_ui_Cell, C02_MODE_PLAY_ONE_TICK_LATER);
                                } else {
                                        G0392_auc_DropMovingCreatureFixedPossessionsCells[G0391_ui_DropMovingCreatureFixedPossessionsCellCount++] = L0384_ui_Cell;
                                }
                        }
                        if (L0383_B_CurrentMapIsPartyMap = (G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex)) {
                                L0378_ps_ActiveGroup = &G0375_ps_ActiveGroups[P0369_ps_Group->ActiveGroupIndex];
                        }
                        if (P0369_ps_Group->Behavior == C6_BEHAVIOR_ATTACK) {
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED /* CHANGE7_11_OPTIMIZATION Comma removed */
                                for (AL0374_ui_EventIndex = 0, L0377_ps_Event = G0370_ps_Events; AL0374_ui_EventIndex < G0369_EventMaximumCount; L0377_ps_Event++, AL0374_ui_EventIndex++) {
#endif
#ifdef MEDIA289_S20E_S21E_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB /* CHANGE7_11_OPTIMIZATION Comma removed */
                                L0377_ps_Event = G0370_ps_Events;
                                for (AL0374_ui_EventIndex = 0; AL0374_ui_EventIndex < G0369_EventMaximumCount; AL0374_ui_EventIndex++) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                L0377_ps_Event = G0370_ps_Events;
                                for (AL0374_ui_EventIndex = 0; AL0374_ui_EventIndex < G2009_i_LargestUsedEventOrdinal; AL0374_ui_EventIndex++) {
#endif
                                        if ((M029_MAP(L0377_ps_Event->Map_Time) == G0272_i_CurrentMapIndex) &&
                                            (L0377_ps_Event->B.Location.MapX == P0371_i_MapX) &&
                                            (L0377_ps_Event->B.Location.MapY == P0372_i_MapY) &&
                                            ((AL0375_ui_EventType = L0377_ps_Event->A.A.Type) > C32_EVENT_UPDATE_ASPECT_GROUP) &&
                                            (AL0375_ui_EventType < C41_EVENT_UPDATE_BEHAVIOR_CREATURE_3 + 1)) {
                                                if (AL0375_ui_EventType < C37_EVENT_UPDATE_BEHAVIOR_GROUP) {
                                                        AL0375_ui_EventType -= C33_EVENT_UPDATE_ASPECT_CREATURE_0; /* Get creature index for events 33 to 36 */
                                                } else {
                                                        AL0375_ui_EventType -= C38_EVENT_UPDATE_BEHAVIOR_CREATURE_0; /* Get creature index for events 38 to 41 */
                                                }
                                                if (AL0375_ui_NextCreatureIndex == P0370_ui_CreatureIndex) {
                                                        F0237_TIMELINE_DeleteEvent(AL0374_ui_EventIndex);
                                                } else {
                                                        if (AL0375_ui_NextCreatureIndex > P0370_ui_CreatureIndex) {
                                                                L0377_ps_Event->A.A.Type--;
                                                                F0236_TIMELINE_FixPlacement(F0235_TIMELINE_GetIndex(AL0374_ui_EventIndex));
                                                        }
                                                }
                                        }
#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 */
                                        L0377_ps_Event++;
#endif
                                }
                                if (L0383_B_CurrentMapIsPartyMap && ((AL0380_ui_FearResistance = M057_FEAR_RESISTANCE(L0376_ps_CreatureInfo->Properties)) != C15_IMMUNE_TO_FEAR) && ((AL0380_ui_FearResistance += L0379_ui_CreatureCount - 1) < (M003_RANDOM(16)))) { /* Test if the death of a creature frigthens the remaining creatures in the group */
                                        L0378_ps_ActiveGroup->DelayFleeingFromTarget = M002_RANDOM(100 - (AL0380_ui_FearResistance << 2)) + 20;
                                        P0369_ps_Group->Behavior = C5_BEHAVIOR_FLEE;
                                }
                        }
                        for (AL0375_ui_NextCreatureIndex = AL0374_ui_CreatureIndex = P0370_ui_CreatureIndex; AL0374_ui_CreatureIndex < L0379_ui_CreatureCount; AL0374_ui_CreatureIndex++) {
                                AL0375_ui_NextCreatureIndex++;
                                P0369_ps_Group->Health[AL0374_ui_CreatureIndex] = P0369_ps_Group->Health[AL0375_ui_NextCreatureIndex];
                                L0382_ui_GroupDirections = F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(L0382_ui_GroupDirections, AL0374_ui_CreatureIndex, M050_CREATURE_VALUE(L0382_ui_GroupDirections, AL0375_ui_NextCreatureIndex));
                                L0381_ui_GroupCells = F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(L0381_ui_GroupCells, AL0374_ui_CreatureIndex, M050_CREATURE_VALUE(L0381_ui_GroupCells, AL0375_ui_NextCreatureIndex));
                                if (L0383_B_CurrentMapIsPartyMap) {
                                        L0378_ps_ActiveGroup->Aspect[AL0374_ui_CreatureIndex] = L0378_ps_ActiveGroup->Aspect[AL0375_ui_NextCreatureIndex];
                                }
                        }
                        L0381_ui_GroupCells &= 0x003F;
                        F0146_DUNGEON_SetGroupCells(P0369_ps_Group, L0381_ui_GroupCells, G0272_i_CurrentMapIndex);
                        F0148_DUNGEON_SetGroupDirections(P0369_ps_Group, L0382_ui_GroupDirections, G0272_i_CurrentMapIndex);
                        P0369_ps_Group->Count--;
                        AL0375_ui_Outcome = C1_OUTCOME_KILLED_SOME_CREATURES_IN_GROUP;
                }
                if ((AL0374_ui_CreatureSize = M007_GET(L0376_ps_CreatureInfo->Attributes, MASK0x0003_SIZE)) == C0_SIZE_QUARTER_SQUARE) {
                        AL0374_ui_Attack = 110;
                } else {
                        if (AL0374_ui_CreatureSize == C1_SIZE_HALF_SQUARE) {
                                AL0374_ui_Attack = 190;
                        } else {
                                AL0374_ui_Attack = 255;
                        }
                }
                F0213_EXPLOSION_Create(C0xFFA8_THING_EXPLOSION_SMOKE, AL0374_ui_Attack, P0371_i_MapX, P0372_i_MapY, L0384_ui_Cell); /* BUG0_66 Smoke is placed on the source map instead of the destination map when a creature dies by falling through a pit. The game has a special case to correctly drop the creature possessions on the destination map but there is no such special case for the smoke. Note that the death must be caused by the damage of the fall (there is no smoke if the creature is removed because its type is not allowed on the destination map). However this bug has no visible consequence because of BUG0_26: the smoke explosion falls in the pit right after being placed in the dungeon and before being drawn on screen so it is only visible on the destination square */
                return AL0375_ui_Outcome;
        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
        else {
#endif
                if (P0373_i_Damage > 0) {
                        P0369_ps_Group->Health[P0370_ui_CreatureIndex] -= P0373_i_Damage;
                }
                T0190024:
                return C0_OUTCOME_KILLED_NO_CREATURES_IN_GROUP;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        }
#endif
}

int16_t F0191_GROUP_GetDamageAllCreaturesOutcome(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0375_ps_Group, P0376_i_MapX, P0377_i_MapY, P0378_i_Attack, P0379_B_NotMoving)
#endif
REGISTER GROUP*  P0375_ps_Group    SEPARATOR
int16_t          P0376_i_MapX      SEPARATOR
int16_t          P0377_i_MapY      SEPARATOR
REGISTER int16_t P0378_i_Attack    SEPARATOR
BOOLEAN          P0379_B_NotMoving FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0385_ui_RandomAttack;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0386_i_CreatureIndex;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0386_i_CreatureIndex;
        REGISTER BOOLEAN L0388_B_KilledSomeCreatures;
        REGISTER BOOLEAN L0389_B_KilledAllCreatures;
#endif
        int16_t L0387_i_Outcome;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        BOOLEAN L0388_B_KilledSomeCreatures;
        BOOLEAN L0389_B_KilledAllCreatures;
#endif


        L0388_B_KilledSomeCreatures = C0_FALSE;
        L0389_B_KilledAllCreatures = C1_TRUE;
        G0391_ui_DropMovingCreatureFixedPossessionsCellCount = 0;
        if (P0378_i_Attack > 0) {
                L0386_i_CreatureIndex = P0375_ps_Group->Count;
                P0378_i_Attack -= (L0385_ui_RandomAttack = (P0378_i_Attack >> 3) + 1);
                L0385_ui_RandomAttack <<= 1;
                do {
                        L0389_B_KilledAllCreatures = (L0387_i_Outcome = F0190_GROUP_GetDamageCreatureOutcome(P0375_ps_Group, L0386_i_CreatureIndex, P0376_i_MapX, P0377_i_MapY, P0378_i_Attack + M002_RANDOM(L0385_ui_RandomAttack), P0379_B_NotMoving)) && L0389_B_KilledAllCreatures;
                        L0388_B_KilledSomeCreatures = L0388_B_KilledSomeCreatures || L0387_i_Outcome;
                } while (L0386_i_CreatureIndex--);
                if (L0389_B_KilledAllCreatures) {
                        return C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP;
                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                else {
#endif
                        if (L0388_B_KilledSomeCreatures) {
                                return C1_OUTCOME_KILLED_SOME_CREATURES_IN_GROUP;
                        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                        else {
#endif
                                return C0_OUTCOME_KILLED_NO_CREATURES_IN_GROUP;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        }
                }
#endif
        } else {
                return C0_OUTCOME_KILLED_NO_CREATURES_IN_GROUP;
        }
}

int16_t F0192_GROUP_GetResistanceAdjustedPoisonAttack(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0380_ui_CreatureType, P0381_i_PoisonAttack)
#endif
unsigned int16_t P0380_ui_CreatureType SEPARATOR
unsigned int16_t P0381_i_PoisonAttack  FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0390_i_PoisonResistance;


        if (!P0381_i_PoisonAttack || ((L0390_i_PoisonResistance = M061_POISON_RESISTANCE(G0243_as_Graphic559_CreatureInfo[P0380_ui_CreatureType].Resistances)) == C15_IMMUNE_TO_POISON)) {
                return 0;
        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
        else {
#endif
                return ((P0381_i_PoisonAttack + M004_RANDOM(4)) << 3) / ++L0390_i_PoisonResistance;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        }
#endif
}

STATICFUNCTION void F0193_GROUP_StealFromChampion(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0382_ps_Group, P0383_ui_ChampionIndex)
#endif
REGISTER GROUP*  P0382_ps_Group         SEPARATOR
unsigned int16_t P0383_ui_ChampionIndex FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0395_ps_Champion;
        REGISTER int16_t L0391_i_Percentage;
        REGISTER unsigned int16_t L0392_ui_StealFromSlotIndex;
        REGISTER unsigned int16_t L0393_ui_Counter;
        REGISTER THING L0394_T_Thing;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        BOOLEAN L0396_B_ObjectStolen;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER BOOLEAN L0396_B_ObjectStolen;
#endif
#ifdef MEDIA015_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA
        static unsigned char G0394_auc_StealFromSlotIndices[8]; /* Initialized with 0 bytes by C loader */
#endif


        L0396_B_ObjectStolen = C0_FALSE;
        L0391_i_Percentage = 100 - F0311_CHAMPION_GetDexterity(L0395_ps_Champion = &M516_CHAMPIONS[P0383_ui_ChampionIndex]);
        L0393_ui_Counter = M003_RANDOM(8);
        while ((L0391_i_Percentage > 0) && !F0308_CHAMPION_IsLucky(L0395_ps_Champion, L0391_i_Percentage)) {
#ifdef MEDIA015_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA
                if ((L0392_ui_StealFromSlotIndex = G0394_auc_StealFromSlotIndices[L0393_ui_Counter]) == C13_SLOT_BACKPACK_LINE1_1) {
                        L0392_ui_StealFromSlotIndex += M002_RANDOM(17); /* Select a random slot in the backpack */
                }
#endif
#ifdef MEDIA599_X30J_P20JB
                if ((L0392_ui_StealFromSlotIndex = G0025_auc_Graphic562_StealFromSlotIndices[L0393_ui_Counter]) == C13_SLOT_BACKPACK_LINE1_1) {
                        L0392_ui_StealFromSlotIndex += M002_RANDOM(17); /* Select a random slot in the backpack */
                }
#endif
#ifdef MEDIA629_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                if ((G2008_i_PanelContent == C10_PANEL_MAGIC_MAP_SCROLL) && M005_RANDOM(2)) {
                        L0392_ui_StealFromSlotIndex = C01_SLOT_ACTION_HAND;
                } else {
                        L0392_ui_StealFromSlotIndex = G0025_auc_Graphic562_StealFromSlotIndices[L0393_ui_Counter];
                }
#endif
#ifdef MEDIA716_I34E_I34M_A36M
                L0392_ui_StealFromSlotIndex = G0025_auc_Graphic562_StealFromSlotIndices[L0393_ui_Counter];
#endif
                if (((L0394_T_Thing = L0395_ps_Champion->Slots[L0392_ui_StealFromSlotIndex]) != C0xFFFF_THING_NONE)) {
                        L0396_B_ObjectStolen = C1_TRUE;
                        L0394_T_Thing = F0300_CHAMPION_GetObjectRemovedFromSlot(P0383_ui_ChampionIndex, L0392_ui_StealFromSlotIndex);
                        if (P0382_ps_Group->Slot == C0xFFFE_THING_ENDOFLIST) {
                                P0382_ps_Group->Slot = L0394_T_Thing; /* BUG0_12 An object is cloned and appears at two different locations in the dungeon and/or inventory. The game may crash when interacting with this object. If a Giggler with no possessions steals an object that was previously in a chest and was not the last object in the chest then the objects that followed it are cloned. In the chest, the object is part of a linked list of objects that is not reset when the object is removed from the chest and placed in the inventory (but not in the dungeon), nor when it is stolen and added as the first Giggler possession. If the Giggler already has a possession before stealing the object then this does not create a cloned object.
                                The following statement is missing: L0394_T_Thing->Next = C0xFFFE_THING_ENDOFLIST;
                                This creates cloned things if L0394_T_Thing->Next is not C0xFFFE_THING_ENDOFLIST which is the case when the object comes from a chest in which it was not the last object */
                        } else {
                                F0163_DUNGEON_LinkThingToList(L0394_T_Thing, P0382_ps_Group->Slot, CM1_MAPX_NOT_ON_A_SQUARE, 0);
                        }
                        F0292_CHAMPION_DrawState(P0383_ui_ChampionIndex);
                }
                ++L0393_ui_Counter;
                L0393_ui_Counter &= 0x0007;
                L0391_i_Percentage -= 20;
        }
        if (!M003_RANDOM(8) || (L0396_B_ObjectStolen && M005_RANDOM(2))) {
                G0375_ps_ActiveGroups[P0382_ps_Group->ActiveGroupIndex].DelayFleeingFromTarget = M003_RANDOM(64) + 20;
                P0382_ps_Group->Behavior = C5_BEHAVIOR_FLEE;
        }
}

void F0194_GROUP_RemoveAllActiveGroups(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER unsigned int16_t L0397_ui_ActiveGroupIndex;


        for (L0397_ui_ActiveGroupIndex = 0; G0377_ui_CurrentActiveGroupCount > 0; L0397_ui_ActiveGroupIndex++) {
                if (G0375_ps_ActiveGroups[L0397_ui_ActiveGroupIndex].GroupThingIndex >= 0) {
                        F0184_GROUP_RemoveActiveGroup(L0397_ui_ActiveGroupIndex);
                }
        }
}

void F0195_GROUP_AddAllActiveGroups(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER unsigned char* L0401_puc_Square;
        REGISTER THING* L0402_pT_SquareFirstThing;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L0400_T_Thing;
#endif
        REGISTER unsigned int16_t L0398_ui_MapX;
        REGISTER unsigned int16_t L0399_ui_MapY;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER THING L0400_T_Thing;
#endif


        L0401_puc_Square = G0271_ppuc_CurrentMapData[0];
        L0402_pT_SquareFirstThing = &G0283_pT_SquareFirstThings[G0270_pui_CurrentMapColumnsCumulativeSquareFirstThingCount[0]];
        for (L0398_ui_MapX = 0; L0398_ui_MapX < G0273_i_CurrentMapWidth; L0398_ui_MapX++) {
                for (L0399_ui_MapY = 0; L0399_ui_MapY < G0274_i_CurrentMapHeight; L0399_ui_MapY++) {
                        if (M007_GET(*L0401_puc_Square++, MASK0x0010_THING_LIST_PRESENT)) {
                                L0400_T_Thing = *L0402_pT_SquareFirstThing++;
                                do {
                                        if (M012_TYPE(L0400_T_Thing) == C04_THING_TYPE_GROUP) {
                                                F0181_GROUP_DeleteEvents(L0398_ui_MapX, L0399_ui_MapY);
                                                F0183_GROUP_AddActiveGroup(L0400_T_Thing, L0398_ui_MapX, L0399_ui_MapY);
                                                F0180_GROUP_StartWandering(L0398_ui_MapX, L0399_ui_MapY);
                                                break;
                                        }
                                } while ((L0400_T_Thing = F0159_DUNGEON_GetNextThing(L0400_T_Thing)) != C0xFFFE_THING_ENDOFLIST);
                        }
                }
        }
}

void F0196_GROUP_InitializeActiveGroups(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER unsigned int16_t L0403_ui_ActiveGroupIndex;
#ifdef MEDIA725_I34E_I34M_A36M_A33M_A35E_A35M
        REGISTER unsigned int16_t L1875_ui_MaximumActiveGroupCount;
#endif


        if (G0298_B_NewGame) {
#ifdef MEDIA026_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_F31E_F31J_X31J_P31J
                G0376_ui_MaximumActiveGroupCount = 60;
#endif
#ifdef MEDIA725_I34E_I34M_A36M_A33M_A35E_A35M
                G0376_ui_MaximumActiveGroupCount = 110;
#endif
        }
#ifdef MEDIA725_I34E_I34M_A36M_A33M_A35E_A35M
        L1875_ui_MaximumActiveGroupCount = F0025_MAIN_GetMaximumValue(G0376_ui_MaximumActiveGroupCount, 110);
#endif
#ifdef MEDIA026_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_F31E_F31J_X31J_P31J
        G0375_ps_ActiveGroups = (ACTIVE_GROUP*)F0468_MEMORY_Allocate((long)(G0376_ui_MaximumActiveGroupCount * sizeof(ACTIVE_GROUP)), C1_ALLOCATION_PERMANENT);
#endif
#ifdef MEDIA725_I34E_I34M_A36M_A33M_A35E_A35M
        G0375_ps_ActiveGroups = (ACTIVE_GROUP*)M533_F0468_MEMORY_Allocate((long)(L1875_ui_MaximumActiveGroupCount * sizeof(ACTIVE_GROUP)), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
#ifdef MEDIA026_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_F31E_F31J_X31J_P31J
        for (L0403_ui_ActiveGroupIndex = 0; L0403_ui_ActiveGroupIndex < G0376_ui_MaximumActiveGroupCount; G0375_ps_ActiveGroups[L0403_ui_ActiveGroupIndex++].GroupThingIndex = -1);
#endif
#ifdef MEDIA725_I34E_I34M_A36M_A33M_A35E_A35M
        for (L0403_ui_ActiveGroupIndex = 0; L0403_ui_ActiveGroupIndex < L1875_ui_MaximumActiveGroupCount; ) {
                G0375_ps_ActiveGroups[L0403_ui_ActiveGroupIndex].GroupThingIndex = -1;
                L0403_ui_ActiveGroupIndex++;
        }
#endif
}

/* Returns 0 if at least one square on the path from source to destination is blocked else returns the distance between the squares */
STATICFUNCTION BOOLEAN F0197_GROUP_IsViewPartyBlocked(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0384_ui_MapX, P0385_ui_MapY)
#endif
unsigned int16_t P0384_ui_MapX SEPARATOR
unsigned int16_t P0385_ui_MapY FINAL_SEPARATOR
{
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        REGISTER DOOR* L0407_ps_Door;
#endif
        REGISTER unsigned int16_t L0404_ui_Square;
        REGISTER int16_t L0405_i_SquareType;
        REGISTER int16_t L0406_i_DoorState;


#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        return (((L0405_i_SquareType = M034_SQUARE_TYPE(L0404_ui_Square = G0271_ppuc_CurrentMapData[P0384_ui_MapX][P0385_ui_MapY])) == C00_ELEMENT_WALL) ||
                ((L0405_i_SquareType == C06_ELEMENT_FAKEWALL) && !M007_GET(L0404_ui_Square, MASK0x0004_FAKEWALL_OPEN)) ||
                ((L0405_i_SquareType == C04_ELEMENT_DOOR) &&
                 (((L0406_i_DoorState = M036_DOOR_STATE(L0404_ui_Square)) == C3_DOOR_STATE_CLOSED_THREE_FOURTH) || (L0406_i_DoorState == C4_DOOR_STATE_CLOSED)) &&
                 !M007_GET(G0275_as_CurrentMapDoorInfo[((DOOR*)G0284_apuc_ThingData[C00_THING_TYPE_DOOR])[M013_INDEX(F0161_DUNGEON_GetSquareFirstThing(P0384_ui_MapX, P0385_ui_MapY))].Type].Attributes, MASK0x0001_CREATURES_CAN_SEE_THROUGH))
                );
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        if ((L0405_i_SquareType = M034_SQUARE_TYPE(L0404_ui_Square = G0271_ppuc_CurrentMapData[P0384_ui_MapX][P0385_ui_MapY])) == C04_ELEMENT_DOOR) {
                L0407_ps_Door = (DOOR*)F0157_DUNGEON_GetSquareFirstThingData(P0384_ui_MapX, P0385_ui_MapY);
                return (((L0406_i_DoorState = M036_DOOR_STATE(L0404_ui_Square)) == C3_DOOR_STATE_CLOSED_THREE_FOURTH) || (L0406_i_DoorState == C4_DOOR_STATE_CLOSED)) && !M007_GET(G0275_as_CurrentMapDoorInfo[L0407_ps_Door->Type].Attributes, MASK0x0001_CREATURES_CAN_SEE_THROUGH);
        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                else {
#endif
        return (L0405_i_SquareType == C00_ELEMENT_WALL) || ((L0405_i_SquareType == C06_ELEMENT_FAKEWALL) && !M007_GET(L0404_ui_Square, MASK0x0004_FAKEWALL_OPEN));
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                }
#endif
#endif
}

STATICFUNCTION BOOLEAN F0198_GROUP_IsSmellPartyBlocked(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0386_ui_MapX, P0387_ui_MapY)
#endif
unsigned int16_t P0386_ui_MapX SEPARATOR
unsigned int16_t P0387_ui_MapY 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 L0408_ui_Square;
#endif
        REGISTER int16_t L0409_i_SquareType;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0408_ui_Square;
#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
        return ((L0409_i_SquareType = M034_SQUARE_TYPE(L0408_ui_Square = G0271_ppuc_CurrentMapData[P0386_ui_MapX][P0387_ui_MapY])) == C00_ELEMENT_WALL) || ((L0409_i_SquareType == C06_ELEMENT_FAKEWALL) && !M007_GET(L0408_ui_Square, MASK0x0004_FAKEWALL_OPEN));
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        return ((L0409_i_SquareType = M034_SQUARE_TYPE(L0408_ui_Square = G0271_ppuc_CurrentMapData[P0386_ui_MapX][P0387_ui_MapY])) == C00_ELEMENT_WALL) || ((L0409_i_SquareType == C06_ELEMENT_FAKEWALL) && !M007_GET(L0408_ui_Square, MASK0x0004_FAKEWALL_OPEN | MASK0x0001_FAKEWALL_IMAGINARY));
#endif
}

/* Returns 0 if at least one square on the path from source to destination is blocked else returns the distance between the squares */
STATICFUNCTION int16_t F0199_GROUP_GetDistanceBetweenUnblockedSquares(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0388_i_SourceMapX, P0389_i_SourceMapY, P0390_i_DestinationMapX, P0391_i_DestinationMapY, P0392_pfB_IsBlockedCallbackFunction)
#endif
int16_t            P0388_i_SourceMapX                     SEPARATOR
int16_t            P0389_i_SourceMapY                     SEPARATOR
int16_t            P0390_i_DestinationMapX                SEPARATOR
int16_t            P0391_i_DestinationMapY                SEPARATOR
REGISTER BOOLEAN (*P0392_pfB_IsBlockedCallbackFunction)(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int, int
#endif
) FINAL_SEPARATOR
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0414_i_LargestAxisDistance;
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L0410_i_XAxisStep;
        REGISTER int16_t L0411_i_YAxisStep;
#endif
        REGISTER int16_t L0412_i_Multiple;
#define AL0412_i_DistanceX L0412_i_Multiple
#define AL0412_i_PathMapX  L0412_i_Multiple
        REGISTER int16_t L0413_i_Multiple;
#define AL0413_i_DistanceY L0413_i_Multiple
#define AL0413_i_PathMapY  L0413_i_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0414_i_LargestAxisDistance;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0410_i_XAxisStep;
        REGISTER int16_t L0411_i_YAxisStep;
#endif
        BOOLEAN L0415_B_DistanceXSmallerThanDistanceY;
        int16_t L0416_i_ValueA;
        int16_t L0417_i_ValueB;
        BOOLEAN L0418_B_DistanceXEqualsDistanceY;
        int16_t L0419_i_ValueC;


        if (M038_DISTANCE(P0388_i_SourceMapX, P0389_i_SourceMapY, P0390_i_DestinationMapX, P0391_i_DestinationMapY) <= 1) {
                return 1;
        }
        L0415_B_DistanceXSmallerThanDistanceY = (AL0412_i_DistanceX = ((AL0412_i_DistanceX = P0390_i_DestinationMapX - P0388_i_SourceMapX) < 0) ? -AL0412_i_DistanceX : AL0412_i_DistanceX) < (AL0413_i_DistanceY = ((AL0413_i_DistanceY = P0391_i_DestinationMapY - P0389_i_SourceMapY) < 0) ? -AL0413_i_DistanceY : AL0413_i_DistanceY);
        L0418_B_DistanceXEqualsDistanceY = (AL0412_i_DistanceX == AL0413_i_DistanceY);
#ifdef MEDIA070_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        L0410_i_XAxisStep = (((AL0412_i_PathMapX = P0390_i_DestinationMapX) - P0388_i_SourceMapX) > 0) ? -1 : 1;
        L0411_i_YAxisStep = (((AL0413_i_PathMapY = P0391_i_DestinationMapY) - P0389_i_SourceMapY) > 0) ? -1 : 1;
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
        L0410_i_XAxisStep = ((int16_t)((AL0412_i_PathMapX = P0390_i_DestinationMapX) - P0388_i_SourceMapX) > 0) ? -1 : 1;
        L0411_i_YAxisStep = ((int16_t)((AL0413_i_PathMapY = P0391_i_DestinationMapY) - P0389_i_SourceMapY) > 0) ? -1 : 1;
#endif
        L0419_i_ValueC = L0415_B_DistanceXSmallerThanDistanceY ? ((L0414_i_LargestAxisDistance = AL0413_i_PathMapY - P0389_i_SourceMapY) ? ((AL0412_i_PathMapX - P0388_i_SourceMapX) << 6) / L0414_i_LargestAxisDistance : 0x80)
                                                               : ((L0414_i_LargestAxisDistance = AL0412_i_PathMapX - P0388_i_SourceMapX) ? ((AL0413_i_PathMapY - P0389_i_SourceMapY) << 6) / L0414_i_LargestAxisDistance : 0x80);
        /* 0x80 = 128 when the creature is on the same row or column as the party */
        do {
                if (L0418_B_DistanceXEqualsDistanceY) {
                        if (((*P0392_pfB_IsBlockedCallbackFunction)(AL0412_i_PathMapX + L0410_i_XAxisStep, AL0413_i_PathMapY) && (*P0392_pfB_IsBlockedCallbackFunction)(AL0412_i_PathMapX, AL0413_i_PathMapY + L0411_i_YAxisStep)) || (*P0392_pfB_IsBlockedCallbackFunction)(AL0412_i_PathMapX += L0410_i_XAxisStep, AL0413_i_PathMapY += L0411_i_YAxisStep)) {
                                return 0;
                        }
                } else {
                        if ((L0416_i_ValueA = ((L0414_i_LargestAxisDistance = (L0415_B_DistanceXSmallerThanDistanceY ? ((L0414_i_LargestAxisDistance = AL0413_i_PathMapY - P0389_i_SourceMapY) ? ((AL0412_i_PathMapX + L0410_i_XAxisStep - P0388_i_SourceMapX) << 6) / L0414_i_LargestAxisDistance : 0x80) : ((L0414_i_LargestAxisDistance = AL0412_i_PathMapX + L0410_i_XAxisStep - P0388_i_SourceMapX) ? ((AL0413_i_PathMapY - P0389_i_SourceMapY) << 6) / L0414_i_LargestAxisDistance : 0x80)) - L0419_i_ValueC) < 0) ? -L0414_i_LargestAxisDistance : L0414_i_LargestAxisDistance) < (L0417_i_ValueB = ((L0414_i_LargestAxisDistance = (L0415_B_DistanceXSmallerThanDistanceY ? ((L0414_i_LargestAxisDistance = AL0413_i_PathMapY + L0411_i_YAxisStep - P0389_i_SourceMapY) ? ((AL0412_i_PathMapX - P0388_i_SourceMapX) << 6) / L0414_i_LargestAxisDistance : 0x80) : ((L0414_i_LargestAxisDistance = AL0412_i_PathMapX - P0388_i_SourceMapX) ? ((AL0413_i_PathMapY + L0411_i_YAxisStep - P0389_i_SourceMapY) << 6) / L0414_i_LargestAxisDistance : 0x80)) - L0419_i_ValueC) < 0) ? -L0414_i_LargestAxisDistance : L0414_i_LargestAxisDistance)) {
                                AL0412_i_PathMapX += L0410_i_XAxisStep;
                        } else {
                                AL0413_i_PathMapY += L0411_i_YAxisStep;
                        }
                        if ((*P0392_pfB_IsBlockedCallbackFunction)(AL0412_i_PathMapX, AL0413_i_PathMapY) && ((L0416_i_ValueA != L0417_i_ValueB) || (*P0392_pfB_IsBlockedCallbackFunction)(AL0412_i_PathMapX += L0410_i_XAxisStep, AL0413_i_PathMapY -= L0411_i_YAxisStep))) {
                                return 0;
                        }
                }
        } while (M038_DISTANCE(AL0412_i_PathMapX, AL0413_i_PathMapY, P0388_i_SourceMapX, P0389_i_SourceMapY) > 1);
        return F0226_GROUP_GetDistanceBetweenSquares(P0388_i_SourceMapX, P0389_i_SourceMapY, P0390_i_DestinationMapX, P0391_i_DestinationMapY);
}

STATICFUNCTION int16_t F0200_GROUP_GetDistanceToVisibleParty(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0393_ps_Group, P0394_i_CreatureIndex, P0395_i_MapX, P0396_i_MapY)
#endif
REGISTER GROUP*  P0393_ps_Group        SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t          P0394_i_CreatureIndex SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t P0394_i_CreatureIndex SEPARATOR
#endif
int16_t          P0395_i_MapX          SEPARATOR
int16_t          P0396_i_MapY          FINAL_SEPARATOR
{
        REGISTER CREATURE_INFO* L0424_ps_CreatureInfo;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register int16_t L0420_i_CreatureDirection;
#endif
        REGISTER int16_t L0421_i_CreatureViewDirectionCount; /* Count of directions to test in L0425_ai_CreatureViewDirections */
        REGISTER int16_t L0422_i_Multiple;
#define AL0422_i_Counter    L0422_i_Multiple
#define AL0422_i_SightRange L0422_i_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
      REGISTER int16_t L0420_i_CreatureDirection;
#endif
        REGISTER unsigned int16_t L0423_ui_GroupDirections;
        int16_t L0425_ai_CreatureViewDirections[4]; /* List of directions to test */


        L0424_ps_CreatureInfo = &G0243_as_Graphic559_CreatureInfo[P0393_ps_Group->Type];
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
        if (G0407_s_Party.Event71Count_Invisibility && !M007_GET(L0424_ps_CreatureInfo->Attributes, MASK0x0800_SEE_INVISIBLE)) {
                return 0;
        }
#endif
        if (M007_GET(L0424_ps_CreatureInfo->Attributes, MASK0x0004_SIDE_ATTACK)) /* If creature can see in all directions */
                goto T0200011;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
        else {
#endif
                L0423_ui_GroupDirections = G0375_ps_ActiveGroups[P0393_ps_Group->ActiveGroupIndex].Directions;
                if (P0394_i_CreatureIndex < 0) { /* Negative index means test if each creature in the group can see the party in their respective direction */
                        L0421_i_CreatureViewDirectionCount = 0;
                        for (P0394_i_CreatureIndex = P0393_ps_Group->Count; P0394_i_CreatureIndex >= 0; P0394_i_CreatureIndex--) {
                                L0420_i_CreatureDirection = M021_NORMALIZE(L0423_ui_GroupDirections >> (P0394_i_CreatureIndex << 1));
                                AL0422_i_Counter = L0421_i_CreatureViewDirectionCount;
                                while (AL0422_i_Counter--) {
                                        if (L0425_ai_CreatureViewDirections[AL0422_i_Counter] == L0420_i_CreatureDirection) /* If the creature looks in the same direction as another one in the group */
                                                goto T0200006;
                                }
                                L0425_ai_CreatureViewDirections[L0421_i_CreatureViewDirectionCount++] = L0420_i_CreatureDirection;
                                T0200006: ;
                        }
                } else { /* Positive index means test only if the specified creature in the group can see the party in its direction */
                        L0425_ai_CreatureViewDirections[0] = M050_CREATURE_VALUE(L0423_ui_GroupDirections, P0394_i_CreatureIndex);
                        L0421_i_CreatureViewDirectionCount = 1;
                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        }
#endif
        while (L0421_i_CreatureViewDirectionCount--) {
                if (F0227_GROUP_IsDestinationVisibleFromSource(L0425_ai_CreatureViewDirections[L0421_i_CreatureViewDirectionCount], P0395_i_MapX, P0396_i_MapY, G0306_i_PartyMapX, G0307_i_PartyMapY)) {
                        T0200011:
                        AL0422_i_SightRange = M054_SIGHT_RANGE(L0424_ps_CreatureInfo->Ranges);
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        if (G0407_s_Party.Event71Count_Invisibility && !M007_GET(L0424_ps_CreatureInfo->Attributes, MASK0x0800_SEE_INVISIBLE)) {
                                AL0422_i_SightRange = -10;
                        } else {
#endif
                                if (!M007_GET(L0424_ps_CreatureInfo->Attributes, MASK0x1000_NIGHT_VISION)) {
                                        AL0422_i_SightRange -= G0304_i_DungeonViewPaletteIndex >> 1;
                                }
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
                                if (G0381_ui_CurrentGroupDistanceToParty > F0025_MAIN_GetMaximumValue(1, AL0422_i_SightRange)) {
                                        return 0;
                                }
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        }
                        if (G0381_ui_CurrentGroupDistanceToParty > AL0422_i_SightRange) {
                                if (G0381_ui_CurrentGroupDistanceToParty == 1) {
                                        AL0422_i_SightRange += M002_RANDOM(M102_XXX_RANGE(L0424_ps_CreatureInfo->Ranges) + 1) + M002_RANDOM(M055_SMELL_RANGE(L0424_ps_CreatureInfo->Ranges) + 1);
                                        if (!M003_RANDOM(8)) {
                                                AL0422_i_SightRange += M005_RANDOM(1) + 5;
                                        }
                                }
                                if (G0381_ui_CurrentGroupDistanceToParty > AL0422_i_SightRange + M003_RANDOM(8) - 3) {
                                        return 0;
                                }
                        }
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        return F0199_GROUP_GetDistanceBetweenUnblockedSquares(P0395_i_MapX, P0396_i_MapY, G0306_i_PartyMapX, G0307_i_PartyMapY, F0197_GROUP_IsViewPartyBlocked);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        return F0199_GROUP_GetDistanceBetweenUnblockedSquares(P0395_i_MapX, P0396_i_MapY, G0306_i_PartyMapX, G0307_i_PartyMapY, (BOOLEAN (*)(int, int))F0197_GROUP_IsViewPartyBlocked);
#endif
                }
        }
        return 0;
}

STATICFUNCTION int16_t F0201_GROUP_GetSmelledPartyPrimaryDirectionOrdinal(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0397_ps_CreatureInfo, P0398_i_MapY, P0399_i_MapX)
#endif
CREATURE_INFO* P0397_ps_CreatureInfo SEPARATOR
int16_t        P0398_i_MapY          SEPARATOR
int16_t        P0399_i_MapX          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 L0426_ui_SmellRange;
#endif
        REGISTER int16_t L0427_i_ScentOrdinal;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0426_ui_SmellRange;
#endif


        if (!(L0426_ui_SmellRange = M055_SMELL_RANGE(P0397_ps_CreatureInfo->Ranges))) {
                return 0;
        }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        if ((((L0426_ui_SmellRange + 1) >> 1) >= G0381_ui_CurrentGroupDistanceToParty) && F0199_GROUP_GetDistanceBetweenUnblockedSquares(P0398_i_MapY, P0399_i_MapX, G0306_i_PartyMapX, G0307_i_PartyMapY, F0198_GROUP_IsSmellPartyBlocked)) {
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if ((((L0426_ui_SmellRange + 1) >> 1) >= G0381_ui_CurrentGroupDistanceToParty) && F0199_GROUP_GetDistanceBetweenUnblockedSquares(P0398_i_MapY, P0399_i_MapX, G0306_i_PartyMapX, G0307_i_PartyMapY, (BOOLEAN (*)(int, int))F0198_GROUP_IsSmellPartyBlocked)) {
#endif
                G0363_i_SecondaryDirectionToOrFromParty = G0383_i_CurrentGroupSecondaryDirectionToParty;
                return M000_INDEX_TO_ORDINAL(G0382_i_CurrentGroupPrimaryDirectionToParty);
        }
#ifdef MEDIA070_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        if ((L0427_i_ScentOrdinal = F0315_CHAMPION_GetScentOrdinal(P0398_i_MapY, P0399_i_MapX)) && ((G0407_s_Party.ScentStrengths[M001_ORDINAL_TO_INDEX(L0427_i_ScentOrdinal)] + M004_RANDOM(4)) > (30 - (L0426_ui_SmellRange << 1)))) { /* If there is a fresh enough party scent on the group square */
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
        if ((L0427_i_ScentOrdinal = F0315_CHAMPION_GetScentOrdinal(P0398_i_MapY, P0399_i_MapX)) && ((G0407_s_Party.ScentStrengths[M001_ORDINAL_TO_INDEX(L0427_i_ScentOrdinal)] + M004_RANDOM(4)) > (30 - (int16_t)(L0426_ui_SmellRange << 1)))) { /* If there is a fresh enough party scent on the group square */
#endif
                return M000_INDEX_TO_ORDINAL(F0228_GROUP_GetDirectionsWhereDestinationIsVisibleFromSource(P0398_i_MapY, P0399_i_MapX, G0407_s_Party.Scents[L0427_i_ScentOrdinal].Location.MapX, G0407_s_Party.Scents[L0427_i_ScentOrdinal].Location.MapY));
        }
        return 0;
}

STATICFUNCTION BOOLEAN F0202_GROUP_IsMovementPossible(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0400_ps_CreatureInfo, P0401_i_MapX, P0402_i_MapY, P0403_ui_Direction, P0404_B_AllowMovementOverImaginaryPitsAndFakeWalls)
#endif
REGISTER CREATURE_INFO* P0400_ps_CreatureInfo                              SEPARATOR
int16_t                 P0401_i_MapX                                       SEPARATOR
int16_t                 P0402_i_MapY                                       SEPARATOR
unsigned int16_t        P0403_ui_Direction                                 SEPARATOR
BOOLEAN                 P0404_B_AllowMovementOverImaginaryPitsAndFakeWalls FINAL_SEPARATOR
{
        REGISTER TELEPORTER* L0432_ps_Teleporter;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0430_ui_Square;
#endif
        REGISTER int16_t L0428_i_MapX;
        REGISTER int16_t L0429_i_MapY;
#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 L0430_ui_Square;
#endif
        REGISTER int16_t L0431_i_SquareType;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        THING L0433_T_Thing;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L0433_T_Thing;
#endif


        G0384_auc_GroupMovementTestedDirections[P0403_ui_Direction] = C1_TRUE;
        G0388_T_GroupMovementBlockedByGroupThing = C0xFFFE_THING_ENDOFLIST;
        G0389_B_GroupMovementBlockedByDoor = C0_FALSE;
        G0390_B_GroupMovementBlockedByParty = C0_FALSE;
        if (P0400_ps_CreatureInfo->MovementTicks == C255_IMMOBILE) {
                return C0_FALSE;
        }
        F0150_DUNGEON_UpdateMapCoordinatesAfterRelativeMovement(P0403_ui_Direction, 1, 0, &P0401_i_MapX, &P0402_i_MapY);
        L0428_i_MapX = P0401_i_MapX;
        L0429_i_MapY = P0402_i_MapY;
        if (G0387_B_GroupMovementBlockedByWallStairsPitFakeWallFluxcageTeleporter =
                !(((L0428_i_MapX >= 0) && (L0428_i_MapX < G0273_i_CurrentMapWidth)) &&
                ((L0429_i_MapY >= 0) && (L0429_i_MapY < G0274_i_CurrentMapHeight)) &&
                ((L0431_i_SquareType = M034_SQUARE_TYPE(L0430_ui_Square = G0271_ppuc_CurrentMapData[L0428_i_MapX][L0429_i_MapY])) != C00_ELEMENT_WALL) &&
                (L0431_i_SquareType != C03_ELEMENT_STAIRS) &&
                ((L0431_i_SquareType != C02_ELEMENT_PIT) || (M007_GET(L0430_ui_Square, MASK0x0001_PIT_IMAGINARY) && P0404_B_AllowMovementOverImaginaryPitsAndFakeWalls) || !M007_GET(L0430_ui_Square, MASK0x0008_PIT_OPEN) || M007_GET(P0400_ps_CreatureInfo->Attributes, MASK0x0020_LEVITATION)) &&
                ((L0431_i_SquareType != C06_ELEMENT_FAKEWALL) || M007_GET(L0430_ui_Square, MASK0x0004_FAKEWALL_OPEN) || (M007_GET(L0430_ui_Square, MASK0x0001_FAKEWALL_IMAGINARY) && P0404_B_AllowMovementOverImaginaryPitsAndFakeWalls)))) {
                return C0_FALSE;
        }
        if (M007_GET(P0400_ps_CreatureInfo->Attributes, MASK0x2000_ARCHENEMY)) {
                L0433_T_Thing = F0161_DUNGEON_GetSquareFirstThing(L0428_i_MapX, L0429_i_MapY);
                while (L0433_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                        if (M012_TYPE(L0433_T_Thing) == C15_THING_TYPE_EXPLOSION) {
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_02_OPTIMIZATION Inline code replaced by function calls */
                                if (((EXPLOSION*)G0284_apuc_ThingData[C15_THING_TYPE_EXPLOSION])[M013_INDEX(L0433_T_Thing)].Type == C050_EXPLOSION_FLUXCAGE) {
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_02_OPTIMIZATION Inline code replaced by function calls */
                                L0432_ps_Teleporter = (TELEPORTER*)F0156_DUNGEON_GetThingData(L0433_T_Thing);
                                if (((EXPLOSION*)L0432_ps_Teleporter)->Type == C050_EXPLOSION_FLUXCAGE) {
#endif
                                        G0385_ac_FluxCages[P0403_ui_Direction] = C1_TRUE;
                                        G0386_ui_FluxCageCount++;
                                        G0387_B_GroupMovementBlockedByWallStairsPitFakeWallFluxcageTeleporter = C1_TRUE;
                                        return C0_FALSE;
                                }
                        }
                        L0433_T_Thing = F0159_DUNGEON_GetNextThing(L0433_T_Thing);
                }
        }
        if ((L0431_i_SquareType == C05_ELEMENT_TELEPORTER) && M007_GET(L0430_ui_Square, MASK0x0008_TELEPORTER_OPEN) && (M059_WARINESS(P0400_ps_CreatureInfo->Properties) >= 10)) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                L0432_ps_Teleporter = (TELEPORTER*)F0156_DUNGEON_GetThingData(F0161_DUNGEON_GetSquareFirstThing(L0428_i_MapX, L0429_i_MapY));
#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 */
                L0432_ps_Teleporter = (TELEPORTER*)F0157_DUNGEON_GetSquareFirstThingData(L0428_i_MapX, L0429_i_MapY);
#endif
                if (M007_GET(L0432_ps_Teleporter->Scope, MASK0x0001_SCOPE_CREATURES) && !F0139_DUNGEON_IsCreatureAllowedOnMap(G0380_T_CurrentGroupThing, L0432_ps_Teleporter->TargetMapIndex)) {
                        G0387_B_GroupMovementBlockedByWallStairsPitFakeWallFluxcageTeleporter = C1_TRUE;
                        return C0_FALSE; /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE */
                }
        }
        if (G0390_B_GroupMovementBlockedByParty = (G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (L0428_i_MapX == G0306_i_PartyMapX) && (L0429_i_MapY == G0307_i_PartyMapY)) {
                return C0_FALSE;
        }
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        if (G0389_B_GroupMovementBlockedByDoor = ((L0431_i_SquareType == C04_ELEMENT_DOOR) && !(((M036_DOOR_STATE(L0430_ui_Square)) <= (((DOOR*)G0284_apuc_ThingData[C00_THING_TYPE_DOOR])[M013_INDEX(F0161_DUNGEON_GetSquareFirstThing(L0428_i_MapX, L0429_i_MapY))].Vertical ? M051_CREATURE_HEIGHT(P0400_ps_CreatureInfo->Attributes) : 1)) || ((M036_DOOR_STATE(L0430_ui_Square)) == C5_DOOR_STATE_DESTROYED) || M007_GET(P0400_ps_CreatureInfo->Attributes, MASK0x0040_NON_MATERIAL)))) {
                return C0_FALSE;
        }
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        if (L0431_i_SquareType == C04_ELEMENT_DOOR) {
                L0432_ps_Teleporter = (TELEPORTER*)F0157_DUNGEON_GetSquareFirstThingData(L0428_i_MapX, L0429_i_MapY);
                if (!(((M036_DOOR_STATE(L0430_ui_Square)) <= (((DOOR*)L0432_ps_Teleporter)->Vertical ? M051_CREATURE_HEIGHT(P0400_ps_CreatureInfo->Attributes) : 1)) || ((M036_DOOR_STATE(L0430_ui_Square)) == C5_DOOR_STATE_DESTROYED) || M007_GET(P0400_ps_CreatureInfo->Attributes, MASK0x0040_NON_MATERIAL))) {
                        G0389_B_GroupMovementBlockedByDoor = C1_TRUE;
                        return C0_FALSE;
                }
        }
#endif
        return (G0388_T_GroupMovementBlockedByGroupThing = F0175_GROUP_GetThing(L0428_i_MapX, L0429_i_MapY)) == C0xFFFE_THING_ENDOFLIST;
}

STATICFUNCTION int16_t F0203_GROUP_GetFirstPossibleMovementDirectionOrdinal(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0405_ps_CreatureInfo, P0406_i_MapX, P0407_i_MapY, P0408_B_AllowMovementOverImaginaryPitsAndFakeWalls)
#endif
CREATURE_INFO* P0405_ps_CreatureInfo                              SEPARATOR
int16_t        P0406_i_MapX                                       SEPARATOR
int16_t        P0407_i_MapY                                       SEPARATOR
BOOLEAN        P0408_B_AllowMovementOverImaginaryPitsAndFakeWalls FINAL_SEPARATOR
{
        REGISTER int16_t L0434_i_Direction;


        for (L0434_i_Direction = C0_DIRECTION_NORTH; L0434_i_Direction <= C3_DIRECTION_WEST; L0434_i_Direction++) {
                if ((!G0384_auc_GroupMovementTestedDirections[L0434_i_Direction]) && F0202_GROUP_IsMovementPossible(P0405_ps_CreatureInfo, P0406_i_MapX, P0407_i_MapY, L0434_i_Direction, P0408_B_AllowMovementOverImaginaryPitsAndFakeWalls)) {
                        return M000_INDEX_TO_ORDINAL(L0434_i_Direction);
                }
        }
        return 0;
}

STATICFUNCTION BOOLEAN F0204_GROUP_IsArchenemyDoubleMovementPossible(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0409_ps_CreatureInfo, P0410_i_MapX, P0411_i_MapY, P0412_ui_Direction)
#endif
CREATURE_INFO*            P0409_ps_CreatureInfo SEPARATOR
int16_t                   P0410_i_MapX          SEPARATOR
int16_t                   P0411_i_MapY          SEPARATOR
REGISTER unsigned int16_t P0412_ui_Direction    FINAL_SEPARATOR
{
        if (G0385_ac_FluxCages[P0412_ui_Direction]) {
                return C0_FALSE;
        }
        P0410_i_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[P0412_ui_Direction], P0411_i_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[P0412_ui_Direction];
        return F0202_GROUP_IsMovementPossible(P0409_ps_CreatureInfo, P0410_i_MapX, P0411_i_MapY, P0412_ui_Direction, C0_FALSE);
}

STATICFUNCTION void F0205_GROUP_SetDirection(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0413_ps_ActiveGroup, P0414_ui_Direction, P0415_ui_CreatureIndex, P0416_B_TwoHalfSquareSizedCreatures)
#endif
REGISTER ACTIVE_GROUP*    P0413_ps_ActiveGroup                SEPARATOR
REGISTER unsigned int16_t P0414_ui_Direction                  SEPARATOR
REGISTER unsigned int16_t P0415_ui_CreatureIndex              SEPARATOR
BOOLEAN                   P0416_B_TwoHalfSquareSizedCreatures FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0435_ui_GroupDirections;
        static long G0395_l_TwoHalfSquareSizedCreaturesGroupLastDirectionSetTime; /* These two variables are used to prevent setting direction of half square sized creatures twice at the same game time */
        static ACTIVE_GROUP* G0396_ps_TwoHalfSquareSizedCreaturesGroupLastDirectionSetActiveGroup;


        if (P0416_B_TwoHalfSquareSizedCreatures && (G0313_ul_GameTime == G0395_l_TwoHalfSquareSizedCreaturesGroupLastDirectionSetTime) && (P0413_ps_ActiveGroup == G0396_ps_TwoHalfSquareSizedCreaturesGroupLastDirectionSetActiveGroup)) {
                return;
        }
        if (M021_NORMALIZE((int16_t)M050_CREATURE_VALUE(L0435_ui_GroupDirections = P0413_ps_ActiveGroup->Directions, P0415_ui_CreatureIndex) - P0414_ui_Direction) == 2) { /* If current and new direction are opposites then change direction only one step at a time */
                L0435_ui_GroupDirections = F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(L0435_ui_GroupDirections, P0415_ui_CreatureIndex, P0414_ui_Direction = M017_NEXT((M006_RANDOM(65536) & 0x0002) + P0414_ui_Direction));
        } else {
                L0435_ui_GroupDirections = F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(L0435_ui_GroupDirections, P0415_ui_CreatureIndex, P0414_ui_Direction);
        }
        if (P0416_B_TwoHalfSquareSizedCreatures) {
                L0435_ui_GroupDirections = F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(L0435_ui_GroupDirections, P0415_ui_CreatureIndex ^ 1, P0414_ui_Direction); /* Set direction of the second half square sized creature */
                G0395_l_TwoHalfSquareSizedCreaturesGroupLastDirectionSetTime = G0313_ul_GameTime;
                G0396_ps_TwoHalfSquareSizedCreaturesGroupLastDirectionSetActiveGroup = P0413_ps_ActiveGroup;
        }
        P0413_ps_ActiveGroup->Directions = L0435_ui_GroupDirections;
}

/* Sets direction of at least one creature in the group */
STATICFUNCTION void F0206_GROUP_SetDirectionGroup(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0417_ps_ActiveGroup, P0418_i_Direction, P0419_i_CreatureIndex, P0420_i_CreatureSize)
#endif
ACTIVE_GROUP*    P0417_ps_ActiveGroup  SEPARATOR
int16_t          P0418_i_Direction     SEPARATOR
REGISTER int16_t P0419_i_CreatureIndex SEPARATOR
int16_t          P0420_i_CreatureSize  FINAL_SEPARATOR
{
        REGISTER BOOLEAN L0436_B_TwoHalfSquareSizedCreatures;


        if (L0436_B_TwoHalfSquareSizedCreatures = P0419_i_CreatureIndex && (P0420_i_CreatureSize == C1_SIZE_HALF_SQUARE)) {
                P0419_i_CreatureIndex--;
        }
        do {
                if (!P0419_i_CreatureIndex || M005_RANDOM(2)) {
                        F0205_GROUP_SetDirection(P0417_ps_ActiveGroup, P0418_i_Direction, P0419_i_CreatureIndex, L0436_B_TwoHalfSquareSizedCreatures);
                }
        } while (P0419_i_CreatureIndex--);
}

STATICFUNCTION BOOLEAN F0207_GROUP_IsCreatureAttacking(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0421_ps_Group, P0422_i_MapX, P0423_i_MapY, P0424_ui_CreatureIndex)
#endif
REGISTER GROUP*  P0421_ps_Group         SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t          P0422_i_MapX           SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t P0422_i_MapX           SEPARATOR
#endif
int16_t          P0423_i_MapY           SEPARATOR
unsigned int16_t P0424_ui_CreatureIndex FINAL_SEPARATOR
{
        REGISTER CREATURE_INFO* L0441_ps_CreatureInfo;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER CHAMPION* L0442_ps_Champion;
#endif
#define AL0440_i_KineticEnergy      L0440_i_Multiple
#define AL0440_i_Counter            L0440_i_Multiple
#define AL0440_i_Damage             L0440_i_Multiple
#define AL0440_i_AttackSoundOrdinal L0440_i_Multiple
        REGISTER unsigned int16_t L0437_ui_Multiple;
#define AL0437_ui_CreatureType L0437_ui_Multiple
#define AL0437_T_Thing         L0437_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 L0438_ui_PrimaryDirectionToParty;
#endif
        REGISTER int16_t L0439_i_Multiple;
#define AL0439_i_GroupCells    L0439_i_Multiple
#define AL0439_i_TargetCell    L0439_i_Multiple
#define AL0439_i_ChampionIndex L0439_i_Multiple
        REGISTER int16_t L0440_i_Multiple;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        CHAMPION* L0442_ps_Champion;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0438_ui_PrimaryDirectionToParty;
#endif
        ACTIVE_GROUP L0443_s_ActiveGroup;
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        BOOLEAN L1876_B_UseSpellSoundAsFallback;


        L1876_B_UseSpellSoundAsFallback = C0_FALSE;
#endif
        G0361_l_LastCreatureAttackTime = G0313_ul_GameTime;
        L0443_s_ActiveGroup = G0375_ps_ActiveGroups[P0421_ps_Group->ActiveGroupIndex];
        L0441_ps_CreatureInfo = &G0243_as_Graphic559_CreatureInfo[AL0437_ui_CreatureType = P0421_ps_Group->Type];
        L0438_ui_PrimaryDirectionToParty = G0382_i_CurrentGroupPrimaryDirectionToParty;
        if ((AL0439_i_GroupCells = L0443_s_ActiveGroup.Cells) == C0xFF_SINGLE_CENTERED_CREATURE) {
                AL0439_i_TargetCell = M005_RANDOM(2);
        } else {
                AL0439_i_TargetCell = ((M050_CREATURE_VALUE(AL0439_i_GroupCells, P0424_ui_CreatureIndex) + 5 - L0438_ui_PrimaryDirectionToParty) & 0x0002) >> 1;
        }
        AL0439_i_TargetCell += L0438_ui_PrimaryDirectionToParty;
        AL0439_i_TargetCell &= 0x0003;
        if ((M056_ATTACK_RANGE(L0441_ps_CreatureInfo->Ranges) > 1) && ((G0381_ui_CurrentGroupDistanceToParty > 1) || M005_RANDOM(2))) {
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                L1876_B_UseSpellSoundAsFallback = C1_TRUE;
#endif
                switch (AL0437_ui_CreatureType) {
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        default:
                                AL0437_T_Thing = C0xFF80_THING_EXPLOSION_FIREBALL;
                                break;
#endif
                        case C14_CREATURE_VEXIRK:
                        case C23_CREATURE_LORD_CHAOS:
                                if (M005_RANDOM(2)) {
                                        AL0437_T_Thing = C0xFF80_THING_EXPLOSION_FIREBALL;
                                } else {
                                        switch (M004_RANDOM(4)) {
                                                case 0:
                                                        AL0437_T_Thing = C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL;
                                                        break;
                                                case 1:
                                                        AL0437_T_Thing = C0xFF82_THING_EXPLOSION_LIGHTNING_BOLT;
                                                        break;
                                                case 2:
                                                        AL0437_T_Thing = C0xFF87_THING_EXPLOSION_POISON_CLOUD;
                                                        break;
                                                case 3:
#ifdef PC_FIX_CODE_SIZE
        L0439_i_Multiple++;
        L0439_i_Multiple++;
        L0439_i_Multiple++;
#endif
                                                        AL0437_T_Thing = C0xFF84_THING_EXPLOSION_OPEN_DOOR;
                                        }
                                }
                                break;
                        case C01_CREATURE_SWAMP_SLIME_SLIME_DEVIL:
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                                L1876_B_UseSpellSoundAsFallback = C0_FALSE;
#endif
                                AL0437_T_Thing = C0xFF81_THING_EXPLOSION_SLIME;
                                break;
                        case C03_CREATURE_WIZARD_EYE_FLYING_EYE:
                                if (M003_RANDOM(8)) {
                                        AL0437_T_Thing = C0xFF82_THING_EXPLOSION_LIGHTNING_BOLT;
                                } else {
                                        AL0437_T_Thing = C0xFF84_THING_EXPLOSION_OPEN_DOOR;
                                }
                                break;
                        case C19_CREATURE_MATERIALIZER_ZYTAZ:
                                if (M005_RANDOM(2)) {
                                        AL0437_T_Thing = C0xFF87_THING_EXPLOSION_POISON_CLOUD;
                                        break;
                                }
#ifdef MEDIA036_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_P31J
                        case C22_CREATURE_DEMON:
#endif
                        case C24_CREATURE_RED_DRAGON:
#ifdef MEDIA749_A36M_A31E_A31M_A33M_A35E_A35M_X31J
                        case C22_CREATURE_DEMON:
#endif
                                AL0437_T_Thing = C0xFF80_THING_EXPLOSION_FIREBALL;
                } /* BUG0_13 The game may crash when 'Lord Order' or 'Grey Lord' cast spells. This cannot happen with the original dungeons as they do not contain any groups of these types. 'Lord Order' and 'Grey Lord' creatures can cast spells (attack range > 1) but no projectile type is defined for them in the code. If these creatures are present in a dungeon they will cast projectiles containing undefined things because the variable is not initialized */
                AL0440_i_KineticEnergy = (L0441_ps_CreatureInfo->Attack >> 2) + 1;
                AL0440_i_KineticEnergy += M002_RANDOM(AL0440_i_KineticEnergy);
                AL0440_i_KineticEnergy += M002_RANDOM(AL0440_i_KineticEnergy);
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                F0064_SOUND_RequestPlay_CPSD(M542_SOUND_SPELL, P0422_i_MapX, P0423_i_MapY, C00_MODE_PLAY_IMMEDIATELY);
#endif
                F0212_PROJECTILE_Create(AL0437_T_Thing, P0422_i_MapX, P0423_i_MapY, AL0439_i_TargetCell, G0382_i_CurrentGroupPrimaryDirectionToParty, F0026_MAIN_GetBoundedValue(20, AL0440_i_KineticEnergy, 255), L0441_ps_CreatureInfo->Dexterity, 8);
        } else {
                if (M007_GET(L0441_ps_CreatureInfo->Attributes, MASK0x0010_ATTACK_ANY_CHAMPION)) {
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED /* CHANGE7_11_OPTIMIZATION Comma removed */
                        for (AL0440_i_Counter = 0, AL0439_i_ChampionIndex = M004_RANDOM(4); (AL0440_i_Counter < 4) && !M516_CHAMPIONS[AL0439_i_ChampionIndex].CurrentHealth; AL0440_i_Counter++, AL0439_i_ChampionIndex = M017_NEXT(AL0439_i_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 */
                        AL0439_i_ChampionIndex = M004_RANDOM(4);
                        for (AL0440_i_Counter = 0; (AL0440_i_Counter < 4) && !M516_CHAMPIONS[AL0439_i_ChampionIndex].CurrentHealth; AL0440_i_Counter++) {
                                AL0439_i_ChampionIndex = M017_NEXT(AL0439_i_ChampionIndex);
                        }
#endif
                        if (AL0440_i_Counter == 4) {
                                return C0_FALSE;
                        }
                } else {
                        if ((AL0439_i_ChampionIndex = F0286_CHAMPION_GetTargetChampionIndex(P0422_i_MapX, P0423_i_MapY, AL0439_i_TargetCell)) < 0) {
                                return C0_FALSE;
                        }
                }
                if (AL0437_ui_CreatureType == C02_CREATURE_GIGGLER) {
                        F0193_GROUP_StealFromChampion(P0421_ps_Group, AL0439_i_ChampionIndex);
                } else {
                        AL0440_i_Damage = F0230_GROUP_GetChampionDamage(P0421_ps_Group, AL0439_i_ChampionIndex) + 1;
                        L0442_ps_Champion = &M516_CHAMPIONS[AL0439_i_ChampionIndex];
                        if (AL0440_i_Damage > L0442_ps_Champion->MaximumDamageReceived) {
                                L0442_ps_Champion->MaximumDamageReceived = AL0440_i_Damage;
                                L0442_ps_Champion->DirectionMaximumDamageReceived = M018_OPPOSITE(L0438_ui_PrimaryDirectionToParty);
                        }
                }
        }
#ifdef MEDIA019_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA
        if (AL0440_i_AttackSoundOrdinal = L0441_ps_CreatureInfo->AttackSoundOrdinal) {
                F0064_SOUND_RequestPlay_CPSD(G0244_auc_Graphic559_CreatureAttackSounds[--AL0440_i_AttackSoundOrdinal], P0422_i_MapX, P0423_i_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
        }
#endif
#ifdef MEDIA485_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if ((AL0440_i_AttackSoundOrdinal = L0441_ps_CreatureInfo->AttackSoundOrdinal) && ((AL0440_i_AttackSoundOrdinal = G2003_aauc_CreatureSounds[--AL0440_i_AttackSoundOrdinal][C0_ATTACK_SOUND]) != CM1_SOUND_NONE)) {
                F0064_SOUND_RequestPlay_CPSD(AL0440_i_AttackSoundOrdinal, P0422_i_MapX, P0423_i_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        } else {
                if (L1876_B_UseSpellSoundAsFallback) {
                        F0064_SOUND_RequestPlay_CPSD(M542_SOUND_SPELL, P0422_i_MapX, P0423_i_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
                }
#endif
        }
#endif
        return C1_TRUE;
}

STATICFUNCTION void F0208_GROUP_AddEvent(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0425_ps_Event, P0426_ul_Time)
#endif
REGISTER EVENT*        P0425_ps_Event SEPARATOR
REGISTER unsigned long P0426_ul_Time  FINAL_SEPARATOR
{
        if (P0426_ul_Time < M030_TIME(P0425_ps_Event->Map_Time)) {
                P0425_ps_Event->A.A.Type -= 5;
                P0425_ps_Event->C.Ticks = M030_TIME(P0425_ps_Event->Map_Time) - P0426_ul_Time;
                M032_SET_TIME(P0425_ps_Event->Map_Time, P0426_ul_Time);
        } else {
                P0425_ps_Event->C.Ticks = P0426_ul_Time - M030_TIME(P0425_ps_Event->Map_Time);
        }
        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(P0425_ps_Event);
}

void F0209_GROUP_ProcessEvents29to41(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0427_i_EventMapX, P0428_i_EventMapY, P0429_i_EventType, P0430_ui_Ticks)
#endif
REGISTER int16_t P0427_i_EventMapX SEPARATOR
REGISTER int16_t P0428_i_EventMapY SEPARATOR
int16_t          P0429_i_EventType SEPARATOR
unsigned int16_t P0430_ui_Ticks    FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER GROUP* L0444_ps_Group;
#endif
        REGISTER ACTIVE_GROUP* L0445_ps_ActiveGroup;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER GROUP* L0444_ps_Group;
#endif
        REGISTER int16_t L0446_i_Multiple;
#define AL0446_i_EventType           L0446_i_Multiple
#define AL0446_i_Direction           L0446_i_Multiple
#define AL0446_i_Ticks               L0446_i_Multiple
#define AL0446_i_Distance            L0446_i_Multiple
#define AL0446_i_Behavior2Or3        L0446_i_Multiple
#define AL0446_i_CreatureAspectIndex L0446_i_Multiple
#define AL0446_i_Range               L0446_i_Multiple
#define AL0446_i_CreatureAttributes  L0446_i_Multiple
#define AL0446_i_Cell                L0446_i_Multiple
#define AL0446_i_GroupCellsCriteria  L0446_i_Multiple
        REGISTER int16_t L0447_i_Multiple;
#define AL0447_i_Behavior           L0447_i_Multiple
#define AL0447_i_CreatureIndex      L0447_i_Multiple
#define AL0447_i_ReferenceDirection L0447_i_Multiple
#define AL0447_i_Ticks              L0447_i_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        CREATURE_INFO L0448_s_CreatureInfo;
        THING L0449_T_GroupThing;
        int16_t L0450_i_Multiple;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0450_i_Multiple;
#endif
#define AL0450_i_DestinationMapX  L0450_i_Multiple
#define AL0450_i_DistanceXToParty L0450_i_Multiple
#define AL0450_i_TargetMapX       L0450_i_Multiple
        int16_t L0451_i_Multiple;
#define AL0451_i_DestinationMapY  L0451_i_Multiple
#define AL0451_i_DistanceYToParty L0451_i_Multiple
#define AL0451_i_TargetMapY       L0451_i_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        THING L0449_T_GroupThing;
#endif
        int16_t L0452_i_DistanceToVisibleParty;
        BOOLEAN L0453_B_NewGroupDirectionFound;
        int16_t L0454_i_PrimaryDirectionToOrFromParty;
        BOOLEAN L0455_B_CurrentEventTypeIsNotUpdateBehavior;
        BOOLEAN L0456_B_AllowMovementOverImaginaryPitsAndFakeWalls;
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
        BOOLEAN L0457_B_MoveToPriorLocation;
#endif
        BOOLEAN L0458_B_SetBehavior7_ApproachAfterReaction;
        int16_t L0459_i_CreatureSize;
        unsigned int16_t L0460_ui_CreatureCount;
        int16_t L0461_i_MovementTicks;
        int16_t L0462_i_TicksSinceLastMove;
        BOOLEAN L0463_B_Archenemy;
        long L0464_l_NextAspectUpdateTime;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        CREATURE_INFO L0448_s_CreatureInfo;
#endif
        EVENT L0465_s_NextEvent;


        /* If the party is not on the map specified in the event and the event type is not one of 32, 33, 37, 38 then the event is ignored */
        if ((G0272_i_CurrentMapIndex != G0309_i_PartyMapIndex) && ((AL0446_i_EventType = P0429_i_EventType) != C37_EVENT_UPDATE_BEHAVIOR_GROUP) && (AL0446_i_EventType != C32_EVENT_UPDATE_ASPECT_GROUP) && (AL0446_i_EventType != C38_EVENT_UPDATE_BEHAVIOR_CREATURE_0) && (AL0446_i_EventType != C33_EVENT_UPDATE_ASPECT_CREATURE_0))
                goto T0209139_Return;
        /* If there is no creature at the location specified in the event then the event is ignored */
        if ((L0449_T_GroupThing = F0175_GROUP_GetThing(P0427_i_EventMapX, P0428_i_EventMapY)) == C0xFFFE_THING_ENDOFLIST) {
                goto T0209139_Return;
        }
        L0444_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L0449_T_GroupThing);
        L0448_s_CreatureInfo = G0243_as_Graphic559_CreatureInfo[L0444_ps_Group->Type];
        /* Update the event */
        M033_SET_MAP_AND_TIME(L0465_s_NextEvent.Map_Time, G0272_i_CurrentMapIndex, G0313_ul_GameTime);
        L0465_s_NextEvent.A.A.Priority = 255 - L0448_s_CreatureInfo.MovementTicks; /* The fastest creatures (with small MovementTicks value) get higher event priority */
        L0465_s_NextEvent.B.Location.MapX = P0427_i_EventMapX;
        L0465_s_NextEvent.B.Location.MapY = P0428_i_EventMapY;
        /* If the creature is not on the party map then try and move the creature in a random direction and place a new event 37 in the timeline for the next creature movement. Note that 'Freeze Life' does not apply to creatures located on maps other than the party map */
        if (G0272_i_CurrentMapIndex != G0309_i_PartyMapIndex) {
                if (F0202_GROUP_IsMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = M004_RANDOM(4), C0_FALSE)) { /* BUG0_67 A group that is not on the party map may wrongly move or not move into a teleporter. Normally, a creature type with Wariness >= 10 (Vexirk, Materializer / Zytaz, Demon, Lord Chaos, Red Dragon / Dragon) would only move into a teleporter if the creature type is allowed on the destination map. However, the variable G0380_T_CurrentGroupThing identifying the group is not set before being used by F0139_DUNGEON_IsCreatureAllowedOnMap called by F0202_GROUP_IsMovementPossible so the check to see if the creature type is allowed may operate on another creature type and thus return an incorrect result, causing the creature to teleport while it should not, or not to teleport while it should */
                        AL0450_i_DestinationMapX = P0427_i_EventMapX;
                        AL0451_i_DestinationMapY = P0428_i_EventMapY;
                        AL0450_i_DestinationMapX += G0233_ai_Graphic559_DirectionToStepEastCount[AL0446_i_Direction], AL0451_i_DestinationMapY += G0234_ai_Graphic559_DirectionToStepNorthCount[AL0446_i_Direction];
                        if (F0267_MOVE_GetMoveResult_CPSCE(L0449_T_GroupThing, P0427_i_EventMapX, P0428_i_EventMapY, AL0450_i_DestinationMapX, AL0451_i_DestinationMapY))
                                goto T0209139_Return;
                        L0465_s_NextEvent.B.Location.MapX = G0397_i_MoveResultMapX;
                        L0465_s_NextEvent.B.Location.MapY = G0398_i_MoveResultMapY;
                }
                L0465_s_NextEvent.A.A.Type = C37_EVENT_UPDATE_BEHAVIOR_GROUP;
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_03_IMPROVEMENT */
                AL0446_i_Ticks = F0025_MAIN_GetMaximumValue(10, L0448_s_CreatureInfo.MovementTicks << 1); /* Slower group movement when not on the party map */
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_03_IMPROVEMENT Group movements are greatly slowed down on maps far from the party to improve the overall game performance (less events to process) */
                AL0446_i_Ticks = F0025_MAIN_GetMaximumValue(F0023_MAIN_GetAbsoluteValue(G0272_i_CurrentMapIndex - G0309_i_PartyMapIndex) << 4, L0448_s_CreatureInfo.MovementTicks << 1);
#endif
                /* BUG0_68 A group moves or acts with a wrong timing. Event is added below but L0465_s_NextEvent.C.Ticks has not been initialized. No consequence while the group is not on the party map. When the party enters the group map the first group event may have a wrong timing */
                T0209005_AddEventAndReturn:
                L0465_s_NextEvent.Map_Time += AL0446_i_Ticks;
                F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0465_s_NextEvent);
                goto T0209139_Return;
        }
        /* If the creature is Lord Chaos then ignore the event if the game is won. Initialize data to analyze Fluxcages */
        if (L0463_B_Archenemy = M007_GET(L0448_s_CreatureInfo.Attributes, MASK0x2000_ARCHENEMY)) {
                if (G0302_B_GameWon) {
                        goto T0209139_Return;
                }
                G0386_ui_FluxCageCount = 0;
                (*(long*)G0385_ac_FluxCages) = 0;
        }
        L0445_ps_ActiveGroup = &G0375_ps_ActiveGroups[L0444_ps_Group->ActiveGroupIndex];
        if ((L0462_i_TicksSinceLastMove = (unsigned char)G0313_ul_GameTime - L0445_ps_ActiveGroup->LastMoveTime) < 0) {
                L0462_i_TicksSinceLastMove += 256;
        }
        if ((L0461_i_MovementTicks = L0448_s_CreatureInfo.MovementTicks) == C255_IMMOBILE) {
                L0461_i_MovementTicks = 100;
        }
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_04_FIX Code moved so that creature reaction events are ignored if life is frozen */
        if (G0407_s_Party.FreezeLifeTicks && !L0463_B_Archenemy) { /* If life is frozen and the creature is not Lord Chaos (Lord Chaos is immune to Freeze Life) then reschedule the event later (except for reactions which are ignored when life if frozen) */
                if (P0429_i_EventType < 0)
                        goto T0209139_Return;
                L0465_s_NextEvent.A.A.Type = P0429_i_EventType;
                L0465_s_NextEvent.C.Ticks = P0430_ui_Ticks;
                AL0446_i_Ticks = 4; /* Retry in 4 ticks */
                goto T0209005_AddEventAndReturn;
        }
#endif
        /* If the specified event type is a 'reaction' instead of a real event from the timeline then create the corresponding reaction event with a delay:
                For event CM1_EVENT_CREATE_REACTION_EVENT_31_PARTY_IS_ADJACENT, the reaction time is 1 tick
                For event CM2_EVENT_CREATE_REACTION_EVENT_30_HIT_BY_PROJECTILE and CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE, the reaction time may be 1 tick or slower: slow moving creatures react more slowly. The more recent the last creature move, the slower the reaction */
        if (P0429_i_EventType < 0) {
                L0465_s_NextEvent.A.A.Type = P0429_i_EventType + C32_EVENT_UPDATE_ASPECT_GROUP;
                if ((P0429_i_EventType == CM1_EVENT_CREATE_REACTION_EVENT_31_PARTY_IS_ADJACENT) || ((AL0446_i_Ticks = ((L0461_i_MovementTicks + 2) >> 2) - L0462_i_TicksSinceLastMove) < 1)) { /* AL0446_i_Ticks is the reaction time */
                        AL0446_i_Ticks = 1; /* Retry in 1 tick */
                }
                goto T0209005_AddEventAndReturn; /* BUG0_68 A group moves or acts with a wrong timing. Event is added but L0465_s_NextEvent.C.Ticks has not been initialized */
        }
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_04_FIX Creature reaction events are not ignored if life is frozen */
/* BUG0_14 While life is frozen, creature reaction events are not ignored as they should. They accumulate and can saturate the timeline. Creature reactions happen after seeing another creature in the group die, being hit by a projectile or a closing door and attacked or bumped into by the party. Each reaction creates an additional event in the timeline and these events are not removed from the timeline while life is frozen by using a Magical Box (except for Lord Chaos which is immune). When events are exhausted, new events are not added to the timeline which can cause many issues (see BUG0_18) */
        if (G0407_s_Party.FreezeLifeTicks && !L0463_B_Archenemy) { /* If life is frozen and the creature is not Lord Chaos (Lord Chaos is immune to Freeze Life) then reschedule the event later */
                L0465_s_NextEvent.A.A.Type = P0429_i_EventType;
                L0465_s_NextEvent.C.Ticks = P0430_ui_Ticks;
                AL0446_i_Ticks = 4; /* Retry in 4 ticks */
                goto T0209005_AddEventAndReturn;
        }
#endif
        AL0447_i_Behavior = L0444_ps_Group->Behavior;
        L0460_ui_CreatureCount = L0444_ps_Group->Count;
        L0459_i_CreatureSize = M007_GET(L0448_s_CreatureInfo.Attributes, MASK0x0003_SIZE);
        AL0450_i_DistanceXToParty = ((AL0446_i_Distance = P0427_i_EventMapX - G0306_i_PartyMapX) < 0) ? -AL0446_i_Distance : AL0446_i_Distance;
        AL0451_i_DistanceYToParty = ((AL0446_i_Distance = P0428_i_EventMapY - G0307_i_PartyMapY) < 0) ? -AL0446_i_Distance : AL0446_i_Distance;
        G0378_i_CurrentGroupMapX = P0427_i_EventMapX;
        G0379_i_CurrentGroupMapY = P0428_i_EventMapY;
        G0380_T_CurrentGroupThing = L0449_T_GroupThing;
        (*(long*)G0384_auc_GroupMovementTestedDirections) = 0;
        G0381_ui_CurrentGroupDistanceToParty = F0226_GROUP_GetDistanceBetweenSquares(P0427_i_EventMapX, P0428_i_EventMapY, G0306_i_PartyMapX, G0307_i_PartyMapY);
        G0382_i_CurrentGroupPrimaryDirectionToParty = F0228_GROUP_GetDirectionsWhereDestinationIsVisibleFromSource(P0427_i_EventMapX, P0428_i_EventMapY, G0306_i_PartyMapX, G0307_i_PartyMapY);
        G0383_i_CurrentGroupSecondaryDirectionToParty = G0363_i_SecondaryDirectionToOrFromParty;
        L0464_l_NextAspectUpdateTime = 0;
        L0455_B_CurrentEventTypeIsNotUpdateBehavior = C1_TRUE;
        if (P0429_i_EventType <= C31_EVENT_GROUP_REACTION_PARTY_IS_ADJACENT) { /* Process Reaction events 29 to 31 */
                switch (P0429_i_EventType -= C32_EVENT_UPDATE_ASPECT_GROUP) {
                        case CM1_EVENT_CREATE_REACTION_EVENT_31_PARTY_IS_ADJACENT: /* This event is used when the party bumps into a group or attacks a group physically (not with a spell). It causes the creature behavior to change to attack if it is not already attacking the party or fleeing from target */
                                if (
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                   (L0448_s_CreatureInfo.AttackTicks != C255_UNKNOWN) &&
#endif
                                   (AL0447_i_Behavior != C6_BEHAVIOR_ATTACK) && (AL0447_i_Behavior != C5_BEHAVIOR_FLEE)) {
                                        F0181_GROUP_DeleteEvents(P0427_i_EventMapX, P0428_i_EventMapY);
                                        goto T0209044_SetBehavior6_Attack;
                                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                                else {
#endif
                                        L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX;
                                        L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY;
                                        goto T0209139_Return;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                }
#endif
                        case CM2_EVENT_CREATE_REACTION_EVENT_30_HIT_BY_PROJECTILE: /* This event is used for the reaction of a group after a projectile impacted with one creature in the group (some creatures may have been killed) */
                                if ((AL0447_i_Behavior == C6_BEHAVIOR_ATTACK) || (AL0447_i_Behavior == C5_BEHAVIOR_FLEE)) /* If the creature is attacking the party or fleeing from the target then there is no reaction */
                                        goto T0209139_Return;
                                if ((AL0446_i_Behavior2Or3 = ((AL0447_i_Behavior == C3_BEHAVIOR_USELESS) || (AL0447_i_Behavior == C2_BEHAVIOR_USELESS))) || (M004_RANDOM(4))) { /* BUG0_00 Useless code. Behavior cannot be 2 nor 3 because these values are never used. The actual condition is thus: if 3/4 chances */
                                        if (!F0200_GROUP_GetDistanceToVisibleParty(L0444_ps_Group, CM1_WHOLE_CREATURE_GROUP, P0427_i_EventMapX, P0428_i_EventMapY)) { /* If the group cannot see the party then look in a random direction to try and search for the party */
                                                L0458_B_SetBehavior7_ApproachAfterReaction = L0453_B_NewGroupDirectionFound = C0_FALSE;
                                                goto T0209073_SetDirectionGroup;
                                        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                                        else {
#endif
                                                if (AL0446_i_Behavior2Or3 || (M004_RANDOM(4))) /* BUG0_00 Useless code. Behavior cannot be 2 nor 3 because these values are never used. The actual condition is thus: if 3/4 chances then no reaction */
                                                        goto T0209139_Return;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                        }
#endif
                                } /* No 'break': proceed to instruction after the next 'case' below. Reaction is to move in a random direction to try and avoid other projectiles */
                        case CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE: /* This event is used when some creatures in the group were killed by a Poison Cloud or by a closing door or if Lord Chaos is surrounded by 3 Fluxcages. It causes the creature to move in a random direction to avoid the danger */
                                L0458_B_SetBehavior7_ApproachAfterReaction = (AL0447_i_Behavior == C6_BEHAVIOR_ATTACK); /* If the creature behavior is 'Attack' and it has to move to avoid danger then it will change its behavior to 'Approach' after the movement */
                                L0453_B_NewGroupDirectionFound = C0_FALSE;
                                goto T0209058_MoveInRandomDirection;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        default:
                                goto T0209139_Return;
#endif
                }
        }
        if (P0429_i_EventType < C37_EVENT_UPDATE_BEHAVIOR_GROUP) { /* Process Update Aspect events 32 to 36 */
                L0465_s_NextEvent.A.A.Type = P0429_i_EventType + 5;
                if (F0200_GROUP_GetDistanceToVisibleParty(L0444_ps_Group, CM1_WHOLE_CREATURE_GROUP, P0427_i_EventMapX, P0428_i_EventMapY)) {
                        if ((AL0447_i_Behavior != C6_BEHAVIOR_ATTACK) && (AL0447_i_Behavior != C5_BEHAVIOR_FLEE)) {
                                if (
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                   (L0448_s_CreatureInfo.AttackTicks != C255_UNKNOWN) &&
#endif
                                   (M038_DISTANCE(G0306_i_PartyMapX, G0307_i_PartyMapY, P0427_i_EventMapX, P0428_i_EventMapY) <= 1))
                                        goto T0209044_SetBehavior6_Attack;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                                else {
#endif
                                        if (((AL0447_i_Behavior == C0_BEHAVIOR_WANDER) || (AL0447_i_Behavior == C3_BEHAVIOR_USELESS)) && (AL0447_i_Behavior != C7_BEHAVIOR_APPROACH)) /* BUG0_00 Useless code. Behavior cannot be 3 because this value is never used. Moreover, the second condition in the && is redundant (if the value is 0 or 3, it cannot be 7). The actual condition is: if (AL0447_i_Behavior == C0_BEHAVIOR_WANDER) */
                                                goto T0209054_SetBehavior7_Approach;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                }
#endif
                        }
                        L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX;
                        L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY;
                }
                if (AL0447_i_Behavior == C6_BEHAVIOR_ATTACK) {
                        AL0446_i_CreatureAspectIndex = P0429_i_EventType - C33_EVENT_UPDATE_ASPECT_CREATURE_0; /* Value -1 for event 32, meaning aspect will be updated for all creatures in the group */
                        L0464_l_NextAspectUpdateTime = F0179_GROUP_GetCreatureAspectUpdateTime(L0445_ps_ActiveGroup, AL0446_i_CreatureAspectIndex, M007_GET(L0445_ps_ActiveGroup->Aspect[AL0446_i_CreatureAspectIndex], MASK0x0080_IS_ATTACKING));
                        goto T0209136;
                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                else {
#endif
                        if ((AL0450_i_DistanceXToParty > 3) || (AL0451_i_DistanceYToParty > 3)) {
                                L0464_l_NextAspectUpdateTime = G0313_ul_GameTime + M063_NEXT_NON_ATTACK_ASPECT_UPDATE_TICKS(L0448_s_CreatureInfo.AnimationTicks);
                                goto T0209136;
                        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                        else {
#endif
                                goto T0209135;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        }
                }
#endif
        }
        /* Process Update Behavior events 37 to 41 */
        L0455_B_CurrentEventTypeIsNotUpdateBehavior = C0_FALSE;
        if (P0430_ui_Ticks) {
                L0464_l_NextAspectUpdateTime = G0313_ul_GameTime;
        }
        if (P0429_i_EventType == C37_EVENT_UPDATE_BEHAVIOR_GROUP) { /* Process event 37, Update Group Behavior */
                if ((AL0447_i_Behavior == C0_BEHAVIOR_WANDER) || (AL0447_i_Behavior == C2_BEHAVIOR_USELESS) || (AL0447_i_Behavior == C3_BEHAVIOR_USELESS)) { /* BUG0_00 Useless code. Behavior cannot be 2 nor 3 because these values are never used. The actual condition is: if (AL0447_i_Behavior == C0_BEHAVIOR_WANDER) */
                        if (L0452_i_DistanceToVisibleParty = F0200_GROUP_GetDistanceToVisibleParty(L0444_ps_Group, CM1_WHOLE_CREATURE_GROUP, P0427_i_EventMapX, P0428_i_EventMapY)) {
                                if ((L0452_i_DistanceToVisibleParty <= M056_ATTACK_RANGE(L0448_s_CreatureInfo.Ranges)) &&
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                   (L0448_s_CreatureInfo.AttackTicks != C255_UNKNOWN) &&
#endif
                                   ((!AL0450_i_DistanceXToParty) || (!AL0451_i_DistanceYToParty))) { /* If the creature is in range for attack and on the same row or column as the party on the map */
                                        T0209044_SetBehavior6_Attack:
                                        if (P0429_i_EventType == CM2_EVENT_CREATE_REACTION_EVENT_30_HIT_BY_PROJECTILE) {
                                                F0181_GROUP_DeleteEvents(P0427_i_EventMapX, P0428_i_EventMapY);
                                        }
                                        L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX;
                                        L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY;
                                        L0444_ps_Group->Behavior = C6_BEHAVIOR_ATTACK;
                                        AL0446_i_Direction = G0382_i_CurrentGroupPrimaryDirectionToParty;
                                        for (AL0447_i_CreatureIndex = L0460_ui_CreatureCount; AL0447_i_CreatureIndex >= 0; AL0447_i_CreatureIndex--) {
                                                if ((M050_CREATURE_VALUE(L0445_ps_ActiveGroup->Directions, AL0447_i_CreatureIndex) != AL0446_i_Direction) &&
                                                    !(AL0447_i_CreatureIndex && M005_RANDOM(2))) {
                                                        F0205_GROUP_SetDirection(L0445_ps_ActiveGroup, AL0446_i_Direction, AL0447_i_CreatureIndex, L0460_ui_CreatureCount && (L0459_i_CreatureSize == C1_SIZE_HALF_SQUARE));
                                                        M032_SET_TIME(L0465_s_NextEvent.Map_Time, G0313_ul_GameTime + M004_RANDOM(4) + 2); /* Random delay represents the time for the creature to turn */
                                                } else {
                                                        M032_SET_TIME(L0465_s_NextEvent.Map_Time, G0313_ul_GameTime + 1);
                                                }
                                                if (L0455_B_CurrentEventTypeIsNotUpdateBehavior) {
                                                        L0465_s_NextEvent.Map_Time += F0024_MAIN_GetMinimumValue((L0448_s_CreatureInfo.AttackTicks >> 1) + M004_RANDOM(4), P0430_ui_Ticks);
                                                }
                                                L0465_s_NextEvent.A.A.Type = C38_EVENT_UPDATE_BEHAVIOR_CREATURE_0 + AL0447_i_CreatureIndex;
                                                F0208_GROUP_AddEvent(&L0465_s_NextEvent, F0179_GROUP_GetCreatureAspectUpdateTime(L0445_ps_ActiveGroup, AL0447_i_CreatureIndex, C0_FALSE));
                                        }
                                        goto T0209139_Return;
                                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                                else {
#endif
                                        if (AL0447_i_Behavior != C2_BEHAVIOR_USELESS) { /* BUG0_00 Useless code. Behavior cannot be 2 because this value is never used */
                                                T0209054_SetBehavior7_Approach:
                                                L0444_ps_Group->Behavior = C7_BEHAVIOR_APPROACH;
                                                L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX;
                                                L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY;
                                                L0465_s_NextEvent.Map_Time++;
                                                goto T0209134_SetEvent37;
                                        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                }
#endif
                        } else {
                                if (AL0447_i_Behavior == C0_BEHAVIOR_WANDER) {
                                        if (L0454_i_PrimaryDirectionToOrFromParty = F0201_GROUP_GetSmelledPartyPrimaryDirectionOrdinal(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY)) {
                                                L0454_i_PrimaryDirectionToOrFromParty--;
                                                L0456_B_AllowMovementOverImaginaryPitsAndFakeWalls = C0_FALSE;
                                                goto T0209085_SingleSquareMove;
                                        }
                                        L0453_B_NewGroupDirectionFound = C0_FALSE;
                                        if (M005_RANDOM(2)) {
                                                T0209058_MoveInRandomDirection:
                                                AL0446_i_Direction = M004_RANDOM(4);
                                                AL0447_i_ReferenceDirection = AL0446_i_Direction;
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
                                                L0457_B_MoveToPriorLocation = C0_FALSE;
#endif
                                                do {
                                                        AL0450_i_DestinationMapX = P0427_i_EventMapX;
                                                        AL0451_i_DestinationMapY = P0428_i_EventMapY;
                                                        AL0450_i_DestinationMapX += G0233_ai_Graphic559_DirectionToStepEastCount[AL0446_i_Direction], AL0451_i_DestinationMapY += G0234_ai_Graphic559_DirectionToStepNorthCount[AL0446_i_Direction];
                                                        if (((L0445_ps_ActiveGroup->PriorMapX != AL0450_i_DestinationMapX) ||
                                                             (L0445_ps_ActiveGroup->PriorMapY != AL0451_i_DestinationMapY) ||
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
                                                             (L0457_B_MoveToPriorLocation = !M004_RANDOM(4))) /* 1/4 chance of moving back to the square that the creature comes from */
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                             !M004_RANDOM(4)) /* 1/4 chance of moving back to the square that the creature comes from */
#endif
                                                            && F0202_GROUP_IsMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction, C0_FALSE)) {
                                                                T0209061_MoveGroup:
                                                                if (L0453_B_NewGroupDirectionFound = (AL0447_i_Ticks = (L0461_i_MovementTicks >> 1) - L0462_i_TicksSinceLastMove) <= 0) {
                                                                        if (F0267_MOVE_GetMoveResult_CPSCE(L0449_T_GroupThing, P0427_i_EventMapX, P0428_i_EventMapY, AL0450_i_DestinationMapX, AL0451_i_DestinationMapY))
                                                                                goto T0209139_Return;
                                                                        L0465_s_NextEvent.B.Location.MapX = G0397_i_MoveResultMapX;
                                                                        L0465_s_NextEvent.B.Location.MapY = G0398_i_MoveResultMapY;
                                                                        L0445_ps_ActiveGroup->PriorMapX = P0427_i_EventMapX;
                                                                        L0445_ps_ActiveGroup->PriorMapY = P0428_i_EventMapY;
                                                                        L0445_ps_ActiveGroup->LastMoveTime = G0313_ul_GameTime;
                                                                } else {
                                                                        L0461_i_MovementTicks = AL0447_i_Ticks;
                                                                        L0462_i_TicksSinceLastMove = -1;
                                                                }
                                                                break;
                                                        }
                                                        if (G0390_B_GroupMovementBlockedByParty) {
                                                                if ((P0429_i_EventType != CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE) &&
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                                    (L0448_s_CreatureInfo.AttackTicks != C255_UNKNOWN) &&
#endif
                                                                    ((L0444_ps_Group->Behavior != C5_BEHAVIOR_FLEE) ||
                                                                    !F0203_GROUP_GetFirstPossibleMovementDirectionOrdinal(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, C0_FALSE) ||
                                                                    M005_RANDOM(2)))
                                                                        goto T0209044_SetBehavior6_Attack;
                                                                L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX;
                                                                L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY;
                                                        }
                                                } while ((AL0446_i_Direction = M017_NEXT(AL0446_i_Direction)) != AL0447_i_ReferenceDirection);
                                        }
                                        if (!L0453_B_NewGroupDirectionFound &&
#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_03_FIX Without this additional condition, the game can freeze when you close a door over Lord Chaos (this creates an event CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE). This may create an infinite loop between the 'goto T0209089_DoubleSquareMove' here and the 'goto T0209061_MoveGroup' there (if L0453_B_NewGroupDirectionFound = C0_FALSE in the condition at T0209061_MoveGroup:) */
                                            (L0462_i_TicksSinceLastMove != -1) &&
#endif
                                            L0463_B_Archenemy &&
                                            ((P0429_i_EventType == CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE) || !M004_RANDOM(4))) { /* BUG0_15 The game hangs when you close a door on Lord Chaos. A condition is missing in the code to manage creatures and this may create an infinite loop between two parts in the code */
#ifdef MEDIA297_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 /* CHANGE7_19_FIX When Lord Chaos senses danger on his square (because of a Poison Cloud, a closing door or 3 surrounding Fluxcages) he teleports in a direction initialized with a random value */
                                                G0363_i_SecondaryDirectionToOrFromParty = M017_NEXT(L0454_i_PrimaryDirectionToOrFromParty = M004_RANDOM(4));
#endif
#ifdef MEDIA382_G14ED_A20ED
                                                L0454_i_PrimaryDirectionToOrFromParty = M004_RANDOM(4);
                                                G0363_i_SecondaryDirectionToOrFromParty = M017_NEXT(L0454_i_PrimaryDirectionToOrFromParty);
#endif
                                                goto T0209089_DoubleSquareMove; /* BUG0_69 Memory corruption when you close a door on Lord Chaos. The local variable (L0454_i_PrimaryDirectionToOrFromParty) containing the direction where Lord Chaos tries to move may be used as an array index without being initialized and cause memory corruption */
                                        }
                                        if (L0453_B_NewGroupDirectionFound || ((!M004_RANDOM(4) || (L0452_i_DistanceToVisibleParty <= M055_SMELL_RANGE(L0448_s_CreatureInfo.Ranges))) && (P0429_i_EventType != CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE))) {
                                                T0209073_SetDirectionGroup:
                                                if (!L0453_B_NewGroupDirectionFound && (L0462_i_TicksSinceLastMove >= 0)) { /* If direction is not found yet then look around in a random direction */
                                                        AL0446_i_Direction = M004_RANDOM(4);
                                                }
                                                F0206_GROUP_SetDirectionGroup(L0445_ps_ActiveGroup, AL0446_i_Direction, L0460_ui_CreatureCount, L0459_i_CreatureSize);
                                        }
                                        /* If event is CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE or CM2_EVENT_CREATE_REACTION_EVENT_30_HIT_BY_PROJECTILE */
                                        if (P0429_i_EventType < CM1_EVENT_CREATE_REACTION_EVENT_31_PARTY_IS_ADJACENT) {
                                                if (!L0453_B_NewGroupDirectionFound)
                                                        goto T0209139_Return;
                                                if (L0458_B_SetBehavior7_ApproachAfterReaction) {
                                                        L0444_ps_Group->Behavior = C7_BEHAVIOR_APPROACH;
                                                }
                                                F0182_GROUP_StopAttacking(L0445_ps_ActiveGroup, P0427_i_EventMapX, P0428_i_EventMapY);
                                        }
                                }
                        }
                } else {
                        if (AL0447_i_Behavior == C7_BEHAVIOR_APPROACH) {
                                if (L0452_i_DistanceToVisibleParty = F0200_GROUP_GetDistanceToVisibleParty(L0444_ps_Group, CM1_WHOLE_CREATURE_GROUP, P0427_i_EventMapX, P0428_i_EventMapY)) {
                                        if ((L0452_i_DistanceToVisibleParty <= M056_ATTACK_RANGE(L0448_s_CreatureInfo.Ranges)) &&
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                           (L0448_s_CreatureInfo.AttackTicks != C255_UNKNOWN) &&
#endif
                                           ((!AL0450_i_DistanceXToParty) || (!AL0451_i_DistanceYToParty))) /* If the creature is in range for attack and on the same row or column as the party on the map */
                                                goto T0209044_SetBehavior6_Attack;
                                        T0209081_RunTowardParty:
                                        L0461_i_MovementTicks++;
                                        L0461_i_MovementTicks >>= 1; /* Running speed is half the movement ticks */
                                        AL0450_i_TargetMapX = (L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX);
                                        AL0451_i_TargetMapY = (L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY);
                                } else {
                                        T0209082_WalkTowardTarget:
                                        AL0450_i_TargetMapX = L0445_ps_ActiveGroup->TargetMapX;
                                        AL0451_i_TargetMapY = L0445_ps_ActiveGroup->TargetMapY;
                                        /* If the creature reached its target but the party is not there anymore */
                                        if ((P0427_i_EventMapX == AL0450_i_TargetMapX) && (P0428_i_EventMapY == AL0451_i_TargetMapY)) {
                                                L0453_B_NewGroupDirectionFound = C0_FALSE;
                                                L0444_ps_Group->Behavior = C0_BEHAVIOR_WANDER;
                                                goto T0209073_SetDirectionGroup;
                                        }
                                }
                                L0456_B_AllowMovementOverImaginaryPitsAndFakeWalls = C1_TRUE;
                                T0209084_SingleSquareMoveTowardTargetSquare:
                                L0454_i_PrimaryDirectionToOrFromParty = F0228_GROUP_GetDirectionsWhereDestinationIsVisibleFromSource(P0427_i_EventMapX, P0428_i_EventMapY, AL0450_i_TargetMapX, AL0451_i_TargetMapY);
                                T0209085_SingleSquareMove:
                                if (F0202_GROUP_IsMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = L0454_i_PrimaryDirectionToOrFromParty, L0456_B_AllowMovementOverImaginaryPitsAndFakeWalls) ||
                                    F0202_GROUP_IsMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = G0363_i_SecondaryDirectionToOrFromParty, L0456_B_AllowMovementOverImaginaryPitsAndFakeWalls && M005_RANDOM(2)) ||
                                    F0202_GROUP_IsMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = M018_OPPOSITE(AL0446_i_Direction), C0_FALSE) ||
                                    (!M004_RANDOM(4) && F0202_GROUP_IsMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = M018_OPPOSITE(L0454_i_PrimaryDirectionToOrFromParty), C0_FALSE))) {
                                        AL0450_i_DestinationMapX = P0427_i_EventMapX;
                                        AL0451_i_DestinationMapY = P0428_i_EventMapY;
                                        AL0450_i_DestinationMapX += G0233_ai_Graphic559_DirectionToStepEastCount[AL0446_i_Direction], AL0451_i_DestinationMapY += G0234_ai_Graphic559_DirectionToStepNorthCount[AL0446_i_Direction];
                                        goto T0209061_MoveGroup;
                                }
                                if (L0463_B_Archenemy) {
                                        T0209089_DoubleSquareMove:
                                        F0203_GROUP_GetFirstPossibleMovementDirectionOrdinal(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, C0_FALSE); /* BUG0_00 Useless code. Returned value is ignored. When Lord Chaos teleports two squares away the ability to move to the first square is ignored which means Lord Chaos can teleport through walls or any other obstacle */
                                        if (F0204_GROUP_IsArchenemyDoubleMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = L0454_i_PrimaryDirectionToOrFromParty) ||
                                            F0204_GROUP_IsArchenemyDoubleMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = G0363_i_SecondaryDirectionToOrFromParty) ||
                                            (G0386_ui_FluxCageCount && F0204_GROUP_IsArchenemyDoubleMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = M018_OPPOSITE(AL0446_i_Direction))) ||
                                            ((G0386_ui_FluxCageCount >= 2) && F0204_GROUP_IsArchenemyDoubleMovementPossible(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, AL0446_i_Direction = M018_OPPOSITE(L0454_i_PrimaryDirectionToOrFromParty)))) {
                                                AL0450_i_DestinationMapX = P0427_i_EventMapX;
                                                AL0451_i_DestinationMapY = P0428_i_EventMapY;
                                                AL0450_i_DestinationMapX += G0233_ai_Graphic559_DirectionToStepEastCount[AL0446_i_Direction] * 2, AL0451_i_DestinationMapY += G0234_ai_Graphic559_DirectionToStepNorthCount[AL0446_i_Direction] * 2;
                                                F0064_SOUND_RequestPlay_CPSD(M560_SOUND_BUZZ, AL0450_i_DestinationMapX, AL0451_i_DestinationMapY, C01_MODE_PLAY_IF_PRIORITIZED);
                                                goto T0209061_MoveGroup;
                                        }
                                }
                                F0206_GROUP_SetDirectionGroup(L0445_ps_ActiveGroup, L0454_i_PrimaryDirectionToOrFromParty, L0460_ui_CreatureCount, L0459_i_CreatureSize);
                        } else {
                                if (AL0447_i_Behavior == C5_BEHAVIOR_FLEE) {
                                        T0209094_FleeFromTarget:
                                        L0456_B_AllowMovementOverImaginaryPitsAndFakeWalls = C1_TRUE;
                                        /* If the creature can see the party then update target coordinates */
                                        if (L0452_i_DistanceToVisibleParty = F0200_GROUP_GetDistanceToVisibleParty(L0444_ps_Group, CM1_WHOLE_CREATURE_GROUP, P0427_i_EventMapX, P0428_i_EventMapY)) {
                                                AL0450_i_TargetMapX = (L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX);
                                                AL0451_i_TargetMapY = (L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY);
                                        } else {
                                                if (!(--(L0445_ps_ActiveGroup->DelayFleeingFromTarget))) { /* If the creature is not afraid anymore then stop fleeing from target */
                                                        T0209096_SetBehavior0_Wander:
                                                        L0453_B_NewGroupDirectionFound = C0_FALSE;
                                                        L0444_ps_Group->Behavior = C0_BEHAVIOR_WANDER;
                                                        goto T0209073_SetDirectionGroup;
                                                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                                                else {
#endif
                                                        if (M005_RANDOM(2)) {
                                                                /* If the creature cannot move and the party is adjacent then stop fleeing */
                                                                if (!F0203_GROUP_GetFirstPossibleMovementDirectionOrdinal(&L0448_s_CreatureInfo, P0427_i_EventMapX, P0428_i_EventMapY, C0_FALSE)) {
                                                                        if (M038_DISTANCE(P0427_i_EventMapX, P0428_i_EventMapY, G0306_i_PartyMapX, G0307_i_PartyMapY) <= 1)
                                                                                goto T0209096_SetBehavior0_Wander;
                                                                }
                                                                /* Set creature target to the home square where the creature was located when the party entered the map */
                                                                AL0450_i_TargetMapX = L0445_ps_ActiveGroup->HomeMapX;
                                                                AL0451_i_TargetMapY = L0445_ps_ActiveGroup->HomeMapY;
                                                                goto T0209084_SingleSquareMoveTowardTargetSquare;
                                                        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                                                        else {
#endif
                                                                AL0450_i_TargetMapX = L0445_ps_ActiveGroup->TargetMapX;
                                                                AL0451_i_TargetMapY = L0445_ps_ActiveGroup->TargetMapY;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                                        }
                                                }
#endif
                                        }
                                        /* Try and flee from the party (opposite direction) */
                                        L0454_i_PrimaryDirectionToOrFromParty = M018_OPPOSITE(F0228_GROUP_GetDirectionsWhereDestinationIsVisibleFromSource(P0427_i_EventMapX, P0428_i_EventMapY, AL0450_i_TargetMapX, AL0451_i_TargetMapY));
                                        G0363_i_SecondaryDirectionToOrFromParty = M018_OPPOSITE(G0363_i_SecondaryDirectionToOrFromParty);
                                        L0461_i_MovementTicks -= (L0461_i_MovementTicks >> 2);
                                        goto T0209085_SingleSquareMove;
                                }
                        }
                }
        } else { /* Process events 38 to 41, Update Creature Behavior */
                if (AL0447_i_Behavior == C5_BEHAVIOR_FLEE) {
                        if (L0460_ui_CreatureCount) {
                                F0182_GROUP_StopAttacking(L0445_ps_ActiveGroup, P0427_i_EventMapX, P0428_i_EventMapY);
                        }
                        goto T0209094_FleeFromTarget;
                }
                /* If the creature is attacking, then compute the next aspect update time and the next attack time */
                if (M007_GET(L0445_ps_ActiveGroup->Aspect[AL0447_i_CreatureIndex = P0429_i_EventType - C38_EVENT_UPDATE_BEHAVIOR_CREATURE_0], MASK0x0080_IS_ATTACKING)) {
                        L0464_l_NextAspectUpdateTime = F0179_GROUP_GetCreatureAspectUpdateTime(L0445_ps_ActiveGroup, AL0447_i_CreatureIndex, C0_FALSE);
                        L0465_s_NextEvent.Map_Time += ((AL0447_i_Ticks = L0448_s_CreatureInfo.AttackTicks) + M004_RANDOM(4) - 1);
                        if (AL0447_i_Ticks > 15) {
                                L0465_s_NextEvent.Map_Time += M003_RANDOM(8) - 2;
                        }
                } else { /* If the creature is not attacking, then try attacking if possible */
                        if (AL0447_i_CreatureIndex > L0460_ui_CreatureCount) { /* Ignore event if it is for a creature that is not in the group */
                                goto T0209139_Return;
                        }
                        L0454_i_PrimaryDirectionToOrFromParty = G0382_i_CurrentGroupPrimaryDirectionToParty;
                        /* If the party is visible, update the target coordinates */
                        if (L0452_i_DistanceToVisibleParty = F0200_GROUP_GetDistanceToVisibleParty(L0444_ps_Group, AL0447_i_CreatureIndex, P0427_i_EventMapX, P0428_i_EventMapY)) {
                                L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX;
                                L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY;
                        }
                        /* If there is a single creature in the group that is not full square sized and 1/4 chance */
                        if (!L0460_ui_CreatureCount && (L0459_i_CreatureSize != C2_SIZE_FULL_SQUARE) && !((AL0446_i_GroupCellsCriteria = M006_RANDOM(65536)) & 0x00C0)) {
                                if (L0445_ps_ActiveGroup->Cells != C0xFF_SINGLE_CENTERED_CREATURE) {
                                        /* If the creature is not already on the center of the square then change its cell */
                                        if (AL0446_i_GroupCellsCriteria & 0x0038) { /* 7/8 chances of changing cell to the center of the square */
                                                L0445_ps_ActiveGroup->Cells = C0xFF_SINGLE_CENTERED_CREATURE;
                                        } else { /* 1/8 chance of changing cell to the next or previous cell on the square */
                                                AL0446_i_GroupCellsCriteria = M021_NORMALIZE(M021_NORMALIZE(L0445_ps_ActiveGroup->Cells) + ((AL0446_i_GroupCellsCriteria & 0x0001) ? 1 : -1));
                                        }
                                }
                                /* If 1/8 chance and the creature is not adjacent to the party and is a quarter square sized creature then process projectile impacts and update the creature cell if still alive. When the creature is not in front of the party, it has 7/8 chances of dodging a projectile by moving to another cell or staying in the center of the square */
                                if (!(AL0446_i_GroupCellsCriteria & 0x0038) && (L0452_i_DistanceToVisibleParty != 1) && (L0459_i_CreatureSize == C0_SIZE_QUARTER_SQUARE)) {
                                        if (F0218_PROJECTILE_GetImpactCount(CM1_ELEMENT_CREATURE, P0427_i_EventMapX, P0428_i_EventMapY, L0445_ps_ActiveGroup->Cells) && (G0364_i_CreatureDamageOutcome == C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP)) /* This call to F0218_PROJECTILE_GetImpactCount works fine because there is a single creature in the group so L0445_ps_ActiveGroup->Cells contains only one cell index */
                                                goto T0209139_Return;
                                        L0445_ps_ActiveGroup->Cells = M021_NORMALIZE(AL0446_i_GroupCellsCriteria);
                                }
                        }
                        /* If the creature can see the party and is looking in the party direction or can attack in all direction */
                        if (L0452_i_DistanceToVisibleParty &&
                            (M007_GET(L0448_s_CreatureInfo.Attributes, MASK0x0004_SIDE_ATTACK) ||
                            M050_CREATURE_VALUE(L0445_ps_ActiveGroup->Directions, AL0447_i_CreatureIndex) == L0454_i_PrimaryDirectionToOrFromParty)) {
                                /* If the creature is in range to attack the party and random test succeeds */
                                if ((L0452_i_DistanceToVisibleParty <= (AL0446_i_Range = M056_ATTACK_RANGE(L0448_s_CreatureInfo.Ranges))) &&
                                    (!AL0450_i_DistanceXToParty || !AL0451_i_DistanceYToParty
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                    || ((AL0446_i_Range > 1) && !M003_RANDOM(8))
#endif
                                    ) &&
                                    (AL0446_i_Range <= (M003_RANDOM(16) + 1))) {
                                        if ((AL0446_i_Range == 1) &&
                                            !(M007_GET(AL0446_i_CreatureAttributes = L0448_s_CreatureInfo.Attributes, MASK0x0008_PREFER_BACK_ROW) && M004_RANDOM(4) && M007_GET(AL0446_i_CreatureAttributes, MASK0x0010_ATTACK_ANY_CHAMPION)) &&
                                            (L0459_i_CreatureSize == C0_SIZE_QUARTER_SQUARE) &&
                                            (L0445_ps_ActiveGroup->Cells != C0xFF_SINGLE_CENTERED_CREATURE) &&
                                            ((AL0446_i_Cell = M050_CREATURE_VALUE(L0445_ps_ActiveGroup->Cells, AL0447_i_CreatureIndex)) != L0454_i_PrimaryDirectionToOrFromParty) &&
                                            (AL0446_i_Cell != M017_NEXT(L0454_i_PrimaryDirectionToOrFromParty))) { /* If the creature cannot cast spells (range = 1) and is not on a cell where it can attack the party directly and is a quarter square sized creature not in the center of the square then the creature moves to another cell and attack does not occur immediately */
                                                if (!L0460_ui_CreatureCount && M005_RANDOM(2)) {
                                                        L0445_ps_ActiveGroup->Cells = C0xFF_SINGLE_CENTERED_CREATURE;
                                                } else {
                                                        if ((L0454_i_PrimaryDirectionToOrFromParty & 0x0001) == (AL0446_i_Cell & 0x0001)) {
                                                                AL0446_i_Cell--;
                                                        } else {
                                                                AL0446_i_Cell++;
                                                        }
                                                        if (!F0176_GROUP_GetCreatureOrdinalInCell(L0444_ps_Group, AL0446_i_Cell &= 3) ||
                                                            (M005_RANDOM(2) && !F0176_GROUP_GetCreatureOrdinalInCell(L0444_ps_Group, AL0446_i_Cell = M018_OPPOSITE(AL0446_i_Cell)))) { /* If the selected cell (or the opposite cell) is not already occupied by a creature */
                                                                if (F0218_PROJECTILE_GetImpactCount(CM1_ELEMENT_CREATURE, P0427_i_EventMapX, P0428_i_EventMapY, L0445_ps_ActiveGroup->Cells) && (G0364_i_CreatureDamageOutcome == C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP)) /* BUG0_70 A projectile impact on a creature may be ignored. The function F0218_PROJECTILE_GetImpactCount to detect projectile impacts when a quarter square sized creature moves inside a group (to another cell on the same square) may fail if there are several creatures in the group because the function expects a single cell index for its last parameter. The function should be called once for each cell where there is a creature */
                                                                        goto T0209139_Return;
                                                                if (G0364_i_CreatureDamageOutcome != C1_OUTCOME_KILLED_SOME_CREATURES_IN_GROUP) {
                                                                        L0445_ps_ActiveGroup->Cells = F0178_GROUP_GetGroupValueUpdatedWithCreatureValue(L0445_ps_ActiveGroup->Cells, AL0447_i_CreatureIndex, AL0446_i_Cell);
                                                                }
                                                        }
                                                }
                                                L0465_s_NextEvent.Map_Time += F0025_MAIN_GetMaximumValue(1, (L0448_s_CreatureInfo.MovementTicks >> 1) + M005_RANDOM(2)); /* Time for the creature to change cell */
                                                L0465_s_NextEvent.A.A.Type = P0429_i_EventType;
                                                goto T0209135;
                                        }
                                        L0464_l_NextAspectUpdateTime = F0179_GROUP_GetCreatureAspectUpdateTime(L0445_ps_ActiveGroup, AL0447_i_CreatureIndex, F0207_GROUP_IsCreatureAttacking(L0444_ps_Group, P0427_i_EventMapX, P0428_i_EventMapY, AL0447_i_CreatureIndex));
#ifdef PC_FIX_CODE_SIZE
L0451_i_Multiple++;
L0451_i_Multiple++;
L0451_i_Multiple++;
L0451_i_Multiple++;
#endif
                                        L0465_s_NextEvent.Map_Time += M062_NEXT_BEHAVIOR_UPDATE_AFTER_ATTACK_TICKS(L0448_s_CreatureInfo.AnimationTicks) + M005_RANDOM(2);
                                } else {
                                        L0444_ps_Group->Behavior = C7_BEHAVIOR_APPROACH;
                                        if (L0460_ui_CreatureCount) {
                                                F0182_GROUP_StopAttacking(L0445_ps_ActiveGroup, P0427_i_EventMapX, P0428_i_EventMapY);
                                        }
                                        goto T0209081_RunTowardParty;
                                }
                        } else {
                                /* If the party is visible, update target coordinates */
                                if (F0200_GROUP_GetDistanceToVisibleParty(L0444_ps_Group, CM1_WHOLE_CREATURE_GROUP, P0427_i_EventMapX, P0428_i_EventMapY)) {
                                        L0445_ps_ActiveGroup->TargetMapX = G0306_i_PartyMapX;
                                        L0445_ps_ActiveGroup->TargetMapY = G0307_i_PartyMapY;
                                        F0205_GROUP_SetDirection(L0445_ps_ActiveGroup, L0454_i_PrimaryDirectionToOrFromParty, AL0447_i_CreatureIndex, L0460_ui_CreatureCount && (L0459_i_CreatureSize == C1_SIZE_HALF_SQUARE));
                                        L0465_s_NextEvent.Map_Time += 2;
                                        L0464_l_NextAspectUpdateTime = M030_TIME(L0465_s_NextEvent.Map_Time);
                                } else { /* If the party is not visible, move to the target (last known party location) */
                                        L0444_ps_Group->Behavior = C7_BEHAVIOR_APPROACH;
                                        if (L0460_ui_CreatureCount) {
                                                F0182_GROUP_StopAttacking(L0445_ps_ActiveGroup, P0427_i_EventMapX, P0428_i_EventMapY);
                                        }
                                        goto T0209082_WalkTowardTarget;
                                }
                        }
                }
                L0465_s_NextEvent.A.A.Type = P0429_i_EventType;
                goto T0209136;
        }
        L0465_s_NextEvent.Map_Time += F0025_MAIN_GetMaximumValue(1, M004_RANDOM(4) + L0461_i_MovementTicks - 1);
        T0209134_SetEvent37:
        L0465_s_NextEvent.A.A.Type = C37_EVENT_UPDATE_BEHAVIOR_GROUP;
        T0209135:
        if (!L0464_l_NextAspectUpdateTime) {
                L0464_l_NextAspectUpdateTime = F0179_GROUP_GetCreatureAspectUpdateTime(L0445_ps_ActiveGroup, CM1_WHOLE_CREATURE_GROUP, C0_FALSE);
        }
        T0209136:
        if (L0455_B_CurrentEventTypeIsNotUpdateBehavior) {
                L0465_s_NextEvent.Map_Time += P0430_ui_Ticks;
        } else {
                L0464_l_NextAspectUpdateTime += P0430_ui_Ticks;
        }
        F0208_GROUP_AddEvent(&L0465_s_NextEvent, L0464_l_NextAspectUpdateTime);
        T0209139_Return: ;
}
#endif
