#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
long G0361_l_LastCreatureAttackTime = -200;
long G0362_l_LastPartyMovementTime;
int16_t G0363_i_SecondaryDirectionToOrFromParty;
int16_t G0364_i_CreatureDamageOutcome;
BOOLEAN G0365_B_CreateLauncherProjectile;
int16_t G0366_i_ProjectilePoisonAttack;
int16_t G0367_i_ProjectileAttackType;
#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* G0368_api_CodePatches_CPSE[6] = {
        G0585_ai_CodePatch0_CPSE,
        G0344_ai_CodePatch1_CPSE,
        G0533_ai_CodePatch2_CPSE,
        G0408_ai_CodePatch3_CPSE,
        G0393_ai_CodePatch4_CPSE,
        G0427_ai_CodePatch5_CPSE };
#endif
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
#ifndef NOCOPYPROTECTION
int16_t* G0368_api_CodePatches_CPSE[6] = {
        (int16_t*)G0585_ai_CodePatch0_CPSE,
        (int16_t*)G0344_ai_CodePatch1_CPSE,
        (int16_t*)G0533_ai_CodePatch2_CPSE,
        (int16_t*)G0408_ai_CodePatch3_CPSE,
        (int16_t*)G0393_ai_CodePatch4_CPSE,
        (int16_t*)G0427_ai_CodePatch5_CPSE };
#endif
#endif


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

void F0212_PROJECTILE_Create(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0433_T_Thing, P0434_i_MapX, P0435_i_MapY, P0436_i_Cell, P0437_i_Direction, P0438_uc_KineticEnergy, P0439_uc_Attack, P0440_uc_StepEnergy)
#endif
REGISTER THING P0433_T_Thing          SEPARATOR
int16_t        P0434_i_MapX           SEPARATOR
int16_t        P0435_i_MapY           SEPARATOR
int16_t        P0436_i_Cell           SEPARATOR
int16_t        P0437_i_Direction      SEPARATOR
unsigned char  P0438_uc_KineticEnergy SEPARATOR
unsigned char  P0439_uc_Attack        SEPARATOR
unsigned char  P0440_uc_StepEnergy    FINAL_SEPARATOR
{
        register PROJECTILE* L0467_ps_Projectile;
        register THING L0466_T_ProjectileThing;
        EVENT L0468_s_Event;


        if ((L0466_T_ProjectileThing = F0166_DUNGEON_GetUnusedThing(C14_THING_TYPE_PROJECTILE)) == C0xFFFF_THING_NONE) { /* BUG0_16 If the game cannot create a projectile thing because it has run out of such things (60 maximum) then the object being thrown/shot/launched is orphaned. If the game has run out of projectile things it will try to remove a projectile from elsewhere in the dungeon, except in an area of 11x11 squares centered around the party (to make sure the player cannot actually see the thing disappear on screen) */
#ifdef MEDIA345_S21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_00_FIX Place object on the floor if the projectile cannot be created */
                if (M012_TYPE(P0433_T_Thing) != C15_THING_TYPE_EXPLOSION) {
                        F0267_MOVE_GetMoveResult_CPSCE(M015_THING_WITH_NEW_CELL(P0433_T_Thing, P0436_i_Cell), CM1_MAPX_NOT_ON_A_SQUARE, 0, P0434_i_MapX, P0435_i_MapY);
                }
#endif
                return;
        }
        L0466_T_ProjectileThing = M015_THING_WITH_NEW_CELL(L0466_T_ProjectileThing, P0436_i_Cell);
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0467_ps_Projectile = &((PROJECTILE*)G0284_apuc_ThingData[C14_THING_TYPE_PROJECTILE])[M013_INDEX(L0466_T_ProjectileThing)];
#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 */
        L0467_ps_Projectile = (PROJECTILE*)F0156_DUNGEON_GetThingData(L0466_T_ProjectileThing);
#endif
        L0467_ps_Projectile->Slot = P0433_T_Thing;
        L0467_ps_Projectile->KineticEnergy = F0024_MAIN_GetMinimumValue(P0438_uc_KineticEnergy, 255);
        L0467_ps_Projectile->Attack = P0439_uc_Attack;
        F0163_DUNGEON_LinkThingToList(L0466_T_ProjectileThing, 0, P0434_i_MapX, P0435_i_MapY); /* Projectiles are added on the square and not 'moved' onto the square. In the case of a projectile launcher sensor, this means that the new projectile traverses the square in front of the launcher without any trouble: there is no impact if it is a wall, the projectile direction is not changed if it is a teleporter. Impacts with creatures and champions are still processed */
        M033_SET_MAP_AND_TIME(L0468_s_Event.Map_Time, G0272_i_CurrentMapIndex, G0313_ul_GameTime + 1);
        if (G0365_B_CreateLauncherProjectile) {
                L0468_s_Event.A.A.Type = C49_EVENT_MOVE_PROJECTILE; /* Launcher projectiles can impact immediately */
        } else {
                L0468_s_Event.A.A.Type = C48_EVENT_MOVE_PROJECTILE_IGNORE_IMPACTS; /* Projectiles created by champions or creatures ignore impacts on their first movement */
        }
        L0468_s_Event.A.A.Priority = 0;
        L0468_s_Event.B.Slot = L0466_T_ProjectileThing;
        L0468_s_Event.C.Projectile.MapX = P0434_i_MapX;
        L0468_s_Event.C.Projectile.MapY = P0435_i_MapY;
        L0468_s_Event.C.Projectile.StepEnergy = P0440_uc_StepEnergy;
        L0468_s_Event.C.Projectile.Direction = P0437_i_Direction;
        L0467_ps_Projectile->EventIndex = F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0468_s_Event);
}

void F0213_EXPLOSION_Create(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0441_T_ExplosionThing, P0442_ui_Attack, P0443_ui_MapXCombo, P0444_ui_MapYCombo, P0445_ui_Cell)
THING                     P0441_T_ExplosionThing SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER THING            P0441_T_ExplosionThing SEPARATOR
#endif
REGISTER unsigned int16_t P0442_ui_Attack        SEPARATOR
REGISTER unsigned int16_t P0443_ui_MapXCombo     SEPARATOR
REGISTER unsigned int16_t P0444_ui_MapYCombo     SEPARATOR
unsigned int16_t          P0445_ui_Cell          FINAL_SEPARATOR
#define AP0443_ui_ProjectileMapX P0443_ui_MapXCombo
#define AP0444_ui_ProjectileMapY P0444_ui_MapYCombo
{
        REGISTER EXPLOSION* L0470_ps_Explosion;
        REGISTER CREATURE_INFO* L0471_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 L0469_i_CreatureFireResistance;
        GROUP* L0472_ps_Group;
        THING L0473_T_Thing;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER GROUP* L0472_ps_Group;
        REGISTER THING L0473_T_Thing;
#endif
        int16_t L0474_i_ProjectileTargetMapX;
        int16_t L0475_i_ProjectileTargetMapY;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0469_i_CreatureFireResistance;
#endif
        EVENT L0476_s_Event;


        if ((L0473_T_Thing = F0166_DUNGEON_GetUnusedThing(C15_THING_TYPE_EXPLOSION)) == C0xFFFF_THING_NONE) {
                return;
        }
        L0470_ps_Explosion = &((EXPLOSION*)G0284_apuc_ThingData[C15_THING_TYPE_EXPLOSION])[M013_INDEX(L0473_T_Thing)];
        if (P0443_ui_MapXCombo <= 255) {
                L0474_i_ProjectileTargetMapX = P0443_ui_MapXCombo;
                L0475_i_ProjectileTargetMapY = P0444_ui_MapYCombo;
        } else {
                L0474_i_ProjectileTargetMapX = P0443_ui_MapXCombo & 0x00FF;
                L0475_i_ProjectileTargetMapY = P0444_ui_MapYCombo & 0x00FF;
                AP0443_ui_ProjectileMapX >>= 8;
                AP0443_ui_ProjectileMapX--;
                AP0444_ui_ProjectileMapY >>= 8;
        }
        if (P0445_ui_Cell == C0xFF_SINGLE_CENTERED_CREATURE) {
                L0470_ps_Explosion->Centered = C1_TRUE;
        } else {
                L0470_ps_Explosion->Centered = C0_FALSE;
                L0473_T_Thing = M015_THING_WITH_NEW_CELL(L0473_T_Thing, P0445_ui_Cell);
        }
        L0470_ps_Explosion->Type = P0441_T_ExplosionThing - C0xFF80_THING_FIRST_EXPLOSION;
        L0470_ps_Explosion->Attack = P0442_ui_Attack;
        if (P0441_T_ExplosionThing < C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL) {
                F0064_SOUND_RequestPlay_CPSD((P0442_ui_Attack > 80) ? C05_SOUND_STRONG_EXPLOSION : M541_SOUND_WEAK_EXPLOSION, AP0443_ui_ProjectileMapX, AP0444_ui_ProjectileMapY, C01_MODE_PLAY_IF_PRIORITIZED);
        } else {
                if (P0441_T_ExplosionThing != C0xFFA8_THING_EXPLOSION_SMOKE) {
                        F0064_SOUND_RequestPlay_CPSD(M542_SOUND_SPELL, AP0443_ui_ProjectileMapX, AP0444_ui_ProjectileMapY, C01_MODE_PLAY_IF_PRIORITIZED);
                }
        }
        F0163_DUNGEON_LinkThingToList(L0473_T_Thing, 0, AP0443_ui_ProjectileMapX, AP0444_ui_ProjectileMapY);
        M033_SET_MAP_AND_TIME(L0476_s_Event.Map_Time, G0272_i_CurrentMapIndex, G0313_ul_GameTime + ((P0441_T_ExplosionThing == C0xFFE4_THING_EXPLOSION_REBIRTH_STEP1) ? 5 : 1));
        L0476_s_Event.A.A.Type = C25_EVENT_EXPLOSION;
        L0476_s_Event.A.A.Priority = 0;
        L0476_s_Event.C.Slot = L0473_T_Thing;
        L0476_s_Event.B.Location.MapX = AP0443_ui_ProjectileMapX;
        L0476_s_Event.B.Location.MapY = AP0444_ui_ProjectileMapY;
        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0476_s_Event);
        if ((P0441_T_ExplosionThing == C0xFF82_THING_EXPLOSION_LIGHTNING_BOLT) || (P0441_T_ExplosionThing == C0xFF80_THING_EXPLOSION_FIREBALL)) {
                AP0443_ui_ProjectileMapX = L0474_i_ProjectileTargetMapX;
                AP0444_ui_ProjectileMapY = L0475_i_ProjectileTargetMapY;
                P0442_ui_Attack = (P0442_ui_Attack >> 1) + 1;
                P0442_ui_Attack += M002_RANDOM(P0442_ui_Attack) + 1;
                if ((P0441_T_ExplosionThing == C0xFF80_THING_EXPLOSION_FIREBALL) || (P0442_ui_Attack >>= 1)) {
                        if ((G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (AP0443_ui_ProjectileMapX == G0306_i_PartyMapX) && (AP0444_ui_ProjectileMapY == G0307_i_PartyMapY)) {
                                F0324_CHAMPION_DamageAll_GetDamagedChampionCount(P0442_ui_Attack, MASK0x0001_WOUND_READY_HAND | MASK0x0002_WOUND_ACTION_HAND | MASK0x0004_WOUND_HEAD | MASK0x0008_WOUND_TORSO | MASK0x0010_WOUND_LEGS | MASK0x0020_WOUND_FEET, C1_ATTACK_FIRE);
                        } else {
                                if ((L0473_T_Thing = F0175_GROUP_GetThing(AP0443_ui_ProjectileMapX, AP0444_ui_ProjectileMapY)) != C0xFFFE_THING_ENDOFLIST) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                                        L0472_ps_Group = &((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(L0473_T_Thing)];
#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 */
                                        L0472_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L0473_T_Thing);
#endif
                                        L0471_ps_CreatureInfo = &G0243_as_Graphic559_CreatureInfo[L0472_ps_Group->Type];
                                        if ((L0469_i_CreatureFireResistance = M060_FIRE_RESISTANCE(L0471_ps_CreatureInfo->Resistances)) != C15_IMMUNE_TO_FIRE) {
                                                if (M007_GET(L0471_ps_CreatureInfo->Attributes, MASK0x0040_NON_MATERIAL)) {
                                                        P0442_ui_Attack >>= 2;
                                                }
                                                if ((P0442_ui_Attack -= M002_RANDOM((L0469_i_CreatureFireResistance << 1) + 1)) > 0) {
                                                        G0364_i_CreatureDamageOutcome = F0191_GROUP_GetDamageAllCreaturesOutcome(L0472_ps_Group, AP0443_ui_ProjectileMapX, AP0444_ui_ProjectileMapY, P0442_ui_Attack, C1_TRUE);
                                                }
                                        }
                                }
                        }
                }
        }
}

void F0214_PROJECTILE_DeleteEvent(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0446_T_Thing)
#endif
THING P0446_T_Thing FINAL_SEPARATOR
{
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        F0237_TIMELINE_DeleteEvent(((PROJECTILE*)G0284_apuc_ThingData[C14_THING_TYPE_PROJECTILE])[M013_INDEX(P0446_T_Thing)].EventIndex);
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        PROJECTILE* L0477_ps_Projectile = (PROJECTILE*)F0156_DUNGEON_GetThingData(P0446_T_Thing);


        F0237_TIMELINE_DeleteEvent(L0477_ps_Projectile->EventIndex);
#endif
}

void F0215_PROJECTILE_Delete(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0447_T_ProjectileThing, P0448_pT_GroupSlot, P0449_i_MapX, P0450_i_MapY)
#endif
THING           P0447_T_ProjectileThing SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
THING*          P0448_pT_GroupSlot      SEPARATOR /* When not NULL, the projectile associated thing is linked to the list of group possessions. This is used for creatures that keep some weapons thrown at them (Daggers, Arrow, Slayer, Poison Dart and Throwing Star) */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER THING* P0448_pT_GroupSlot      SEPARATOR /* When not NULL, the projectile associated thing is linked to the list of group possessions. This is used for creatures that keep some weapons thrown at them (Daggers, Arrow, Slayer, Poison Dart and Throwing Star) */
#endif
int16_t         P0449_i_MapX            SEPARATOR /* If P0448_pT_GroupSlot is NULL then the projectile associated thing is moved to the specified square */
int16_t         P0450_i_MapY            FINAL_SEPARATOR
{
        REGISTER PROJECTILE* L0480_ps_Projectile;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register THING L0478_T_PreviousThing;
        REGISTER THING L0479_T_Thing;
        GENERIC* L0481_ps_Generic;
        char L0482_ac_Unreferenced[10]; /* BUG0_00 Useless code */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER GENERIC* L0481_ps_Generic;
        REGISTER THING L0479_T_Thing;
        REGISTER THING L0478_T_PreviousThing;
#endif


#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0480_ps_Projectile = &((PROJECTILE*)G0284_apuc_ThingData[C14_THING_TYPE_PROJECTILE])[M013_INDEX(P0447_T_ProjectileThing)];
#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 */
        L0480_ps_Projectile = (PROJECTILE*)F0156_DUNGEON_GetThingData(P0447_T_ProjectileThing);
#endif
        if (M012_TYPE(L0479_T_Thing = L0480_ps_Projectile->Slot) != C15_THING_TYPE_EXPLOSION) {
                if (P0448_pT_GroupSlot != NULL) {
                        if ((L0478_T_PreviousThing = *P0448_pT_GroupSlot) == C0xFFFE_THING_ENDOFLIST) {
                                L0481_ps_Generic = (GENERIC*)F0156_DUNGEON_GetThingData(L0479_T_Thing);
                                L0481_ps_Generic->Next = C0xFFFE_THING_ENDOFLIST;
                                *P0448_pT_GroupSlot = L0479_T_Thing;
                        } else {
                                F0163_DUNGEON_LinkThingToList(L0479_T_Thing, L0478_T_PreviousThing, CM1_MAPX_NOT_ON_A_SQUARE, 0);
                        }
                } else {
                        F0267_MOVE_GetMoveResult_CPSCE(M014_TYPE_AND_INDEX(L0479_T_Thing) | M007_GET(P0447_T_ProjectileThing, MASK0xC000_THING_CELL), CM2_MAPX_PROJECTILE_ASSOCIATED_OBJECT, 0, P0449_i_MapX, P0450_i_MapY);
                }
        }
        L0480_ps_Projectile->Next = C0xFFFF_THING_NONE;
}

STATICFUNCTION unsigned int16_t F0216_PROJECTILE_GetImpactAttack(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0451_ps_Projectile, P0452_T_Thing)
register PROJECTILE* P0451_ps_Projectile SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
PROJECTILE*          P0451_ps_Projectile SEPARATOR
#endif
REGISTER THING       P0452_T_Thing       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 WEAPON_INFO* L0485_ps_WeaponInfo;
#endif
        REGISTER unsigned int16_t L0483_ui_Multiple;
#define AL0483_ui_ThingType L0483_ui_Multiple
#define AL0483_ui_Attack    L0483_ui_Multiple
        REGISTER unsigned int16_t L0484_ui_KineticEnergy;


        G0366_i_ProjectilePoisonAttack = 0;
        G0367_i_ProjectileAttackType = C3_ATTACK_BLUNT;
        L0484_ui_KineticEnergy = P0451_ps_Projectile->KineticEnergy;
        if ((AL0483_ui_ThingType = M012_TYPE(P0452_T_Thing)) != C15_THING_TYPE_EXPLOSION) {
                if (AL0483_ui_ThingType == C05_THING_TYPE_WEAPON) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        AL0483_ui_Attack = G0238_as_Graphic559_WeaponInfo[((WEAPON*)G0284_apuc_ThingData[C05_THING_TYPE_WEAPON])[M013_INDEX(P0452_T_Thing)].Type].KineticEnergy;
#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 */
                        L0485_ps_WeaponInfo = F0158_DUNGEON_GetWeaponInfo(P0452_T_Thing);
                        AL0483_ui_Attack = L0485_ps_WeaponInfo->KineticEnergy;
#endif
                        G0367_i_ProjectileAttackType = C3_ATTACK_BLUNT;
                } else {
                        AL0483_ui_Attack = M004_RANDOM(4);
                }
#ifdef MEDIA029_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J
                AL0483_ui_Attack += F0140_DUNGEON_GetObjectWeight(P0452_T_Thing) >> 1;
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                AL0483_ui_Attack += F0140_DUNGEON_GetObjectWeight(P0452_T_Thing);
#endif
        } else {
                if (P0452_T_Thing == C0xFF81_THING_EXPLOSION_SLIME) {
                        AL0483_ui_Attack = M003_RANDOM(16);
                        G0366_i_ProjectilePoisonAttack = AL0483_ui_Attack + 10;
                        AL0483_ui_Attack += M003_RANDOM(32);
                } else {
                        if (P0452_T_Thing >= C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL) {
                                G0367_i_ProjectileAttackType = C5_ATTACK_MAGIC;
                                if (P0452_T_Thing == C0xFF86_THING_EXPLOSION_POISON_BOLT) {
                                        G0366_i_ProjectilePoisonAttack = L0484_ui_KineticEnergy;
#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 1;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                        return (L0484_ui_KineticEnergy >> 4) + 1;
#endif
                                }
                                return 0;
                        }
#ifdef MEDIA351_G14ED_G20E_G21E
                          else { /* else must NOT be present in Atari ST versions (with Megamax 1.1, maybe it would be OK with Megamax 1.2) */
#endif
                                G0367_i_ProjectileAttackType = C1_ATTACK_FIRE;
                                AL0483_ui_Attack = M003_RANDOM(16) + M003_RANDOM(16) + 10;
                                if (P0452_T_Thing == C0xFF82_THING_EXPLOSION_LIGHTNING_BOLT) {
                                        G0367_i_ProjectileAttackType = C7_ATTACK_LIGHTNING;
#ifdef MEDIA029_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J
                                        AL0483_ui_Attack *= 5;
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                                        AL0483_ui_Attack <<= 4;
                                        AL0483_ui_Attack += L0484_ui_KineticEnergy;
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
                                }
#endif
                        }
                }
        }
        AL0483_ui_Attack = ((AL0483_ui_Attack + L0484_ui_KineticEnergy) >> 4) + 1;
        AL0483_ui_Attack += M002_RANDOM((AL0483_ui_Attack >> 1) + 1) + M004_RANDOM(4);
        AL0483_ui_Attack = F0025_MAIN_GetMaximumValue(AL0483_ui_Attack >> 1, AL0483_ui_Attack - (32 - (P0451_ps_Projectile->Attack >> 3)));
        return AL0483_ui_Attack;
}

BOOLEAN F0217_PROJECTILE_HasImpactOccured(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0453_i_ImpactType, P0454_i_MapXCombo, P0455_i_MapYCombo, P0456_i_Cell, P0457_i_ProjectileThing)
#endif
int16_t          P0453_i_ImpactType      SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t          P0454_i_MapXCombo       SEPARATOR
int16_t          P0455_i_MapYCombo       SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t P0454_i_MapXCombo       SEPARATOR
REGISTER int16_t P0455_i_MapYCombo       SEPARATOR
#endif
int16_t          P0456_i_Cell            SEPARATOR
int16_t          P0457_i_ProjectileThing FINAL_SEPARATOR
#define AP0454_i_ProjectileTargetMapX P0454_i_MapXCombo
#define AP0455_i_ProjectileTargetMapY P0455_i_MapYCombo
#define AP0456_i_ChampionIndex P0456_i_Cell
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER GROUP* L0491_ps_Group;
#endif
        REGISTER PROJECTILE* L0490_ps_Projectile;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER GROUP* L0491_ps_Group;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER CREATURE_INFO* L0493_ps_CreatureInfo;
        THING* L0497_pT_GroupSlot;
#endif
        REGISTER THING L0486_T_ProjectileAssociatedThing;
        REGISTER int16_t L0487_i_Multiple;
#define AL0487_i_DoorState  L0487_i_Multiple
#define AL0487_i_IconIndex  L0487_i_Multiple
#define AL0487_i_Outcome    L0487_i_Multiple
#define AL0487_i_WeaponType L0487_i_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0507_ui_Multiple;
#endif
#define AL0507_ui_ExplosionAttack L0507_ui_Multiple
#define AL0507_ui_SoundIndex      L0507_ui_Multiple
        REGISTER unsigned int16_t L0488_ui_Attack;
#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 L0489_ui_ChampionAttack;
#endif
        POTION* L0492_ps_Potion;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        CREATURE_INFO* L0493_ps_CreatureInfo;
#endif
        DOOR* L0494_ps_Door;
#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 */
        WEAPON* L0495_ps_Weapon;
#endif
        unsigned int16_t* L0496_pui_CreatureHealth;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        THING* L0497_pT_GroupSlot;
#endif
        THING L0498_T_ExplosionThing;
        int16_t L0499_i_ProjectileMapX;
        int16_t L0500_i_ProjectileMapY;
        int16_t L0501_i_MapXCombo;
        int16_t L0502_i_MapYCombo;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned char L0503_uc_Square;
        EVENT L0504_s_Unreferenced; /* BUG0_00 Useless code */
#endif
        BOOLEAN L0505_B_CreateExplosionOnImpact;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0489_ui_ChampionAttack;
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0506_i_Unreferenced; /* BUG0_00 Useless code */
        unsigned int16_t L0507_ui_Multiple;
#endif
        int16_t L0508_i_PotionPower;
        BOOLEAN L0509_B_RemovePotion;
        int16_t L0510_i_ProjectileAssociatedThingType;
        unsigned int16_t L0511_ui_CreatureType;
        unsigned int16_t L0512_ui_CreatureIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        EVENT L0504_s_Unreferenced; /* BUG0_00 Useless code */
#endif


#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0490_ps_Projectile = &((PROJECTILE*)G0284_apuc_ThingData[C14_THING_TYPE_PROJECTILE])[M013_INDEX(P0457_i_ProjectileThing)];
#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 */
        L0490_ps_Projectile = (PROJECTILE*)F0156_DUNGEON_GetThingData(P0457_i_ProjectileThing);
#endif
        L0501_i_MapXCombo = P0454_i_MapXCombo;
        L0502_i_MapYCombo = P0455_i_MapYCombo;
        L0509_B_RemovePotion = C0_FALSE;
        G0364_i_CreatureDamageOutcome = C0_OUTCOME_KILLED_NO_CREATURES_IN_GROUP;
        if ((L0510_i_ProjectileAssociatedThingType = M012_TYPE(L0486_T_ProjectileAssociatedThing = L0490_ps_Projectile->Slot)) == C08_THING_TYPE_POTION) {
                L0491_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L0486_T_ProjectileAssociatedThing);
                switch (((POTION*)L0491_ps_Group)->Type) {
                        case C03_POTION_VEN_POTION:
                                L0498_T_ExplosionThing = C0xFF87_THING_EXPLOSION_POISON_CLOUD;
                                goto T0217004;
                        case C19_POTION_FUL_BOMB:
                                L0498_T_ExplosionThing = C0xFF80_THING_EXPLOSION_FIREBALL;
                                T0217004:
                                L0509_B_RemovePotion = C1_TRUE;
                                L0508_i_PotionPower = ((POTION*)L0491_ps_Group)->Power;
                                L0492_ps_Potion = (POTION*)L0491_ps_Group;
                                break;
                }
        }
        L0505_B_CreateExplosionOnImpact = (L0510_i_ProjectileAssociatedThingType == C15_THING_TYPE_EXPLOSION) && (L0486_T_ProjectileAssociatedThing != C0xFF81_THING_EXPLOSION_SLIME) && (L0486_T_ProjectileAssociatedThing != C0xFF86_THING_EXPLOSION_POISON_BOLT);
        L0497_pT_GroupSlot = NULL;
        L0489_ui_ChampionAttack = 0;
        if (P0454_i_MapXCombo <= 255) {
                L0499_i_ProjectileMapX = P0454_i_MapXCombo;
                L0500_i_ProjectileMapY = P0455_i_MapYCombo;
        } else {
                L0499_i_ProjectileMapX = (P0454_i_MapXCombo >> 8) - 1;
                L0500_i_ProjectileMapY = (P0455_i_MapYCombo >> 8);
                AP0454_i_ProjectileTargetMapX &= 0x00FF;
                AP0455_i_ProjectileTargetMapY &= 0x00FF;
        }
        switch (P0453_i_ImpactType) {
                case C04_ELEMENT_DOOR:
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        AL0487_i_DoorState = M036_DOOR_STATE(L0503_uc_Square = G0271_ppuc_CurrentMapData[AP0454_i_ProjectileTargetMapX][AP0455_i_ProjectileTargetMapY]);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        AL0487_i_DoorState = M036_DOOR_STATE(G0271_ppuc_CurrentMapData[AP0454_i_ProjectileTargetMapX][AP0455_i_ProjectileTargetMapY]);
#endif
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        L0494_ps_Door = &((DOOR*)G0284_apuc_ThingData[C00_THING_TYPE_DOOR])[M013_INDEX(F0161_DUNGEON_GetSquareFirstThing(AP0454_i_ProjectileTargetMapX, AP0455_i_ProjectileTargetMapY))];
#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 */
                        L0494_ps_Door = (DOOR*)F0157_DUNGEON_GetSquareFirstThingData(AP0454_i_ProjectileTargetMapX, AP0455_i_ProjectileTargetMapY);
#endif
                        if ((AL0487_i_DoorState != C5_DOOR_STATE_DESTROYED) && (L0486_T_ProjectileAssociatedThing == C0xFF84_THING_EXPLOSION_OPEN_DOOR)) {
                                if (L0494_ps_Door->Button) {
                                        F0268_SENSOR_AddEvent(C10_EVENT_DOOR, AP0454_i_ProjectileTargetMapX, AP0455_i_ProjectileTargetMapY, 0, C02_EFFECT_TOGGLE, G0313_ul_GameTime + 1);
                                }
                                break;
                        }
                        if ((AL0487_i_DoorState == C5_DOOR_STATE_DESTROYED) ||
                            (AL0487_i_DoorState <= C1_DOOR_STATE_CLOSED_ONE_FOURTH) ||
                            (M007_GET(G0275_as_CurrentMapDoorInfo[L0494_ps_Door->Type].Attributes, MASK0x0002_PROJECTILES_CAN_PASS_THROUGH) &&
                             ((L0510_i_ProjectileAssociatedThingType == C15_THING_TYPE_EXPLOSION) ?
                                (L0486_T_ProjectileAssociatedThing >= C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL) :
                                ((L0490_ps_Projectile->Attack > M003_RANDOM(128)) &&
                                 M007_GET(G0237_as_Graphic559_ObjectInfo[F0141_DUNGEON_GetObjectInfoIndex(L0486_T_ProjectileAssociatedThing)].AllowedSlots, MASK0x0100_POUCH_AND_PASS_THROUGH_DOORS)
#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_04_IMPROVEMENT Keys cannot pass through a closed door anymore. In previous versions, this could prevent the player from completing the game when throwing a required key through a locked door */
                                 && ((L0510_i_ProjectileAssociatedThingType != C10_THING_TYPE_JUNK) ||
                                  ((AL0487_i_IconIndex = F0033_OBJECT_GetIconIndex(L0486_T_ProjectileAssociatedThing)) < 0) ||
                                  (!((AL0487_i_IconIndex >= C176_ICON_JUNK_IRON_KEY) && (AL0487_i_IconIndex <= C191_ICON_JUNK_MASTER_KEY))))
#endif
                                 )))) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
                                return C0_FALSE;
                        }
                        L0488_ui_Attack = F0216_PROJECTILE_GetImpactAttack(L0490_ps_Projectile, L0486_T_ProjectileAssociatedThing) + 1;
                        F0232_GROUP_IsDoorDestroyedByAttack(AP0454_i_ProjectileTargetMapX, AP0455_i_ProjectileTargetMapY, L0488_ui_Attack + M002_RANDOM(L0488_ui_Attack), C0_FALSE, 0);
                        break;
                case CM2_ELEMENT_CHAMPION:
                        if ((AP0456_i_ChampionIndex = F0285_CHAMPION_GetIndexInCell(P0456_i_Cell)) < 0) {
                                return C0_FALSE;
                        }
                        L0489_ui_ChampionAttack = L0488_ui_Attack = F0216_PROJECTILE_GetImpactAttack(L0490_ps_Projectile, L0486_T_ProjectileAssociatedThing);
                        break;
                case CM1_ELEMENT_CREATURE:
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                        L0491_ps_Group = &((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(F0175_GROUP_GetThing(AP0454_i_ProjectileTargetMapX, AP0455_i_ProjectileTargetMapY))];
#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 */
                        L0491_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(F0175_GROUP_GetThing(AP0454_i_ProjectileTargetMapX, AP0455_i_ProjectileTargetMapY));
#endif
                        if (!(L0512_ui_CreatureIndex = F0176_GROUP_GetCreatureOrdinalInCell(L0491_ps_Group, P0456_i_Cell))) {
                                return C0_FALSE;
                        }
                        L0512_ui_CreatureIndex--;
                        L0493_ps_CreatureInfo = &G0243_as_Graphic559_CreatureInfo[L0511_ui_CreatureType = L0491_ps_Group->Type];
                        if ((L0486_T_ProjectileAssociatedThing == C0xFF80_THING_EXPLOSION_FIREBALL) && (L0511_ui_CreatureType == C11_CREATURE_BLACK_FLAME)) {
                                L0496_pui_CreatureHealth = &L0491_ps_Group->Health[L0512_ui_CreatureIndex];
                                *L0496_pui_CreatureHealth = F0024_MAIN_GetMinimumValue(1000, *L0496_pui_CreatureHealth + F0216_PROJECTILE_GetImpactAttack(L0490_ps_Projectile, L0486_T_ProjectileAssociatedThing));
                                goto T0217044;
                        }
                        if (M007_GET(L0493_ps_CreatureInfo->Attributes, MASK0x0040_NON_MATERIAL) && (L0486_T_ProjectileAssociatedThing != C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL)) {
                                return C0_FALSE;
                        }
                        if (L0488_ui_Attack = (unsigned int16_t)((long)F0216_PROJECTILE_GetImpactAttack(L0490_ps_Projectile, L0486_T_ProjectileAssociatedThing) << 6) / L0493_ps_CreatureInfo->Defense) {
                                if ((AL0487_i_Outcome = F0190_GROUP_GetDamageCreatureOutcome(L0491_ps_Group, L0512_ui_CreatureIndex, AP0454_i_ProjectileTargetMapX, AP0455_i_ProjectileTargetMapY, L0488_ui_Attack + F0192_GROUP_GetResistanceAdjustedPoisonAttack(L0511_ui_CreatureType, G0366_i_ProjectilePoisonAttack), C1_TRUE)) != C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP) {
                                        F0209_GROUP_ProcessEvents29to41(AP0454_i_ProjectileTargetMapX, AP0455_i_ProjectileTargetMapY, CM2_EVENT_CREATE_REACTION_EVENT_30_HIT_BY_PROJECTILE, 0);
                                }
                                G0364_i_CreatureDamageOutcome = AL0487_i_Outcome;
                                if (!L0505_B_CreateExplosionOnImpact &&
                                    (AL0487_i_Outcome == C0_OUTCOME_KILLED_NO_CREATURES_IN_GROUP) &&
                                    (L0510_i_ProjectileAssociatedThingType == C05_THING_TYPE_WEAPON) &&
                                    M007_GET(L0493_ps_CreatureInfo->Attributes, MASK0x0400_KEEP_THROWN_SHARP_WEAPONS)) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                                        AL0487_i_WeaponType = ((WEAPON*)G0284_apuc_ThingData[C05_THING_TYPE_WEAPON])[M013_INDEX(L0486_T_ProjectileAssociatedThing)].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 */
                                        L0495_ps_Weapon = (WEAPON*)F0156_DUNGEON_GetThingData(L0486_T_ProjectileAssociatedThing);
                                        AL0487_i_WeaponType = L0495_ps_Weapon->Type;
#endif
                                        if ((AL0487_i_WeaponType == C08_WEAPON_DAGGER) || (AL0487_i_WeaponType == C27_WEAPON_ARROW) || (AL0487_i_WeaponType == C28_WEAPON_SLAYER) || (AL0487_i_WeaponType == C31_WEAPON_POISON_DART) || (AL0487_i_WeaponType == C32_WEAPON_THROWING_STAR)) {
                                                L0497_pT_GroupSlot = &L0491_ps_Group->Slot;
                                        }
                                }
                        }
        }
        if (L0489_ui_ChampionAttack && F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage(AP0456_i_ChampionIndex, L0488_ui_Attack, MASK0x0004_WOUND_HEAD | MASK0x0008_WOUND_TORSO, G0367_i_ProjectileAttackType) && G0366_i_ProjectilePoisonAttack && M005_RANDOM(2)) {
                F0322_CHAMPION_Poison(AP0456_i_ChampionIndex, G0366_i_ProjectilePoisonAttack);
        }
        if (L0505_B_CreateExplosionOnImpact || L0509_B_RemovePotion
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
            || (L0486_T_ProjectileAssociatedThing == C0xFF86_THING_EXPLOSION_POISON_BOLT)
#endif
           ) {
                if (L0509_B_RemovePotion) {
                        L0486_T_ProjectileAssociatedThing = L0498_T_ExplosionThing;
                        AL0507_ui_ExplosionAttack = L0508_i_PotionPower;
                } else {
                        AL0507_ui_ExplosionAttack = L0490_ps_Projectile->KineticEnergy;
#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
                }
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        if (L0486_T_ProjectileAssociatedThing == C0xFF86_THING_EXPLOSION_POISON_BOLT) {
                                if (!(AL0507_ui_ExplosionAttack >>= 2))
                                        goto T0217044;
                        } else {
#endif
                                if ((L0486_T_ProjectileAssociatedThing == C0xFF82_THING_EXPLOSION_LIGHTNING_BOLT) && !(AL0507_ui_ExplosionAttack >>= 1))
                                        goto T0217044;
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        }
                }
#endif
                F0213_EXPLOSION_Create(L0486_T_ProjectileAssociatedThing, AL0507_ui_ExplosionAttack, L0501_i_MapXCombo, L0502_i_MapYCombo, (L0486_T_ProjectileAssociatedThing == C0xFF87_THING_EXPLOSION_POISON_CLOUD) ? C0xFF_SINGLE_CENTERED_CREATURE : P0456_i_Cell);
        } else {
                if (M012_TYPE(L0486_T_ProjectileAssociatedThing) == C05_THING_TYPE_WEAPON) {
                        AL0507_ui_SoundIndex = C00_SOUND_METALLIC_THUD;
                } else {
#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 (L0486_T_ProjectileAssociatedThing == C0xFF86_THING_EXPLOSION_POISON_BOLT) {
                                AL0507_ui_SoundIndex = M542_SOUND_SPELL;
                        } else {
#endif
                                AL0507_ui_SoundIndex = C04_SOUND_WOODEN_THUD_ATTACK_TROLIN_ANTMAN_STONE_GOLEM;
#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
                        }
#endif
                }
                F0064_SOUND_RequestPlay_CPSD(AL0507_ui_SoundIndex, L0499_i_ProjectileMapX, L0500_i_ProjectileMapY, C01_MODE_PLAY_IF_PRIORITIZED);
        }
        T0217044:
        if (L0509_B_RemovePotion) {
                L0492_ps_Potion->Next = C0xFFFF_THING_NONE;
                L0490_ps_Projectile->Slot = L0498_T_ExplosionThing;
        }
        F0164_DUNGEON_UnlinkThingFromList(P0457_i_ProjectileThing, 0, L0499_i_ProjectileMapX, L0500_i_ProjectileMapY);
        F0215_PROJECTILE_Delete(P0457_i_ProjectileThing, L0497_pT_GroupSlot, L0499_i_ProjectileMapX, L0500_i_ProjectileMapY);
        return C1_TRUE;
}

int16_t F0218_PROJECTILE_GetImpactCount(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0458_i_ImpactType, P0459_i_MapX, P0460_i_MapY, P0461_i_Cell)
#endif
int16_t          P0458_i_ImpactType SEPARATOR
int16_t          P0459_i_MapX       SEPARATOR
int16_t          P0460_i_MapY       SEPARATOR
REGISTER int16_t P0461_i_Cell       FINAL_SEPARATOR
{
        REGISTER THING L0513_T_Thing;
        REGISTER int16_t L0514_i_ImpactCount;


        L0514_i_ImpactCount = 0;
        G0364_i_CreatureDamageOutcome = C0_OUTCOME_KILLED_NO_CREATURES_IN_GROUP;
        T0218001:
        L0513_T_Thing = F0161_DUNGEON_GetSquareFirstThing(P0459_i_MapX, P0460_i_MapY);
        while (L0513_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                if ((M012_TYPE(L0513_T_Thing) == C14_THING_TYPE_PROJECTILE) &&
                    (M011_CELL(L0513_T_Thing) == P0461_i_Cell) &&
                    F0217_PROJECTILE_HasImpactOccured(P0458_i_ImpactType, P0459_i_MapX, P0460_i_MapY, P0461_i_Cell, L0513_T_Thing)) {
                        F0214_PROJECTILE_DeleteEvent(L0513_T_Thing);
                        L0514_i_ImpactCount++;
                        if ((P0458_i_ImpactType == CM1_ELEMENT_CREATURE) && (G0364_i_CreatureDamageOutcome == C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP))
                                break;
                        goto T0218001;
                }
                L0513_T_Thing = F0159_DUNGEON_GetNextThing(L0513_T_Thing);
        }
        return L0514_i_ImpactCount;
}

void F0219_PROJECTILE_ProcessEvents48To49_Projectile(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0462_ps_Event)
#endif
EVENT* P0462_ps_Event FINAL_SEPARATOR
{
        REGISTER EVENT* L0519_ps_Event;
        REGISTER PROJECTILE* L0520_ps_Projectile;
        REGISTER THING L0515_T_ProjectileThingNewCell;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0523_i_DestinationMapX;
        REGISTER int16_t L0524_i_DestinationMapY;
        REGISTER int16_t L0518_i_Cell;
#endif
        REGISTER unsigned int16_t L0516_ui_Multiple;
#define AL0516_ui_StepEnergy L0516_ui_Multiple
#define AL0516_ui_Square     L0516_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 L0517_ui_ProjectileDirection;
        register int16_t L0518_i_Cell;
#endif
        THING L0521_T_ProjectileThing;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0517_ui_ProjectileDirection;
#endif
        BOOLEAN L0522_B_ProjectileMovesToOtherSquare;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0523_i_DestinationMapX;
        int16_t L0524_i_DestinationMapY;
#endif
        int16_t L0525_i_SourceMapX;
        int16_t L0526_i_SourceMapY;
        EVENT L0527_s_Event;


        L0527_s_Event = *P0462_ps_Event;
        L0519_ps_Event = &L0527_s_Event;
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0520_ps_Projectile = &((PROJECTILE*)G0284_apuc_ThingData[C14_THING_TYPE_PROJECTILE])[M013_INDEX(L0521_T_ProjectileThing = L0515_T_ProjectileThingNewCell = L0519_ps_Event->B.Slot)];
#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 */
        L0520_ps_Projectile = (PROJECTILE*)F0156_DUNGEON_GetThingData(L0521_T_ProjectileThing = L0515_T_ProjectileThingNewCell = L0519_ps_Event->B.Slot);
#endif
        L0523_i_DestinationMapX = L0519_ps_Event->C.Projectile.MapX;
        L0524_i_DestinationMapY = L0519_ps_Event->C.Projectile.MapY;
        if (L0519_ps_Event->A.A.Type == C48_EVENT_MOVE_PROJECTILE_IGNORE_IMPACTS) {
                L0519_ps_Event->A.A.Type = C49_EVENT_MOVE_PROJECTILE;
        } else {
                L0518_i_Cell = M011_CELL(L0515_T_ProjectileThingNewCell);
                if ((G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (L0523_i_DestinationMapX == G0306_i_PartyMapX) && (L0524_i_DestinationMapY == G0307_i_PartyMapY) && F0217_PROJECTILE_HasImpactOccured(CM2_ELEMENT_CHAMPION, L0523_i_DestinationMapX, L0524_i_DestinationMapY, L0518_i_Cell, L0515_T_ProjectileThingNewCell)) {
                        return;
                }
                if ((F0175_GROUP_GetThing(L0523_i_DestinationMapX, L0524_i_DestinationMapY) != C0xFFFE_THING_ENDOFLIST) && F0217_PROJECTILE_HasImpactOccured(CM1_ELEMENT_CREATURE, L0523_i_DestinationMapX, L0524_i_DestinationMapY, L0518_i_Cell, L0521_T_ProjectileThing)) {
                        return;
                }
                if (L0520_ps_Projectile->KineticEnergy <= (AL0516_ui_StepEnergy = L0519_ps_Event->C.Projectile.StepEnergy)) {
                        F0164_DUNGEON_UnlinkThingFromList(L0515_T_ProjectileThingNewCell = L0521_T_ProjectileThing, 0, L0523_i_DestinationMapX, L0524_i_DestinationMapY);
                        F0215_PROJECTILE_Delete(L0515_T_ProjectileThingNewCell, NULL, L0523_i_DestinationMapX, L0524_i_DestinationMapY);
                        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
                        L0520_ps_Projectile->KineticEnergy -= AL0516_ui_StepEnergy;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                }
#endif
                if (L0520_ps_Projectile->Attack < AL0516_ui_StepEnergy) {
                        L0520_ps_Projectile->Attack = 0;
                } else {
                        L0520_ps_Projectile->Attack -= AL0516_ui_StepEnergy;
                }
        }
        if (L0522_B_ProjectileMovesToOtherSquare = ((L0517_ui_ProjectileDirection = L0519_ps_Event->C.Projectile.Direction) == (L0518_i_Cell = M011_CELL(L0515_T_ProjectileThingNewCell = L0519_ps_Event->B.Slot))) || (M017_NEXT(L0517_ui_ProjectileDirection) == L0518_i_Cell)) {
                        L0525_i_SourceMapX = L0523_i_DestinationMapX;
                        L0526_i_SourceMapY = L0524_i_DestinationMapY;
                        L0523_i_DestinationMapX += G0233_ai_Graphic559_DirectionToStepEastCount[L0517_ui_ProjectileDirection], L0524_i_DestinationMapY += G0234_ai_Graphic559_DirectionToStepNorthCount[L0517_ui_ProjectileDirection];
                        if ((M034_SQUARE_TYPE(AL0516_ui_Square = F0151_DUNGEON_GetSquare(L0523_i_DestinationMapX, L0524_i_DestinationMapY)) == C00_ELEMENT_WALL) ||
                            ((M034_SQUARE_TYPE(AL0516_ui_Square) == C06_ELEMENT_FAKEWALL) && !M007_GET(AL0516_ui_Square, (MASK0x0001_FAKEWALL_IMAGINARY | MASK0x0004_FAKEWALL_OPEN))) ||
                            ((M034_SQUARE_TYPE(AL0516_ui_Square) == C03_ELEMENT_STAIRS)  && (M034_SQUARE_TYPE(G0271_ppuc_CurrentMapData[L0525_i_SourceMapX][L0526_i_SourceMapY]) == C03_ELEMENT_STAIRS))) {
                                if (F0217_PROJECTILE_HasImpactOccured(M034_SQUARE_TYPE(AL0516_ui_Square), L0525_i_SourceMapX, L0526_i_SourceMapY, L0518_i_Cell, L0515_T_ProjectileThingNewCell)) {
                                        return;
                                }
                        }
        }
        if ((L0517_ui_ProjectileDirection & 0x0001) == (L0518_i_Cell & 0x0001)) {
                L0518_i_Cell--;
        } else {
                L0518_i_Cell++;
        }
        L0515_T_ProjectileThingNewCell = M015_THING_WITH_NEW_CELL(L0515_T_ProjectileThingNewCell, L0518_i_Cell &= 0x0003);
        if (L0522_B_ProjectileMovesToOtherSquare) {
                F0267_MOVE_GetMoveResult_CPSCE(L0515_T_ProjectileThingNewCell, L0525_i_SourceMapX, L0526_i_SourceMapY, L0523_i_DestinationMapX, L0524_i_DestinationMapY);
                L0519_ps_Event->C.Projectile.MapX = G0397_i_MoveResultMapX;
                L0519_ps_Event->C.Projectile.MapY = G0398_i_MoveResultMapY;
                L0519_ps_Event->C.Projectile.Direction = G0400_i_MoveResultDirection;
                L0515_T_ProjectileThingNewCell = M015_THING_WITH_NEW_CELL(L0515_T_ProjectileThingNewCell, G0401_ui_MoveResultCell);
                M031_SET_MAP(L0519_ps_Event->Map_Time, G0399_ui_MoveResultMapIndex);
        } else {
                if ((M034_SQUARE_TYPE(F0151_DUNGEON_GetSquare(L0523_i_DestinationMapX, L0524_i_DestinationMapY)) == C04_ELEMENT_DOOR) && F0217_PROJECTILE_HasImpactOccured(C04_ELEMENT_DOOR, L0523_i_DestinationMapX, L0524_i_DestinationMapY, L0518_i_Cell, L0521_T_ProjectileThing)) {
                        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
                        F0164_DUNGEON_UnlinkThingFromList(L0515_T_ProjectileThingNewCell, 0, L0523_i_DestinationMapX, L0524_i_DestinationMapY);
                        F0163_DUNGEON_LinkThingToList(L0515_T_ProjectileThingNewCell, 0, L0523_i_DestinationMapX, L0524_i_DestinationMapY);
#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 MEDIA183_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_20_IMPROVEMENT */
        L0519_ps_Event->Map_Time += (G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) ? 1 : 3;
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_20_IMPROVEMENT Projectiles now move at the same speed on all maps instead of moving slower on maps other than the party map */
        L0519_ps_Event->Map_Time++;
#endif
        L0519_ps_Event->B.Slot = L0515_T_ProjectileThingNewCell;
        L0520_ps_Projectile->EventIndex = F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(L0519_ps_Event);
}

void F0220_EXPLOSION_ProcessEvent25_Explosion(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0463_ps_Event)
#endif
REGISTER EVENT* P0463_ps_Event FINAL_SEPARATOR
{
        REGISTER EXPLOSION* L0532_ps_Explosion;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER GROUP* L0533_ps_Group;
        CREATURE_INFO* L0534_ps_CreatureInfo;
        REGISTER int16_t L0530_i_Attack;
#endif
        REGISTER unsigned int16_t L0528_ui_MapX;
        REGISTER unsigned int16_t L0529_ui_MapY;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register int16_t L0530_i_Attack;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0537_ui_Multiple;
#endif
#define AL0537_ui_CreatureType                L0537_ui_Multiple
#define AL0537_ui_NonMaterialAdditionalAttack L0537_ui_Multiple
        REGISTER int16_t L0531_i_Multiple;
#define AL0531_i_SquareType    L0531_i_Multiple
#define AL0531_i_CreatureCount L0531_i_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        GROUP* L0533_ps_Group;
        CREATURE_INFO* L0534_ps_CreatureInfo;
#endif
        THING L0535_T_GroupThing;
        THING L0536_T_ExplosionThing;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned int16_t L0537_ui_Multiple;
#endif
        BOOLEAN L0538_B_ExplosionOnPartySquare;
        EVENT L0539_s_Event;


        L0528_ui_MapX = P0463_ps_Event->B.Location.MapX;
        L0529_ui_MapY = P0463_ps_Event->B.Location.MapY;
        L0532_ps_Explosion = &((EXPLOSION*)G0284_apuc_ThingData[C15_THING_TYPE_EXPLOSION])[M013_INDEX(P0463_ps_Event->C.Slot)];
        AL0531_i_SquareType = M034_SQUARE_TYPE(G0271_ppuc_CurrentMapData[L0528_ui_MapX][L0529_ui_MapY]);
        L0538_B_ExplosionOnPartySquare = (G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex) && (L0528_ui_MapX == G0306_i_PartyMapX) && (L0529_ui_MapY == G0307_i_PartyMapY);
        if ((L0535_T_GroupThing = F0175_GROUP_GetThing(L0528_ui_MapX, L0529_ui_MapY)) != C0xFFFE_THING_ENDOFLIST) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                L0533_ps_Group = &((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(L0535_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 */
                L0533_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L0535_T_GroupThing);
#endif
                L0534_ps_CreatureInfo = &G0243_as_Graphic559_CreatureInfo[AL0537_ui_CreatureType = L0533_ps_Group->Type];
        }
        if ((L0536_T_ExplosionThing = C0xFF80_THING_FIRST_EXPLOSION + L0532_ps_Explosion->Type) == C0xFF87_THING_EXPLOSION_POISON_CLOUD) {
                L0530_i_Attack = F0025_MAIN_GetMaximumValue(1, F0024_MAIN_GetMinimumValue(L0532_ps_Explosion->Attack >> 5, 4) + M005_RANDOM(2)); /* Value between 1 and 5 */
        } else {
                L0530_i_Attack = (L0532_ps_Explosion->Attack >> 1) + 1;
                L0530_i_Attack += M002_RANDOM(L0530_i_Attack) + 1;
        }
        switch (L0536_T_ExplosionThing) {
                case C0xFF82_THING_EXPLOSION_LIGHTNING_BOLT:
                        if (!(L0530_i_Attack >>= 1))
                                break;
                case C0xFF80_THING_EXPLOSION_FIREBALL:
                        if (AL0531_i_SquareType == C04_ELEMENT_DOOR) {
                                F0232_GROUP_IsDoorDestroyedByAttack(L0528_ui_MapX, L0529_ui_MapY, L0530_i_Attack, C1_TRUE, 0);
                        }
                        break;
                case C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL:
                        if ((L0535_T_GroupThing != C0xFFFE_THING_ENDOFLIST) && M007_GET(L0534_ps_CreatureInfo->Attributes, MASK0x0040_NON_MATERIAL)) {
                                if ((AL0537_ui_CreatureType == C19_CREATURE_MATERIALIZER_ZYTAZ) && (G0272_i_CurrentMapIndex == G0309_i_PartyMapIndex)) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
                                        L0530_i_Attack -= (AL0537_ui_NonMaterialAdditionalAttack = L0530_i_Attack >> 3);
                                        AL0537_ui_NonMaterialAdditionalAttack <<= 1;
                                        AL0537_ui_NonMaterialAdditionalAttack++;
                                        AL0531_i_CreatureCount = L0533_ps_Group->Count;
                                        do {
                                                if (M007_GET(G0375_ps_ActiveGroups[L0533_ps_Group->ActiveGroupIndex].Aspect[AL0531_i_CreatureCount], MASK0x0080_IS_ATTACKING)) { /* Materializer / Zytaz can only be damaged while they are attacking */
                                                        F0190_GROUP_GetDamageCreatureOutcome(L0533_ps_Group, AL0531_i_CreatureCount, L0528_ui_MapX, L0529_ui_MapY, L0530_i_Attack + M002_RANDOM(AL0537_ui_NonMaterialAdditionalAttack) + M004_RANDOM(4), C1_TRUE);
                                                }
                                        } while (--AL0531_i_CreatureCount >= 0);
                                } else {
                                        F0191_GROUP_GetDamageAllCreaturesOutcome(L0533_ps_Group, L0528_ui_MapX, L0529_ui_MapY, L0530_i_Attack, C1_TRUE);
                                }
                        }
                        break;
                case C0xFFE4_THING_EXPLOSION_REBIRTH_STEP1:
                        L0532_ps_Explosion->Type++;
                        F0064_SOUND_RequestPlay_CPSD(C05_SOUND_STRONG_EXPLOSION, L0528_ui_MapX, L0529_ui_MapY, C01_MODE_PLAY_IF_PRIORITIZED);
                        goto T0220026;
                case C0xFFA8_THING_EXPLOSION_SMOKE:
                        if (L0532_ps_Explosion->Attack > 55) {
                                L0532_ps_Explosion->Attack -= 40;
                                goto T0220026;
                        }
                        break;
                case C0xFF87_THING_EXPLOSION_POISON_CLOUD:
                        if (L0538_B_ExplosionOnPartySquare) {
                                F0324_CHAMPION_DamageAll_GetDamagedChampionCount(L0530_i_Attack, MASK0x0000_WOUND_NONE, C0_ATTACK_NORMAL);
                        } else {
                                if ((L0535_T_GroupThing != C0xFFFE_THING_ENDOFLIST) && (L0530_i_Attack = F0192_GROUP_GetResistanceAdjustedPoisonAttack(AL0537_ui_CreatureType, L0530_i_Attack)) && (F0191_GROUP_GetDamageAllCreaturesOutcome(L0533_ps_Group, L0528_ui_MapX, L0529_ui_MapY, L0530_i_Attack, C1_TRUE) != C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP) && (L0530_i_Attack > 2)) {
                                        F0209_GROUP_ProcessEvents29to41(L0528_ui_MapX, L0529_ui_MapY, CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE, 0);
                                }
                        }
                        if (L0532_ps_Explosion->Attack >= 6) {
                                L0532_ps_Explosion->Attack -= 3;
                                T0220026:
                                L0539_s_Event = *P0463_ps_Event;
                                L0539_s_Event.Map_Time++;
                                F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0539_s_Event);
                                return;
                        }
        }
        F0164_DUNGEON_UnlinkThingFromList(P0463_ps_Event->C.Slot, 0, L0528_ui_MapX, L0529_ui_MapY);
        L0532_ps_Explosion->Next = C0xFFFF_THING_NONE;
}

#ifdef MEDIA129_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
STATICFUNCTION BOOLEAN F0221_GROUP_IsFluxcageOnSquare(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0464_i_MapX, P0465_i_MapY)
#endif
int16_t P0464_i_MapX SEPARATOR
int16_t P0465_i_MapY FINAL_SEPARATOR
{
        REGISTER THING L0540_T_Thing;
        REGISTER int16_t L0541_i_SquareType;


        if (((L0541_i_SquareType = M034_SQUARE_TYPE(F0151_DUNGEON_GetSquare(P0464_i_MapX, P0465_i_MapY))) == C00_ELEMENT_WALL) || (L0541_i_SquareType == C03_ELEMENT_STAIRS)) {
                return C0_FALSE;
        }
        L0540_T_Thing = F0161_DUNGEON_GetSquareFirstThing(P0464_i_MapX, P0465_i_MapY);
        while (L0540_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                if ((M012_TYPE(L0540_T_Thing) == C15_THING_TYPE_EXPLOSION) && (((EXPLOSION*)G0284_apuc_ThingData[C15_THING_TYPE_EXPLOSION])[M013_INDEX(L0540_T_Thing)].Type == C050_EXPLOSION_FLUXCAGE)) {
                        return C1_TRUE;
                }
                L0540_T_Thing = F0159_DUNGEON_GetNextThing(L0540_T_Thing);
        }
        return C0_FALSE;
}

STATICFUNCTION unsigned int16_t F0222_GROUP_IsLordChaosOnSquare(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0466_i_MapX, P0467_i_MapY)
#endif
int16_t P0466_i_MapX SEPARATOR
int16_t P0467_i_MapY FINAL_SEPARATOR
{
#ifdef MEDIA231_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        REGISTER GROUP* L0543_ps_Group;
#endif
        REGISTER THING L0542_T_Thing;


        if ((L0542_T_Thing = F0175_GROUP_GetThing(P0466_i_MapX, P0467_i_MapY)) == C0xFFFE_THING_ENDOFLIST) {
                return 0;
        }
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        if (((GROUP*)G0284_apuc_ThingData[C04_THING_TYPE_GROUP])[M013_INDEX(L0542_T_Thing)].Type == C23_CREATURE_LORD_CHAOS) {
#endif
#ifdef MEDIA231_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0543_ps_Group = (GROUP*)F0156_DUNGEON_GetThingData(L0542_T_Thing);
        if (L0543_ps_Group->Type == C23_CREATURE_LORD_CHAOS) {
#endif
                return L0542_T_Thing;
        }
#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 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
        }
#endif
}
#endif

#ifdef MEDIA226_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
BOOLEAN F0223_GROUP_IsLordChaosAllowed(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0468_i_MapX, P0469_i_MapY)
#endif
int16_t P0468_i_MapX SEPARATOR
int16_t P0469_i_MapY FINAL_SEPARATOR
{
#ifdef MEDIA230_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J
        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
#ifdef MEDIA410_A20ED
        return C0_FALSE;
#endif
}
#endif

#ifdef MEDIA129_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
void F0224_GROUP_FluxCageAction(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0470_i_MapX, P0471_i_MapY)
#endif
REGISTER int16_t P0470_i_MapX SEPARATOR
REGISTER int16_t P0471_i_MapY FINAL_SEPARATOR
{
#ifdef MEDIA121_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J
        REGISTER THING L0545_T_Thing;
#endif
        REGISTER int16_t L0546_i_Multiple;
#ifdef MEDIA610_X30J_A36M
        REGISTER THING L0545_T_Thing;
#endif
#define AL0546_i_SquareType    L0546_i_Multiple
#define AL0546_i_FluxcageCount L0546_i_Multiple
        EVENT L0547_s_Event;


        if (((AL0546_i_SquareType = M034_SQUARE_TYPE(F0151_DUNGEON_GetSquare(P0470_i_MapX, P0471_i_MapY))) == C00_ELEMENT_WALL) || (AL0546_i_SquareType == C03_ELEMENT_STAIRS)) {
                return;
        }
        if ((L0545_T_Thing = F0166_DUNGEON_GetUnusedThing(C15_THING_TYPE_EXPLOSION)) == C0xFFFF_THING_NONE) {
                return;
        }
        F0163_DUNGEON_LinkThingToList(L0545_T_Thing, 0, P0470_i_MapX, P0471_i_MapY);
        (((EXPLOSION*)G0284_apuc_ThingData[C15_THING_TYPE_EXPLOSION])[M013_INDEX(L0545_T_Thing)]).Type = C050_EXPLOSION_FLUXCAGE;
        M033_SET_MAP_AND_TIME(L0547_s_Event.Map_Time, G0272_i_CurrentMapIndex, G0313_ul_GameTime + 100);
        L0547_s_Event.A.A.Type = C24_EVENT_REMOVE_FLUXCAGE;
        L0547_s_Event.A.A.Priority = 0;
        L0547_s_Event.C.Slot = L0545_T_Thing;
        L0547_s_Event.B.Location.MapX = P0470_i_MapX;
        L0547_s_Event.B.Location.MapY = P0471_i_MapY;
        F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0547_s_Event);
        if (F0222_GROUP_IsLordChaosOnSquare(P0470_i_MapX, P0471_i_MapY - 1)) {
                P0471_i_MapY--;
                AL0546_i_FluxcageCount = F0221_GROUP_IsFluxcageOnSquare(P0470_i_MapX + 1, P0471_i_MapY);
                goto T0224005;
        }
#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 (F0222_GROUP_IsLordChaosOnSquare(P0470_i_MapX - 1, P0471_i_MapY)) {
                        P0470_i_MapX--;
                        AL0546_i_FluxcageCount = F0221_GROUP_IsFluxcageOnSquare(P0470_i_MapX, P0471_i_MapY + 1);
                        T0224005:
                        AL0546_i_FluxcageCount += F0221_GROUP_IsFluxcageOnSquare(P0470_i_MapX, P0471_i_MapY - 1) + F0221_GROUP_IsFluxcageOnSquare(P0470_i_MapX - 1, P0471_i_MapY);
                } else {
                        if (F0222_GROUP_IsLordChaosOnSquare(P0470_i_MapX + 1, P0471_i_MapY)) {
                                P0470_i_MapX++;
                                AL0546_i_FluxcageCount = F0221_GROUP_IsFluxcageOnSquare(P0470_i_MapX, P0471_i_MapY - 1);
                                goto T0224008;
                        }
#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 (F0222_GROUP_IsLordChaosOnSquare(P0470_i_MapX, P0471_i_MapY + 1)) {
                                        P0471_i_MapY++;
                                        AL0546_i_FluxcageCount = F0221_GROUP_IsFluxcageOnSquare(P0470_i_MapX - 1, P0471_i_MapY);
                                        T0224008:
                                        AL0546_i_FluxcageCount += F0221_GROUP_IsFluxcageOnSquare(P0470_i_MapX, P0471_i_MapY + 1) + F0221_GROUP_IsFluxcageOnSquare(P0470_i_MapX + 1, P0471_i_MapY);
                                } else {
                                        AL0546_i_FluxcageCount = 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
                        }
#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
        }
#endif
        if (AL0546_i_FluxcageCount == 2) {
                F0209_GROUP_ProcessEvents29to41(P0470_i_MapX, P0471_i_MapY, CM3_EVENT_CREATE_REACTION_EVENT_29_DANGER_ON_SQUARE, 0);
        }
}

void F0225_GROUP_FuseAction(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0472_ui_MapX, P0473_ui_MapY)
#endif
REGISTER unsigned int16_t P0472_ui_MapX SEPARATOR
REGISTER unsigned int16_t P0473_ui_MapY FINAL_SEPARATOR
{
        REGISTER int16_t L0548_i_MapX;
        REGISTER int16_t L0549_i_MapY;
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        int16_t L0550_i_SquareType;
#endif
#ifdef MEDIA117_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned int16_t L0551_ui_FluxcageCount;
#endif
#ifdef MEDIA121_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J
        unsigned int16_t L0552_ui_FluxcageIndex;
#endif
#ifdef MEDIA610_X30J_A36M
        register unsigned int16_t L0552_ui_FluxcageIndex;
#endif
#ifdef MEDIA533_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J
        THING L0555_T_LordChaosThing;
        unsigned int16_t L0551_ui_FluxcageCount;
#endif
        unsigned int16_t L0553_ui_Counter;
        BOOLEAN L0554_aB_Fluxcages[4];
#ifdef MEDIA117_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G
        THING L0555_T_LordChaosThing;
#endif


#ifdef MEDIA260_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M /* CHANGE5_02_FIX The Fuse action is aborted if the specified coordinates are outside the map bounds */
        if (!((P0472_ui_MapX >= 0) && (P0472_ui_MapX < G0273_i_CurrentMapWidth)) || !((P0473_ui_MapY >= 0) && (P0473_ui_MapY < G0274_i_CurrentMapHeight))) {
                return;
        }
#endif
#ifdef MEDIA495_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J
        if ((P0472_ui_MapX >= 0) && (P0472_ui_MapX < G0273_i_CurrentMapWidth) && (P0473_ui_MapY >= 0) && (P0473_ui_MapY < G0274_i_CurrentMapHeight)) {
#endif
                F0213_EXPLOSION_Create(C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL, 255, P0472_ui_MapX, P0473_ui_MapY, C0xFF_SINGLE_CENTERED_CREATURE); /* BUG0_17 The game crashes after the Fuse action is performed while looking at a wall on a map boundary. An explosion thing is created on the square in front of the party but there is no check to ensure the square coordinates are in the map bounds. This corrupts a memory location and leads to a game crash */
                if (L0555_T_LordChaosThing = F0222_GROUP_IsLordChaosOnSquare(P0472_ui_MapX, P0473_ui_MapY)) {
                        L0551_ui_FluxcageCount = (L0554_aB_Fluxcages[0] = F0221_GROUP_IsFluxcageOnSquare(P0472_ui_MapX - 1, P0473_ui_MapY)) +
                                                 (L0554_aB_Fluxcages[1] = F0221_GROUP_IsFluxcageOnSquare(P0472_ui_MapX + 1, P0473_ui_MapY)) +
                                                 (L0554_aB_Fluxcages[2] = F0221_GROUP_IsFluxcageOnSquare(P0472_ui_MapX, P0473_ui_MapY - 1)) +
                                                 (L0554_aB_Fluxcages[3] = F0221_GROUP_IsFluxcageOnSquare(P0472_ui_MapX, P0473_ui_MapY + 1));
                        while (L0551_ui_FluxcageCount++ < 4) {
                                L0548_i_MapX = P0472_ui_MapX;
                                L0549_i_MapY = P0473_ui_MapY;
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_11_OPTIMIZATION Comma removed */
                                for (L0553_ui_Counter = 5, L0552_ui_FluxcageIndex = M004_RANDOM(4); --L0553_ui_Counter; L0552_ui_FluxcageIndex = M017_NEXT(L0552_ui_FluxcageIndex)) {
#endif
#ifdef MEDIA298_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J /* CHANGE7_11_OPTIMIZATION Comma removed */
                                L0552_ui_FluxcageIndex = M004_RANDOM(4);
                                for (L0553_ui_Counter = 5; --L0553_ui_Counter; L0552_ui_FluxcageIndex = M017_NEXT(L0552_ui_FluxcageIndex)) {
#endif
                                        if (!L0554_aB_Fluxcages[L0552_ui_FluxcageIndex]) {
                                                L0554_aB_Fluxcages[L0552_ui_FluxcageIndex] = C1_TRUE;
                                                switch (L0552_ui_FluxcageIndex) {
                                                        case 0:
                                                                L0548_i_MapX--;
                                                                break;
                                                        case 1:
                                                                L0548_i_MapX++;
                                                                break;
                                                        case 2:
                                                                L0549_i_MapY--;
                                                                break;
                                                        case 3:
                                                                L0549_i_MapY++;
                                                }
                                                break;
                                        }
                                }
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                                if (((L0550_i_SquareType = M034_SQUARE_TYPE(F0151_DUNGEON_GetSquare(L0548_i_MapX, L0549_i_MapY))) == C01_ELEMENT_CORRIDOR) || (L0550_i_SquareType == C05_ELEMENT_TELEPORTER) || (L0550_i_SquareType == C02_ELEMENT_PIT) || (L0550_i_SquareType == C04_ELEMENT_DOOR)) {
#endif
#ifdef MEDIA231_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                                if (F0223_GROUP_IsLordChaosAllowed(L0548_i_MapX, L0549_i_MapY)) {
#endif
                                        if (!F0267_MOVE_GetMoveResult_CPSCE(L0555_T_LordChaosThing, P0472_ui_MapX, P0473_ui_MapY, L0548_i_MapX, L0549_i_MapY)) {
                                                F0180_GROUP_StartWandering(L0548_i_MapX, L0549_i_MapY);
                                        }
                                        return;
                                }
                        }
                        F0446_STARTEND_FuseSequence();
                }
#ifdef MEDIA495_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J
        }
#endif
}
#endif

int16_t F0226_GROUP_GetDistanceBetweenSquares(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0474_i_SourceMapX, P0475_i_SourceMapY, P0476_i_DestinationMapX, P0477_i_DestinationMapY)
#endif
REGISTER int16_t P0474_i_SourceMapX      SEPARATOR
REGISTER int16_t P0475_i_SourceMapY      SEPARATOR
int16_t          P0476_i_DestinationMapX SEPARATOR
int16_t          P0477_i_DestinationMapY FINAL_SEPARATOR
{
        return ((((P0474_i_SourceMapX -= P0476_i_DestinationMapX) < 0) ? -P0474_i_SourceMapX : P0474_i_SourceMapX) +
                (((P0475_i_SourceMapY -= P0477_i_DestinationMapY) < 0) ? -P0475_i_SourceMapY : P0475_i_SourceMapY));
}

BOOLEAN F0227_GROUP_IsDestinationVisibleFromSource(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0478_ui_Direction, P0479_i_SourceMapX, P0480_i_SourceMapY, P0481_i_DestinationMapX, P0482_i_DestinationMapY)
#endif
unsigned int16_t P0478_ui_Direction      SEPARATOR
REGISTER int16_t P0479_i_SourceMapX      SEPARATOR
REGISTER int16_t P0480_i_SourceMapY      SEPARATOR
REGISTER int16_t P0481_i_DestinationMapX SEPARATOR
REGISTER int16_t P0482_i_DestinationMapY FINAL_SEPARATOR
{
#ifdef MEDIA354_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB_I34E_I34M_P31J
        int16_t L1637_i_Temp;
#endif
#ifdef MEDIA548_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        register int16_t L1637_i_Temp;
#endif


        switch (P0478_ui_Direction) { /* If direction is not 'West' then swap variables so that the same test as for west can be applied */
                case C2_DIRECTION_SOUTH:
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        asm {
                                exg     P0479_i_SourceMapX,P0482_i_DestinationMapY        /* Exchange values */
                                exg     P0481_i_DestinationMapX,P0480_i_SourceMapY        /* Exchange values */
                        }
#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
                        L1637_i_Temp = P0479_i_SourceMapX;
                        P0479_i_SourceMapX = P0482_i_DestinationMapY;
                        P0482_i_DestinationMapY = L1637_i_Temp;
                        L1637_i_Temp = P0481_i_DestinationMapX;
                        P0481_i_DestinationMapX = P0480_i_SourceMapY;
                        P0480_i_SourceMapY = L1637_i_Temp;
#endif
                        break;
                case C1_DIRECTION_EAST:
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        asm {
                                exg     P0479_i_SourceMapX,P0481_i_DestinationMapX        /* Exchange values */
                                exg     P0480_i_SourceMapY,P0482_i_DestinationMapY        /* Exchange values */
                        }
#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
                        L1637_i_Temp = P0479_i_SourceMapX;
                        P0479_i_SourceMapX = P0481_i_DestinationMapX;
                        P0481_i_DestinationMapX = L1637_i_Temp;
                        L1637_i_Temp = P0482_i_DestinationMapY;
                        P0482_i_DestinationMapY = P0480_i_SourceMapY;
                        P0480_i_SourceMapY = L1637_i_Temp;
#endif
                        break;
                case C0_DIRECTION_NORTH:
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        asm {
                                exg     P0479_i_SourceMapX,P0480_i_SourceMapY             /* Exchange values */
                                exg     P0481_i_DestinationMapX,P0482_i_DestinationMapY   /* Exchange values */
                        }
#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
                        L1637_i_Temp = P0479_i_SourceMapX;
                        P0479_i_SourceMapX = P0480_i_SourceMapY;
                        P0480_i_SourceMapY = L1637_i_Temp;
                        L1637_i_Temp = P0481_i_DestinationMapX;
                        P0481_i_DestinationMapX = P0482_i_DestinationMapY;
                        P0482_i_DestinationMapY = L1637_i_Temp;
#endif
        }
        return ((P0479_i_SourceMapX -= (P0481_i_DestinationMapX - 1)) > 0) && ((((P0480_i_SourceMapY -= P0482_i_DestinationMapY) < 0) ? -P0480_i_SourceMapY : P0480_i_SourceMapY) <= P0479_i_SourceMapX);
}

int16_t F0228_GROUP_GetDirectionsWhereDestinationIsVisibleFromSource(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0483_i_SourceMapX, P0484_i_SourceMapY, P0485_i_DestinationMapX, P0486_i_DestinationMapY)
#endif
REGISTER int16_t P0483_i_SourceMapX      SEPARATOR
REGISTER int16_t P0484_i_SourceMapY      SEPARATOR
REGISTER int16_t P0485_i_DestinationMapX SEPARATOR
#ifdef MEDIA012_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB_I34E_I34M_P31J
int16_t          P0486_i_DestinationMapY FINAL_SEPARATOR
#endif
#ifdef MEDIA548_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
REGISTER int16_t P0486_i_DestinationMapY FINAL_SEPARATOR
#endif
#define AP0483_i_PrimaryDirection P0483_i_SourceMapX
{
        REGISTER int16_t L0556_i_Direction;


        if (P0483_i_SourceMapX == P0485_i_DestinationMapX) {
                G0363_i_SecondaryDirectionToOrFromParty = (M006_RANDOM(65536) & 0x0002) + 1; /* Resulting direction may be 1 or 3 (East or West) */
                if (P0484_i_SourceMapY > P0486_i_DestinationMapY) {
                        return C0_DIRECTION_NORTH;
                }
#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 C2_DIRECTION_SOUTH;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                }
#endif
        }
        if (P0484_i_SourceMapY == P0486_i_DestinationMapY) {
                G0363_i_SecondaryDirectionToOrFromParty = (M006_RANDOM(65536) & 0x0002) + 0; /* Resulting direction may be 0 or 2 (North or South) */
                if (P0483_i_SourceMapX > P0485_i_DestinationMapX) {
                        return C3_DIRECTION_WEST;
                }
#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 C1_DIRECTION_EAST;
#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
        }
        L0556_i_Direction = C0_DIRECTION_NORTH;
        for (;;) { /*_Infinite loop_*/
                if (F0227_GROUP_IsDestinationVisibleFromSource(L0556_i_Direction, P0483_i_SourceMapX, P0484_i_SourceMapY, P0485_i_DestinationMapX, P0486_i_DestinationMapY)) {
                        if (!F0227_GROUP_IsDestinationVisibleFromSource(G0363_i_SecondaryDirectionToOrFromParty = M017_NEXT(L0556_i_Direction), P0483_i_SourceMapX, P0484_i_SourceMapY, P0485_i_DestinationMapX, P0486_i_DestinationMapY)) {
                                if ((L0556_i_Direction != C0_DIRECTION_NORTH) || !F0227_GROUP_IsDestinationVisibleFromSource(G0363_i_SecondaryDirectionToOrFromParty = M019_PREVIOUS(L0556_i_Direction), P0483_i_SourceMapX, P0484_i_SourceMapY, P0485_i_DestinationMapX, P0486_i_DestinationMapY)) {
                                        G0363_i_SecondaryDirectionToOrFromParty = M017_NEXT((M006_RANDOM(65536) & 0x0002) + L0556_i_Direction);
                                        return L0556_i_Direction;
                                }
                        }
                        if (M005_RANDOM(2)) {
                                AP0483_i_PrimaryDirection = G0363_i_SecondaryDirectionToOrFromParty;
                                G0363_i_SecondaryDirectionToOrFromParty = L0556_i_Direction;
                                return AP0483_i_PrimaryDirection;
                        }
#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 L0556_i_Direction;
#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
                }
                L0556_i_Direction++;
        }
}

void F0229_GROUP_SetOrderedCellsToAttack(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0487_pc_OrderedCellsToAttack, P0488_i_TargetMapX, P0489_i_TargetMapY, P0490_i_AttackerMapX, P0491_i_AttackerMapY, P0492_ui_CellSource)
#endif
char*            P0487_pc_OrderedCellsToAttack SEPARATOR
int16_t          P0488_i_TargetMapX            SEPARATOR
int16_t          P0489_i_TargetMapY            SEPARATOR
int16_t          P0490_i_AttackerMapX          SEPARATOR
int16_t          P0491_i_AttackerMapY          SEPARATOR
unsigned int16_t P0492_ui_CellSource           FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0557_ui_OrderedCellsToAttackIndex;


        if (!((L0557_ui_OrderedCellsToAttackIndex = F0228_GROUP_GetDirectionsWhereDestinationIsVisibleFromSource(P0488_i_TargetMapX, P0489_i_TargetMapY, P0490_i_AttackerMapX, P0491_i_AttackerMapY) << 1) & 0x0002)) {
                P0492_ui_CellSource++;
        }
        L0557_ui_OrderedCellsToAttackIndex += (P0492_ui_CellSource >> 1) & 0x0001;
        F0007_MAIN_CopyBytes(G0023_aac_Graphic562_OrderedCellsToAttack[L0557_ui_OrderedCellsToAttackIndex], P0487_pc_OrderedCellsToAttack, M543_BYTE_COUNT_INT(4));
}

int16_t F0230_GROUP_GetChampionDamage(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0493_ps_Group, P0494_ui_ChampionIndex)
#endif
#ifdef MEDIA012_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB_I34E_I34M_P31J
REGISTER GROUP*           P0493_ps_Group         SEPARATOR
unsigned int16_t          P0494_ui_ChampionIndex FINAL_SEPARATOR
#endif
#ifdef MEDIA548_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
GROUP*                    P0493_ps_Group         SEPARATOR
REGISTER unsigned int16_t P0494_ui_ChampionIndex FINAL_SEPARATOR
#endif
{
        REGISTER CHAMPION* L0562_ps_Champion;
        REGISTER int16_t L0558_i_Multiple;
#define AL0558_i_Attack L0558_i_Multiple
#define AL0558_i_Damage L0558_i_Multiple
        REGISTER unsigned int16_t L0559_ui_Multiple;
#define AL0559_ui_WoundTest          L0559_ui_Multiple
#define AL0559_ui_PoisonAttack       L0559_ui_Multiple
#define AL0559_ui_CreatureDifficulty L0559_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 L0560_ui_WoundProbabilities;
#endif
        REGISTER unsigned int16_t L0561_ui_Multiple;
#define AL0561_ui_WoundProbabilityIndex L0561_ui_Multiple
#define AL0561_ui_AllowedWound          L0561_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 L0560_ui_WoundProbabilities;
#endif
        int16_t L0563_i_DoubledMapDifficulty;
        CREATURE_INFO L0564_s_CreatureInfo;


        L0562_ps_Champion = &M516_CHAMPIONS[P0494_ui_ChampionIndex];
        if (P0494_ui_ChampionIndex >= G0305_ui_PartyChampionCount) {
                return 0;
        }
        if (!L0562_ps_Champion->CurrentHealth) {
                return 0;
        }
        if (G0300_B_PartyIsResting) {
                F0314_CHAMPION_WakeUp();
        }
        L0563_i_DoubledMapDifficulty = G0269_ps_CurrentMap->C.Difficulty << 1;
        L0564_s_CreatureInfo = G0243_as_Graphic559_CreatureInfo[P0493_ps_Group->Type];
        F0304_CHAMPION_AddSkillExperience(P0494_ui_ChampionIndex, C07_SKILL_PARRY, M058_EXPERIENCE(L0564_s_CreatureInfo.Properties));
#ifdef MEDIA064_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB
        if (G0300_B_PartyIsResting || (((F0311_CHAMPION_GetDexterity(L0562_ps_Champion) < (M003_RANDOM(32) + L0564_s_CreatureInfo.Dexterity + L0563_i_DoubledMapDifficulty - 16)) || !M004_RANDOM(4)) && !F0308_CHAMPION_IsLucky(L0562_ps_Champion, 60))) {
#endif
#ifdef MEDIA488_F20E_F20J
        if (G0300_B_PartyIsResting || (((F0311_CHAMPION_GetDexterity(L0562_ps_Champion) < ((int16_t)(M003_RANDOM(32) + L0564_s_CreatureInfo.Dexterity + L0563_i_DoubledMapDifficulty) - 16)) || !M004_RANDOM(4)) && !F0308_CHAMPION_IsLucky(L0562_ps_Champion, 60))) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (G0407_s_Party.Event71Count_Invisibility && !M007_GET(L0564_s_CreatureInfo.Attributes, MASK0x0800_SEE_INVISIBLE)) {
                AL0559_ui_CreatureDifficulty = 16;
        } else {
                if (M007_GET(L0564_s_CreatureInfo.Attributes, MASK0x1000_NIGHT_VISION)) {
                        AL0559_ui_CreatureDifficulty = 0;
                } else {
                        AL0559_ui_CreatureDifficulty = G0304_i_DungeonViewPaletteIndex << 1;
                }
        }
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        if (G0300_B_PartyIsResting || (L0564_s_CreatureInfo.Dexterity == 255) || (((F0311_CHAMPION_GetDexterity(L0562_ps_Champion) < (M003_RANDOM(32) + L0564_s_CreatureInfo.Dexterity + L0563_i_DoubledMapDifficulty + AL0559_ui_CreatureDifficulty - 16)) || !M004_RANDOM(4)) && !F0308_CHAMPION_IsLucky(L0562_ps_Champion, 60))) {
#endif
#ifdef MEDIA670_F31E_F31J
        if (G0300_B_PartyIsResting || (L0564_s_CreatureInfo.Dexterity == 255) || (((F0311_CHAMPION_GetDexterity(L0562_ps_Champion) < ((int16_t)(M003_RANDOM(32) + L0564_s_CreatureInfo.Dexterity + L0563_i_DoubledMapDifficulty) + AL0559_ui_CreatureDifficulty - 16)) || !M004_RANDOM(4)) && !F0308_CHAMPION_IsLucky(L0562_ps_Champion, 60))) {
#endif
                if ((AL0559_ui_WoundTest = M006_RANDOM(65536)) & 0x0070) {
                        AL0559_ui_WoundTest &= 0x000F;
                        L0560_ui_WoundProbabilities = L0564_s_CreatureInfo.WoundProbabilities;
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED /* CHANGE7_11_OPTIMIZATION Comma removed */
                        for (AL0561_ui_WoundProbabilityIndex = 0; AL0559_ui_WoundTest > (L0560_ui_WoundProbabilities & 0x000F); L0560_ui_WoundProbabilities >>= 4, AL0561_ui_WoundProbabilityIndex++);
#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 */
                        for (AL0561_ui_WoundProbabilityIndex = 0; AL0559_ui_WoundTest > (L0560_ui_WoundProbabilities & 0x000F); L0560_ui_WoundProbabilities >>= 4) {
                                AL0561_ui_WoundProbabilityIndex++;
                        }
#endif
                        AL0561_ui_AllowedWound = G0024_auc_Graphic562_WoundProbabilityIndexToWoundMask[AL0561_ui_WoundProbabilityIndex];
                } else {
                        AL0561_ui_AllowedWound = M007_GET(AL0559_ui_WoundTest, MASK0x0001_WOUND_READY_HAND);
                }
                if ((AL0558_i_Attack = (M003_RANDOM(16) + L0564_s_CreatureInfo.Attack + L0563_i_DoubledMapDifficulty) - (F0303_CHAMPION_GetSkillLevel(P0494_ui_ChampionIndex, C07_SKILL_PARRY) << 1)) <= 1) {
                        if (M005_RANDOM(2)) {
                                goto T0230014;
                        }
                        AL0558_i_Attack = M004_RANDOM(4) + 2;
                }
                AL0558_i_Attack >>= 1;
                AL0558_i_Attack += M002_RANDOM(AL0558_i_Attack) + M004_RANDOM(4);
                AL0558_i_Attack += M002_RANDOM(AL0558_i_Attack);
                AL0558_i_Attack >>= 2;
                AL0558_i_Attack += M004_RANDOM(4) + 1;
                if (M005_RANDOM(2)) {
                        AL0558_i_Attack -= M002_RANDOM((AL0558_i_Attack >> 1) + 1) - 1;
                }
                if (AL0558_i_Damage = F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage(P0494_ui_ChampionIndex, AL0558_i_Attack, AL0561_ui_AllowedWound, L0564_s_CreatureInfo.AttackType)) {
                        F0064_SOUND_RequestPlay_CPSD(C09_SOUND_CHAMPION_0_DAMAGED + P0494_ui_ChampionIndex, G0306_i_PartyMapX, G0307_i_PartyMapY, C02_MODE_PLAY_ONE_TICK_LATER);
                        if ((AL0559_ui_PoisonAttack = L0564_s_CreatureInfo.PoisonAttack) && M005_RANDOM(2) && ((AL0559_ui_PoisonAttack = F0307_CHAMPION_GetStatisticAdjustedAttack(L0562_ps_Champion, C4_STATISTIC_VITALITY, AL0559_ui_PoisonAttack)) >= 0)) {
                                F0322_CHAMPION_Poison(P0494_ui_ChampionIndex, AL0559_ui_PoisonAttack);
                        }
                        return AL0558_i_Damage;
                }
        }
        T0230014:
        return 0;
}

int16_t F0231_GROUP_GetMeleeActionDamage(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0495_ps_Champion, P0496_i_ChampionIndex, P0497_ps_Group, P0498_i_CreatureIndex, P0499_i_MapX, P0500_i_MapY, P0501_ui_ActionHitProbability, P0502_ui_ActionDamageFactor, P0503_i_SkillIndex)
#endif
REGISTER CHAMPION* P0495_ps_Champion             SEPARATOR
unsigned int16_t   P0496_i_ChampionIndex         SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
REGISTER GROUP*    P0497_ps_Group                SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
GROUP*             P0497_ps_Group                SEPARATOR
#endif
int16_t            P0498_i_CreatureIndex         SEPARATOR
int16_t            P0499_i_MapX                  SEPARATOR
int16_t            P0500_i_MapY                  SEPARATOR
unsigned int16_t   P0501_ui_ActionHitProbability SEPARATOR
unsigned int16_t   P0502_ui_ActionDamageFactor   SEPARATOR
int16_t            P0503_i_SkillIndex            FINAL_SEPARATOR
{
#ifdef MEDIA548_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        REGISTER int16_t L0565_i_Damage;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER CREATURE_INFO* L0572_ps_CreatureInfo;
        REGISTER int16_t L0568_i_Defense;
        REGISTER int16_t L0571_i_ActionHandObjectIconIndex;
#endif
#ifdef MEDIA012_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB_I34E_I34M_P31J
        REGISTER int16_t L0565_i_Damage;
#endif
        REGISTER int16_t L0566_i_Damage;
        REGISTER int16_t L0567_i_DoubledMapDifficulty;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L0568_i_Defense;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        BOOLEAN L0570_B_ActionHitsNonMaterialCreatures;
#endif
        int16_t L0569_i_Outcome;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        BOOLEAN L0570_B_ActionHitsNonMaterialCreatures;
        int16_t L0571_i_ActionHandObjectIconIndex;
        CREATURE_INFO* L0572_ps_CreatureInfo;
#endif


        if (P0496_i_ChampionIndex >= G0305_ui_PartyChampionCount) {
                return 0;
        }
        if (!P0495_ps_Champion->CurrentHealth) {
                return 0;
        }
        L0567_i_DoubledMapDifficulty = G0269_ps_CurrentMap->C.Difficulty << 1;
        L0572_ps_CreatureInfo = &G0243_as_Graphic559_CreatureInfo[P0497_ps_Group->Type];
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (L0572_ps_CreatureInfo->Dexterity != 255) {
#endif
                L0571_i_ActionHandObjectIconIndex = F0033_OBJECT_GetIconIndex(P0495_ps_Champion->Slots[C01_SLOT_ACTION_HAND]);
                if (L0570_B_ActionHitsNonMaterialCreatures = M007_GET(P0501_ui_ActionHitProbability, MASK0x8000_HIT_NON_MATERIAL_CREATURES)) {
                        M009_CLEAR(P0501_ui_ActionHitProbability, MASK0x8000_HIT_NON_MATERIAL_CREATURES);
                }
                if ((!M007_GET(L0572_ps_CreatureInfo->Attributes, MASK0x0040_NON_MATERIAL) || L0570_B_ActionHitsNonMaterialCreatures) &&
#ifdef MEDIA064_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB
                    ((F0311_CHAMPION_GetDexterity(P0495_ps_Champion) > (M003_RANDOM(32) + L0572_ps_CreatureInfo->Dexterity + L0567_i_DoubledMapDifficulty - 16)) ||
#endif
#ifdef MEDIA488_F20E_F20J
                    ((F0311_CHAMPION_GetDexterity(P0495_ps_Champion) > ((int16_t)(M003_RANDOM(32) + L0572_ps_CreatureInfo->Dexterity + L0567_i_DoubledMapDifficulty) - 16)) ||
#endif
#ifdef MEDIA670_F31E_F31J
                    ((F0311_CHAMPION_GetDexterity(P0495_ps_Champion) > ((int16_t)(M003_RANDOM(32) + L0572_ps_CreatureInfo->Dexterity + L0567_i_DoubledMapDifficulty) + (G0304_i_DungeonViewPaletteIndex << 1) - 16)) ||
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                    ((F0311_CHAMPION_GetDexterity(P0495_ps_Champion) > (M003_RANDOM(32) + L0572_ps_CreatureInfo->Dexterity + L0567_i_DoubledMapDifficulty + (G0304_i_DungeonViewPaletteIndex << 1) + -16)) ||
#endif
                     (!M004_RANDOM(4)) ||
                     (F0308_CHAMPION_IsLucky(P0495_ps_Champion, 75 - P0501_ui_ActionHitProbability)))) {
                        if (!(L0565_i_Damage = F0312_CHAMPION_GetStrength(P0496_i_ChampionIndex, C01_SLOT_ACTION_HAND))) {
                                goto T0231009; /* BUG0_81: A weak champion may inflict high damage. If a champion's strength (computed value between 0 and 100) is 0 then a modifier may be added to the damage value without being initialized first and may thus contain a large value. This may happen for a champion with a low strength statistic (like Tiggy), a wounded action hand holding a heavy weapon (like a Stone Club) and a very low stamina. If F0312_CHAMPION_GetStrength returns 0 then L0566_i_Damage may be used without being initialized */
                        }
                        L0565_i_Damage += M002_RANDOM((L0565_i_Damage >> 1) + 1);
                        L0565_i_Damage = ((long)L0565_i_Damage * (long)P0502_ui_ActionDamageFactor) >> 5;
                        L0568_i_Defense = M003_RANDOM(32) + L0572_ps_CreatureInfo->Defense + L0567_i_DoubledMapDifficulty;
                        if (L0571_i_ActionHandObjectIconIndex == C039_ICON_WEAPON_DIAMOND_EDGE) {
                                L0568_i_Defense -= L0568_i_Defense >> 2;
                        } else {
                                if (L0571_i_ActionHandObjectIconIndex == C043_ICON_WEAPON_HARDCLEAVE_EXECUTIONER) {
                                        L0568_i_Defense -= L0568_i_Defense >> 3;
                                }
                        }
                        if ((L0566_i_Damage = L0565_i_Damage = M003_RANDOM(32) + L0565_i_Damage - L0568_i_Defense) <= 1) {
                                T0231009:
                                if (!(L0565_i_Damage = M004_RANDOM(4))) {
                                        goto T0231015;
                                }
#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
                                        L0565_i_Damage++;
                                        if (((L0566_i_Damage += M003_RANDOM(16)) > 0) || (M005_RANDOM(2))) {
                                                L0565_i_Damage += M004_RANDOM(4);
                                                if (!M004_RANDOM(4)) {
                                                        L0565_i_Damage += F0025_MAIN_GetMaximumValue(0, L0566_i_Damage + M003_RANDOM(16));
                                                }
                                        }
#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
                        }
                        L0565_i_Damage >>= 1;
                        L0565_i_Damage += M002_RANDOM(L0565_i_Damage) + M004_RANDOM(4);
                        L0565_i_Damage += M002_RANDOM(L0565_i_Damage);
                        L0565_i_Damage >>= 2;
                        L0565_i_Damage += M004_RANDOM(4) + 1;
                        if ((L0571_i_ActionHandObjectIconIndex == C040_ICON_WEAPON_VORPAL_BLADE) && !M007_GET(L0572_ps_CreatureInfo->Attributes, MASK0x0040_NON_MATERIAL) && !(L0565_i_Damage >>= 1))
                                goto T0231015;
                        if (M003_RANDOM(64) < F0303_CHAMPION_GetSkillLevel(P0496_i_ChampionIndex, P0503_i_SkillIndex)) {
                                L0565_i_Damage += L0565_i_Damage + 10;
                        }
                        L0569_i_Outcome = F0190_GROUP_GetDamageCreatureOutcome(P0497_ps_Group, P0498_i_CreatureIndex, P0499_i_MapX, P0500_i_MapY, L0565_i_Damage, C1_TRUE);
                        F0304_CHAMPION_AddSkillExperience(P0496_i_ChampionIndex, P0503_i_SkillIndex, (L0565_i_Damage * M058_EXPERIENCE(L0572_ps_CreatureInfo->Properties) >> 4) + 3);
                        F0325_CHAMPION_DecrementStamina(P0496_i_ChampionIndex, M004_RANDOM(4) + 4);
                        goto T0231016;
                }
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        }
#endif
        T0231015:
        L0565_i_Damage = 0;
        L0569_i_Outcome = C0_OUTCOME_KILLED_NO_CREATURES_IN_GROUP;
        F0325_CHAMPION_DecrementStamina(P0496_i_ChampionIndex, M005_RANDOM(2) + 2);
        T0231016:
        F0292_CHAMPION_DrawState(P0496_i_ChampionIndex);
        if (L0569_i_Outcome != C2_OUTCOME_KILLED_ALL_CREATURES_IN_GROUP) {
                F0209_GROUP_ProcessEvents29to41(P0499_i_MapX, P0500_i_MapY, CM1_EVENT_CREATE_REACTION_EVENT_31_PARTY_IS_ADJACENT, 0);
        }
        return L0565_i_Damage;
}

BOOLEAN F0232_GROUP_IsDoorDestroyedByAttack(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0504_ui_MapX, P0505_ui_MapY, P0506_i_Attack, P0507_B_MagicAttack, P0508_Ticks)
#endif
unsigned int16_t P0504_ui_MapX       SEPARATOR
unsigned int16_t P0505_ui_MapY       SEPARATOR
int16_t          P0506_i_Attack      SEPARATOR
BOOLEAN          P0507_B_MagicAttack SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t          P0508_Ticks         FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
unsigned int16_t P0508_Ticks         FINAL_SEPARATOR
#endif
{
        REGISTER DOOR* L0573_ps_Door;
        REGISTER unsigned char* L0574_puc_Square;
        EVENT L0575_s_Event;


#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
        L0573_ps_Door = &((DOOR*)G0284_apuc_ThingData[C00_THING_TYPE_DOOR])[M013_INDEX(F0161_DUNGEON_GetSquareFirstThing(P0504_ui_MapX, P0505_ui_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 */
        L0573_ps_Door = (DOOR*)F0157_DUNGEON_GetSquareFirstThingData(P0504_ui_MapX, P0505_ui_MapY);
#endif
        if ((P0507_B_MagicAttack && !L0573_ps_Door->MagicDestructible) || (!P0507_B_MagicAttack && !L0573_ps_Door->MeleeDestructible)) {
                return C0_FALSE;
        }
        if (P0506_i_Attack >= G0275_as_CurrentMapDoorInfo[L0573_ps_Door->Type].Defense) {
                L0574_puc_Square = &G0271_ppuc_CurrentMapData[P0504_ui_MapX][P0505_ui_MapY];
                if (M036_DOOR_STATE(*L0574_puc_Square) == C4_DOOR_STATE_CLOSED) {
                        if (P0508_Ticks) {
                                M033_SET_MAP_AND_TIME(L0575_s_Event.Map_Time, G0272_i_CurrentMapIndex, G0313_ul_GameTime + P0508_Ticks);
                                L0575_s_Event.A.A.Type = C02_EVENT_DOOR_DESTRUCTION;
                                L0575_s_Event.A.A.Priority = 0;
                                L0575_s_Event.B.Location.MapX = P0504_ui_MapX;
                                L0575_s_Event.B.Location.MapY = P0505_ui_MapY;
                                F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0575_s_Event);
                        } else {
                                M037_SET_DOOR_STATE(*L0574_puc_Square, C5_DOOR_STATE_DESTROYED);
                        }
                        return C1_TRUE;
                }
        }
        return C0_FALSE;
}
#endif
