#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA042_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA459_P20JA_P20JB_P31J
int16_t G0587_i_HideMousePointerRequestCount = 1;
int16_t G0588_i_MouseButtonsStatus;
BOOLEAN G0592_B_BuildMousePointerScreenAreaRequested; /* Unused */
BOOLEAN G0597_B_IgnoreMouseMovements;
BOOLEAN G0598_B_MousePointerBitmapUpdated = C1_TRUE;
unsigned int16_t G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap; /* If non zero then the mouse pointer bitmap is a champion icon */
BOOLEAN G0600_B_UseObjectAsMousePointerBitmap; /* If true and G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap = 0 then the mouse pointer bitmap is an object icon */
BOOLEAN G0601_B_UseHandAsMousePointerBitmap; /* If true and G0600_B_UseObjectAsMousePointerBitmap = C0_FALSE and G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap = 0 then the mouse pointer bitmap is the hand else it is the arrow */
int16_t G2010_; /* G0589_i_MousePointerHotspotX ? */
int16_t G2011_; /* G0590_i_MousePointerHotspotY ? */
int16_t G2194_Unreferenced = 0;
char G2205_Unreferenced[8];
char G2233_Unreferenced[6];
int16_t G2234_Unreferenced;
long G2235_Unreferenced;
int16_t G2236_Unreferenced;
char G2239_Unreferenced[6];
#endif
#ifdef MEDIA418_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_P31J
CHAMPION G1068_as_Champions[4];
#endif
PARTY_INFO G0407_s_Party;
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#ifndef NOCOPYPROTECTION
int16_t G0068_i_CheckLastEvent22Time_CPSE = C00512_FALSE;
#endif
#endif
#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 G0408_ai_CodePatch3_CPSE[34];
#endif
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
#ifndef NOCOPYPROTECTION
char G0408_ai_CodePatch3_CPSE[289];
#endif
#endif
int16_t G0409_ai_ChampionPendingDamage[4];
unsigned int16_t G0410_ai_ChampionPendingWounds[4];
int16_t G0411_i_LeaderIndex = CM1_CHAMPION_NONE;
#ifdef MEDIA099_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
LEADER_HAND_OBJECT G4055_s_LeaderHandObject;
unsigned int16_t G0415_ui_LeaderEmptyHanded;
#endif
int16_t G0416_i_DelayMouse_Useless; /* BUG0_00 Useless code */
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t G2139_i_RenameCommand;
#endif
#ifdef MEDIA191_S10EA_S10EB_S11E_S12E_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A21E_A22E /* CHANGE4_00_LOCALIZATION Translation to German language */
char* G0417_apc_BaseSkillNames[4] = { "FIGHTER", "NINJA", "PRIEST", "WIZARD" };
#endif
#ifdef MEDIA252_S12G /* CHANGE4_00_LOCALIZATION Translation to German language */
char* G0417_apc_BaseSkillNames[4] = { "KAMPFER", "NINJA", "PRIESTER", "MAGIER" };
#endif
#ifdef MEDIA446_A20G_A22G
char* G0417_apc_BaseSkillNames[4] = { "KAEMPFER", "NINJA", "PRIESTER", "MAGIER" };
#endif
#ifdef MEDIA261_S13FA_S13FB_A20F /* CHANGE5_00_LOCALIZATION Translation to French language */
char* G0417_apc_BaseSkillNames[4] = { "GUERRIER", "NINJA", "PRETRE", "SORCIER" };
#endif
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_04_IMPROVEMENT */
#ifndef NOCOPYPROTECTION
long G0418_l_LastEvent22Time_CPSE;
#endif
#endif
#ifdef MEDIA282_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE7_04_IMPROVEMENT */
#ifndef NOCOPYPROTECTION
long G0418_l_LastEvent22Time_CPSE = -505; /* This value ensures that the first time F0003_MAIN_ProcessNewPartyMap_CPSE is run it will trigger CPSE and allows adding events in F0238_TIMELINE_AddEvent_GetEventIndex_CPSE */
#endif
#endif


#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "player"
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
segment "playsub"
#endif

#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#include "REVIVE.C"
#endif

#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#include "PORTRAIT.C"
#endif

void F0284_CHAMPION_SetPartyDirection(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0600_i_Direction)
#endif
#ifdef MEDIA182_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
REGISTER int16_t P0600_i_Direction FINAL_SEPARATOR
#endif
#ifdef MEDIA331_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
int16_t P0600_i_Direction FINAL_SEPARATOR
#endif
{
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        REGISTER CHAMPION* L0835_ps_Champion;
        REGISTER int16_t L0834_i_Delta;
#endif
#ifdef MEDIA182_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        REGISTER unsigned int16_t L0833_ui_ChampionIndex;
#endif
#ifdef MEDIA180_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L0834_i_Delta;
        REGISTER CHAMPION* L0835_ps_Champion;
#endif


#ifdef MEDIA182_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE7_16_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        if (P0600_i_Direction == G0308_i_PartyDirection)
                return;
        if ((L0834_i_Delta = P0600_i_Direction - G0308_i_PartyDirection) < 0) {
                L0834_i_Delta += 4;
        }
        L0835_ps_Champion = M516_CHAMPIONS;
        for (L0833_ui_ChampionIndex = C00_CHAMPION_FIRST; L0833_ui_ChampionIndex < G0305_ui_PartyChampionCount; L0833_ui_ChampionIndex++) {
                L0835_ps_Champion->Cell = M021_NORMALIZE(L0835_ps_Champion->Cell + L0834_i_Delta);
                L0835_ps_Champion->Direction = M021_NORMALIZE(L0835_ps_Champion->Direction + L0834_i_Delta);
                L0835_ps_Champion++;
        }
        G0308_i_PartyDirection = P0600_i_Direction;
        F0296_CHAMPION_DrawChangedObjectIcons();
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_16_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                        move.w  P0600_i_Direction(A6),D3
                        move.w  G0308_i_PartyDirection(A4),D2
                        move.w  D3,G0308_i_PartyDirection(A4)
                        sub.w   D2,D3
                        beq.s   T0284005_Return
                        addq.w  #4,D3
                        lea     M516_CHAMPIONS(A4),A0
                        move.w  G0305_ui_PartyChampionCount(A4),D0
                T0284001_Loop:
                        add.b   D3,0x001D(A0)                           /* Champion Cell */
                        andi.b  #0x03,0x001D(A0)                        /* Champion Cell */
                        add.b   D3,0x001C(A0)                           /* Champion Direction */
                        andi.b  #0x03,0x001C(A0)                        /* Champion Direction */
                        lea     800(A0),A0                              /* Proceed to next champion in party */
                        subq.w  #1,D0
                        bgt.s   T0284001_Loop
        }
        F0296_CHAMPION_DrawChangedObjectIcons();
        T0284005_Return: ;
#endif
#ifdef MEDIA613_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
        asm {
                        move.w  P0600_i_Direction(A6),D1
                        move.w  G0308_i_PartyDirection(A5),D2
                        move.w  D1,G0308_i_PartyDirection(A5)
                        sub.w   D2,D1
                        beq.s   @T0284005
                        addq.w  #4,D1
                        lea     M516_CHAMPIONS(A5),A0
                        move.w  G0305_ui_PartyChampionCount(A5),D0
                @T0284001:
                        add.b   D1,0x001D(A0)                           /* Champion Cell */
                        andi.b  #0x03,0x001D(A0)                        /* Champion Cell */
                        add.b   D1,0x001C(A0)                           /* Champion Direction */
                        andi.b  #0x03,0x001C(A0)                        /* Champion Direction */
                        lea     320(A0),A0                              /* Proceed to next champion in party */
                        subq.w  #1,D0
                        bgt.s   @T0284001
        }
        F0296_CHAMPION_DrawChangedObjectIcons();
        asm {
                @T0284005:
        }
#endif
}

int16_t F0285_CHAMPION_GetIndexInCell(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0601_ui_Cell)
REGISTER unsigned int16_t P0601_ui_Cell 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 P0601_ui_Cell FINAL_SEPARATOR
#endif
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER CHAMPION* L0837_ps_Champion;
#endif
        REGISTER unsigned int16_t L0836_ui_ChampionIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER CHAMPION* L0837_ps_Champion;
#endif


#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        for (L0836_ui_ChampionIndex = C00_CHAMPION_FIRST, L0837_ps_Champion = M516_CHAMPIONS; L0836_ui_ChampionIndex < G0305_ui_PartyChampionCount; L0836_ui_ChampionIndex++, L0837_ps_Champion++) {
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L0837_ps_Champion = M516_CHAMPIONS;
        for (L0836_ui_ChampionIndex = C00_CHAMPION_FIRST; L0836_ui_ChampionIndex < G0305_ui_PartyChampionCount; L0836_ui_ChampionIndex++, L0837_ps_Champion++) {
#endif
                if ((L0837_ps_Champion->Cell == P0601_ui_Cell) && L0837_ps_Champion->CurrentHealth) {
                        return L0836_ui_ChampionIndex;
                }
        }
        return CM1_CHAMPION_NONE;
}

int16_t F0286_CHAMPION_GetTargetChampionIndex(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0602_i_MapX, P0603_i_MapY, P0604_ui_Cell)
#endif
int16_t          P0602_i_MapX  SEPARATOR
int16_t          P0603_i_MapY  SEPARATOR
unsigned int16_t P0604_ui_Cell FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0838_ui_Counter;
        REGISTER int16_t L0839_i_ChampionIndex;
        unsigned char L0840_auc_OrderedCellsToAttack[4];


        if (G0305_ui_PartyChampionCount && (M038_DISTANCE(P0602_i_MapX, P0603_i_MapY, G0306_i_PartyMapX, G0307_i_PartyMapY) <= 1)) {
                F0229_GROUP_SetOrderedCellsToAttack(M772_CAST_PC(L0840_auc_OrderedCellsToAttack), G0306_i_PartyMapX, G0307_i_PartyMapY, P0602_i_MapX, P0603_i_MapY, P0604_ui_Cell);
                for (L0838_ui_Counter = 0; L0838_ui_Counter < 4; L0838_ui_Counter++) {
                        if ((L0839_i_ChampionIndex = F0285_CHAMPION_GetIndexInCell(L0840_auc_OrderedCellsToAttack[L0838_ui_Counter])) >= 0) {
                                return L0839_i_ChampionIndex;
                        }
                }
        }
        return CM1_CHAMPION_NONE;
}

#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#include "CHAMDRAW.C"
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#include "AMMO.C"
#endif

void F0297_CHAMPION_PutObjectInLeaderHand(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0621_T_Thing, P0622_B_SetMousePointerToObjectInMainLoop)
#endif
THING   P0621_T_Thing                             SEPARATOR
BOOLEAN P0622_B_SetMousePointerToObjectInMainLoop FINAL_SEPARATOR /* If C1_TRUE, the mouse pointer is refreshed on screen by F0002_MAIN_GameLoop_CPSDF() but only if the viewport does not contain an inventory (G0423_i_InventoryChampionOrdinal = 0). If C0_FALSE, the mouse pointer is refreshed immediately. This is used when the viewport contains an inventory (G0423_i_InventoryChampionOrdinal != 0) */
{
        if (P0621_T_Thing == C0xFFFF_THING_NONE) {
                return;
        }
        G0415_ui_LeaderEmptyHanded = C0_FALSE;
        F0036_OBJECT_ExtractIconFromBitmap(G4055_s_LeaderHandObject.IconIndex = F0033_OBJECT_GetIconIndex(G4055_s_LeaderHandObject.Thing = P0621_T_Thing), M775_CAST_PL(G4055_s_LeaderHandObject.BitmapIconForMousePointer));
        F0077_MOUSE_EnableScreenUpdate_CPSE();
        F0034_OBJECT_DrawLeaderHandObjectName(P0621_T_Thing);
        if (P0622_B_SetMousePointerToObjectInMainLoop) {
                G0325_B_SetMousePointerToObjectInMainLoop = C1_TRUE;
        } else {
                F0068_MOUSE_SetPointerToObject(G4055_s_LeaderHandObject.BitmapIconForMousePointer);
        }
        F0078_MOUSE_DisableScreenUpdate();
        if (G0411_i_LeaderIndex != CM1_CHAMPION_NONE) {
                M516_CHAMPIONS[G0411_i_LeaderIndex].Load += F0140_DUNGEON_GetObjectWeight(P0621_T_Thing);
                M008_SET(M516_CHAMPIONS[G0411_i_LeaderIndex].Attributes, MASK0x0200_LOAD);
                F0292_CHAMPION_DrawState(G0411_i_LeaderIndex);
        }
}

THING F0298_CHAMPION_GetObjectRemovedFromLeaderHand(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER THING L0890_T_LeaderHandObject;


        G0415_ui_LeaderEmptyHanded = C1_TRUE;
        if ((L0890_T_LeaderHandObject = G4055_s_LeaderHandObject.Thing) != C0xFFFF_THING_NONE) {
                G4055_s_LeaderHandObject.Thing = C0xFFFF_THING_NONE;
                G4055_s_LeaderHandObject.IconIndex = C0xFFFF_ICON_NONE;
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                F0035_OBJECT_ClearLeaderHandObjectName();
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_13_OPTIMIZATION */
                F0067_MOUSE_SetPointerToNormal((G0411_i_LeaderIndex == CM1_CHAMPION_NONE) ? C0_POINTER_ARROW : C1_POINTER_HAND);
#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_13_OPTIMIZATION Function call replaced by an equivalent and smaller call. This function includes the function call and test used in previous versions */
                F0069_MOUSE_SetPointer();
#endif
                F0078_MOUSE_DisableScreenUpdate();
                if (G0411_i_LeaderIndex != CM1_CHAMPION_NONE) {
                        M516_CHAMPIONS[G0411_i_LeaderIndex].Load -= F0140_DUNGEON_GetObjectWeight(L0890_T_LeaderHandObject);
                        M008_SET(M516_CHAMPIONS[G0411_i_LeaderIndex].Attributes, MASK0x0200_LOAD);
                        F0292_CHAMPION_DrawState(G0411_i_LeaderIndex);
                }
        }
        return L0890_T_LeaderHandObject;
}

STATICFUNCTION void F0299_CHAMPION_ApplyObjectModifiersToStatistics(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0623_ps_Champion, P0624_ui_SlotIndex, P0625_ui_IconIndex, P0626_i_ModifierFactor, P0627_T_Thing)
#endif
REGISTER CHAMPION*        P0623_ps_Champion      SEPARATOR
REGISTER unsigned int16_t P0624_ui_SlotIndex     SEPARATOR
REGISTER unsigned int16_t P0625_ui_IconIndex     SEPARATOR
int16_t                   P0626_i_ModifierFactor SEPARATOR
THING                     P0627_T_Thing          FINAL_SEPARATOR
#define AP0624_ui_StatisticValueIndex P0624_ui_SlotIndex
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER WEAPON* L0893_ps_Weapon;
        REGISTER int16_t L0892_i_Modifier;
#endif
        REGISTER int16_t L0891_i_Multiple;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L0892_i_Modifier;
        WEAPON* L0893_ps_Weapon;
#endif
#define AL0891_i_StatisticIndex L0891_i_Multiple
#define AL0891_i_ThingType      L0891_i_Multiple


        L0892_i_Modifier = 0;
        if ((((AL0891_i_ThingType = M012_TYPE(P0627_T_Thing)) == C05_THING_TYPE_WEAPON) || (AL0891_i_ThingType == C06_THING_TYPE_ARMOUR)) && (P0624_ui_SlotIndex >= C00_SLOT_READY_HAND) && (P0624_ui_SlotIndex <= C12_SLOT_QUIVER_LINE1_1)) {
                L0893_ps_Weapon = (WEAPON*)F0156_DUNGEON_GetThingData(P0627_T_Thing);
                if (((AL0891_i_ThingType == C05_THING_TYPE_WEAPON) && L0893_ps_Weapon->Cursed) || ((AL0891_i_ThingType == C06_THING_TYPE_ARMOUR) && ((ARMOUR*)L0893_ps_Weapon)->Cursed)) {
                        AL0891_i_StatisticIndex = C0_STATISTIC_LUCK;
                        L0892_i_Modifier = -3;
                        goto T0299044_ApplyModifier;
                }
        }
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_25_FIX The Luck modifier of the Rabbit's Foot is applied when it is inside a chest */
        if (P0625_ui_IconIndex == C137_ICON_JUNK_RABBITS_FOOT) { /* BUG0_37 The contents of a chest are refreshed when grabbing or putting a Rabbit's Foot anywhere in the inventory. An object in a chest may disappear when grabbing a Rabbit's Foot from a chest. A champion may have a permanent bonus or malus to the (hidden) Luck statistic. The Luck modifier of the Rabbit's Foot is applied when it is inside a chest while it should not. This causes the following issues:
- If a chest is open then each time you grab or put a Rabbit's Foot anywhere in the inventory the chest contents are drawn again in the panel. If there are empty slots in the chest then objects are reorganized so they occupy the first slots of the chest
- If there is an object in the leader hand when grabbing a Rabbit's Foot from a chest then the next object in the chest disappears and becomes an orphan. This occurs because when processing F0302_CHAMPION_ProcessCommands28To65_ClickOnSlotBox:
a) F0300_CHAMPION_GetObjectRemovedFromSlot is called to remove the Rabbit's Foot from the slot which in turn calls F0299_CHAMPION_ApplyObjectModifiersToStatistics to remove the Rabbit's Foot modifier. This sets the MASK0x0800_PANEL flag for the champion.
b) F0297_CHAMPION_PutObjectInLeaderHand is called to place the Rabbit's Foot in hand. This calls F0292_CHAMPION_DrawState. Because MASK0x0800_PANEL is set, the chest is closed an opened again, shifting the object right after the slot where the Rabbit's Foot was to the previous slot.
c) F0301_CHAMPION_AddObjectInSlot is called to place the object that was in the leader hand in the Chest, overwriting the object that was shifted there which has now become an orphan thing.
- When a champion puts a Rabbit's Foot in a chest, that champion's Luck is increased. When a champion removes a Rabbit's Foot from a chest, that champion's Luck is decreased. If you move a chest containing a Rabbit's Foot from one champion to another between these two operations, then the first champion keeps a permanent Luck bonus and the second champion has no bonus for possessing a Rabbit's Foot and will even get a malus when removing it from the chest */
#endif
#ifdef MEDIA278_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 /* CHANGE7_25_FIX The Luck modifier of the Rabbit's Foot is not applied when it is inside a chest */
        if ((P0625_ui_IconIndex == C137_ICON_JUNK_RABBITS_FOOT) && (P0624_ui_SlotIndex < C30_SLOT_CHEST_1)) {
#endif
                AL0891_i_StatisticIndex = C0_STATISTIC_LUCK;
                L0892_i_Modifier = 10;
        } else {
                if (P0624_ui_SlotIndex == C01_SLOT_ACTION_HAND) {
                        if (P0625_ui_IconIndex == C045_ICON_WEAPON_MACE_OF_ORDER) {
                                AL0891_i_StatisticIndex = C1_STATISTIC_STRENGTH;
#ifdef PC_FIX_CODE_SIZE
        L0891_i_Multiple = 40;
        L0891_i_Multiple = 30;
#endif
                                L0892_i_Modifier = 5;
                        } else {
                                AL0891_i_StatisticIndex = C8_STATISTIC_MANA;
                                if ((P0625_ui_IconIndex >= C020_ICON_WEAPON_STAFF_OF_CLAWS_EMPTY) && (P0625_ui_IconIndex <= C022_ICON_WEAPON_STAFF_OF_CLAWS_FULL)) {
                                        L0892_i_Modifier = 4;
                                } else {
                                        if ((P0625_ui_IconIndex >= C058_ICON_WEAPON_STAFF) && (P0625_ui_IconIndex <= C066_ICON_WEAPON_SCEPTRE_OF_LYF)) {
                                                switch (P0625_ui_IconIndex) {
                                                        case C058_ICON_WEAPON_STAFF:
                                                                L0892_i_Modifier = 2;
                                                                break;
                                                        case C059_ICON_WEAPON_WAND:
                                                                L0892_i_Modifier = 1;
                                                                break;
                                                        case C060_ICON_WEAPON_TEOWAND:
                                                                L0892_i_Modifier = 6;
                                                                break;
                                                        case C061_ICON_WEAPON_YEW_STAFF:
#ifdef PC_FIX_CODE_SIZE
        L0891_i_Multiple++;
        L0891_i_Multiple++;
        L0891_i_Multiple = 28;
#endif
                                                                L0892_i_Modifier = 4;
                                                                break;
                                                        case C062_ICON_WEAPON_STAFF_OF_MANAR_STAFF_OF_IRRA:
                                                                L0892_i_Modifier = 10;
                                                                break;
                                                        case C063_ICON_WEAPON_SNAKE_STAFF_CROSS_OF_NETA:
                                                                L0892_i_Modifier = 8;
                                                                break;
                                                        case C064_ICON_WEAPON_THE_CONDUIT_SERPENT_STAFF:
                                                                L0892_i_Modifier = 16;
                                                                break;
                                                        case C065_ICON_WEAPON_DRAGON_SPIT:
                                                                L0892_i_Modifier = 7;
                                                                break;
                                                        case C066_ICON_WEAPON_SCEPTRE_OF_LYF:
                                                                L0892_i_Modifier = 5;
                                                }
                                        } else {
                                                switch (P0625_ui_IconIndex) {
                                                        case C038_ICON_WEAPON_DELTA_SIDE_SPLITTER:
                                                                L0892_i_Modifier = 1;
                                                                break;
                                                        case C041_ICON_WEAPON_THE_INQUISITOR_DRAGON_FANG:
                                                                L0892_i_Modifier = 2;
                                                                break;
                                                        case C040_ICON_WEAPON_VORPAL_BLADE:
                                                                L0892_i_Modifier = 4;
                                                }
                                        }
                                }
                        }
                } else {
                        if (P0624_ui_SlotIndex == C04_SLOT_LEGS) {
                                if (P0625_ui_IconIndex == C142_ICON_ARMOUR_POWERTOWERS) {
                                        AL0891_i_StatisticIndex = C1_STATISTIC_STRENGTH;
#ifdef PC_FIX_CODE_SIZE
        L0891_i_Multiple = 21;
        L0891_i_Multiple = 22;
#endif
                                        L0892_i_Modifier = 10;
                                }
                        } else {
                                if (P0624_ui_SlotIndex == C02_SLOT_HEAD) {
                                        if (P0625_ui_IconIndex == C104_ICON_ARMOUR_CROWN_OF_NERRA) {
                                                AL0891_i_StatisticIndex = C3_STATISTIC_WISDOM;
#ifdef PC_FIX_CODE_SIZE
        L0891_i_Multiple++;
        L0891_i_Multiple++;
        L0891_i_Multiple = 23;
#endif
                                                L0892_i_Modifier = 10;
                                        } else {
                                                if (P0625_ui_IconIndex == C140_ICON_ARMOUR_DEXHELM) {
                                                        AL0891_i_StatisticIndex = C2_STATISTIC_DEXTERITY;
                                                        L0892_i_Modifier = 10;
                                                }
                                        }
                                } else {
                                        if (P0624_ui_SlotIndex == C03_SLOT_TORSO) {
                                                if (P0625_ui_IconIndex == C141_ICON_ARMOUR_FLAMEBAIN) {
                                                        AL0891_i_StatisticIndex = C6_STATISTIC_ANTIFIRE;
                                                        L0892_i_Modifier = 12;
                                                } else {
                                                        if (P0625_ui_IconIndex == C081_ICON_ARMOUR_CLOAK_OF_NIGHT) {
#ifdef PC_FIX_CODE_SIZE
        L0891_i_Multiple++;
        L0891_i_Multiple++;
        L0891_i_Multiple = 25;
        L0891_i_Multiple = 26;
#endif
                                                                AL0891_i_StatisticIndex = C2_STATISTIC_DEXTERITY;
                                                                L0892_i_Modifier = 8;
                                                        }
                                                }
                                        } else {
                                                if (P0624_ui_SlotIndex == C10_SLOT_NECK) {
                                                        if ((P0625_ui_IconIndex >= C010_ICON_JUNK_JEWEL_SYMAL_UNEQUIPPED) && (P0625_ui_IconIndex <= C011_ICON_JUNK_JEWEL_SYMAL_EQUIPPED)) {
                                                                AL0891_i_StatisticIndex = C5_STATISTIC_ANTIMAGIC;
                                                                L0892_i_Modifier = 15;
                                                        } else {
                                                                if (P0625_ui_IconIndex == C081_ICON_ARMOUR_CLOAK_OF_NIGHT) {
                                                                        AL0891_i_StatisticIndex = C2_STATISTIC_DEXTERITY;
                                                                        L0892_i_Modifier = 8;
                                                                } else {
                                                                        if (P0625_ui_IconIndex == C122_ICON_JUNK_MOONSTONE) {
                                                                                AL0891_i_StatisticIndex = C8_STATISTIC_MANA;
                                                                                L0892_i_Modifier = 3;
                                                                        }
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }
        T0299044_ApplyModifier:
        if (L0892_i_Modifier) {
                L0892_i_Modifier *= P0626_i_ModifierFactor;
                if (AL0891_i_StatisticIndex == C8_STATISTIC_MANA) {
                        P0623_ps_Champion->MaximumMana += L0892_i_Modifier;
                } else {
                        if (AL0891_i_StatisticIndex < C6_STATISTIC_ANTIFIRE + 1) {
                                for (AP0624_ui_StatisticValueIndex = C0_MAXIMUM; AP0624_ui_StatisticValueIndex <= C2_MINIMUM; P0623_ps_Champion->Statistics[AL0891_i_StatisticIndex][AP0624_ui_StatisticValueIndex++] += L0892_i_Modifier); /* BUG0_38 A champion is much luckier than expected during combat when equipped with at least 4 cursed objects. Champion statistic values are stored as one byte unsigned integers which can store values between 0 to 255. Each champion has a minimum, a maximum and a current value for each of the statistics. When an object modifier is applied to a statistic, all three values are modified but there is no check to make sure the new values stay in the bounds of 0 to 255. This is not an issue in most cases because nearly all modifiers are positive and with relatively small values so that any combination of champion statistic value with these modifiers will result in valid values. The only issue is with the hidden luck statistic and the modifier for cursed objects which is the only negative modifier in the game (-3). The minimum luck value for all champions is set to 10 at the beginning of the game and is only changed by object modifiers. If enough cursed objects are equipped (between 4 and 6) then the minimum value 'wraps around' and becomes a large value (254 with 4 cursed objects, 251 with 5 cursed objects and 248 with 6 cursed objects). The first time that the luck of the champion is tested after the cursed objects are equipped, the current luck value is set to its minimum value (248, 251 or 254) because the game detects that the current value is smaller than the minimum allowed. During the following luck tests, if the test succeeds, the current luck is decreased by 2 and then bounded between the minimum and maximum values. The current value is then smaller than the minimum value so the current luck value is set to its minimum value (248, 251 or 254). If the test fails, the current luck is increased by 2 and then bounded between the minimum and maximum values. The current value is then larger than the minimum value, however it is larger than the maximum value so the current value is set to its maximum value. During the next luck test, the current value will again be smaller than the minimum and be reset to the minimum value. As a consequence, while the cursed objects are equipped, the current luck value can only have two possible values: either its maximum value, or its minimum value (which is even larger at 248, 251 or 254) so the champion is always luckier than he should be */
                        }
                }
                M008_SET(P0623_ps_Champion->Attributes, MASK0x0800_PANEL | MASK0x0100_STATISTICS);
        }
}

THING F0300_CHAMPION_GetObjectRemovedFromSlot(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0628_ui_ChampionIndex, P0629_ui_SlotIndex)
unsigned int16_t          P0628_ui_ChampionIndex SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0628_ui_ChampionIndex SEPARATOR
#endif
REGISTER unsigned int16_t P0629_ui_SlotIndex     FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0896_ps_Champion;
        REGISTER WEAPON* L0897_ps_Weapon;
        REGISTER THING L0894_T_Thing;
        REGISTER int16_t L0895_i_IconIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        BOOLEAN L0898_B_IsInventoryChampion;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER BOOLEAN L0898_B_IsInventoryChampion;
#endif


        L0896_ps_Champion = &M516_CHAMPIONS[P0628_ui_ChampionIndex];
        if (P0629_ui_SlotIndex >= C30_SLOT_CHEST_1) {
                L0894_T_Thing = G0425_aT_ChestSlots[P0629_ui_SlotIndex - C30_SLOT_CHEST_1];
                G0425_aT_ChestSlots[P0629_ui_SlotIndex - C30_SLOT_CHEST_1] = C0xFFFF_THING_NONE;
        } else {
                L0894_T_Thing = L0896_ps_Champion->Slots[P0629_ui_SlotIndex];
                L0896_ps_Champion->Slots[P0629_ui_SlotIndex] = C0xFFFF_THING_NONE;
        }
        if (L0894_T_Thing == C0xFFFF_THING_NONE) {
                return C0xFFFF_THING_NONE;
        }
        L0898_B_IsInventoryChampion = (M000_INDEX_TO_ORDINAL(P0628_ui_ChampionIndex) == G0423_i_InventoryChampionOrdinal);
        L0895_i_IconIndex = F0033_OBJECT_GetIconIndex(L0894_T_Thing);
        F0299_CHAMPION_ApplyObjectModifiersToStatistics(L0896_ps_Champion, P0629_ui_SlotIndex, L0895_i_IconIndex, -1, L0894_T_Thing); /* Remove objet modifiers */
        L0897_ps_Weapon = (WEAPON*)F0156_DUNGEON_GetThingData(L0894_T_Thing);
        if (P0629_ui_SlotIndex == C10_SLOT_NECK) {
                if ((L0895_i_IconIndex >= C012_ICON_JUNK_ILLUMULET_UNEQUIPPED) && (L0895_i_IconIndex <= C013_ICON_JUNK_ILLUMULET_EQUIPPED)) {
                        ((JUNK*)L0897_ps_Weapon)->ChargeCount = 0;
                        G0407_s_Party.MagicalLightAmount -= G0039_ai_Graphic562_LightPowerToLightAmount[2];
                        F0337_INVENTORY_SetDungeonViewPalette();
                } else {
                        if ((L0895_i_IconIndex >= C010_ICON_JUNK_JEWEL_SYMAL_UNEQUIPPED) && (L0895_i_IconIndex <= C011_ICON_JUNK_JEWEL_SYMAL_EQUIPPED)) {
                                ((JUNK*)L0897_ps_Weapon)->ChargeCount = 0;
                        }
                }
        }
        F0291_CHAMPION_DrawSlot(P0628_ui_ChampionIndex, P0629_ui_SlotIndex);
        if (L0898_B_IsInventoryChampion) {
                M008_SET(L0896_ps_Champion->Attributes, MASK0x4000_VIEWPORT);
        }
        if (P0629_ui_SlotIndex < C02_SLOT_HEAD) {
                if (P0629_ui_SlotIndex == C01_SLOT_ACTION_HAND) {
                        M008_SET(L0896_ps_Champion->Attributes, MASK0x8000_ACTION_HAND);
                        if (G0506_ui_ActingChampionOrdinal == M000_INDEX_TO_ORDINAL(P0628_ui_ChampionIndex)) {
                                F0388_MENUS_ClearActingChampion();
                        }
                        if ((L0895_i_IconIndex >= C030_ICON_SCROLL_SCROLL_OPEN) && (L0895_i_IconIndex <= C031_ICON_SCROLL_SCROLL_CLOSED)) {
                                ((SCROLL*)L0897_ps_Weapon)->Closed = C1_TRUE;
                                F0296_CHAMPION_DrawChangedObjectIcons();
                        }
                }
                if ((L0895_i_IconIndex >= C004_ICON_WEAPON_TORCH_UNLIT) && (L0895_i_IconIndex <= C007_ICON_WEAPON_TORCH_LIT)) {
                        L0897_ps_Weapon->Lit = C0_FALSE;
                        F0337_INVENTORY_SetDungeonViewPalette();
                        F0296_CHAMPION_DrawChangedObjectIcons();
                }
                if (L0898_B_IsInventoryChampion && (P0629_ui_SlotIndex == C01_SLOT_ACTION_HAND)) {
                        if (L0895_i_IconIndex == C144_ICON_CONTAINER_CHEST_CLOSED) {
#ifdef MEDIA602_X30J_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                if (L0894_T_Thing == G0426_T_OpenChest)
#endif
                                        F0334_INVENTORY_CloseChest();
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_26_OPTIMIZATION */
                                M008_SET(L0896_ps_Champion->Attributes, MASK0x0800_PANEL);
#endif
#ifdef MEDIA278_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 /* CHANGE7_26_OPTIMIZATION Code deduplication */
                                goto T0300011;
#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_26_OPTIMIZATION */ /* ANOMALY_ST_BRANCH */
                        else {
#endif
                                if ((L0895_i_IconIndex >= C030_ICON_SCROLL_SCROLL_OPEN) && (L0895_i_IconIndex <= C031_ICON_SCROLL_SCROLL_CLOSED)) {
                                        T0300011:
                                        M008_SET(L0896_ps_Champion->Attributes, MASK0x0800_PANEL);
                                }
#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_26_OPTIMIZATION */
                        }
#endif
                }
        }
        L0896_ps_Champion->Load -= F0140_DUNGEON_GetObjectWeight(L0894_T_Thing);
        M008_SET(L0896_ps_Champion->Attributes, MASK0x0200_LOAD);
        return L0894_T_Thing;
}

void F0301_CHAMPION_AddObjectInSlot(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0630_ui_ChampionIndex, P0631_T_Thing, P0632_ui_SlotIndex)
#endif
REGISTER unsigned int16_t P0630_ui_ChampionIndex SEPARATOR
REGISTER THING            P0631_T_Thing          SEPARATOR
REGISTER unsigned int16_t P0632_ui_SlotIndex     FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0900_ps_Champion;
        REGISTER WEAPON* L0901_ps_Weapon;
        REGISTER int16_t L0899_i_IconIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        BOOLEAN L0902_B_IsInventoryChampion;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER BOOLEAN L0902_B_IsInventoryChampion;
#endif


        if (P0631_T_Thing == C0xFFFF_THING_NONE)
                return;
        L0900_ps_Champion = &M516_CHAMPIONS[P0630_ui_ChampionIndex];
        if (P0632_ui_SlotIndex >= C30_SLOT_CHEST_1) {
                G0425_aT_ChestSlots[P0632_ui_SlotIndex - C30_SLOT_CHEST_1] = P0631_T_Thing;
        } else {
                L0900_ps_Champion->Slots[P0632_ui_SlotIndex] = P0631_T_Thing;
        }
        L0900_ps_Champion->Load += F0140_DUNGEON_GetObjectWeight(P0631_T_Thing);
        M008_SET(L0900_ps_Champion->Attributes, MASK0x0200_LOAD);
        L0899_i_IconIndex = F0033_OBJECT_GetIconIndex(P0631_T_Thing);
        L0902_B_IsInventoryChampion = (M000_INDEX_TO_ORDINAL(P0630_ui_ChampionIndex) == G0423_i_InventoryChampionOrdinal);
        F0299_CHAMPION_ApplyObjectModifiersToStatistics(L0900_ps_Champion, P0632_ui_SlotIndex, L0899_i_IconIndex, 1, P0631_T_Thing); /* Add objet modifiers */
        L0901_ps_Weapon = (WEAPON*)F0156_DUNGEON_GetThingData(P0631_T_Thing);
        if (P0632_ui_SlotIndex < C02_SLOT_HEAD) {
                if (P0632_ui_SlotIndex == C01_SLOT_ACTION_HAND) {
                        M008_SET(L0900_ps_Champion->Attributes, MASK0x8000_ACTION_HAND);
                        if (G0506_ui_ActingChampionOrdinal == M000_INDEX_TO_ORDINAL(P0630_ui_ChampionIndex)) {
                                F0388_MENUS_ClearActingChampion();
                        }
                        if ((L0899_i_IconIndex >= C030_ICON_SCROLL_SCROLL_OPEN) && (L0899_i_IconIndex <= C031_ICON_SCROLL_SCROLL_CLOSED)) {
                                ((SCROLL*)L0901_ps_Weapon)->Closed = C0_FALSE;
                                F0296_CHAMPION_DrawChangedObjectIcons();
                        }
                }
                if (L0899_i_IconIndex == C004_ICON_WEAPON_TORCH_UNLIT) {
                        L0901_ps_Weapon->Lit = C1_TRUE;
                        F0337_INVENTORY_SetDungeonViewPalette();
                        F0296_CHAMPION_DrawChangedObjectIcons();
                } else {
                        if (L0902_B_IsInventoryChampion && (P0632_ui_SlotIndex == C01_SLOT_ACTION_HAND) &&
                            ((L0899_i_IconIndex == C144_ICON_CONTAINER_CHEST_CLOSED) || ((L0899_i_IconIndex >= C030_ICON_SCROLL_SCROLL_OPEN) && (L0899_i_IconIndex <= C031_ICON_SCROLL_SCROLL_CLOSED)))) {
                                M008_SET(L0900_ps_Champion->Attributes, MASK0x0800_PANEL);
                        }
                }
        } else {
                if (P0632_ui_SlotIndex == C10_SLOT_NECK) {
                        if ((L0899_i_IconIndex >= C012_ICON_JUNK_ILLUMULET_UNEQUIPPED) && (L0899_i_IconIndex <= C013_ICON_JUNK_ILLUMULET_EQUIPPED)) {
                                ((JUNK*)L0901_ps_Weapon)->ChargeCount = 1;
                                G0407_s_Party.MagicalLightAmount += G0039_ai_Graphic562_LightPowerToLightAmount[2];
                                F0337_INVENTORY_SetDungeonViewPalette();
                                L0899_i_IconIndex++;
                        } else {
                                if ((L0899_i_IconIndex >= C010_ICON_JUNK_JEWEL_SYMAL_UNEQUIPPED) && (L0899_i_IconIndex <= C011_ICON_JUNK_JEWEL_SYMAL_EQUIPPED)) {
                                        ((JUNK*)L0901_ps_Weapon)->ChargeCount = 1;
                                        L0899_i_IconIndex++;
                                }
                        }
                }
        }
        F0291_CHAMPION_DrawSlot(P0630_ui_ChampionIndex, P0632_ui_SlotIndex);
        if (L0902_B_IsInventoryChampion) {
                M008_SET(L0900_ps_Champion->Attributes, MASK0x4000_VIEWPORT);
        }
}

void F0302_CHAMPION_ProcessCommands28To65_ClickOnSlotBox(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0633_ui_SlotBoxIndex)
unsigned int16_t P0633_ui_SlotBoxIndex FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0633_ui_SlotBoxIndex FINAL_SEPARATOR
#endif
{
        REGISTER unsigned int16_t L0903_ui_ChampionIndex;
        REGISTER unsigned int16_t L0904_ui_SlotIndex;
        REGISTER THING L0905_T_LeaderHandObject;
        REGISTER THING L0906_T_SlotThing;


        if (P0633_ui_SlotBoxIndex < C08_SLOT_BOX_INVENTORY_FIRST_SLOT) {
                if (G0299_ui_CandidateChampionOrdinal)
                        return;
                L0903_ui_ChampionIndex = P0633_ui_SlotBoxIndex >> 1;
                if ((L0903_ui_ChampionIndex >= G0305_ui_PartyChampionCount) || (M000_INDEX_TO_ORDINAL(L0903_ui_ChampionIndex) == (int16_t)G0423_i_InventoryChampionOrdinal) || !M516_CHAMPIONS[L0903_ui_ChampionIndex].CurrentHealth)
                        return;
                L0904_ui_SlotIndex = M070_HAND_SLOT_INDEX(P0633_ui_SlotBoxIndex);
        } else {
                L0903_ui_ChampionIndex = M001_ORDINAL_TO_INDEX(G0423_i_InventoryChampionOrdinal);
                L0904_ui_SlotIndex = P0633_ui_SlotBoxIndex - C08_SLOT_BOX_INVENTORY_FIRST_SLOT;
        }
        L0905_T_LeaderHandObject = G4055_s_LeaderHandObject.Thing;
        if (L0904_ui_SlotIndex >= C30_SLOT_CHEST_1) {
                L0906_T_SlotThing = G0425_aT_ChestSlots[L0904_ui_SlotIndex - C30_SLOT_CHEST_1];
        } else {
                L0906_T_SlotThing = M516_CHAMPIONS[L0903_ui_ChampionIndex].Slots[L0904_ui_SlotIndex];
        }
        if ((L0906_T_SlotThing == C0xFFFF_THING_NONE) && (L0905_T_LeaderHandObject == C0xFFFF_THING_NONE)) {
                return;
        }
        if ((L0905_T_LeaderHandObject != C0xFFFF_THING_NONE) && (!(G0237_as_Graphic559_ObjectInfo[F0141_DUNGEON_GetObjectInfoIndex(L0905_T_LeaderHandObject)].AllowedSlots & G0038_ai_Graphic562_SlotMasks[L0904_ui_SlotIndex]))) {
                return;
        }
        F0077_MOUSE_EnableScreenUpdate_CPSE();
        if (L0905_T_LeaderHandObject != C0xFFFF_THING_NONE) {
                F0298_CHAMPION_GetObjectRemovedFromLeaderHand();
        }
        if (L0906_T_SlotThing != C0xFFFF_THING_NONE) {
                F0300_CHAMPION_GetObjectRemovedFromSlot(L0903_ui_ChampionIndex, L0904_ui_SlotIndex);
                F0297_CHAMPION_PutObjectInLeaderHand(L0906_T_SlotThing, C0_FALSE); /* BUG0_39 In the leader inventory, the Food/Water/Poisoned panel is briefly drawn when replacing a scroll or chest by another scroll or chest in the action hand. This does not occur for champions other than the leader. When swapping the objects between the action hand and the leader hand, the program first removes the object in the action hand with a call to F0300_CHAMPION_GetObjectRemovedFromSlot. If the removed object is a chest or a scroll then this sets the MASK0x0800_PANEL flag in the champion data to refresh the panel. Then the object in the leader hand is removed with a call to F0297_CHAMPION_PutObjectInLeaderHand. The weight of the object in the leader hand is part of the load of the leader, so this sets another flag MASK0x0200_LOAD in the champion data of the leader to refresh the Load value and then calls the function F0292_CHAMPION_DrawState to draw the leader champion state. If the champion is not the leader, nothing is drawn. If the champion is the leader, the Food/Water/Poisoned panel is drawn because at this point the action hand is empty. Then the object that was removed from the leader hand is put in the action hand with a call to F0301_CHAMPION_AddObjectInSlot and this draws the panel again, this time showing the chest contents or scroll text. The fix would be to swap the calls to F0300_CHAMPION_GetObjectRemovedFromSlot and F0297_CHAMPION_PutObjectInLeaderHand (note this would not fix the double refresh of the Load value after removing the first object and after putting the second object) */
        }
        if (L0905_T_LeaderHandObject != C0xFFFF_THING_NONE) {
                F0301_CHAMPION_AddObjectInSlot(L0903_ui_ChampionIndex, L0905_T_LeaderHandObject, L0904_ui_SlotIndex);
        }
        F0292_CHAMPION_DrawState(L0903_ui_ChampionIndex);
        F0078_MOUSE_DisableScreenUpdate();
}

unsigned int16_t F0303_CHAMPION_GetSkillLevel(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0634_i_ChampionIndex, P0635_ui_SkillIndex)
#endif
int16_t                   P0634_i_ChampionIndex SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
unsigned int16_t          P0635_ui_SkillIndex   FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0635_ui_SkillIndex   FINAL_SEPARATOR
#endif
{
        REGISTER SKILL* L0911_ps_Skill;
        REGISTER CHAMPION* L0912_ps_Champion;
#ifdef MEDIA010_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB
        REGISTER long L0907_Experience;
#endif
        REGISTER int16_t L0908_i_SkillLevel;
#ifdef MEDIA506_F20E_F20J_X30J
        REGISTER long L0907_Experience;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned long L0907_Experience;
#endif
        REGISTER int16_t L0909_i_NeckIconIndex;
        REGISTER int16_t L0910_i_ActionHandIconIndex;
        BOOLEAN L0913_B_IgnoreTemporaryExperience;
        BOOLEAN L0914_B_IgnoreObjectModifiers;


        if (G0300_B_PartyIsResting) {
                return 1;
        }
        L0913_B_IgnoreTemporaryExperience = M007_GET(P0635_ui_SkillIndex, MASK0x8000_IGNORE_TEMPORARY_EXPERIENCE);
        L0914_B_IgnoreObjectModifiers = M007_GET(P0635_ui_SkillIndex, MASK0x4000_IGNORE_OBJECT_MODIFIERS);
        M009_CLEAR(P0635_ui_SkillIndex, MASK0x8000_IGNORE_TEMPORARY_EXPERIENCE | MASK0x4000_IGNORE_OBJECT_MODIFIERS);
        L0912_ps_Champion = &M516_CHAMPIONS[P0634_i_ChampionIndex];
        L0911_ps_Skill = &L0912_ps_Champion->Skills[P0635_ui_SkillIndex];
        L0907_Experience = L0911_ps_Skill->Experience;
        if (!L0913_B_IgnoreTemporaryExperience) {
                L0907_Experience += L0911_ps_Skill->TemporaryExperience;
        }
        if (P0635_ui_SkillIndex > C03_SKILL_WIZARD) { /* Hidden skill */
                L0911_ps_Skill = &L0912_ps_Champion->Skills[(P0635_ui_SkillIndex - C04_SKILL_SWING) >> 2];
                L0907_Experience += L0911_ps_Skill->Experience; /* Add experience in the base skill */
                if (!L0913_B_IgnoreTemporaryExperience) {
                        L0907_Experience += L0911_ps_Skill->TemporaryExperience;
                }
                L0907_Experience >>= 1; /* Halve experience to get average of base skill + hidden skill experience */
        }
        L0908_i_SkillLevel = 1;
        while (L0907_Experience >= 500) {
                L0907_Experience >>= 1;
                L0908_i_SkillLevel++;
        }
        if (!L0914_B_IgnoreObjectModifiers) {
                if ((L0910_i_ActionHandIconIndex = F0033_OBJECT_GetIconIndex(L0912_ps_Champion->Slots[C01_SLOT_ACTION_HAND])) == C027_ICON_WEAPON_THE_FIRESTAFF) {
                        L0908_i_SkillLevel++;
                } else {
                        if (L0910_i_ActionHandIconIndex == C028_ICON_WEAPON_THE_FIRESTAFF_COMPLETE) {
                                L0908_i_SkillLevel += 2;
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_09_FIX The skill modifier of the Firestaff is not cumulative with other modifiers */
                        } else { /* BUG0_40 If a champion has The Firestaff in the action hand then skill modifiers from other objects (Pendant Feral, Ekkhard Cross, Gem of Ages and Moonstone) are ignored. Wrong code causes the skill modifier of the Firestaff not to be cumulative with other modifiers */
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_09_FIX The skill modifier of the Firestaff is cumulative with other modifiers */
                        }
                }
#endif
                                L0909_i_NeckIconIndex = F0033_OBJECT_GetIconIndex(L0912_ps_Champion->Slots[C10_SLOT_NECK]);
                                switch (P0635_ui_SkillIndex) {
                                        case C03_SKILL_WIZARD:
#ifdef PC_FIX_CODE_SIZE
        L0908_i_SkillLevel++;
#endif
                                                if (L0909_i_NeckIconIndex == C124_ICON_JUNK_PENDANT_FERAL) {
                                                        L0908_i_SkillLevel++;
                                                }
                                                break;
                                        case C15_SKILL_DEFEND:
#ifdef PC_FIX_CODE_SIZE
        L0908_i_SkillLevel++;
#endif
                                                if (L0909_i_NeckIconIndex == C121_ICON_JUNK_EKKHARD_CROSS) {
                                                        L0908_i_SkillLevel++;
                                                }
                                                break;
                                        case C13_SKILL_HEAL:
#ifdef PC_FIX_CODE_SIZE
        L0908_i_SkillLevel++;
#endif
                                                if ((L0909_i_NeckIconIndex == C120_ICON_JUNK_GEM_OF_AGES) || (L0910_i_ActionHandIconIndex == C066_ICON_WEAPON_SCEPTRE_OF_LYF)) { /* The skill modifiers of these two objects are not cumulative */
                                                        L0908_i_SkillLevel++;
                                                }
                                                break;
                                        case C14_SKILL_INFLUENCE:
                                                if (L0909_i_NeckIconIndex == C122_ICON_JUNK_MOONSTONE) {
                                                        L0908_i_SkillLevel++;
                                                }
                                                break;
                                }
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_09_FIX */
                        }
                }
#endif
        }
        return L0908_i_SkillLevel;
}

void F0304_CHAMPION_AddSkillExperience(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0636_ui_ChampionIndex, P0637_ui_SkillIndex, P0638_ui_Experience)
#endif
unsigned int16_t          P0636_ui_ChampionIndex SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
unsigned int16_t          P0637_ui_SkillIndex    SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0637_ui_SkillIndex    SEPARATOR
#endif
REGISTER unsigned int16_t P0638_ui_Experience    FINAL_SEPARATOR
#define AP0638_ui_SkillLevelAfter P0638_ui_Experience
#define AP0638_ui_ChampionColor   P0638_ui_Experience
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER SKILL* L0918_ps_Skill;
#endif
        REGISTER CHAMPION* L0919_ps_Champion;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER SKILL* L0918_ps_Skill;
#endif
#ifdef MEDIA724_I34E_I34M_A36M_A31M_A33M_A35E_A35M
        REGISTER char *L2248_pc_;
        char *L2249_pc_;
#endif
        REGISTER unsigned int16_t L0915_ui_Multiple;
#define AL0915_ui_MapDifficulty    L0915_ui_Multiple
#define AL0915_ui_SkillLevelBefore L0915_ui_Multiple
#define AL0915_ui_VitalityAmount   L0915_ui_Multiple
#define AL0915_ui_StaminaAmount    L0915_ui_Multiple
        REGISTER unsigned int16_t L0916_ui_BaseSkillIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER long L0917_l_Experience_Useless; /* BUG0_00 Useless code */
        int16_t L0920_i_MinorStatisticIncrease;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0920_i_MinorStatisticIncrease;
#endif
        int16_t L0921_i_MajorStatisticIncrease;
        int16_t L0922_i_BaseSkillLevel;


        if ((P0637_ui_SkillIndex >= C04_SKILL_SWING) && (P0637_ui_SkillIndex <= C11_SKILL_SHOOT) && (G0361_l_LastCreatureAttackTime < (G0313_ul_GameTime - 150))) {
                P0638_ui_Experience >>= 1;
        }
        if (P0638_ui_Experience) {
                if (AL0915_ui_MapDifficulty = G0269_ps_CurrentMap->C.Difficulty) {
                        P0638_ui_Experience *= AL0915_ui_MapDifficulty;
                }
                L0919_ps_Champion = &M516_CHAMPIONS[P0636_ui_ChampionIndex];
                if (P0637_ui_SkillIndex >= C04_SKILL_SWING) {
                        L0916_ui_BaseSkillIndex = (P0637_ui_SkillIndex - C04_SKILL_SWING) >> 2;
                } else {
                        L0916_ui_BaseSkillIndex = P0637_ui_SkillIndex;
                }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                L0917_l_Experience_Useless = L0918_ps_Skill->Experience; /* BUG0_00 Useless code. Use of uninitialized variable L0918_ps_Skill */
#endif
                AL0915_ui_SkillLevelBefore = F0303_CHAMPION_GetSkillLevel(P0636_ui_ChampionIndex, L0916_ui_BaseSkillIndex | (MASK0x4000_IGNORE_OBJECT_MODIFIERS | MASK0x8000_IGNORE_TEMPORARY_EXPERIENCE));
                if ((P0637_ui_SkillIndex >= C04_SKILL_SWING) && (G0361_l_LastCreatureAttackTime > (G0313_ul_GameTime - 25))) {
                        P0638_ui_Experience <<= 1;
                }
                L0918_ps_Skill = &L0919_ps_Champion->Skills[P0637_ui_SkillIndex];
                L0918_ps_Skill->Experience += P0638_ui_Experience;
                if (L0918_ps_Skill->TemporaryExperience < 32000) {
                        L0918_ps_Skill->TemporaryExperience += F0026_MAIN_GetBoundedValue(1, P0638_ui_Experience >> 3, 100);
                }
                L0918_ps_Skill = &L0919_ps_Champion->Skills[L0916_ui_BaseSkillIndex];
                if (P0637_ui_SkillIndex >= C04_SKILL_SWING) {
                        L0918_ps_Skill->Experience += P0638_ui_Experience;
                }
                AP0638_ui_SkillLevelAfter = F0303_CHAMPION_GetSkillLevel(P0636_ui_ChampionIndex, L0916_ui_BaseSkillIndex | (MASK0x4000_IGNORE_OBJECT_MODIFIERS | MASK0x8000_IGNORE_TEMPORARY_EXPERIENCE));
                if (AP0638_ui_SkillLevelAfter > AL0915_ui_SkillLevelBefore) {
                        L0922_i_BaseSkillLevel = AP0638_ui_SkillLevelAfter;
                        L0920_i_MinorStatisticIncrease = M005_RANDOM(2);
                        L0921_i_MajorStatisticIncrease = 1 + M005_RANDOM(2);
                        AL0915_ui_VitalityAmount = M005_RANDOM(2); /* For Priest skill, the amount is 0 or 1 for all skill levels */
                        if (L0916_ui_BaseSkillIndex != C02_SKILL_PRIEST) {
                                AL0915_ui_VitalityAmount &= AP0638_ui_SkillLevelAfter; /* For non Priest skills the amount is 0 for even skill levels. The amount is 0 or 1 for odd skill levels */
                        }
                        L0919_ps_Champion->Statistics[C4_STATISTIC_VITALITY][C0_MAXIMUM] += AL0915_ui_VitalityAmount;
                        AL0915_ui_StaminaAmount = L0919_ps_Champion->MaximumStamina;
                        L0919_ps_Champion->Statistics[C6_STATISTIC_ANTIFIRE][C0_MAXIMUM] += M005_RANDOM(2) & ~AP0638_ui_SkillLevelAfter; /* The amount is 0 for odd skill levels. The amount is 0 or 1 for even skill levels */
                        switch (L0916_ui_BaseSkillIndex) {
                                case C00_SKILL_FIGHTER:
#ifdef MEDIA732_I34E_A35E
                                        L2248_pc_ = "";
                                        L2249_pc_ = " JUST GAINED A FIGHTER LEVEL!";
#endif
#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
                                        L2248_pc_ = F0758_TranslateLanguage(C61_TEXT);
                                        L2249_pc_ = F0758_TranslateLanguage(C62_TEXT);
#endif
                                        AL0915_ui_StaminaAmount >>= 4;
                                        AP0638_ui_SkillLevelAfter *= 3;
                                        L0919_ps_Champion->Statistics[C1_STATISTIC_STRENGTH][C0_MAXIMUM] += L0921_i_MajorStatisticIncrease;
                                        L0919_ps_Champion->Statistics[C2_STATISTIC_DEXTERITY][C0_MAXIMUM] += L0920_i_MinorStatisticIncrease;
                                        break;
                                case C01_SKILL_NINJA:
#ifdef MEDIA732_I34E_A35E
                                        L2248_pc_ = "";
                                        L2249_pc_ = " JUST GAINED A NINJA LEVEL!";
#endif
#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
                                        L2248_pc_ = F0758_TranslateLanguage(C63_TEXT);
                                        L2249_pc_ = F0758_TranslateLanguage(C64_TEXT);
#endif
                                        AL0915_ui_StaminaAmount /= 21;
                                        AP0638_ui_SkillLevelAfter <<= 1;
                                        L0919_ps_Champion->Statistics[C1_STATISTIC_STRENGTH][C0_MAXIMUM] += L0920_i_MinorStatisticIncrease;
                                        L0919_ps_Champion->Statistics[C2_STATISTIC_DEXTERITY][C0_MAXIMUM] += L0921_i_MajorStatisticIncrease;
                                        break;
                                case C03_SKILL_WIZARD:
#ifdef MEDIA732_I34E_A35E
                                        L2248_pc_ = "";
                                        L2249_pc_ = " JUST GAINED A WIZARD LEVEL!";
#endif
#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
                                        L2248_pc_ = F0758_TranslateLanguage(C67_TEXT);
                                        L2249_pc_ = F0758_TranslateLanguage(C68_TEXT);
#endif
                                        AL0915_ui_StaminaAmount >>= 5;
                                        L0919_ps_Champion->MaximumMana += AP0638_ui_SkillLevelAfter + (AP0638_ui_SkillLevelAfter >> 1);
                                        L0919_ps_Champion->Statistics[C3_STATISTIC_WISDOM][C0_MAXIMUM] += L0921_i_MajorStatisticIncrease;
                                        goto T0304016;
                                case C02_SKILL_PRIEST:
#ifdef MEDIA732_I34E_A35E
                                        L2248_pc_ = "";
                                        L2249_pc_ = " JUST GAINED A PRIEST LEVEL!";
#endif
#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
                                        L2248_pc_ = F0758_TranslateLanguage(C65_TEXT);
                                        L2249_pc_ = F0758_TranslateLanguage(C66_TEXT);
#endif
                                        AL0915_ui_StaminaAmount /= 25;
                                        L0919_ps_Champion->MaximumMana += AP0638_ui_SkillLevelAfter;
                                        AP0638_ui_SkillLevelAfter += (AP0638_ui_SkillLevelAfter + 1) >> 1;
                                        L0919_ps_Champion->Statistics[C3_STATISTIC_WISDOM][C0_MAXIMUM] += L0920_i_MinorStatisticIncrease;
                                        T0304016:
                                        if ((L0919_ps_Champion->MaximumMana += F0024_MAIN_GetMinimumValue(M004_RANDOM(4), L0922_i_BaseSkillLevel - 1)) > 900) {
                                                L0919_ps_Champion->MaximumMana = 900;
                                        }
#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
                                        L0919_ps_Champion->Statistics[C5_STATISTIC_ANTIMAGIC][C0_MAXIMUM] += M002_RANDOM(3);
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                                        L0919_ps_Champion->Statistics[C5_STATISTIC_ANTIMAGIC][C0_MAXIMUM] += M004_RANDOM(4);
#endif
                        }
                        if ((L0919_ps_Champion->MaximumHealth += AP0638_ui_SkillLevelAfter + M002_RANDOM((AP0638_ui_SkillLevelAfter >> 1) + 1)) > 999) {
                                L0919_ps_Champion->MaximumHealth = 999;
                        }
                        if ((L0919_ps_Champion->MaximumStamina += AL0915_ui_StaminaAmount + M002_RANDOM((AL0915_ui_StaminaAmount >> 1) + 1)) > 9999) {
                                L0919_ps_Champion->MaximumStamina = 9999;
                        }
                        M008_SET(L0919_ps_Champion->Attributes, MASK0x0100_STATISTICS);
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        G2016_ai_SkillRecentlyUpgraded[P0636_ui_ChampionIndex][L0916_ui_BaseSkillIndex] = C1_TRUE;
#endif
                        F0292_CHAMPION_DrawState(P0636_ui_ChampionIndex);
                        F0051_TEXT_MESSAGEAREA_PrintLineFeed();
#ifdef MEDIA059_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_A31E_F31E
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor = G0046_auc_Graphic562_ChampionColor[P0636_ui_ChampionIndex], L0919_ps_Champion->Name);
#endif
#ifdef MEDIA195_S10EA_S10EB_S11E_S12E_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A21E_A22E_F20E_A31E_F31E /* CHANGE4_00_LOCALIZATION Translation to German language */
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, " JUST GAINED A ");
#endif
#ifdef MEDIA252_S12G /* CHANGE4_00_LOCALIZATION Translation to German language */
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, " HAT SOEBEN ");
#endif
#ifdef MEDIA446_A20G_A22G
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, " HAT SOEBEN STUFE");
#endif
#ifdef MEDIA261_S13FA_S13FB_A20F /* CHANGE5_00_LOCALIZATION Translation to French language */
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, " VIENT DE DEVENIR ");
#endif
#ifdef MEDIA059_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_A31E_F31E
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, G0417_apc_BaseSkillNames[L0916_ui_BaseSkillIndex]);
#endif
#ifdef MEDIA195_S10EA_S10EB_S11E_S12E_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A21E_A22E_F20E_A31E_F31E /* CHANGE4_00_LOCALIZATION Translation to German language */
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, " LEVEL!");
#endif
#ifdef MEDIA252_S12G /* CHANGE4_00_LOCALIZATION Translation to German language */
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, " STUFE ERREICHT!");
#endif
#ifdef MEDIA446_A20G_A22G
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, " ERREICHT!");
#endif
#ifdef MEDIA261_S13FA_S13FB_A20F /* CHANGE5_00_LOCALIZATION Translation to French language */
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "!");
#endif
#ifdef MEDIA571_F20J_X30J_P20JA_P20JB_F31J_X31J_P31J
                        F0819_TEXT_MESSAGEAREA_PrintMessageAsJapanese(AP0638_ui_ChampionColor = G0046_auc_Graphic562_ChampionColor[P0636_ui_ChampionIndex], L0919_ps_Champion->Name);
                        switch (L0916_ui_BaseSkillIndex) {
                                case C00_SKILL_FIGHTER:
#ifdef MEDIA569_F20J_X30J_P20JA_P20JB
                                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "は戦士の技術が向上!");
#endif
#ifdef MEDIA689_F31J_X31J_P31J
                                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "は|戦士の技術が向上!");
#endif
                                        break;
                                case C01_SKILL_NINJA:
#ifdef MEDIA569_F20J_X30J_P20JA_P20JB
                                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "は忍者の技術が向上!");
#endif
#ifdef MEDIA689_F31J_X31J_P31J
                                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "は|忍者の技術が向上!");
#endif
                                        break;
                                case C02_SKILL_PRIEST:
#ifdef MEDIA569_F20J_X30J_P20JA_P20JB
                                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "は僧侶の技術が向上!");
#endif
#ifdef MEDIA689_F31J_X31J_P31J
                                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "は|僧侶の技術が向上!");
#endif
                                        break;
                                case C03_SKILL_WIZARD:
#ifdef MEDIA569_F20J_X30J_P20JA_P20JB
                                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "は魔術師の技術が向上!");
#endif
#ifdef MEDIA689_F31J_X31J_P31J
                                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, "は|魔術師の技術が向上!");
#endif
                        }
#endif
#ifdef MEDIA724_I34E_I34M_A36M_A31M_A33M_A35E_A35M
                        AP0638_ui_ChampionColor = G0046_auc_Graphic562_ChampionColor[P0636_ui_ChampionIndex];
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, L2248_pc_);
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, L0919_ps_Champion->Name);
                        F0047_TEXT_MESSAGEAREA_PrintMessage(AP0638_ui_ChampionColor, L2249_pc_);
#endif
                }
        }
}

int16_t F0305_CHAMPION_GetThrowingStaminaCost(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0639_T_Thing)
#endif
THING P0639_T_Thing FINAL_SEPARATOR
{
        REGISTER int16_t L0923_i_Weight;
        REGISTER int16_t L0924_i_StaminaCost;


        L0924_i_StaminaCost = F0026_MAIN_GetBoundedValue(1, L0923_i_Weight = F0140_DUNGEON_GetObjectWeight(P0639_T_Thing) >> 1, 10);
        while ((L0923_i_Weight -= 10) > 0) {
                L0924_i_StaminaCost += L0923_i_Weight >> 1;
        }
        return L0924_i_StaminaCost;
}

STATICFUNCTION int16_t F0306_CHAMPION_GetStaminaAdjustedValue(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0640_ps_Champion, P0641_i_Value)
#endif
REGISTER CHAMPION* P0640_ps_Champion SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t            P0641_i_Value     FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t   P0641_i_Value     FINAL_SEPARATOR
#endif
{
        REGISTER int16_t L0925_i_CurrentStamina;
        REGISTER int16_t L0926_i_HalfMaximumStamina;


        if ((L0925_i_CurrentStamina = P0640_ps_Champion->CurrentStamina) < (L0926_i_HalfMaximumStamina = P0640_ps_Champion->MaximumStamina >> 1)) {
                return (P0641_i_Value >>= 1) + (int16_t)(((long)P0641_i_Value * (long)L0925_i_CurrentStamina) / L0926_i_HalfMaximumStamina); /* BUGX_XX: A champion may temporarily benefit from a larger than expected Strength or Maximum Load value. If the stamina of a champion drops below half of its maximum value, the Strength and Maximum Load values of the champion are decreased. However, while computing the decreased value, two sub expressions are not evaluated in the same order by all compilers. In order to compute the correct adjusted value, the first operand of the addition must be evaluated first so that its updated value is used in the second operand. However, there is no guarantee that the code produced by the compiler will evaluate the operands in this particular order. The following compilers produce code showing the expected behavior where the first operand of the addition is executed first: Megamax C (DM 1.x and CSB 2.x for Atari ST), High C (DM 2.0 and CSB 3.1 for FM-Towns), THINK C 4.0 (CSB 3.x for Amiga and X68000, DM 3.0 for X68000). The following compilers produce code showing the unexpected behavior where the second operand of the addition is executed first: Aztec C 3.6a (DM 2.x for Amiga), MPW IIGS C compiler (DM 2.x for Apple IIGS), Turbo C 2.0 (DM 2.0 and CSB 3.1 for PC-98), Turbo C++ 1.01 (DM 3.4 for PC), THINK C 5.0 (DM 3.6 Amiga). For example, on platforms where operands are evaluated in the expected order a champion with a maximum stamina of 100 and strong enough to carry 40 KG when his current stamina is more than half its maximum is able to carry only 29 KG if its current stamina drops to 45. On platforms where operands are not evaluated in the expected order the resulting maximum load is 38 KG instead which is higher than expected */
        }
#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 P0641_i_Value;
#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
}

unsigned int16_t F0307_CHAMPION_GetStatisticAdjustedAttack(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0642_ps_Champion, P0643_ui_StatisticIndex, P0644_ui_Attack)
#endif
CHAMPION*        P0642_ps_Champion       SEPARATOR
unsigned int16_t P0643_ui_StatisticIndex SEPARATOR
unsigned int16_t P0644_ui_Attack         FINAL_SEPARATOR
{
        REGISTER int16_t L0927_i_Factor;


        if ((L0927_i_Factor = 170 - P0642_ps_Champion->Statistics[P0643_ui_StatisticIndex][C1_CURRENT]) < 16) { /* BUG0_41 The Antifire and Antimagic statistics are completely ignored. The Vitality statistic is ignored against poison and to determine the probability of being wounded. Vitality is still used normally to compute the defense against wounds and the speed of health regeneration. A bug in the Megamax C compiler produces wrong machine code for this statement. It always returns 0 for the current statistic value so that L0927_i_Factor = 170 in all cases */
                return P0644_ui_Attack >> 3;
        }
        return F0030_MAIN_GetScaledProduct(P0644_ui_Attack, 7, L0927_i_Factor);
}

BOOLEAN F0308_CHAMPION_IsLucky(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0645_ps_Champion, P0646_ui_Percentage)
#endif
CHAMPION*                 P0645_ps_Champion   SEPARATOR
REGISTER unsigned int16_t P0646_ui_Percentage FINAL_SEPARATOR
#define AP0646_ui_IsLucky P0646_ui_Percentage
{
#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
        REGISTER unsigned char* L0928_Statistic;
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        REGISTER char* L0928_Statistic;
#endif


        if (M005_RANDOM(2) && (M002_RANDOM(100) > P0646_ui_Percentage)) {
                return C1_TRUE;
        }
        L0928_Statistic = P0645_ps_Champion->Statistics[C0_STATISTIC_LUCK];
#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
        AP0646_ui_IsLucky = (M002_RANDOM(L0928_Statistic[C1_CURRENT]) > P0646_ui_Percentage); /* BUG0_38 A champion is much luckier than expected during combat when equipped with at least 4 cursed objects. Luck value may be negative (when multiple cursed objects are worn) which is equivalent to a large unsigned value, greater than the value of P0646_ui_Percentage which is no more than 100 */
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        if (L0928_Statistic[C1_CURRENT] <= 0) {
                AP0646_ui_IsLucky = 0;
        } else {
                AP0646_ui_IsLucky = (M002_RANDOM((unsigned char)L0928_Statistic[C1_CURRENT] << 1) > P0646_ui_Percentage);
        }
#endif
        L0928_Statistic[C1_CURRENT] = F0026_MAIN_GetBoundedValue(L0928_Statistic[C2_MINIMUM], L0928_Statistic[C1_CURRENT] + (AP0646_ui_IsLucky ? -2 : 2), L0928_Statistic[C0_MAXIMUM]);
        return AP0646_ui_IsLucky;
}

unsigned int16_t F0309_CHAMPION_GetMaximumLoad(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0647_ps_Champion)
#endif
REGISTER CHAMPION* P0647_ps_Champion FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0929_ui_MaximumLoad;
        REGISTER unsigned int16_t L0930_ui_Wounds;


        L0929_ui_MaximumLoad = (P0647_ps_Champion->Statistics[C1_STATISTIC_STRENGTH][C1_CURRENT] << 3) + 100;
        L0929_ui_MaximumLoad = F0306_CHAMPION_GetStaminaAdjustedValue(P0647_ps_Champion, L0929_ui_MaximumLoad);
        if (L0930_ui_Wounds = P0647_ps_Champion->Wounds) {
                L0929_ui_MaximumLoad -= L0929_ui_MaximumLoad >> (M007_GET(L0930_ui_Wounds, MASK0x0010_WOUND_LEGS) ? 2 : 3);
        }
        if (F0033_OBJECT_GetIconIndex(P0647_ps_Champion->Slots[C05_SLOT_FEET]) == C119_ICON_ARMOUR_ELVEN_BOOTS) {
                L0929_ui_MaximumLoad += L0929_ui_MaximumLoad >> 4;
        }
        L0929_ui_MaximumLoad += 9;
        L0929_ui_MaximumLoad -= L0929_ui_MaximumLoad % 10; /* Round the value to the next multiple of 10 */
        return L0929_ui_MaximumLoad;
}

int16_t F0310_CHAMPION_GetMovementTicks(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0648_ps_Champion)
#endif
REGISTER CHAMPION* P0648_ps_Champion FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0931_ui_Multiple;
#define AL0931_ui_Load       L0931_ui_Multiple
#define AL0931_ui_WoundTicks L0931_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 L0932_ui_MaximumLoad;
#endif
        REGISTER unsigned int16_t L0933_ui_Ticks;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0932_ui_MaximumLoad;
#endif


        if ((L0932_ui_MaximumLoad = F0309_CHAMPION_GetMaximumLoad(P0648_ps_Champion)) > (AL0931_ui_Load = P0648_ps_Champion->Load)) { /* BUG0_72 The party moves very slowly even though no champion 'Load' value is drawn in red. When the Load of a champion has exactly the maximum value he can carry then the Load is drawn in yellow but the speed is the same as when the champion is overloaded (when the Load is drawn in red). The comparison operator should be >= instead of > */
                L0933_ui_Ticks = 2;
                if (((long)AL0931_ui_Load << 3) > ((long)L0932_ui_MaximumLoad * 5)) {
                        L0933_ui_Ticks++;
                }
                AL0931_ui_WoundTicks = 1;
        } else {
                L0933_ui_Ticks = 4 + (((AL0931_ui_Load - L0932_ui_MaximumLoad) << 2) / L0932_ui_MaximumLoad);
                AL0931_ui_WoundTicks = 2;
        }
        if (M007_GET(P0648_ps_Champion->Wounds, MASK0x0020_WOUND_FEET)) {
                L0933_ui_Ticks += AL0931_ui_WoundTicks;
        }
        if (F0033_OBJECT_GetIconIndex(P0648_ps_Champion->Slots[C05_SLOT_FEET]) == C194_ICON_ARMOUR_BOOT_OF_SPEED) {
                L0933_ui_Ticks--;
        }
        return L0933_ui_Ticks;
}

unsigned int16_t F0311_CHAMPION_GetDexterity(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0649_ps_Champion)
#endif
REGISTER CHAMPION* P0649_ps_Champion FINAL_SEPARATOR
{
        REGISTER int16_t L0934_i_Dexterity;


        L0934_i_Dexterity = M003_RANDOM(8) + P0649_ps_Champion->Statistics[C2_STATISTIC_DEXTERITY][C1_CURRENT];
        L0934_i_Dexterity -= (int16_t)(((long)(L0934_i_Dexterity >> 1) * (long)P0649_ps_Champion->Load) / F0309_CHAMPION_GetMaximumLoad(P0649_ps_Champion));
#ifdef MEDIA609_X30J_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L0934_i_Dexterity = F0025_MAIN_GetMaximumValue(2, L0934_i_Dexterity);
#endif
        if (G0300_B_PartyIsResting) {
                L0934_i_Dexterity >>= 1;
        }
        return F0026_MAIN_GetBoundedValue(1 + M003_RANDOM(8), L0934_i_Dexterity >> 1, 100 - M003_RANDOM(8));
}

unsigned int16_t F0312_CHAMPION_GetStrength(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0650_i_ChampionIndex, P0651_i_SlotIndex)
int16_t          P0650_i_ChampionIndex SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t P0650_i_ChampionIndex SEPARATOR
#endif
int16_t          P0651_i_SlotIndex     FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0939_ps_Champion;
        REGISTER WEAPON_INFO* L0940_ps_WeaponInfo;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0937_ui_Multiple;
#endif
        REGISTER int16_t L0935_i_Strength;
        REGISTER unsigned int16_t L0936_ui_Multiple;
#define AL0936_ui_ObjectWeight L0936_ui_Multiple
#define AL0936_ui_SkillLevel   L0936_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 L0937_ui_Multiple;
#endif
#define AL0937_ui_OneSixteenthMaximumLoad L0937_ui_Multiple
#define AL0937_ui_Class                   L0937_ui_Multiple
        REGISTER THING L0938_T_Thing;
        unsigned int16_t L0941_ui_LoadThreshold;


        L0939_ps_Champion = &M516_CHAMPIONS[P0650_i_ChampionIndex];
        L0935_i_Strength = M003_RANDOM(16) + L0939_ps_Champion->Statistics[C1_STATISTIC_STRENGTH][C1_CURRENT];
        L0938_T_Thing = L0939_ps_Champion->Slots[P0651_i_SlotIndex];
        if ((AL0936_ui_ObjectWeight = F0140_DUNGEON_GetObjectWeight(L0938_T_Thing)) <= (AL0937_ui_OneSixteenthMaximumLoad = F0309_CHAMPION_GetMaximumLoad(L0939_ps_Champion) >> 4)) {
                L0935_i_Strength += AL0936_ui_ObjectWeight - 12;
        } else {
                if (AL0936_ui_ObjectWeight <= (L0941_ui_LoadThreshold = AL0937_ui_OneSixteenthMaximumLoad + ((AL0937_ui_OneSixteenthMaximumLoad - 12) >> 1))) {
                        L0935_i_Strength += (AL0936_ui_ObjectWeight - AL0937_ui_OneSixteenthMaximumLoad) >> 1;
                } else {
                        L0935_i_Strength -= (AL0936_ui_ObjectWeight - L0941_ui_LoadThreshold) << 1;
                }
        }
        if (M012_TYPE(L0938_T_Thing) == C05_THING_TYPE_WEAPON) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                L0940_ps_WeaponInfo = &G0238_as_Graphic559_WeaponInfo[((WEAPON*)G0284_apuc_ThingData[C05_THING_TYPE_WEAPON])[M013_INDEX(L0938_T_Thing)].Type];
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                L0940_ps_WeaponInfo = F0158_DUNGEON_GetWeaponInfo(L0938_T_Thing);
#endif
                L0935_i_Strength += L0940_ps_WeaponInfo->Strength;
                AL0936_ui_SkillLevel = 0;
                AL0937_ui_Class = L0940_ps_WeaponInfo->Class;
                if ((AL0937_ui_Class == C000_CLASS_SWING_WEAPON) || (AL0937_ui_Class == C002_CLASS_DAGGER_AND_AXES)) {
                        AL0936_ui_SkillLevel = F0303_CHAMPION_GetSkillLevel(P0650_i_ChampionIndex, C04_SKILL_SWING);
                }
                if ((AL0937_ui_Class != C000_CLASS_SWING_WEAPON) && (AL0937_ui_Class < C016_CLASS_FIRST_BOW)) {
                        AL0936_ui_SkillLevel += F0303_CHAMPION_GetSkillLevel(P0650_i_ChampionIndex, C10_SKILL_THROW);
                }
                if ((AL0937_ui_Class >= C016_CLASS_FIRST_BOW) && (AL0937_ui_Class < C112_CLASS_FIRST_MAGIC_WEAPON)) {
                        AL0936_ui_SkillLevel += F0303_CHAMPION_GetSkillLevel(P0650_i_ChampionIndex, C11_SKILL_SHOOT);
                }
                L0935_i_Strength += AL0936_ui_SkillLevel << 1;
        }
        L0935_i_Strength = F0306_CHAMPION_GetStaminaAdjustedValue(L0939_ps_Champion, L0935_i_Strength);
        if (M007_GET(L0939_ps_Champion->Wounds, (P0651_i_SlotIndex == C00_SLOT_READY_HAND) ? MASK0x0001_WOUND_READY_HAND : MASK0x0002_WOUND_ACTION_HAND)) {
                L0935_i_Strength >>= 1;
        }
        return F0026_MAIN_GetBoundedValue(0, L0935_i_Strength >> 1, 100);
}

int16_t F0313_CHAMPION_GetWoundDefense(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0652_i_ChampionIndex, P0653_ui_WoundIndex)
#endif
int16_t                   P0652_i_ChampionIndex SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
unsigned int16_t          P0653_ui_WoundIndex   FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0653_ui_WoundIndex   FINAL_SEPARATOR
#endif
{
        REGISTER CHAMPION* L0946_ps_Champion;
        REGISTER ARMOUR_INFO* L0947_ps_ArmourInfo;
        REGISTER int16_t L0942_i_Multiple;
#define AL0942_i_SlotIndex    L0942_i_Multiple
#define AL0942_i_WoundDefense L0942_i_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 L0943_ui_ArmourShieldDefense;
#endif
        REGISTER BOOLEAN L0944_B_UseSharpDefense;
        REGISTER THING L0945_T_Thing;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0943_ui_ArmourShieldDefense;
#endif


        L0946_ps_Champion = &M516_CHAMPIONS[P0652_i_ChampionIndex];
        if (L0944_B_UseSharpDefense = M007_GET(P0653_ui_WoundIndex, MASK0x8000_USE_SHARP_DEFENSE)) {
                M009_CLEAR(P0653_ui_WoundIndex, MASK0x8000_USE_SHARP_DEFENSE);
        }
        for (L0943_ui_ArmourShieldDefense = 0, AL0942_i_SlotIndex = C00_SLOT_READY_HAND; AL0942_i_SlotIndex <= C01_SLOT_ACTION_HAND; AL0942_i_SlotIndex++) {
                if (M012_TYPE(L0945_T_Thing = L0946_ps_Champion->Slots[AL0942_i_SlotIndex]) == C06_THING_TYPE_ARMOUR) {
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_02_OPTIMIZATION Inline code replaced by function calls */
                        L0947_ps_ArmourInfo = &G0239_as_Graphic559_ArmourInfo[(((ARMOUR*)G0284_apuc_ThingData[C06_THING_TYPE_ARMOUR])[M013_INDEX(L0945_T_Thing)]).Type];
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_02_OPTIMIZATION Inline code replaced by function calls */
                        L0947_ps_ArmourInfo = (ARMOUR_INFO*)F0156_DUNGEON_GetThingData(L0945_T_Thing);
                        L0947_ps_ArmourInfo = &G0239_as_Graphic559_ArmourInfo[((ARMOUR*)L0947_ps_ArmourInfo)->Type];
#endif
                        if (M007_GET(L0947_ps_ArmourInfo->Attributes, MASK0x0080_IS_A_SHIELD)) {
                                L0943_ui_ArmourShieldDefense += ((F0312_CHAMPION_GetStrength(P0652_i_ChampionIndex, AL0942_i_SlotIndex) + F0143_DUNGEON_GetArmourDefense(L0947_ps_ArmourInfo, L0944_B_UseSharpDefense)) * G0050_auc_Graphic562_WoundDefenseFactor[P0653_ui_WoundIndex]) >> ((AL0942_i_SlotIndex == P0653_ui_WoundIndex) ? 4 : 5);
                        }
                }
        }
        AL0942_i_WoundDefense = M002_RANDOM((L0946_ps_Champion->Statistics[C4_STATISTIC_VITALITY][C1_CURRENT] >> 3) + 1);
        if (L0944_B_UseSharpDefense) {
                AL0942_i_WoundDefense >>= 1;
        }
        AL0942_i_WoundDefense += L0946_ps_Champion->ActionDefense + L0946_ps_Champion->ShieldDefense + G0407_s_Party.ShieldDefense + L0943_ui_ArmourShieldDefense;
        if ((P0653_ui_WoundIndex > C01_SLOT_ACTION_HAND) && (M012_TYPE(L0945_T_Thing = L0946_ps_Champion->Slots[P0653_ui_WoundIndex]) == C06_THING_TYPE_ARMOUR)) {
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_02_OPTIMIZATION Inline code replaced by function calls */
                AL0942_i_WoundDefense += F0143_DUNGEON_GetArmourDefense(&G0239_as_Graphic559_ArmourInfo[(((ARMOUR*)G0284_apuc_ThingData[C06_THING_TYPE_ARMOUR])[M013_INDEX(L0945_T_Thing)]).Type], L0944_B_UseSharpDefense);
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_02_OPTIMIZATION Inline code replaced by function calls */
                L0947_ps_ArmourInfo = (ARMOUR_INFO*)F0156_DUNGEON_GetThingData(L0945_T_Thing);
                AL0942_i_WoundDefense += F0143_DUNGEON_GetArmourDefense(&G0239_as_Graphic559_ArmourInfo[((ARMOUR*)L0947_ps_ArmourInfo)->Type], L0944_B_UseSharpDefense);
#endif
        }
        if (M007_GET(L0946_ps_Champion->Wounds, 1 << P0653_ui_WoundIndex)) {
                AL0942_i_WoundDefense -= 8 + M004_RANDOM(4);
        }
        if (G0300_B_PartyIsResting) {
                AL0942_i_WoundDefense >>= 1;
        }
        return F0026_MAIN_GetBoundedValue(0, AL0942_i_WoundDefense >> 1, 100);
}

#ifdef MEDIA423_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#include "COPYPRO7.C"
#endif

#ifdef MEDIA351_G14ED_G20E_G21E
segment "player"
#endif


void F0314_CHAMPION_WakeUp(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0948_i_Unreferenced; /* BUG0_00 Useless code */
#endif


        G0321_B_StopWaitingForPlayerInput = C1_TRUE;
        G0300_B_PartyIsResting = C0_FALSE;
#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
        G0318_i_WaitForInputMaximumVerticalBlankCount = 10;
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
        G0318_i_WaitForInputMaximumVerticalBlankCount = 12;
#endif
        F0098_DUNGEONVIEW_DrawFloorAndCeiling();
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_10_FIX */
        if (!G0509_B_ActionAreaContainsIcons && !G0506_ui_ActingChampionOrdinal) { /* BUG0_42 The action icons are not drawn in the action area after you unfreeze the game. The variable G0509_B_ActionAreaContainsIcons defining what to draw in the action area is not set in the right function in the code.
        If you press ESC to freeze the game right after clicking on an action name while damage to a creature is being displayed in the action area, then when you unfreeze the game the action icons are not drawn in the action area which remains empty. You can get the action icons back by resting and waking up. This was fixed by moving this code from F0314_CHAMPION_WakeUp (the condition is different but the result is perfectly equivalent) */
                G0509_B_ActionAreaContainsIcons = C1_TRUE;
        }
#endif
        G0441_ps_PrimaryMouseInput = G0447_as_Graphic561_PrimaryMouseInput_Interface;
        G0442_ps_SecondaryMouseInput = G0448_as_Graphic561_SecondaryMouseInput_Movement;
        G0443_ps_PrimaryKeyboardInput = G0458_as_Graphic561_PrimaryKeyboardInput_Interface;
        G0444_ps_SecondaryKeyboardInput = G0459_as_Graphic561_SecondaryKeyboardInput_Movement;
        F0357_COMMAND_DiscardAllInput();
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
        F0457_START_DrawEnabledMenus_CPSF();
#endif
}

int16_t F0315_CHAMPION_GetScentOrdinal(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0654_i_MapX, P0655_i_MapY)
#endif
unsigned int16_t P0654_i_MapX SEPARATOR
unsigned int16_t P0655_i_MapY FINAL_SEPARATOR
{
        REGISTER unsigned int16_t* L0951_pui_Scent;
#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 L0949_ui_SearchedScent;
#endif
        REGISTER int16_t L0950_i_ScentIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0949_ui_SearchedScent;
#endif
        SCENT L0952_s_SearchedScent;


        if (L0950_i_ScentIndex = G0407_s_Party.ScentCount) {
                L0952_s_SearchedScent.Location.MapX = P0654_i_MapX;
                L0952_s_SearchedScent.Location.MapY = P0655_i_MapY;
                L0952_s_SearchedScent.Location.MapIndex = G0272_i_CurrentMapIndex;
                L0949_ui_SearchedScent = L0952_s_SearchedScent.Scent;
                L0951_pui_Scent = (unsigned int16_t*)&G0407_s_Party.Scents[L0950_i_ScentIndex--];
                do {
                        if ((*(--L0951_pui_Scent)) == L0949_ui_SearchedScent) {
                                return M000_INDEX_TO_ORDINAL(L0950_i_ScentIndex);
                        }
                } while (L0950_i_ScentIndex--);
        }
        return 0;
}

void F0316_CHAMPION_DeleteScent(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0656_ui_ScentIndex)
#endif
REGISTER unsigned int16_t P0656_ui_ScentIndex FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0953_ui_Count;


        if (L0953_ui_Count = --G0407_s_Party.ScentCount - P0656_ui_ScentIndex) {
                F0007_MAIN_CopyBytes(M772_CAST_PC(&G0407_s_Party.Scents[P0656_ui_ScentIndex + 1]), M772_CAST_PC(&G0407_s_Party.Scents[P0656_ui_ScentIndex]), M543_BYTE_COUNT_INT(L0953_ui_Count * sizeof(SCENT)));
                F0007_MAIN_CopyBytes(M772_CAST_PC(&G0407_s_Party.ScentStrengths[P0656_ui_ScentIndex + 1]), M772_CAST_PC(&G0407_s_Party.ScentStrengths[P0656_ui_ScentIndex]), M543_BYTE_COUNT_INT(L0953_ui_Count));
        }
        if (P0656_ui_ScentIndex < G0407_s_Party.FirstScentIndex) {
                G0407_s_Party.FirstScentIndex--;
        }
        if (P0656_ui_ScentIndex < G0407_s_Party.LastScentIndex) {
                G0407_s_Party.LastScentIndex--;
        }
}

void F0317_CHAMPION_AddScentStrength(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0657_i_MapX, P0658_i_MapY, P0659_ui_CycleCount)
#endif
unsigned int16_t          P0657_i_MapX        SEPARATOR
unsigned int16_t          P0658_i_MapY        SEPARATOR
REGISTER unsigned int16_t P0659_ui_CycleCount FINAL_SEPARATOR
{
        REGISTER SCENT* L0957_ps_Scent; /* BUG0_00 Useless code */
        REGISTER int16_t L0954_i_ScentIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER BOOLEAN L0955_B_Merge;
#endif
        REGISTER BOOLEAN L0956_B_CycleCountDefined;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER BOOLEAN L0955_B_Merge;
#endif
        SCENT L0958_s_Scent; /* BUG0_00 Useless code */


        if (L0954_i_ScentIndex = G0407_s_Party.ScentCount) {
                if (L0955_B_Merge = M007_GET(P0659_ui_CycleCount, MASK0x8000_MERGE_CYCLES)) {
                        M009_CLEAR(P0659_ui_CycleCount, MASK0x8000_MERGE_CYCLES);
                }
                L0958_s_Scent.Location.MapX = P0657_i_MapX; /* BUG0_00 Useless code */
                L0958_s_Scent.Location.MapY = P0658_i_MapY; /* BUG0_00 Useless code */
                L0958_s_Scent.Location.MapIndex = G0272_i_CurrentMapIndex; /* BUG0_00 Useless code */
                L0957_ps_Scent = G0407_s_Party.Scents; /* BUG0_00 Useless code */
                L0956_B_CycleCountDefined = C0_FALSE;
                while (L0954_i_ScentIndex--) {
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        *L0957_ps_Scent++ == L0958_s_Scent; /* BUG0_00 Useless code. The result of the comparison is ignored */
#endif
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        if ((*L0957_ps_Scent++).Location == L0958_s_Scent.Location) {
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        if ((*L0957_ps_Scent++).Scent == L0958_s_Scent.Scent) {
#endif
                                if (!L0956_B_CycleCountDefined) {
                                        L0956_B_CycleCountDefined = C1_TRUE;
                                        if (L0955_B_Merge) {
                                                P0659_ui_CycleCount = F0025_MAIN_GetMaximumValue(G0407_s_Party.ScentStrengths[L0954_i_ScentIndex], P0659_ui_CycleCount);
                                        } else {
                                                P0659_ui_CycleCount = F0024_MAIN_GetMinimumValue(80, G0407_s_Party.ScentStrengths[L0954_i_ScentIndex] + P0659_ui_CycleCount);
                                        }
                                }
                                G0407_s_Party.ScentStrengths[L0954_i_ScentIndex] = P0659_ui_CycleCount;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        }
#endif
                }
        }
}

STATICFUNCTION void F0318_CHAMPION_DropAllObjects(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0660_ui_ChampionIndex)
#endif
REGISTER unsigned int16_t P0660_ui_ChampionIndex FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned int16_t L0959_ui_Cell;
        REGISTER THING L0960_T_Thing;
#endif
        REGISTER unsigned int16_t L0961_ui_SlotIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L0960_T_Thing;
        REGISTER unsigned int16_t L0959_ui_Cell;
#endif


        L0959_ui_Cell = M516_CHAMPIONS[P0660_ui_ChampionIndex].Cell;
        for (L0961_ui_SlotIndex = C00_SLOT_READY_HAND; L0961_ui_SlotIndex < C30_SLOT_CHEST_1; L0961_ui_SlotIndex++) {
                if ((L0960_T_Thing = F0300_CHAMPION_GetObjectRemovedFromSlot(P0660_ui_ChampionIndex, G0057_ai_Graphic562_SlotDropOrder[L0961_ui_SlotIndex])) != C0xFFFF_THING_NONE) {
                        F0267_MOVE_GetMoveResult_CPSCE(M015_THING_WITH_NEW_CELL(L0960_T_Thing, L0959_ui_Cell), CM1_MAPX_NOT_ON_A_SQUARE, 0, G0306_i_PartyMapX, G0307_i_PartyMapY);
                }
        }
}

void F0319_CHAMPION_Kill(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0661_ui_ChampionIndex)
#endif
REGISTER unsigned int16_t P0661_ui_ChampionIndex FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0965_ps_Champion;
        REGISTER JUNK* L0966_ps_Junk;
        REGISTER unsigned int16_t L0962_ui_Multiple;
#define AL0962_ui_Cell              L0962_ui_Multiple
#define AL0962_ui_ChampionIconIndex L0962_ui_Multiple
        REGISTER unsigned int16_t L0963_ui_AliveChampionIndex;
        REGISTER THING L0964_T_Thing;


        L0965_ps_Champion = &M516_CHAMPIONS[P0661_ui_ChampionIndex];
#ifdef MEDIA485_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (P0661_ui_ChampionIndex == M001_ORDINAL_TO_INDEX(G0506_ui_ActingChampionOrdinal)) {
                F0388_MENUS_ClearActingChampion();
        }
#endif
        L0965_ps_Champion->CurrentHealth = 0;
        M008_SET(L0965_ps_Champion->Attributes, MASK0x1000_STATUS_BOX);
        if (M000_INDEX_TO_ORDINAL(P0661_ui_ChampionIndex) == G0423_i_InventoryChampionOrdinal) {
                if (G0331_B_PressingEye) {
                        G0331_B_PressingEye = C0_FALSE;
                        G0597_B_IgnoreMouseMovements = C0_FALSE;
                        if (!G0415_ui_LeaderEmptyHanded) {
                                F0034_OBJECT_DrawLeaderHandObjectName(G4055_s_LeaderHandObject.Thing);
                        }
                        G0587_i_HideMousePointerRequestCount = 1;
                        M523_MOUSE_ShowPointer();
                }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                else {
#endif
                        if (G0333_B_PressingMouth) {
                                G0333_B_PressingMouth = C0_FALSE;
                                G0597_B_IgnoreMouseMovements = C0_FALSE;
                                G0587_i_HideMousePointerRequestCount = 1;
                                M523_MOUSE_ShowPointer();
                        }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                }
#endif
                F0355_INVENTORY_Toggle_CPSE(C04_CHAMPION_CLOSE_INVENTORY);
        }
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if ((P0661_ui_ChampionIndex == G0411_i_LeaderIndex) && G2152_B_PressingClosedImaginaryFakeWall) {
                G2152_B_PressingClosedImaginaryFakeWall = C0_FALSE;
                G0597_B_IgnoreMouseMovements = C0_FALSE;
                G0587_i_HideMousePointerRequestCount = 1;
                M523_MOUSE_ShowPointer();
        }
#endif
        F0318_CHAMPION_DropAllObjects(P0661_ui_ChampionIndex);
        L0964_T_Thing = F0166_DUNGEON_GetUnusedThing(MASK0x8000_CHAMPION_BONES | C10_THING_TYPE_JUNK);
        if (L0964_T_Thing == C0xFFFF_THING_NONE) {
        } else {
                L0966_ps_Junk = (JUNK*)F0156_DUNGEON_GetThingData(L0964_T_Thing);
                L0966_ps_Junk->Type = C05_JUNK_BONES;
                L0966_ps_Junk->DoNotDiscard = C1_TRUE;
                L0966_ps_Junk->ChargeCount = P0661_ui_ChampionIndex;
                AL0962_ui_Cell = L0965_ps_Champion->Cell;
                F0267_MOVE_GetMoveResult_CPSCE(M015_THING_WITH_NEW_CELL(L0964_T_Thing, AL0962_ui_Cell), CM1_MAPX_NOT_ON_A_SQUARE, 0, G0306_i_PartyMapX, G0307_i_PartyMapY);
        }
#ifdef MEDIA485_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
        L0965_ps_Champion->SymbolStep = 0;
        L0965_ps_Champion->Symbols[0] = '\0';
        L0965_ps_Champion->Direction = G0308_i_PartyDirection;
        L0965_ps_Champion->MaximumDamageReceived = 0;
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_07_FIX */
        if (M000_INDEX_TO_ORDINAL(M026_CHAMPION_ICON_INDEX(AL0962_ui_Cell, G0308_i_PartyDirection)) == G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap) {
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_07_FIX */
        AL0962_ui_ChampionIconIndex = M026_CHAMPION_ICON_INDEX(AL0962_ui_Cell, G0308_i_PartyDirection);
        if (M000_INDEX_TO_ORDINAL(AL0962_ui_ChampionIconIndex) == G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap) {
#endif
                G0598_B_MousePointerBitmapUpdated = C1_TRUE;
                G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap = M000_INDEX_TO_ORDINAL(CM1_CHAMPION_NONE);
                G0592_B_BuildMousePointerScreenAreaRequested = C1_TRUE;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        } else {
#endif
#ifdef MEDIA457_P20JA
                F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                F0733_FillZoneByIndex(AL0962_ui_ChampionIconIndex + C113_ZONE_CHAMPION_ICON_TOP_LEFT, C00_COLOR_BLACK);
#endif
#ifdef MEDIA457_P20JA
                F0078_MOUSE_DisableScreenUpdate();
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0621_ClearChampionIconBox(AL0962_ui_ChampionIconIndex);
#endif
        }
        if (L0965_ps_Champion->PoisonEventCount) {
                F0323_CHAMPION_Unpoison(P0661_ui_ChampionIndex);
        }
#ifdef MEDIA238_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* CHANGE3_07_FIX The champion icon is erased when the champion is killed and simply not drawn anymore when drawing the state of a dead champion */
        G0578_B_UseByteBoxCoordinates = C0_FALSE;
        M524_FillScreenBox(&G0054_ai_Graphic562_Box_ChampionIcons[AL0962_ui_ChampionIconIndex << 2], C00_COLOR_BLACK);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0700_TriggerImmediateMouseEvent();
#endif
        F0292_CHAMPION_DrawState(P0661_ui_ChampionIndex);
        for (L0963_ui_AliveChampionIndex = C00_CHAMPION_FIRST, L0965_ps_Champion = M516_CHAMPIONS; L0963_ui_AliveChampionIndex < G0305_ui_PartyChampionCount; L0963_ui_AliveChampionIndex++, L0965_ps_Champion++) {
                if (L0965_ps_Champion->CurrentHealth)
                        break;
        }
        if (L0963_ui_AliveChampionIndex == G0305_ui_PartyChampionCount) { /* BUG0_43 The game does not end if the last living champion in the party is killed while looking at a candidate champion in a portrait. The condition to end the game when the whole party is killed is not true because the code considers the candidate champion as alive (in the loop above) */
                G0303_B_PartyDead = C1_TRUE;
#ifdef MEDIA019_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA
                return;
        }
#endif
#ifdef MEDIA485_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        } else {
#endif
                if (P0661_ui_ChampionIndex == G0411_i_LeaderIndex) {
                        F0368_COMMAND_SetLeader(L0963_ui_AliveChampionIndex);
                }
                if (P0661_ui_ChampionIndex == G0514_i_MagicCasterChampionIndex) {
                        F0394_MENUS_SetMagicCasterAndDrawSpellArea(L0963_ui_AliveChampionIndex);
                } else {
                        F0393_MENUS_DrawSpellAreaControls(G0514_i_MagicCasterChampionIndex);
                }
#ifdef MEDIA485_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        }
        F0078_MOUSE_DisableScreenUpdate();
#endif
}

void F0320_CHAMPION_ApplyAndDrawPendingDamageAndWounds(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER CHAMPION* L0971_ps_Champion;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER EVENT* L0972_ps_Event;
#endif
        REGISTER unsigned int16_t L0967_ui_ChampionIndex;
#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 L0968_ui_PendingDamage;
#endif
        REGISTER int16_t L0969_i_Multiple;
#define AL0969_i_Health     L0969_i_Multiple
#define AL0969_i_X          L0969_i_Multiple
#define AL0969_i_EventIndex L0969_i_Multiple
        REGISTER unsigned int16_t L0970_i_PendingWounds;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0973_i_Y;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0968_ui_PendingDamage;
#endif
        EVENT L0974_s_Event;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0975_ai_Box[4];
#endif


        L0971_ps_Champion = M516_CHAMPIONS;
        for (L0967_ui_ChampionIndex = C00_CHAMPION_FIRST; L0967_ui_ChampionIndex < G0305_ui_PartyChampionCount; L0967_ui_ChampionIndex++, L0971_ps_Champion++) {
                M008_SET(L0971_ps_Champion->Wounds, L0970_i_PendingWounds = G0410_ai_ChampionPendingWounds[L0967_ui_ChampionIndex]);
                G0410_ai_ChampionPendingWounds[L0967_ui_ChampionIndex] = 0;
                if (!(L0968_ui_PendingDamage = G0409_ai_ChampionPendingDamage[L0967_ui_ChampionIndex]))
                        continue;
                G0409_ai_ChampionPendingDamage[L0967_ui_ChampionIndex] = 0;
                if (!(AL0969_i_Health = L0971_ps_Champion->CurrentHealth))
                        continue;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                if ((AL0969_i_Health = AL0969_i_Health - L0968_ui_PendingDamage) <= 0) {
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                if ((AL0969_i_Health -= L0968_ui_PendingDamage) <= 0) {
#endif
                        F0319_CHAMPION_Kill(L0967_ui_ChampionIndex);
                } else {
                        L0971_ps_Champion->CurrentHealth = AL0969_i_Health;
                        M008_SET(L0971_ps_Champion->Attributes, MASK0x0100_STATISTICS);
                        if (L0970_i_PendingWounds) {
                                M008_SET(L0971_ps_Champion->Attributes, MASK0x2000_WOUNDS);
                        }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        AL0969_i_X = L0967_ui_ChampionIndex * C69_CHAMPION_STATUS_BOX_SPACING;
                        M770_BOX_TOP(L0975_ai_Box) = 0;
                        F0077_MOUSE_EnableScreenUpdate_CPSE();
                        if (M000_INDEX_TO_ORDINAL(L0967_ui_ChampionIndex) == G0423_i_InventoryChampionOrdinal) {
                                M771_BOX_BOTTOM(L0975_ai_Box) = 28;
                                M769_BOX_RIGHT(L0975_ai_Box) = (M768_BOX_LEFT(L0975_ai_Box) = AL0969_i_X + 7) + 31; /* Box is over the champion portrait in the status box */
                                M520_F0021_MAIN_BlitToScreen(F0489_MEMORY_GetNativeBitmapOrGraphic(C016_GRAPHIC_DAMAGE_TO_CHAMPION_BIG), L0975_ai_Box, C016_BYTE_WIDTH, C10_COLOR_FLESH, 29);
                                if (L0968_ui_PendingDamage < 10) { /* 1 digit */
                                        AL0969_i_X += 21;
                                } else {
                                        if (L0968_ui_PendingDamage < 100) { /* 2 digits */
                                                AL0969_i_X += 18;
                                        } else { /* 3 digits */
                                                AL0969_i_X += 15;
                                        }
                                }
                                L0973_i_Y = 16;
                        } else {
                                M771_BOX_BOTTOM(L0975_ai_Box) = 6;
                                M769_BOX_RIGHT(L0975_ai_Box) = (M768_BOX_LEFT(L0975_ai_Box) = AL0969_i_X) + 47; /* Box is over the champion name in the status box */
                                M520_F0021_MAIN_BlitToScreen(F0489_MEMORY_GetNativeBitmapOrGraphic(C015_GRAPHIC_DAMAGE_TO_CHAMPION_SMALL), L0975_ai_Box, C024_BYTE_WIDTH, C10_COLOR_FLESH, 7);
                                if (L0968_ui_PendingDamage < 10) { /* 1 digit */
                                        AL0969_i_X += 19;
                                } else {
                                        if (L0968_ui_PendingDamage < 100) { /* 2 digits */
                                                AL0969_i_X += 16;
                                        } else { /* 3 digits */
                                                AL0969_i_X += 13;
                                        }
                                }
                                L0973_i_Y = 5;
                        }
                        F0053_TEXT_PrintToLogicalScreen(AL0969_i_X, L0973_i_Y, C15_COLOR_WHITE, C08_COLOR_RED, F0288_CHAMPION_GetStringFromInteger(L0968_ui_PendingDamage, C0_FALSE, 3));
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        F0623_DrawDamageToChampion_F0320_sub(L0967_ui_ChampionIndex, L0968_ui_PendingDamage);
#endif
                        if ((AL0969_i_EventIndex = L0971_ps_Champion->HideDamageReceivedEventIndex) == -1) {
                                L0974_s_Event.A.A.Type = C12_EVENT_HIDE_DAMAGE_RECEIVED;
                                M033_SET_MAP_AND_TIME(L0974_s_Event.Map_Time, G0309_i_PartyMapIndex, G0313_ul_GameTime + 5);
                                L0974_s_Event.A.A.Priority = L0967_ui_ChampionIndex;
                                L0971_ps_Champion->HideDamageReceivedEventIndex = F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0974_s_Event);
                        } else {
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                L0972_ps_Event = &G0370_ps_Events[AL0969_i_EventIndex];
                                M033_SET_MAP_AND_TIME(L0972_ps_Event->Map_Time, G0309_i_PartyMapIndex, G0313_ul_GameTime + 5);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                M033_SET_MAP_AND_TIME(G0370_ps_Events[AL0969_i_EventIndex].Map_Time, G0309_i_PartyMapIndex, G0313_ul_GameTime + 5);
#endif
                                F0236_TIMELINE_FixPlacement(F0235_TIMELINE_GetIndex(AL0969_i_EventIndex));
                        }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        F0292_CHAMPION_DrawState(L0967_ui_ChampionIndex);
                        F0078_MOUSE_DisableScreenUpdate();
#endif
                }
        }
}

int16_t F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0662_i_ChampionIndex, P0663_i_Attack, P0664_ui_AllowedWounds, P0665_ui_AttackType)
int16_t          P0662_i_ChampionIndex  SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t P0662_i_ChampionIndex  SEPARATOR
#endif
REGISTER int16_t P0663_i_Attack         SEPARATOR
unsigned int16_t P0664_ui_AllowedWounds SEPARATOR
unsigned int16_t P0665_ui_AttackType    FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0979_ps_Champion;
        REGISTER int16_t L0976_i_Multiple;
#define AL0976_i_WoundIndex     L0976_i_Multiple
#define AL0976_i_WisdomFactor   L0976_i_Multiple
#define AL0976_i_AdjustedAttack L0976_i_Multiple
        REGISTER unsigned int16_t L0977_ui_Defense;
        REGISTER unsigned int16_t L0978_ui_WoundCount;


        if ((P0662_i_ChampionIndex == CM1_CHAMPION_NONE) || (M000_INDEX_TO_ORDINAL(P0662_i_ChampionIndex) == G0299_ui_CandidateChampionOrdinal || G0302_B_GameWon)) { /* BUG0_00 Useless code. This condition is never true (except in the context of BUG0_43) */
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
                return; /* BUG0_01 Coding error without consequence. Undefined return value. No consequence because this code is never executed (except in the context of BUG0_43) */
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                return 0;
#endif
        }
        if (P0663_i_Attack <= 0) {
                return 0;
        }
        L0979_ps_Champion = &M516_CHAMPIONS[P0662_i_ChampionIndex];
        if (!L0979_ps_Champion->CurrentHealth) {
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_11_OPTIMIZATION */
                T0321004:
#endif
                return 0;
        }
        if (P0665_ui_AttackType != C0_ATTACK_NORMAL) {
                for (L0978_ui_WoundCount = 0, AL0976_i_WoundIndex = C00_SLOT_READY_HAND, L0977_ui_Defense = 0; AL0976_i_WoundIndex <= C05_SLOT_FEET; AL0976_i_WoundIndex++) {
                        if (P0664_ui_AllowedWounds & (1 << AL0976_i_WoundIndex)) { /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE test */
                                L0978_ui_WoundCount++;
                                L0977_ui_Defense += F0313_CHAMPION_GetWoundDefense(P0662_i_ChampionIndex, AL0976_i_WoundIndex | ((P0665_ui_AttackType == C4_ATTACK_SHARP) ? MASK0x8000_USE_SHARP_DEFENSE : MASK0x0000_DO_NOT_USE_SHARP_DEFENSE));
                        }
                }
                if (L0978_ui_WoundCount) {
                        L0977_ui_Defense /= L0978_ui_WoundCount;
                }
                switch (P0665_ui_AttackType) {
                        case C6_ATTACK_PSYCHIC:
                                if ((AL0976_i_WisdomFactor = 115 - L0979_ps_Champion->Statistics[C3_STATISTIC_WISDOM][C1_CURRENT]) <= 0) {
                                        P0663_i_Attack = 0;
                                } else {
#ifdef PC_FIX_CODE_SIZE
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
        P0663_i_Attack++;
#endif
                                        P0663_i_Attack = F0030_MAIN_GetScaledProduct(P0663_i_Attack, 6, AL0976_i_WisdomFactor);
                                }
                                goto T0321024;
                        case C5_ATTACK_MAGIC:
                                P0663_i_Attack = F0307_CHAMPION_GetStatisticAdjustedAttack(L0979_ps_Champion, C5_STATISTIC_ANTIMAGIC, P0663_i_Attack);
                                P0663_i_Attack -= G0407_s_Party.SpellShieldDefense;
                                goto T0321024;
                        case C1_ATTACK_FIRE:
                                P0663_i_Attack = F0307_CHAMPION_GetStatisticAdjustedAttack(L0979_ps_Champion, C6_STATISTIC_ANTIFIRE, P0663_i_Attack);
                                P0663_i_Attack -= G0407_s_Party.FireShieldDefense;
                                break;
                        case C2_ATTACK_SELF:
                                L0977_ui_Defense >>= 1;
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                L0977_ui_Defense += F0303_CHAMPION_GetSkillLevel(P0662_i_ChampionIndex, C01_SKILL_NINJA);
#endif
                        case C3_ATTACK_BLUNT:
                        case C4_ATTACK_SHARP:
                        case C7_ATTACK_LIGHTNING:
                                break;
                }
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_12_FIX The champion damage is 0 if the party fire shield value is higher than the fire attack value */
                if (P0663_i_Attack <= 0)
                        goto T0321004;
#endif
                P0663_i_Attack = F0030_MAIN_GetScaledProduct(P0663_i_Attack, 6, 130 - L0977_ui_Defense); /* BUG0_44 A champion may take much more damage than expected after a Black Flame attack or an impact with a Fireball projectile. If the party has a fire shield defense value higher than the fire attack value then the resulting intermediary attack value is negative and damage should be 0. However, the negative value is still used for further computations and the result may be a very high positive attack value which may kill a champion. This can occur only for C1_ATTACK_FIRE and if P0663_i_Attack is negative before calling F0030_MAIN_GetScaledProduct */
                T0321024:
                if (P0663_i_Attack <= 0)
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_11_OPTIMIZATION */
                        return 0;
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_11_OPTIMIZATION Code deduplication */
                        goto T0321004;
#endif
                if (P0663_i_Attack > (AL0976_i_AdjustedAttack = F0307_CHAMPION_GetStatisticAdjustedAttack(L0979_ps_Champion, C4_STATISTIC_VITALITY, M003_RANDOM(128) + 10))) { /* BUG0_45 Champions with a high vitality are more likely to get wounded. This bug is present in all versions but Atari ST versions are not affected because of BUG0_41 that ignores Vitality while determining the probability of being wounded. The behavior is be the opposite of what it should be: the higher the vitality of a champion, the lower the result of F0307_CHAMPION_GetStatisticAdjustedAttack and the more likely the champion could get wounded (because of more iterations in the loop below) */
                        do {
                                M008_SET(G0410_ai_ChampionPendingWounds[P0662_i_ChampionIndex], (1 << M003_RANDOM(8)) & P0664_ui_AllowedWounds);
                        } while ((P0663_i_Attack > (AL0976_i_AdjustedAttack <<= 1)) && AL0976_i_AdjustedAttack);
                }
                if (G0300_B_PartyIsResting) {
                        F0314_CHAMPION_WakeUp();
                }
        }
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_12_FIX This condition cannot be true, if P0663_i_Attack was negative then the function would have already returned in a previous check */
        if (P0663_i_Attack <= 0) { /* BUG0_00 Useless code */
                P0663_i_Attack = 0;
        }
#endif
        G0409_ai_ChampionPendingDamage[P0662_i_ChampionIndex] += P0663_i_Attack;
        return P0663_i_Attack;
}

void F0322_CHAMPION_Poison(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0666_i_ChampionIndex, P0667_ui_Attack)
int16_t          P0666_i_ChampionIndex SEPARATOR
unsigned int16_t P0667_ui_Attack       FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t          P0666_i_ChampionIndex SEPARATOR
REGISTER unsigned int16_t P0667_ui_Attack       FINAL_SEPARATOR
#endif
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER CHAMPION* L0981_ps_Champion;
#endif
        EVENT L0980_s_Event;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        CHAMPION* L0981_ps_Champion;
#endif


        if ((P0666_i_ChampionIndex == CM1_CHAMPION_NONE) || (M000_INDEX_TO_ORDINAL(P0666_i_ChampionIndex) == G0299_ui_CandidateChampionOrdinal))
                return;
        L0981_ps_Champion = &M516_CHAMPIONS[P0666_i_ChampionIndex];
        F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage(P0666_i_ChampionIndex, F0025_MAIN_GetMaximumValue(1, P0667_ui_Attack >> 6), MASK0x0000_WOUND_NONE, C0_ATTACK_NORMAL);
        M008_SET(L0981_ps_Champion->Attributes, MASK0x0100_STATISTICS);
        if ((M000_INDEX_TO_ORDINAL(P0666_i_ChampionIndex) == G0423_i_InventoryChampionOrdinal) && (G0424_i_PanelContent == M565_PANEL_FOOD_WATER_POISONED)) {
                M008_SET(L0981_ps_Champion->Attributes, MASK0x0800_PANEL);
        }
        if (--P0667_ui_Attack) {
                L0981_ps_Champion->PoisonEventCount++;
                L0980_s_Event.A.A.Type = C75_EVENT_POISON_CHAMPION;
                L0980_s_Event.A.A.Priority = P0666_i_ChampionIndex;
                M033_SET_MAP_AND_TIME(L0980_s_Event.Map_Time, G0309_i_PartyMapIndex, G0313_ul_GameTime + 36);
                L0980_s_Event.B.Attack = P0667_ui_Attack;
                F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L0980_s_Event);
        }
        F0292_CHAMPION_DrawState(P0666_i_ChampionIndex);
}

void F0323_CHAMPION_Unpoison(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0668_i_ChampionIndex)
#endif
int16_t P0668_i_ChampionIndex FINAL_SEPARATOR
{
        REGISTER EVENT* L0983_ps_Event;
        REGISTER unsigned int16_t L0982_ui_EventIndex;


        if (P0668_i_ChampionIndex == CM1_CHAMPION_NONE) {
                return;
        }
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
        for (L0982_ui_EventIndex = 0, L0983_ps_Event = G0370_ps_Events; L0982_ui_EventIndex < G0369_EventMaximumCount; L0983_ps_Event++, L0982_ui_EventIndex++) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        for (L0982_ui_EventIndex = 0, L0983_ps_Event = G0370_ps_Events; L0982_ui_EventIndex < G2009_i_LargestUsedEventOrdinal; L0983_ps_Event++, L0982_ui_EventIndex++) {
#endif
                if ((L0983_ps_Event->A.A.Type == C75_EVENT_POISON_CHAMPION) && (L0983_ps_Event->A.A.Priority == P0668_i_ChampionIndex)) {
                        F0237_TIMELINE_DeleteEvent(L0982_ui_EventIndex);
                }
        }
        M516_CHAMPIONS[P0668_i_ChampionIndex].PoisonEventCount = 0;
}

int16_t F0324_CHAMPION_DamageAll_GetDamagedChampionCount(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0669_ui_Attack, P0670_i_Wounds, P0671_i_AttackType)
#endif
REGISTER unsigned int16_t P0669_ui_Attack    SEPARATOR
int16_t                   P0670_i_Wounds     SEPARATOR
int16_t                   P0671_i_AttackType FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER char* L0987_pc_Unreferenced; /* BUG0_00 Useless code */
#endif
        REGISTER unsigned int16_t L0984_ui_ChampionIndex;
        REGISTER unsigned int16_t L0985_ui_RandomAttack;
        REGISTER int16_t L0986_i_DamagedChampionCount;


        if (!P0669_ui_Attack) {
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
                return; /* BUG0_01 Coding error without consequence. Undefined return value. No consequence because this code is never executed */
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                return 0;
#endif
        }
        P0669_ui_Attack -= (L0985_ui_RandomAttack = (P0669_ui_Attack >> 3) + 1);
        L0985_ui_RandomAttack <<= 1;
        for (L0986_i_DamagedChampionCount = 0, L0984_ui_ChampionIndex = C00_CHAMPION_FIRST; L0984_ui_ChampionIndex < G0305_ui_PartyChampionCount; L0984_ui_ChampionIndex++) {
                if (F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage(L0984_ui_ChampionIndex, F0025_MAIN_GetMaximumValue(1, P0669_ui_Attack + M002_RANDOM(L0985_ui_RandomAttack)), P0670_i_Wounds, P0671_i_AttackType)) { /* Actual attack is P0669_ui_Attack +/- (P0669_ui_Attack / 8) */
                        L0986_i_DamagedChampionCount++;
                }
        }
        return L0986_i_DamagedChampionCount;
}

void F0325_CHAMPION_DecrementStamina(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0672_i_ChampionIndex, P0673_i_Decrement)
#endif
int16_t P0672_i_ChampionIndex SEPARATOR
int16_t P0673_i_Decrement     FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0989_ps_Champion;
        REGISTER int16_t L0988_i_Stamina;


        if (P0672_i_ChampionIndex == CM1_CHAMPION_NONE) {
                return;
        }
        L0989_ps_Champion = &M516_CHAMPIONS[P0672_i_ChampionIndex];
        if ((L0988_i_Stamina = (L0989_ps_Champion->CurrentStamina -= P0673_i_Decrement)) <= 0) {
                L0989_ps_Champion->CurrentStamina = 0;
                F0321_CHAMPION_AddPendingDamageAndWounds_GetDamage(P0672_i_ChampionIndex, (-L0988_i_Stamina) >> 1, MASK0x0000_WOUND_NONE, C0_ATTACK_NORMAL);
        } else {
                if (L0988_i_Stamina > L0989_ps_Champion->MaximumStamina) {
                        L0989_ps_Champion->CurrentStamina = L0989_ps_Champion->MaximumStamina;
                }
        }
        M008_SET(L0989_ps_Champion->Attributes, MASK0x0200_LOAD | MASK0x0100_STATISTICS);
}

void F0326_CHAMPION_ShootProjectile(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0674_ps_Champion, P0675_T_Thing, P0676_i_KineticEnergy, P0677_i_Attack, P0678_i_StepEnergy)
#endif
REGISTER CHAMPION* P0674_ps_Champion     SEPARATOR
THING              P0675_T_Thing         SEPARATOR
int16_t            P0676_i_KineticEnergy SEPARATOR
int16_t            P0677_i_Attack        SEPARATOR
int16_t            P0678_i_StepEnergy    FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L0990_ui_Direction;


        L0990_ui_Direction = P0674_ps_Champion->Direction;
        F0212_PROJECTILE_Create(P0675_T_Thing, G0306_i_PartyMapX, G0307_i_PartyMapY, M021_NORMALIZE((((P0674_ps_Champion->Cell - L0990_ui_Direction + 1) & 0x0002) >> 1) + L0990_ui_Direction), L0990_ui_Direction, P0676_i_KineticEnergy, P0677_i_Attack, P0678_i_StepEnergy);
        /* BUG0_46 You can run into a projectile shot by a champion. When a champion throws an object, movement is disabled for a short time in the direction in which the object was thrown to prevent the party from running into the projectile. However, when a champion shoots an object or casts a spell, movement is not disabled and the party can run into the projectile. This applies to the actions 'Shoot' (Bow/Claw Bow, Crossbow, Speedbow, Sling), 'Lightning' (Stormring, Bolt Blade/Storm, The Conduit/Serpent Staff), 'Dispell' (Yew Staff, Staff Of Manar/Staff Of Irra), 'Fireball' (Flamitt, Fury/Ra Blade), 'Spit' (none), 'Invoke' (The Firestaff) and to all projectile spells (Fireball, Lightning Bolt, Harm Non Material, Open Door, Poison Bolt, Poison Cloud) */
#ifdef MEDIA348_S21E_X30J_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE8_07_FIX Movement is disabled for a short time after shooting projectiles */
        G0311_i_ProjectileDisabledMovementTicks = 4;
        G0312_i_LastProjectileDisabledMovementDirection = L0990_ui_Direction;
#endif
}

BOOLEAN F0327_CHAMPION_IsProjectileSpellCast(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0679_ui_ChampionIndex, P0680_T_Thing, P0681_i_KineticEnergy, P0682_ui_RequiredManaAmount)
#endif
unsigned int16_t P0679_ui_ChampionIndex      SEPARATOR
THING            P0680_T_Thing               SEPARATOR
REGISTER int16_t P0681_i_KineticEnergy       SEPARATOR
unsigned int16_t P0682_ui_RequiredManaAmount FINAL_SEPARATOR
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER CHAMPION* L0992_ps_Champion;
#endif
        REGISTER int16_t L0991_i_StepEnergy;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER CHAMPION* L0992_ps_Champion;
#endif


        L0992_ps_Champion = &M516_CHAMPIONS[P0679_ui_ChampionIndex];
        if (L0992_ps_Champion->CurrentMana < P0682_ui_RequiredManaAmount) {
                return C0_FALSE;
        }
        L0992_ps_Champion->CurrentMana -= P0682_ui_RequiredManaAmount;
        M008_SET(L0992_ps_Champion->Attributes, MASK0x0100_STATISTICS);
        L0991_i_StepEnergy = 10 - F0024_MAIN_GetMinimumValue(8, L0992_ps_Champion->MaximumMana >> 3);
        if (P0681_i_KineticEnergy < (L0991_i_StepEnergy << 2)) {
                P0681_i_KineticEnergy += 3;
                L0991_i_StepEnergy--;
        }
        F0326_CHAMPION_ShootProjectile(L0992_ps_Champion, P0680_T_Thing, P0681_i_KineticEnergy, 90, L0991_i_StepEnergy);
        /* BUG0_01 Coding error without consequence. Undefined return value. A 'return C1_TRUE;' statement is missing. No consequence because the actual value returned cannot be 0: it is the value of register D0 at the end of execution of F0326_CHAMPION_ShootProjectile, which is the return value of F0212_PROJECTILE_Create, which in turn is the return value of F0238_TIMELINE_AddEvent_GetEventIndex_CPSE, which is the index of the event added for the projectile. This index cannot be 0 because event 0 is always event C53_EVENT_WATCHDOG */
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        return C1_TRUE;
#endif
}

BOOLEAN F0328_CHAMPION_IsObjectThrown(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0683_ui_ChampionIndex, P0684_i_SlotIndex, P0685_i_Side)
unsigned int16_t          P0683_ui_ChampionIndex SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0683_ui_ChampionIndex SEPARATOR
#endif
int16_t                   P0684_i_SlotIndex      SEPARATOR
int16_t                   P0685_i_Side           FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0997_ps_Champion;
        REGISTER WEAPON_INFO* L0998_ps_WeaponInfo;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L0993_i_KineticEnergy;
        REGISTER int16_t L0994_i_Multiple;
#define AL0994_i_Experience L0994_i_Multiple
#define AL0994_i_Attack     L0994_i_Multiple
#endif
        REGISTER int16_t L0995_i_Multiple;
#define AL0995_i_WeaponKineticEnergy L0995_i_Multiple
#define AL0995_i_SkillLevel          L0995_i_Multiple
#define AL0995_i_StepEnergy          L0995_i_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER THING L0996_T_Thing;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER THING L0996_T_Thing;
        REGISTER int16_t L0994_i_Multiple;
#define AL0994_i_Experience L0994_i_Multiple
#define AL0994_i_Attack     L0994_i_Multiple
        REGISTER int16_t L0993_i_KineticEnergy;
#endif
        THING L0999_T_ActionHandThing;
        BOOLEAN L1000_B_ThrowingLeaderHandObject;


        L1000_B_ThrowingLeaderHandObject = C0_FALSE;
        if (P0684_i_SlotIndex < 0) { /* Throw object in leader hand, which is temporarily placed in action hand */
                if (G0415_ui_LeaderEmptyHanded) {
                        return C0_FALSE;
                }
                L0996_T_Thing = F0298_CHAMPION_GetObjectRemovedFromLeaderHand();
                L0997_ps_Champion = &M516_CHAMPIONS[P0683_ui_ChampionIndex];
                L0999_T_ActionHandThing = L0997_ps_Champion->Slots[C01_SLOT_ACTION_HAND];
                L0997_ps_Champion->Slots[C01_SLOT_ACTION_HAND] = L0996_T_Thing;
                P0684_i_SlotIndex = C01_SLOT_ACTION_HAND;
                L1000_B_ThrowingLeaderHandObject = C1_TRUE;
        }
        L0993_i_KineticEnergy = F0312_CHAMPION_GetStrength(P0683_ui_ChampionIndex, P0684_i_SlotIndex);
        if (L1000_B_ThrowingLeaderHandObject) {
                L0997_ps_Champion->Slots[P0684_i_SlotIndex] = L0999_T_ActionHandThing;
        } else {
                if ((L0996_T_Thing = F0300_CHAMPION_GetObjectRemovedFromSlot(P0683_ui_ChampionIndex, P0684_i_SlotIndex)) == C0xFFFF_THING_NONE) {
                        return C0_FALSE;
                }
        }
        F0064_SOUND_RequestPlay_CPSD(M563_SOUND_COMBAT_ATTACK_SKELETON_ANIMATED_ARMOUR_DETH_KNIGHT, G0306_i_PartyMapX, G0307_i_PartyMapY, C01_MODE_PLAY_IF_PRIORITIZED);
        F0325_CHAMPION_DecrementStamina(P0683_ui_ChampionIndex, F0305_CHAMPION_GetThrowingStaminaCost(L0996_T_Thing));
        F0330_CHAMPION_DisableAction(P0683_ui_ChampionIndex, 4);
        AL0994_i_Experience = 8;
        AL0995_i_WeaponKineticEnergy = 1;
        if (M012_TYPE(L0996_T_Thing) == C05_THING_TYPE_WEAPON) {
                AL0994_i_Experience += 4;
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                L0998_ps_WeaponInfo = &G0238_as_Graphic559_WeaponInfo[((WEAPON*)G0284_apuc_ThingData[C05_THING_TYPE_WEAPON])[M013_INDEX(L0996_T_Thing)].Type];
#endif
#ifdef MEDIA227_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE2_01_OPTIMIZATION Inline code replaced by function calls */
                L0998_ps_WeaponInfo = F0158_DUNGEON_GetWeaponInfo(L0996_T_Thing);
#endif
                if (L0998_ps_WeaponInfo->Class <= C012_CLASS_POISON_DART) {
                        AL0994_i_Experience += (AL0995_i_WeaponKineticEnergy = L0998_ps_WeaponInfo->KineticEnergy) >> 2;
                }
        }
        F0304_CHAMPION_AddSkillExperience(P0683_ui_ChampionIndex, C10_SKILL_THROW, AL0994_i_Experience);
        L0993_i_KineticEnergy += AL0995_i_WeaponKineticEnergy;
        AL0995_i_SkillLevel = F0303_CHAMPION_GetSkillLevel(P0683_ui_ChampionIndex, C10_SKILL_THROW);
        L0993_i_KineticEnergy += M003_RANDOM(16) + (L0993_i_KineticEnergy >> 1) + AL0995_i_SkillLevel;
        AL0994_i_Attack = F0026_MAIN_GetBoundedValue(40, (AL0995_i_SkillLevel << 3) + M003_RANDOM(32), 200);
        AL0995_i_StepEnergy = F0025_MAIN_GetMaximumValue(5, 11 - AL0995_i_SkillLevel);
        F0212_PROJECTILE_Create(L0996_T_Thing, G0306_i_PartyMapX, G0307_i_PartyMapY, M021_NORMALIZE(G0308_i_PartyDirection + P0685_i_Side), G0308_i_PartyDirection, L0993_i_KineticEnergy, AL0994_i_Attack, AL0995_i_StepEnergy);
        G0311_i_ProjectileDisabledMovementTicks = 4;
        G0312_i_LastProjectileDisabledMovementDirection = G0308_i_PartyDirection;
        F0292_CHAMPION_DrawState(P0683_ui_ChampionIndex);
        return C1_TRUE;
}

BOOLEAN F0329_CHAMPION_IsLeaderHandObjectThrown(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0686_i_Side)
#endif
int16_t P0686_i_Side FINAL_SEPARATOR
{
        if (G0411_i_LeaderIndex == CM1_CHAMPION_NONE) {
                return C0_FALSE;
        }
        return F0328_CHAMPION_IsObjectThrown(G0411_i_LeaderIndex, CM1_SLOT_LEADER_HAND, P0686_i_Side);
}

void F0330_CHAMPION_DisableAction(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0687_ui_ChampionIndex, P0688_ui_Ticks)
unsigned int16_t          P0687_ui_ChampionIndex SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned int16_t P0687_ui_ChampionIndex SEPARATOR
#endif
unsigned int16_t          P0688_ui_Ticks         FINAL_SEPARATOR
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER CHAMPION* L1004_ps_Champion;
        REGISTER long L1001_l_UpdatedEnableActionEventTime;
        REGISTER long L1002_l_CurrentEnableActionEventTime;
        REGISTER int16_t L1003_i_EventIndex;
#endif
        EVENT L1005_s_Event;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER long L1001_l_UpdatedEnableActionEventTime;
        REGISTER long L1002_l_CurrentEnableActionEventTime;
        REGISTER int16_t L1003_i_EventIndex;
        REGISTER CHAMPION* L1004_ps_Champion;
#endif


        L1004_ps_Champion = &M516_CHAMPIONS[P0687_ui_ChampionIndex];
        L1001_l_UpdatedEnableActionEventTime = G0313_ul_GameTime + P0688_ui_Ticks;
        L1005_s_Event.A.A.Type = C11_EVENT_ENABLE_CHAMPION_ACTION;
        L1005_s_Event.A.A.Priority = P0687_ui_ChampionIndex;
        L1005_s_Event.B.SlotOrdinal = 0;
        if ((L1003_i_EventIndex = L1004_ps_Champion->EnableActionEventIndex) >= 0) {
                L1002_l_CurrentEnableActionEventTime = M030_TIME(G0370_ps_Events[L1003_i_EventIndex].Map_Time);
                if (L1001_l_UpdatedEnableActionEventTime >= L1002_l_CurrentEnableActionEventTime) {
                        L1001_l_UpdatedEnableActionEventTime += (L1002_l_CurrentEnableActionEventTime - G0313_ul_GameTime) >> 1;
                } else {
                        L1001_l_UpdatedEnableActionEventTime = L1002_l_CurrentEnableActionEventTime + (P0688_ui_Ticks >> 1);
                }
                F0237_TIMELINE_DeleteEvent(L1003_i_EventIndex);
        } else {
                M008_SET(L1004_ps_Champion->Attributes, MASK0x8000_ACTION_HAND | MASK0x0008_DISABLE_ACTION);
                F0292_CHAMPION_DrawState(P0687_ui_ChampionIndex);
        }
        M033_SET_MAP_AND_TIME(L1005_s_Event.Map_Time, G0309_i_PartyMapIndex, L1001_l_UpdatedEnableActionEventTime);
        L1004_ps_Champion->EnableActionEventIndex = F0238_TIMELINE_AddEvent_GetEventIndex_CPSE(&L1005_s_Event);
}

void F0331_CHAMPION_ApplyTimeEffects_CPSF(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER CHAMPION* L1010_ps_Champion;
        REGISTER unsigned char* L1011_puc_Statistic;
#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 L1006_ui_Multiple;
#define AL9998_ui_GameTime      L1006_ui_Multiple
#define AL9997_ui_ChampionIndex L1006_ui_Multiple
        REGISTER unsigned int16_t L1007_Multiple;
#define AL9995_ui_StaminaGainCycleCount L1007_Multiple
#endif
#define AL1007_ScentIndex         L1007_Multiple
#define AL1007_ManaGain           L1007_Multiple
#define AL1007_StatisticIndex     L1007_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#define AL9995_ui_StaminaGainCycleCount L1006_ui_Multiple
        REGISTER int16_t L1007_Multiple;
#define AL9996_i_SkillIndex       L1007_Multiple
#define AL9994_i_StaminaMagnitude L1007_Multiple
#define AL9993_i_StaminaLoss      L1007_Multiple
#endif
        REGISTER unsigned int16_t L1008_ui_Multiple;
#define AL1008_ui_WizardPriestSkillLevel L1008_ui_Multiple
#define AL1008_ui_Delay                  L1008_ui_Multiple
#define AL1008_ui_StaminaAboveHalf       L1008_ui_Multiple
#define AL1008_ui_StatisticMaximum       L1008_ui_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L1009_i_Multiple;
#define AL9996_i_SkillIndex       L1009_i_Multiple
#define AL9994_i_StaminaMagnitude L1009_i_Multiple
#define AL9993_i_StaminaLoss      L1009_i_Multiple
        unsigned int16_t L1012_ui_TimeCriteria;
        int16_t L1013_i_Multiple;
#endif
#define AL1013_i_StaminaAmount L1013_i_Multiple
#define AL1013_i_HealthGain    L1013_i_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#define AL9998_ui_GameTime L1008_ui_Multiple
        REGISTER unsigned int16_t L1006_ui_Multiple;
        REGISTER unsigned int16_t L1009_i_Multiple;
#define AL9997_ui_ChampionIndex L1009_i_Multiple
        REGISTER int16_t L1013_i_Multiple;
        unsigned int16_t L1012_ui_TimeCriteria;
#endif
        SCENT L1014_s_Scent;


        if (!G0305_ui_PartyChampionCount) {
                return;
        }
        L1014_s_Scent.Location.MapX = G0306_i_PartyMapX;
        L1014_s_Scent.Location.MapY = G0307_i_PartyMapY;
        L1014_s_Scent.Location.MapIndex = G0309_i_PartyMapIndex;
        AL1007_ScentIndex = 0;
        while ((int16_t)AL1007_ScentIndex < (int16_t)G0407_s_Party.ScentCount - 1) {
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                G0407_s_Party.Scents[AL1007_ScentIndex] == L1014_s_Scent; /* BUG0_00 Useless code. The result of the comparison is ignored */
#endif
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                if (G0407_s_Party.Scents[AL1007_ScentIndex].Location != L1014_s_Scent.Location) {
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                if (G0407_s_Party.Scents[AL1007_ScentIndex].Scent != L1014_s_Scent.Scent) {
#endif
                        if (!(G0407_s_Party.ScentStrengths[AL1007_ScentIndex] = F0025_MAIN_GetMaximumValue(0, G0407_s_Party.ScentStrengths[AL1007_ScentIndex] - 1)) && !AL1007_ScentIndex) {
                                F0316_CHAMPION_DeleteScent(0);
                                continue;
                        }
#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
                AL1007_ScentIndex++;
        }
        AL9998_ui_GameTime = G0313_ul_GameTime;
        L1012_ui_TimeCriteria = (((AL9998_ui_GameTime & 0x0080) + ((AL9998_ui_GameTime & 0x0100) >> 2)) + ((AL9998_ui_GameTime & 0x0040) << 2)) >> 2;
        for (AL9997_ui_ChampionIndex = C00_CHAMPION_FIRST, L1010_ps_Champion = M516_CHAMPIONS; AL9997_ui_ChampionIndex < G0305_ui_PartyChampionCount; AL9997_ui_ChampionIndex++, L1010_ps_Champion++) {
                if (L1010_ps_Champion->CurrentHealth && (M000_INDEX_TO_ORDINAL(AL9997_ui_ChampionIndex) != G0299_ui_CandidateChampionOrdinal)) {
                        if ((L1010_ps_Champion->CurrentMana < L1010_ps_Champion->MaximumMana) && (L1012_ui_TimeCriteria < (L1010_ps_Champion->Statistics[C3_STATISTIC_WISDOM][C1_CURRENT] + (AL1008_ui_WizardPriestSkillLevel = F0303_CHAMPION_GetSkillLevel(AL9997_ui_ChampionIndex, C03_SKILL_WIZARD) + F0303_CHAMPION_GetSkillLevel(AL9997_ui_ChampionIndex, C02_SKILL_PRIEST))))) {
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_00_IMPROVEMENT Faster regeneration. Mana gain is ((MaximumMana / 64) + 1) and Stamina cost is Max(7, 16 - WizardPriestLevel) */
                                F0325_CHAMPION_DecrementStamina(AL9997_ui_ChampionIndex, F0025_MAIN_GetMaximumValue(7, 16 - AL1008_ui_WizardPriestSkillLevel));
                                L1010_ps_Champion->CurrentMana += (L1010_ps_Champion->MaximumMana >> 6) + 1;
                                if (L1010_ps_Champion->CurrentMana > L1010_ps_Champion->MaximumMana) {
                                        L1010_ps_Champion->CurrentMana = L1010_ps_Champion->MaximumMana;
                                }
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_00_IMPROVEMENT Faster regeneration. Mana gain is ((MaximumMana / 40) + 1) if not resting and (((MaximumMana / 40) * 2) + 1) if resting. Stamina cost is ManaGain * Max(7, 16 - WizardPriestLevel). Higher mana gain for higher stamina cost */
                                AL1007_ManaGain = L1010_ps_Champion->MaximumMana / 40;
                                if (G0300_B_PartyIsResting) {
                                        AL1007_ManaGain <<= 1;
                                }
                                AL1007_ManaGain++;
                                F0325_CHAMPION_DecrementStamina(AL9997_ui_ChampionIndex, AL1007_ManaGain * F0025_MAIN_GetMaximumValue(7, 16 - AL1008_ui_WizardPriestSkillLevel));
                                L1010_ps_Champion->CurrentMana += F0024_MAIN_GetMinimumValue(AL1007_ManaGain, L1010_ps_Champion->MaximumMana - L1010_ps_Champion->CurrentMana);
#endif
                        } else {
                                if (L1010_ps_Champion->CurrentMana > L1010_ps_Champion->MaximumMana) {
                                        L1010_ps_Champion->CurrentMana--;
                                }
                        }
                        for (AL9996_i_SkillIndex = C19_SKILL_WATER; AL9996_i_SkillIndex >= C00_SKILL_FIGHTER; AL9996_i_SkillIndex--) {
                                if (L1010_ps_Champion->Skills[AL9996_i_SkillIndex].TemporaryExperience > 0) {
                                        L1010_ps_Champion->Skills[AL9996_i_SkillIndex].TemporaryExperience--;
                                }
                        }
                        AL9995_ui_StaminaGainCycleCount = 4;
                        AL9994_i_StaminaMagnitude = L1010_ps_Champion->MaximumStamina;
                        while (L1010_ps_Champion->CurrentStamina < (AL9994_i_StaminaMagnitude >>= 1)) {
                                AL9995_ui_StaminaGainCycleCount += 2;
                        }
                        AL9993_i_StaminaLoss = 0;
                        AL1013_i_StaminaAmount = F0026_MAIN_GetBoundedValue(1, (L1010_ps_Champion->MaximumStamina >> 8) - 1, 6);
                        if (G0300_B_PartyIsResting) {
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_00_IMPROVEMENT Faster regeneration */
                                AL1013_i_StaminaAmount += F0025_MAIN_GetMaximumValue(1, AL1013_i_StaminaAmount >> 1);
                        }
                        if ((AL1008_ui_Delay = (G0313_ul_GameTime - G0362_l_LastPartyMovementTime)) > 100) {
                                AL1013_i_StaminaAmount++;
                                if (AL1008_ui_Delay > 500) {
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_00_IMPROVEMENT Faster regeneration */
                                AL1013_i_StaminaAmount <<= 1;
                        }
                        if ((AL1008_ui_Delay = (G0313_ul_GameTime - G0362_l_LastPartyMovementTime)) > 80) {
                                AL1013_i_StaminaAmount++;
                                if (AL1008_ui_Delay > 250) {
#endif
                                        AL1013_i_StaminaAmount++;
                                }
                        }
                        do {
                                AL1008_ui_StaminaAboveHalf = (AL9995_ui_StaminaGainCycleCount <= 4);
                                if (L1010_ps_Champion->Food < -512) {
                                        if (AL1008_ui_StaminaAboveHalf) {
                                               AL9993_i_StaminaLoss += AL1013_i_StaminaAmount;
                                               L1010_ps_Champion->Food -= 2;
                                        }
                                } else {
                                        if (L1010_ps_Champion->Food >= 0) {
                                                AL9993_i_StaminaLoss -= AL1013_i_StaminaAmount;
                                        }
                                        L1010_ps_Champion->Food -= AL1008_ui_StaminaAboveHalf ? 2 : AL9995_ui_StaminaGainCycleCount >> 1;
                                }
                                if (L1010_ps_Champion->Water < -512) {
                                        if (AL1008_ui_StaminaAboveHalf) {
                                               AL9993_i_StaminaLoss += AL1013_i_StaminaAmount;
                                               L1010_ps_Champion->Water--;
                                        }
                                } else {
                                        if (L1010_ps_Champion->Water >= 0) {
                                                AL9993_i_StaminaLoss -= AL1013_i_StaminaAmount;
                                        }
                                        L1010_ps_Champion->Water -= AL1008_ui_StaminaAboveHalf ? 1 : AL9995_ui_StaminaGainCycleCount >> 2;
                                }
                        } while (--AL9995_ui_StaminaGainCycleCount && ((L1010_ps_Champion->CurrentStamina - AL9993_i_StaminaLoss) < L1010_ps_Champion->MaximumStamina));
                        F0325_CHAMPION_DecrementStamina(AL9997_ui_ChampionIndex, AL9993_i_StaminaLoss);
                        if (L1010_ps_Champion->Food < -1024) {
                                L1010_ps_Champion->Food = -1024;
                        }
                        if (L1010_ps_Champion->Water < -1024) {
                                L1010_ps_Champion->Water = -1024;
                        }
                        if ((L1010_ps_Champion->CurrentHealth < L1010_ps_Champion->MaximumHealth) && (L1010_ps_Champion->CurrentStamina >= (L1010_ps_Champion->MaximumStamina >> 2)) && (L1012_ui_TimeCriteria < (L1010_ps_Champion->Statistics[C4_STATISTIC_VITALITY][C1_CURRENT] + 12))) {
                                AL1013_i_HealthGain = (L1010_ps_Champion->MaximumHealth >> 7) + 1;
                                if (G0300_B_PartyIsResting) {
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_00_IMPROVEMENT Faster regeneration */
                                        AL1013_i_HealthGain += F0025_MAIN_GetMaximumValue(1, AL1013_i_HealthGain >> 1);
                                }
                                if (F0033_OBJECT_GetIconIndex(L1010_ps_Champion->Slots[C10_SLOT_NECK]) == C121_ICON_JUNK_EKKHARD_CROSS) {
                                        AL1013_i_HealthGain += 1;
                                }
                                if ((L1010_ps_Champion->CurrentHealth += AL1013_i_HealthGain) > L1010_ps_Champion->MaximumHealth) {
                                        L1010_ps_Champion->CurrentHealth = L1010_ps_Champion->MaximumHealth;
                                }
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_00_IMPROVEMENT Faster regeneration */
                                        AL1013_i_HealthGain <<= 1;
                                }
                                if (F0033_OBJECT_GetIconIndex(L1010_ps_Champion->Slots[C10_SLOT_NECK]) == C121_ICON_JUNK_EKKHARD_CROSS) {
                                        AL1013_i_HealthGain += (AL1013_i_HealthGain >> 1) + 1;
                                }
                                L1010_ps_Champion->CurrentHealth += F0024_MAIN_GetMinimumValue(AL1013_i_HealthGain, L1010_ps_Champion->MaximumHealth - L1010_ps_Champion->CurrentHealth);
#endif
                        }
#ifdef MEDIA137_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#ifndef NOCOPYPROTECTION
                        if (G0328_i_TimeBombToKillParty_CPSF && !(--G0328_i_TimeBombToKillParty_CPSF)) {
                                G0524_B_RestartGameAllowed = C0_FALSE;
                                F0324_CHAMPION_DamageAll_GetDamagedChampionCount(4096, MASK0x0000_WOUND_NONE, C0_ATTACK_NORMAL);
                        }
#endif
#endif
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_00_IMPROVEMENT Faster regeneration */
                        if (!((int16_t)G0313_ul_GameTime & 255)) {
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_00_IMPROVEMENT Faster regeneration */
                        if (!((unsigned int16_t)G0313_ul_GameTime & (G0300_B_PartyIsResting ? 63 : 255))) {
#endif
                                for (AL1007_StatisticIndex = C0_STATISTIC_LUCK; AL1007_StatisticIndex <= C6_STATISTIC_ANTIFIRE; AL1007_StatisticIndex++) {
                                        L1011_puc_Statistic = L1010_ps_Champion->Statistics[AL1007_StatisticIndex];
#ifdef MEDIA002_S10EA_S10EB_S11E /* CHANGE3_00_IMPROVEMENT Faster regeneration */
                                        if (L1011_puc_Statistic[C1_CURRENT] < L1011_puc_Statistic[C0_MAXIMUM]) {
                                                L1011_puc_Statistic[C1_CURRENT]++;
                                        } else {
                                                if (L1011_puc_Statistic[C1_CURRENT] > L1011_puc_Statistic[C0_MAXIMUM]) {
                                                        L1011_puc_Statistic[C1_CURRENT]--;
                                                }
#endif
#ifdef MEDIA240_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_00_IMPROVEMENT Faster regeneration. If the current statistic is higher than the maximum, it is decreased by current/maximum instead of by 1 */
                                        AL1008_ui_StatisticMaximum = L1011_puc_Statistic[C0_MAXIMUM];
                                        if (L1011_puc_Statistic[C1_CURRENT] < AL1008_ui_StatisticMaximum) {
                                                L1011_puc_Statistic[C1_CURRENT]++;
                                        } else {
                                                if (L1011_puc_Statistic[C1_CURRENT] > AL1008_ui_StatisticMaximum) {
                                                        L1011_puc_Statistic[C1_CURRENT] -= L1011_puc_Statistic[C1_CURRENT] / AL1008_ui_StatisticMaximum;
                                                }
#endif
                                        }
                                }
                        }
                        if (!G0300_B_PartyIsResting && (L1010_ps_Champion->Direction != G0308_i_PartyDirection) && (G0361_l_LastCreatureAttackTime < (G0313_ul_GameTime - 60))) {
                                L1010_ps_Champion->Direction = G0308_i_PartyDirection;
                                L1010_ps_Champion->MaximumDamageReceived = 0;
                                M008_SET(L1010_ps_Champion->Attributes, MASK0x0400_ICON);
                        }
                        M008_SET(L1010_ps_Champion->Attributes, MASK0x0100_STATISTICS);
                        if (M000_INDEX_TO_ORDINAL(AL9997_ui_ChampionIndex) == G0423_i_InventoryChampionOrdinal) {
#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 (G0333_B_PressingMouth || G0331_B_PressingEye || (G0424_i_PanelContent == M565_PANEL_FOOD_WATER_POISONED)) {
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                if ((G0424_i_PanelContent == M565_PANEL_FOOD_WATER_POISONED) || (G0424_i_PanelContent == C02_PANEL_SKILLS_AND_STATISTICS)) {
#endif
                                        M008_SET(L1010_ps_Champion->Attributes, MASK0x0800_PANEL);
                                }
                        }
                }
        }
#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
        F0293_CHAMPION_DrawAllChampionStates();
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0293_CHAMPION_DrawAllChampionStates(MASK0x0000_NONE);
#endif
}
#endif
