#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 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
#include "CHAMPRST.C"
#endif

STATICFUNCTION unsigned int16_t F0279_CHAMPION_GetDecodedValue(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0594_pc_String, P0595_CharacterCount)
#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 */
REGISTER char*     P0594_pc_String         SEPARATOR
#endif
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED
REGISTER unsigned int16_t P0595_CharacterCount FINAL_SEPARATOR
#endif
#ifdef MEDIA390_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
REGISTER int16_t          P0595_CharacterCount FINAL_SEPARATOR
#endif
#ifdef MEDIA331_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
char*                     P0594_pc_String         SEPARATOR
int16_t                   P0595_CharacterCount FINAL_SEPARATOR
#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 */
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED
        REGISTER int16_t L0791_CharacterIndex;
#endif
#ifdef MEDIA390_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        REGISTER unsigned int16_t L0791_CharacterIndex;
#endif
        REGISTER unsigned int16_t L0792_ui_Value;


        L0792_ui_Value = 0;
#ifdef MEDIA349_G14ED
        for (L0791_CharacterIndex = 0; P0595_CharacterCount > L0791_CharacterIndex; L0791_CharacterIndex++) { /* Comparison operands and their types had to be swapped */
#endif
#ifdef MEDIA186_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        for (L0791_CharacterIndex = 0; L0791_CharacterIndex < P0595_CharacterCount; L0791_CharacterIndex++) {
#endif
                L0792_ui_Value = (L0792_ui_Value << 4) + (*P0594_pc_String++ - 'A');
        }
        return L0792_ui_Value;
#endif
#ifdef MEDIA331_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE7_16_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                        movea.l P0594_pc_String(A6),A0
                        moveq   #0,D0
                @T0279001:
                        asl.w   #4,D0                           /* Make place for the next nibble */
                        moveq   #-'A',D1
                        add.b   (A0)+,D1                        /* This converts one ASCII character to a nibble value 0..15 (only characters 'A' to 'P' are permitted in the strings) */
                        add.b   D1,D0
                        subq.w  #1,P0595_CharacterCount(A6)
                        bne.s   @T0279001
        }
#endif
}

void F0280_CHAMPION_AddCandidateChampionToParty(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0596_ui_ChampionPortraitIndex)
#endif
unsigned int16_t P0596_ui_ChampionPortraitIndex FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0797_ps_Champion;
        REGISTER char* L0798_pc_Character;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER THING L0793_T_Thing;
#endif
        REGISTER unsigned int16_t L0794_ui_Multiple;
#define AL0794_ui_ViewCell       L0794_ui_Multiple
#define AL0794_ui_SlotIndex      L0794_ui_Multiple
#define AL0794_ui_CharacterIndex L0794_ui_Multiple
#define AL0794_ui_StatisticIndex L0794_ui_Multiple
#define AL0794_ui_SkillIndex     L0794_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 L0795_i_HiddenSkillIndex;
#define AL0796_i_HiddenSkillIndex L0795_i_HiddenSkillIndex
#endif
        REGISTER unsigned int16_t L0796_ui_Multiple;
#define AL0796_ui_Character       L0796_ui_Multiple
#define AL0796_ui_SkillValue      L0796_ui_Multiple
#define AL0796_ui_ThingType       L0796_ui_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned int16_t L0799_ui_PreviousPartyChampionCount;
        unsigned int16_t L0800_ui_Multiple; /* Merged with L0801_ui_Multiple in later versions */
#define AL9999_B_SecondPartOfChampionTitleCopied L0800_ui_Multiple
#define AL9999_ui_HiddenSkillCounter             L0800_ui_Multiple
        unsigned int16_t L0801_ui_Multiple;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#define AL0796_i_HiddenSkillIndex L0796_ui_Multiple
        REGISTER THING L0793_T_Thing;
        REGISTER unsigned int16_t L0801_ui_Multiple;
        REGISTER unsigned int16_t L0799_ui_PreviousPartyChampionCount;
        long L0806_l_BaseSkillExperience;
#define AL9999_B_SecondPartOfChampionTitleCopied L0801_ui_Multiple
#define AL9999_ui_HiddenSkillCounter             L0801_ui_Multiple
#endif
#define AL0801_ui_SlotIndex                      L0801_ui_Multiple
        int16_t L0802_i_MapX;
        int16_t L0803_i_MapY;
        unsigned int16_t L0804_ui_ChampionObjectsCell;
        int16_t L0805_i_ObjectAllowedSlots;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        long L0806_l_BaseSkillExperience;
        char L0807_ac_DecodedChampionText[77];
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        char L0807_ac_DecodedChampionText[78];
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned char* L1639_puc_Bitmap_Portrait_ChipMemory;
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        int16_t L2262_ai_XYZ[4];
#endif


        if (!G0415_ui_LeaderEmptyHanded)
                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
        if (G0305_ui_PartyChampionCount == 4)
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (G0305_ui_PartyChampionCount >= 4)
#endif
                return;
        L0797_ps_Champion = &M516_CHAMPIONS[L0799_ui_PreviousPartyChampionCount = G0305_ui_PartyChampionCount];
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L0798_pc_Character = M772_CAST_PC(L0797_ps_Champion->Portrait); /* Backup portrait address so it is not erased (versions where portrait is not part of the CHAMPION structure) */
#endif
        F0008_MAIN_ClearBytes(M772_CAST_PC(L0797_ps_Champion), M543_BYTE_COUNT_INT(sizeof(CHAMPION)));
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L0797_ps_Champion->Portrait = M772_CAST_PC(L0798_pc_Character); /* Restore portrait address */
#endif
#ifdef MEDIA008_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E
        G0578_B_UseByteBoxCoordinates = C1_TRUE, F0132_VIDEO_Blit(F0489_MEMORY_GetNativeBitmapOrGraphic(C026_GRAPHIC_CHAMPION_PORTRAITS), L0797_ps_Champion->Portrait, G0047_auc_Graphic562_Box_ChampionPortrait, M027_PORTRAIT_X(P0596_ui_ChampionPortraitIndex), M028_PORTRAIT_Y(P0596_ui_ChampionPortraitIndex), C128_BYTE_WIDTH, C016_BYTE_WIDTH, CM1_COLOR_NO_TRANSPARENCY);
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L1639_puc_Bitmap_Portrait_ChipMemory = F0468_MEMORY_Allocate((long)M075_BITMAP_BYTE_COUNT(32, 29), C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
        G0578_B_UseByteBoxCoordinates = C1_TRUE, F0132_VIDEO_Blit(F0489_MEMORY_GetNativeBitmapOrGraphic(C026_GRAPHIC_CHAMPION_PORTRAITS), L1639_puc_Bitmap_Portrait_ChipMemory, G0047_auc_Graphic562_Box_ChampionPortrait, M027_PORTRAIT_X(P0596_ui_ChampionPortraitIndex), M028_PORTRAIT_Y(P0596_ui_ChampionPortraitIndex), 128, 16, CM1_COLOR_NO_TRANSPARENCY, 87, 29);
        WaitBlit();
        F0007_MAIN_CopyBytes(L1639_puc_Bitmap_Portrait_ChipMemory, L0797_ps_Champion->Portrait, sizeof(L0797_ps_Champion->Portrait));
        F0469_MEMORY_FreeAtHeapTop((long)M075_BITMAP_BYTE_COUNT(32, 29));
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L0798_pc_Character = M772_CAST_PC((char*)F0489_MEMORY_GetNativeBitmapOrGraphic(C026_GRAPHIC_CHAMPION_PORTRAITS));
#endif
#ifdef MEDIA458_P20JA_P20JB
        F0132_VIDEO_Blit(L0798_pc_Character, L0797_ps_Champion->Portrait, F0787_GetZoneInitializedFromCoordinates(L2262_ai_XYZ, 0, G2078_C32_PortraitWidth - 1, 0, G2079_C29_PortraitHeight - 1), M027_PORTRAIT_X(P0596_ui_ChampionPortraitIndex), M028_PORTRAIT_Y(P0596_ui_ChampionPortraitIndex), M100_PIXEL_WIDTH(L0798_pc_Character), G2078_C32_PortraitWidth, CM1_COLOR_NO_TRANSPARENCY, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA709_I34E_I34M_P31J
        F0132_VIDEO_Blit(L0798_pc_Character, L0797_ps_Champion->Portrait, F0627_GetTemporaryZoneInitializedFromDimensions(G2078_C32_PortraitWidth, G2079_C29_PortraitHeight), M027_PORTRAIT_X(P0596_ui_ChampionPortraitIndex), M028_PORTRAIT_Y(P0596_ui_ChampionPortraitIndex), M100_PIXEL_WIDTH(L0798_pc_Character), G2078_C32_PortraitWidth, CM1_COLOR_NO_TRANSPARENCY, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA506_F20E_F20J_X30J
        F0132_VIDEO_Blit(M774_CAST_PUC(L0798_pc_Character), M774_CAST_PUC(L0797_ps_Champion->Portrait), F0787_GetZoneInitializedFromCoordinates(L2262_ai_XYZ, 0, G2078_C32_PortraitWidth - 1, 0, G2079_C29_PortraitHeight - 1), M027_PORTRAIT_X(P0596_ui_ChampionPortraitIndex), M028_PORTRAIT_Y(P0596_ui_ChampionPortraitIndex), M100_PIXEL_WIDTH(L0798_pc_Character), G2078_C32_PortraitWidth, CM1_COLOR_NO_TRANSPARENCY);
#endif
#ifdef MEDIA673_F31E_F31J_X31J
        F0132_VIDEO_Blit(M774_CAST_PUC(L0798_pc_Character), M774_CAST_PUC(L0797_ps_Champion)->Portrait, F0627_GetTemporaryZoneInitializedFromDimensions(G2078_C32_PortraitWidth, G2079_C29_PortraitHeight), M027_PORTRAIT_X(P0596_ui_ChampionPortraitIndex), M028_PORTRAIT_Y(P0596_ui_ChampionPortraitIndex), M100_PIXEL_WIDTH(L0798_pc_Character), G2078_C32_PortraitWidth, CM1_COLOR_NO_TRANSPARENCY);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        F0132_VIDEO_Blit(L0798_pc_Character, L0797_ps_Champion->Portrait, F0627_GetTemporaryZoneInitializedFromDimensions(G2078_C32_PortraitWidth, G2079_C29_PortraitHeight), M027_PORTRAIT_X(P0596_ui_ChampionPortraitIndex), M028_PORTRAIT_Y(P0596_ui_ChampionPortraitIndex), M100_PIXEL_WIDTH(L0798_pc_Character), G2078_C32_PortraitWidth, CM1_COLOR_NO_TRANSPARENCY, M101_PIXEL_HEIGHT(L0798_pc_Character), G2079_C29_PortraitHeight);
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L0797_ps_Champion->Useless1 = 1; /* BUG0_00 Useless code */
        L0797_ps_Champion->Useless2 = 2; /* BUG0_00 Useless code */
#endif
        L0797_ps_Champion->ActionIndex = C0xFF_ACTION_NONE;
        L0797_ps_Champion->EnableActionEventIndex = -1;
        L0797_ps_Champion->HideDamageReceivedEventIndex = -1;
        L0797_ps_Champion->Direction = G0308_i_PartyDirection;
        AL0794_ui_ViewCell = C00_VIEW_CELL_FRONT_LEFT;
        while (F0285_CHAMPION_GetIndexInCell(M021_NORMALIZE(AL0794_ui_ViewCell + G0308_i_PartyDirection)) != CM1_CHAMPION_NONE) {
                AL0794_ui_ViewCell++;
        }
        L0797_ps_Champion->Cell = M021_NORMALIZE(AL0794_ui_ViewCell + G0308_i_PartyDirection);
        L0797_ps_Champion->Attributes = MASK0x0400_ICON;
        L0797_ps_Champion->DirectionMaximumDamageReceived = G0308_i_PartyDirection;
        L0797_ps_Champion->Food = 1500 + M003_RANDOM(256);
        L0797_ps_Champion->Water = 1500 + M003_RANDOM(256);
        for (AL0794_ui_SlotIndex = C00_SLOT_READY_HAND; AL0794_ui_SlotIndex < C30_SLOT_CHEST_1; AL0794_ui_SlotIndex++) {
                L0797_ps_Champion->Slots[AL0794_ui_SlotIndex] = C0xFFFF_THING_NONE;
        }
        L0793_T_Thing = F0161_DUNGEON_GetSquareFirstThing(G0306_i_PartyMapX, G0307_i_PartyMapY);
        while (M012_TYPE(L0793_T_Thing) != C02_THING_TYPE_TEXTSTRING) {
                L0793_T_Thing = F0159_DUNGEON_GetNextThing(L0793_T_Thing);
        }
#ifdef MEDIA571_F20J_X30J_P20JA_P20JB_F31J_X31J_P31J
        F0168_DUNGEON_DecodeText(M774_CAST_PUC(L0798_pc_Character = M772_CAST_PC(L0807_ac_DecodedChampionText)), L0793_T_Thing, C2_TEXT_TYPE_SCROLL | MASK0x8000_DECODE_EVEN_IF_INVISIBLE | MASK0x4000_NOT_JAPANESE_TEXT); /* In Japanese versions, champion texts must be decoded as English texts instead of Japanese */
#endif
#ifdef MEDIA061_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E
        F0168_DUNGEON_DecodeText(M774_CAST_PUC(L0798_pc_Character = M772_CAST_PC(L0807_ac_DecodedChampionText)), L0793_T_Thing, C2_TEXT_TYPE_SCROLL | MASK0x8000_DECODE_EVEN_IF_INVISIBLE);
#endif
        AL0794_ui_CharacterIndex = 0;
        while ((AL0796_ui_Character = *L0798_pc_Character++) != '\n') { /* New line */
                L0797_ps_Champion->Name[AL0794_ui_CharacterIndex++] = AL0796_ui_Character;
        }
        L0797_ps_Champion->Name[AL0794_ui_CharacterIndex] = '\0';
        AL0794_ui_CharacterIndex = 0;
        AL9999_B_SecondPartOfChampionTitleCopied = C0_FALSE; /* The title string may be stored as two parts separated by a '\n' character */
        for (;;) { /*_Infinite loop_*/
                AL0796_ui_Character = *L0798_pc_Character++;
                if (AL0796_ui_Character == '\n') { /* New line */
                        if (AL9999_B_SecondPartOfChampionTitleCopied)
                                break;
#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
                                AL9999_B_SecondPartOfChampionTitleCopied = C1_TRUE;
                                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
                }
                L0797_ps_Champion->Title[AL0794_ui_CharacterIndex++] = AL0796_ui_Character;
        }
        L0797_ps_Champion->Title[AL0794_ui_CharacterIndex] = '\0';
        if (*L0798_pc_Character++ == 'M') {
                M008_SET(L0797_ps_Champion->Attributes, MASK0x0010_MALE);
        }
        L0798_pc_Character++;
        L0797_ps_Champion->CurrentHealth = L0797_ps_Champion->MaximumHealth = F0279_CHAMPION_GetDecodedValue(L0798_pc_Character, 4);
        L0798_pc_Character += 4;
        L0797_ps_Champion->CurrentStamina = L0797_ps_Champion->MaximumStamina = F0279_CHAMPION_GetDecodedValue(L0798_pc_Character, 4);
        L0798_pc_Character += 4;
        L0797_ps_Champion->CurrentMana = L0797_ps_Champion->MaximumMana = F0279_CHAMPION_GetDecodedValue(L0798_pc_Character, 4);
        L0798_pc_Character += 4;
        L0798_pc_Character++;
        for (AL0794_ui_StatisticIndex = C0_STATISTIC_LUCK; AL0794_ui_StatisticIndex <= C6_STATISTIC_ANTIFIRE; AL0794_ui_StatisticIndex++) {
                L0797_ps_Champion->Statistics[AL0794_ui_StatisticIndex][C2_MINIMUM] = 30;
#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
                L0797_ps_Champion->Statistics[AL0794_ui_StatisticIndex][C1_CURRENT] = L0797_ps_Champion->Statistics[AL0794_ui_StatisticIndex][C0_MAXIMUM] = F0279_CHAMPION_GetDecodedValue(L0798_pc_Character, 2);
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                L0797_ps_Champion->Statistics[AL0794_ui_StatisticIndex][C1_CURRENT] = L0797_ps_Champion->Statistics[AL0794_ui_StatisticIndex][C0_MAXIMUM] = F0025_MAIN_GetMaximumValue(30, F0279_CHAMPION_GetDecodedValue(L0798_pc_Character, 2));
#endif
                L0798_pc_Character += 2;
        }
#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
        L0797_ps_Champion->Statistics[C0_STATISTIC_LUCK][C2_MINIMUM] = 10;
#endif
        L0798_pc_Character++;
        for (AL0794_ui_SkillIndex = C04_SKILL_SWING; AL0794_ui_SkillIndex <= C19_SKILL_WATER; AL0794_ui_SkillIndex++) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_06_FIX Useless code removed. All bytes are already cleared before this loop */
                L0797_ps_Champion->Skills[AL0794_ui_SkillIndex].TemporaryExperience = 0;
                if ((AL0796_ui_SkillValue = *L0798_pc_Character++ - 'A') == 0) {
                        L0797_ps_Champion->Skills[AL0794_ui_SkillIndex].Experience = 0;
                } else {
#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_06_FIX Useless code removed */
                if ((AL0796_ui_SkillValue = *L0798_pc_Character++ - 'A') > 0) {
#endif
                        L0797_ps_Champion->Skills[AL0794_ui_SkillIndex].Experience = 125L << AL0796_ui_SkillValue;
                }
        }
        for (AL0794_ui_SkillIndex = C00_SKILL_FIGHTER; AL0794_ui_SkillIndex <= C03_SKILL_WIZARD; AL0794_ui_SkillIndex++) {
#ifdef MEDIA001_S10EA_S10EB /* CHANGE2_06_FIX Useless code removed. All bytes are already cleared before this loop */
                L0797_ps_Champion->Skills[AL0794_ui_SkillIndex].TemporaryExperience = 0;
#endif
                L0806_l_BaseSkillExperience = 0;
                AL0796_i_HiddenSkillIndex = (AL0794_ui_SkillIndex + 1) << 2;
                for (AL9999_ui_HiddenSkillCounter = 0; AL9999_ui_HiddenSkillCounter < 4; AL9999_ui_HiddenSkillCounter++) {
                        L0806_l_BaseSkillExperience += L0797_ps_Champion->Skills[AL0796_i_HiddenSkillIndex + AL9999_ui_HiddenSkillCounter].Experience;
                }
                L0797_ps_Champion->Skills[AL0794_ui_SkillIndex].Experience = L0806_l_BaseSkillExperience;
        }
        G0299_ui_CandidateChampionOrdinal = L0799_ui_PreviousPartyChampionCount + 1;
#ifdef MEDIA467_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        M008_SET(L0797_ps_Champion->Attributes, MASK0x8000_ACTION_HAND);
#endif
        if (++G0305_ui_PartyChampionCount == 1) {
                F0368_COMMAND_SetLeader(C00_CHAMPION_FIRST);
#ifdef MEDIA018_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J
                G0508_B_RefreshActionArea = C1_TRUE;
#endif
#ifdef MEDIA467_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0394_MENUS_SetMagicCasterAndDrawSpellArea(C00_CHAMPION_FIRST);
#endif
        } else { /* BUG0_33 The highlighted box around the acting champion's action hand is not cleared when clicking on a champion mirror. There is no code to clear the acting champion before opening the inventory of a candidate champion in a mirror */
#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_08_FIX Clear the acting champion before drawing the action icon of the candidate champion */
                F0388_MENUS_ClearActingChampion();
#endif
#ifdef MEDIA018_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J
                F0386_MENUS_DrawActionIcon(G0305_ui_PartyChampionCount - 1); /* BUG0_34 Graphical glitch when you quickly move the mouse into the action area after clicking on a portrait. If you quickly move the mouse pointer over the action area where the action icon for the candidate champion will be drawn after clicking on a portrait and before the inventory is drawn on screen then there may be a graphical glitch where the mouse pointer erases a part of the action icon with a black rectangle in the action area 'behind' the mouse pointer. This is because the mouse pointer is not hidden while drawing the action icon (with F0077_MOUSE_EnableScreenUpdate_CPSE and F0078_MOUSE_DisableScreenUpdate). When the mouse pointer is moved over the action area, it captures the black pixels behind the pointer. The action icon is drawn and when the inventory is open, the mouse cursor is hidden which causes the captured black pixels to replace part of the action icon */
#endif
#ifdef MEDIA467_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0393_MENUS_DrawSpellAreaControls(G0514_i_MagicCasterChampionIndex);
#endif
        }
        L0802_i_MapX = G0306_i_PartyMapX;
        L0803_i_MapY = G0307_i_PartyMapY;
        L0804_ui_ChampionObjectsCell = M018_OPPOSITE(G0308_i_PartyDirection);
        L0802_i_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[G0308_i_PartyDirection], L0803_i_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[G0308_i_PartyDirection];
        L0793_T_Thing = F0161_DUNGEON_GetSquareFirstThing(L0802_i_MapX, L0803_i_MapY);
        AL0794_ui_SlotIndex = C13_SLOT_BACKPACK_LINE1_1;
        while (L0793_T_Thing != C0xFFFE_THING_ENDOFLIST) {
                if (((AL0796_ui_ThingType = M012_TYPE(L0793_T_Thing)) > C03_THING_TYPE_SENSOR) && (M011_CELL(L0793_T_Thing) == L0804_ui_ChampionObjectsCell)) {
                        L0805_i_ObjectAllowedSlots = G0237_as_Graphic559_ObjectInfo[F0141_DUNGEON_GetObjectInfoIndex(L0793_T_Thing)].AllowedSlots;
                        switch (AL0796_ui_ThingType) {
                                case C06_THING_TYPE_ARMOUR:
                                        for (AL0801_ui_SlotIndex = C02_SLOT_HEAD; AL0801_ui_SlotIndex <= C05_SLOT_FEET; AL0801_ui_SlotIndex++) {
                                                if (L0805_i_ObjectAllowedSlots & G0038_ai_Graphic562_SlotMasks[AL0801_ui_SlotIndex])
                                                        goto T0280048;
                                        }
                                        if ((L0805_i_ObjectAllowedSlots & G0038_ai_Graphic562_SlotMasks[C10_SLOT_NECK]) && (L0797_ps_Champion->Slots[C10_SLOT_NECK] == C0xFFFF_THING_NONE)) {
                                                AL0801_ui_SlotIndex = C10_SLOT_NECK;
                                        } else {
                                                goto T0280046;
                                        }
                                        break;
                                case C05_THING_TYPE_WEAPON:
                                        if (L0797_ps_Champion->Slots[C01_SLOT_ACTION_HAND] == C0xFFFF_THING_NONE) {
                                                AL0801_ui_SlotIndex = C01_SLOT_ACTION_HAND;
                                        } else {
                                                goto T0280046;
                                        }
                                        break;
                                case C07_THING_TYPE_SCROLL:
                                case C08_THING_TYPE_POTION:
                                        if (L0797_ps_Champion->Slots[C11_SLOT_POUCH_1] == C0xFFFF_THING_NONE) {
                                                AL0801_ui_SlotIndex = C11_SLOT_POUCH_1;
                                        } else {
                                                if (L0797_ps_Champion->Slots[C06_SLOT_POUCH_2] == C0xFFFF_THING_NONE) {
                                                        AL0801_ui_SlotIndex = C06_SLOT_POUCH_2;
                                                } else {
                                                        goto T0280046;
                                                }
                                        }
                                        break;
                                case C09_THING_TYPE_CONTAINER:
                                case C10_THING_TYPE_JUNK:
                                        T0280046:
                                        if ((L0805_i_ObjectAllowedSlots & G0038_ai_Graphic562_SlotMasks[C10_SLOT_NECK]) && (L0797_ps_Champion->Slots[C10_SLOT_NECK] == C0xFFFF_THING_NONE)) {
                                                AL0801_ui_SlotIndex = C10_SLOT_NECK;
                                        } else {
                                                AL0801_ui_SlotIndex = AL0794_ui_SlotIndex++; /* BUG0_80: Data is corrupted in memory and the game eventually crashes. The engine does not enforce a maximum number of things to place in the backpack of a potential champion and will overwrite arbitrary data in memory if there are too many things on the champion mirror square */
                                        }
                                        break;
                        }
                        T0280048:
                        if (L0797_ps_Champion->Slots[AL0801_ui_SlotIndex] != C0xFFFF_THING_NONE) {
                                goto T0280046;
                        }
                        F0301_CHAMPION_AddObjectInSlot(L0799_ui_PreviousPartyChampionCount, L0793_T_Thing, AL0801_ui_SlotIndex);
                }
                L0793_T_Thing = F0159_DUNGEON_GetNextThing(L0793_T_Thing);
        }
        F0355_INVENTORY_Toggle_CPSE(L0799_ui_PreviousPartyChampionCount);
        F0456_START_DrawDisabledMenus();
}

STATICFUNCTION void F0281_CHAMPION_Rename(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0597_ps_Champion)
#endif
REGISTER CHAMPION* P0597_ps_Champion FINAL_SEPARATOR
{
        REGISTER char* L0812_pc_RenamedChampionString;
        REGISTER unsigned int16_t L0808_ui_Multiple;
#define AL0808_ui_CharacterIndex L0808_ui_Multiple
#define AL0808_ui_ChampionIndex  L0808_ui_Multiple
        REGISTER int16_t L0809_i_RenamedChampionString;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L0813_i_X;
        REGISTER int16_t L0814_i_Y;
#endif
        REGISTER int16_t L0810_i_Character;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER BOOLEAN L0811_B_ChampionTitleIsFull;
        int16_t L0813_i_X;
        int16_t L0814_i_Y;
        int16_t L0815_ai_Box[4];
        unsigned int16_t L0816_ui_MousePointerHotspotX;
        unsigned int16_t L0817_ui_MousePointerHotspotY;
        int16_t L0818_i_NewLeftMouseButtonStatus;
        int16_t L0819_i_OldLeftMouseButtonStatus;
        int16_t L0820_i_CharacterIndexBackup;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        int16_t L0820_i_CharacterIndexBackup;
        REGISTER BOOLEAN L0811_B_ChampionTitleIsFull;
        MOUSE_INPUT* L2263_ps_PrimaryMouseInputBackup;
        MOUSE_INPUT* L2264_ps_SecondaryMouseInputBackup;
        KEYBOARD_INPUT* L2265_ps_PrimaryKeyboardInputBackup;
        KEYBOARD_INPUT* L2266_ps_SecondaryKeyboardInputBackup;
        int16_t L2267_i_X1;
        int16_t L2268_i_Y1;
        int16_t L2269_i_X2;
        int16_t L2270_i_Y2;
        int16_t L2271_i_X;
        int16_t L2272_i_Y;
        int16_t L2273_ai_XYZ[4];
#endif
        char L0821_ac_ChampionNameBackupString[8];


#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        M770_BOX_TOP(L0815_ai_Box) = 3;
        M771_BOX_BOTTOM(L0815_ai_Box) = 8;
        M769_BOX_RIGHT(L0815_ai_Box) = (M768_BOX_LEFT(L0815_ai_Box) = 3) + 167;
        M525_F0135_VIDEO_FillBox(G0296_puc_Bitmap_Viewport, L0815_ai_Box, C12_COLOR_DARKEST_GRAY, C112_BYTE_WIDTH_VIEWPORT, C136_HEIGHT_VIEWPORT); /* Erase the champion name and title */
        M519_F0020_MAIN_BlitToViewport(F0489_MEMORY_GetNativeBitmapOrGraphic(C027_GRAPHIC_PANEL_RENAME_CHAMPION), G0032_ai_Graphic562_Box_Panel, C072_BYTE_WIDTH, C04_COLOR_CYAN, 73);
        F0052_TEXT_PrintToViewport(177, 58, C13_COLOR_LIGHTEST_GRAY, "_______");
        F0052_TEXT_PrintToViewport(105, 76, C13_COLOR_LIGHTEST_GRAY, "___________________");
        F0077_MOUSE_EnableScreenUpdate_CPSE();
        F0097_DUNGEONVIEW_DrawViewport(C0_VIEWPORT_NOT_DUNGEON_VIEW);
        F0067_MOUSE_SetPointerToNormal(C0_POINTER_ARROW);
        F0078_MOUSE_DisableScreenUpdate();
        P0597_ps_Champion->Name[AL0808_ui_CharacterIndex = 0] = '\0';
        P0597_ps_Champion->Title[0] = '\0';
        L0809_i_RenamedChampionString = C1_RENAME_CHAMPION_NAME;
        L0812_pc_RenamedChampionString = P0597_ps_Champion->Name;
        L0813_i_X = 177;
        L0814_i_Y = 91;
#ifdef MEDIA137_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L0819_i_OldLeftMouseButtonStatus = M007_GET(G0588_i_MouseButtonsStatus, MASK0x0002_MOUSE_LEFT_BUTTON);
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        L0819_i_OldLeftMouseButtonStatus = M007_GET(F2158_GetMouseButtonsStatus(), MASK0x0002_MOUSE_LEFT_BUTTON);
#endif
        for (;;) { /*_Infinite loop_*/
                if (!(L0811_B_ChampionTitleIsFull = ((L0809_i_RenamedChampionString == C2_RENAME_CHAMPION_TITLE) && (AL0808_ui_CharacterIndex == 19)))) {
                        F0077_MOUSE_EnableScreenUpdate_CPSE();
                        M521_F0040_TEXT_Print(G0348_Bitmap_Screen, C160_BYTE_WIDTH_SCREEN, L0813_i_X, L0814_i_Y, C09_COLOR_GOLD, C12_COLOR_DARKEST_GRAY, G0051_ac_Graphic562_UnderscoreCharacterString, C200_HEIGHT_SCREEN);
                        F0078_MOUSE_DisableScreenUpdate();
                }
                while (!M527_IsCharacterInKeyboardBuffer()) {
#ifdef MEDIA137_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        L0818_i_NewLeftMouseButtonStatus = M007_GET(G0588_i_MouseButtonsStatus, MASK0x0002_MOUSE_LEFT_BUTTON);
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
                        L0818_i_NewLeftMouseButtonStatus = M007_GET(F2158_GetMouseButtonsStatus(), MASK0x0002_MOUSE_LEFT_BUTTON);
#endif
                        if (L0818_i_NewLeftMouseButtonStatus && !L0819_i_OldLeftMouseButtonStatus) { /* If left mouse button status has changed */
#ifdef MEDIA137_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                L0816_ui_MousePointerHotspotX = G0589_i_MousePointerHotspotX;
                                L0817_ui_MousePointerHotspotY = G0590_i_MousePointerHotspotY;
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
                                L0816_ui_MousePointerHotspotX = F2160_GetMousePointerHotspotX();
                                L0817_ui_MousePointerHotspotY = F2161_GetMousePointerHotspotY();
#endif
                                if ((L0809_i_RenamedChampionString == C2_RENAME_CHAMPION_TITLE || (AL0808_ui_CharacterIndex > 0)) && (L0816_ui_MousePointerHotspotX >= 197) && (L0816_ui_MousePointerHotspotX <= 215) && (L0817_ui_MousePointerHotspotY >= 147) && (L0817_ui_MousePointerHotspotY <= 155)) { /* Coordinates of 'OK' button */
                                        L0820_i_CharacterIndexBackup = AL0808_ui_CharacterIndex;
                                        M547_STRCPY(L0821_ac_ChampionNameBackupString, L0812_pc_RenamedChampionString = P0597_ps_Champion->Name);
                                        AL0808_ui_CharacterIndex = M544_STRLEN(L0812_pc_RenamedChampionString);
                                        while (L0812_pc_RenamedChampionString[--AL0808_ui_CharacterIndex] == ' ') { /* Replace space characters on the right of the champion name by '\0' characters */
                                                L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex] = '\0';
                                        }
                                        for (AL0808_ui_ChampionIndex = C00_CHAMPION_FIRST; AL0808_ui_ChampionIndex < G0305_ui_PartyChampionCount - 1; AL0808_ui_ChampionIndex++) {
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                                                if (!M546_STRCMP(M516_CHAMPIONS[AL0808_ui_ChampionIndex].Name, L0812_pc_RenamedChampionString)) /* If an existing champion already has the specified name for the new champion */ /* ANOMALY_ST_COMPARISON_WITH_ZERO */
#endif
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                                if (M546_STRCMP(M516_CHAMPIONS[AL0808_ui_ChampionIndex].Name, L0812_pc_RenamedChampionString) == 0) /* If an existing champion already has the specified name for the new champion */
#endif
                                                        goto T0281011_ContinueRename;
                                        }
                                        return;
                                        T0281011_ContinueRename:
                                        if (L0809_i_RenamedChampionString == C2_RENAME_CHAMPION_TITLE) {
                                                L0812_pc_RenamedChampionString = P0597_ps_Champion->Title;
                                        }
                                        M547_STRCPY(L0812_pc_RenamedChampionString = P0597_ps_Champion->Name, L0821_ac_ChampionNameBackupString);
                                        AL0808_ui_CharacterIndex = L0820_i_CharacterIndexBackup;
                                } else {
                                        if ((L0816_ui_MousePointerHotspotX >= 107) && (L0816_ui_MousePointerHotspotX <= 175) && (L0817_ui_MousePointerHotspotY >= 147) && (L0817_ui_MousePointerHotspotY <= 155)) { /* Coordinates of 'BACKSPACE' button */
                                                L0810_i_Character = '\b';
                                                break;
                                        }
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G /* ANOMALY_ST_BRANCH */
                                        else {
#endif
                                                if ((L0816_ui_MousePointerHotspotX < 107) || (L0816_ui_MousePointerHotspotX > 215) || (L0817_ui_MousePointerHotspotY < 116) || (L0817_ui_MousePointerHotspotY > 144)) {/* Coordinates of table of all other characters */
                                                        goto T0281023;
                                                }
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                                                if (!((L0816_ui_MousePointerHotspotX + 4) % 10) || (!((L0817_ui_MousePointerHotspotY + 5) % 10) && ((L0816_ui_MousePointerHotspotX < 207) || (L0817_ui_MousePointerHotspotY != 135)))) { /* ANOMALY_ST_COMPARISON_WITH_ZERO */
#endif
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                                if ((((L0816_ui_MousePointerHotspotX + 4) % 10) == 0) || ((((L0817_ui_MousePointerHotspotY + 5) % 10) == 0) && ((L0816_ui_MousePointerHotspotX < 207) || (L0817_ui_MousePointerHotspotY != 135)))) {
#endif
                                                        goto T0281023;
                                                }
                                                L0810_i_Character = 'A' + (11 * ((L0817_ui_MousePointerHotspotY - 116) / 10)) + ((L0816_ui_MousePointerHotspotX - 107) / 10);
                                                if ((L0810_i_Character == 86) || (L0810_i_Character == 97)) { /* The 'Return' button occupies two cells in the table */
                                                        L0810_i_Character = '\r'; /* Carriage return */
                                                        break;
                                                }
                                                if (L0810_i_Character >= 87) { /* Compensate for the first cell occupied by 'Return' button */
                                                        L0810_i_Character--;
                                                }
                                                if (L0810_i_Character > 'Z') {
                                                        L0810_i_Character = G0053_ac_Graphic562_ReincarnateSpecialCharacters[(L0810_i_Character - 'Z') - 1];
                                                }
                                                break;
#ifdef MEDIA353_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                        }
#endif
                                }
                        }
                        T0281023:
                        L0819_i_OldLeftMouseButtonStatus = L0818_i_NewLeftMouseButtonStatus;
                        M526_WaitVerticalBlank();
                }
                L0819_i_OldLeftMouseButtonStatus = L0818_i_NewLeftMouseButtonStatus;
                if (M527_IsCharacterInKeyboardBuffer()) {
                        L0810_i_Character = M528_GetCharacterInKeyboardBuffer();
                }
                if ((L0810_i_Character >= 'a') && (L0810_i_Character <= 'z')) {
                        L0810_i_Character -= 32; /* Convert to uppercase */
                }
                if (((L0810_i_Character >= 'A') && (L0810_i_Character <= 'Z')) || (L0810_i_Character == '.') || (L0810_i_Character == ',') || (L0810_i_Character == ';') || (L0810_i_Character == ':') || (L0810_i_Character == ' ')) {
                        if ((L0810_i_Character == ' ') && (AL0808_ui_CharacterIndex == 0)) {
                        } else {
                                if (!L0811_B_ChampionTitleIsFull) {
                                        G0052_ac_Graphic562_RenameChampionInputCharacterString[0] = L0810_i_Character;
                                        F0077_MOUSE_EnableScreenUpdate_CPSE();
                                        M521_F0040_TEXT_Print(G0348_Bitmap_Screen, C160_BYTE_WIDTH_SCREEN, L0813_i_X, L0814_i_Y, C13_COLOR_LIGHTEST_GRAY, C12_COLOR_DARKEST_GRAY, G0052_ac_Graphic562_RenameChampionInputCharacterString, C200_HEIGHT_SCREEN);
                                        F0078_MOUSE_DisableScreenUpdate();
                                        L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex++] = L0810_i_Character;
                                        L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex] = '\0';
                                        L0813_i_X += 6;
                                        if ((L0809_i_RenamedChampionString == C1_RENAME_CHAMPION_NAME) && (AL0808_ui_CharacterIndex == 7))
                                                goto T0281033_ProceedToTitle;
                                }
                        }
                        continue;
                }
                if (L0810_i_Character == '\r') { /* Carriage return */
                        if ((L0809_i_RenamedChampionString == C1_RENAME_CHAMPION_NAME) && (AL0808_ui_CharacterIndex > 0)) {
                                F0077_MOUSE_EnableScreenUpdate_CPSE();
                                M521_F0040_TEXT_Print(G0348_Bitmap_Screen, C160_BYTE_WIDTH_SCREEN, L0813_i_X, L0814_i_Y, C13_COLOR_LIGHTEST_GRAY, C12_COLOR_DARKEST_GRAY, G0051_ac_Graphic562_UnderscoreCharacterString, C200_HEIGHT_SCREEN);
                                F0078_MOUSE_DisableScreenUpdate();
                                T0281033_ProceedToTitle:
                                L0809_i_RenamedChampionString = C2_RENAME_CHAMPION_TITLE;
                                L0812_pc_RenamedChampionString = P0597_ps_Champion->Title;
                                L0813_i_X = 105;
                                L0814_i_Y = 109;
                                AL0808_ui_CharacterIndex = 0;
                        }
                        continue;
                }
                if (L0810_i_Character == '\b') { /* Backspace */
                        if ((L0809_i_RenamedChampionString == C1_RENAME_CHAMPION_NAME) && (AL0808_ui_CharacterIndex == 0))
                                continue;
                        if (!L0811_B_ChampionTitleIsFull) {
                                F0077_MOUSE_EnableScreenUpdate_CPSE();
                                M521_F0040_TEXT_Print(G0348_Bitmap_Screen, C160_BYTE_WIDTH_SCREEN, L0813_i_X, L0814_i_Y, C13_COLOR_LIGHTEST_GRAY, C12_COLOR_DARKEST_GRAY, G0051_ac_Graphic562_UnderscoreCharacterString, C200_HEIGHT_SCREEN);
                                F0078_MOUSE_DisableScreenUpdate();
                        }
                        if (AL0808_ui_CharacterIndex == 0) {
                                L0812_pc_RenamedChampionString = P0597_ps_Champion->Name;
                                AL0808_ui_CharacterIndex = strlen(L0812_pc_RenamedChampionString) - 1;
                                L0809_i_RenamedChampionString = C1_RENAME_CHAMPION_NAME;
                                L0813_i_X = 177 + (AL0808_ui_CharacterIndex * 6);
                                L0814_i_Y = 91;
                        } else {
                                AL0808_ui_CharacterIndex--;
                                L0813_i_X -= 6;
                        }
                        L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex] = '\0';
                }
        }
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        L2271_i_X = (G2087_C6_TextCharacterWidth * 28) - G2084_C1_;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        G2008_i_PanelContent = G0424_i_PanelContent = C08_PANEL_RENAME;
        L2271_i_X = (G2087_C6_TextCharacterWidth * 27) - G2084_C1_;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L2272_i_Y = G2083_C6_;
        M525_F0135_VIDEO_FillBox(G0296_puc_Bitmap_Viewport, F0635_(NULL, L2273_ai_XYZ, C553_ZONE_CHAMPION_NAME_AND_TITLE, &L2271_i_X, &L2272_i_Y), C12_COLOR_DARKEST_GRAY, G2073_C224_ViewportPixelWidth, G2074_C136_ViewportHeight);
        F0658_BlitBitmapIndexToZoneIndexWithTransparency(C027_GRAPHIC_PANEL_RENAME_CHAMPION, C101_ZONE_PANEL, C04_COLOR_CYAN);
        F0648_PrintTextInViewportZone(M702_ZONE_CHAMPION_NAME, C13_COLOR_LIGHTEST_GRAY, "_______");
        F0648_PrintTextInViewportZone(M703_ZONE_CHAMPION_TITLE, C13_COLOR_LIGHTEST_GRAY, "___________________");
        F0077_MOUSE_EnableScreenUpdate_CPSE();
        F0097_DUNGEONVIEW_DrawViewport(C0_VIEWPORT_NOT_DUNGEON_VIEW);
        F0067_MOUSE_SetPointerToNormal(C0_POINTER_ARROW);
        F0078_MOUSE_DisableScreenUpdate();
        F0636_GetZoneTopLeftCoordinatesWith1PixelMargin(M702_ZONE_CHAMPION_NAME, &L2267_i_X1, &L2268_i_Y1);
        F0636_GetZoneTopLeftCoordinatesWith1PixelMargin(M703_ZONE_CHAMPION_TITLE, &L2269_i_X2, &L2270_i_Y2);
        AL0808_ui_CharacterIndex = 0;
        P0597_ps_Champion->Name[0] = '\0';
        P0597_ps_Champion->Title[0] = '\0';
        L0809_i_RenamedChampionString = C1_RENAME_CHAMPION_NAME;
        L0812_pc_RenamedChampionString = P0597_ps_Champion->Name;
        L0813_i_X = L2267_i_X1;
        L0814_i_Y = L2268_i_Y1;
        L2263_ps_PrimaryMouseInputBackup = G0441_ps_PrimaryMouseInput;
        L2264_ps_SecondaryMouseInputBackup = G0442_ps_SecondaryMouseInput;
        L2265_ps_PrimaryKeyboardInputBackup = G0443_ps_PrimaryKeyboardInput;
        L2266_ps_SecondaryKeyboardInputBackup = G0444_ps_SecondaryKeyboardInput;
        G0441_ps_PrimaryMouseInput = G2045_as_MouseInput_PanelChampionRename;
        G0442_ps_SecondaryMouseInput = NULL;
        G0443_ps_PrimaryKeyboardInput = G2046_as_PrimaryKeyboardInput_PanelChampionRename;
        G0444_ps_SecondaryKeyboardInput = NULL;
        F0357_COMMAND_DiscardAllInput();
        for (;;) { /*_Infinite loop_*/
                if (!(L0811_B_ChampionTitleIsFull = ((L0809_i_RenamedChampionString == C0_RENAME_CHAMPION_TITLE) && (AL0808_ui_CharacterIndex == 19)))) {
                        F0077_MOUSE_EnableScreenUpdate_CPSE();
                        F0052_TEXT_PrintToViewport(L0813_i_X, L0814_i_Y, C09_COLOR_GOLD, G0051_ac_Graphic562_UnderscoreCharacterString);
                        F0097_DUNGEONVIEW_DrawViewport(C0_VIEWPORT_NOT_DUNGEON_VIEW);
                        F0078_MOUSE_DisableScreenUpdate();
                }
                G2139_i_RenameCommand = CM1_COMMAND_NONE;
                while (G2139_i_RenameCommand == CM1_COMMAND_NONE) {
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        while (F0539_INPUT_Cconis()) {
                                F0361_COMMAND_ProcessKeyPress(F0540_INPUT_Crawcin());
                        }
#endif
                        F0380_COMMAND_ProcessQueue_CPSC();
                }
                if (G2139_i_RenameCommand == C166_COMMAND_RENAME_OK) {
                        if ((L0809_i_RenamedChampionString == C0_RENAME_CHAMPION_TITLE) || (AL0808_ui_CharacterIndex > 0)) {
                                L0820_i_CharacterIndexBackup = AL0808_ui_CharacterIndex;
                                M547_STRCPY(L0821_ac_ChampionNameBackupString, L0812_pc_RenamedChampionString = P0597_ps_Champion->Name);
                                AL0808_ui_CharacterIndex = M544_STRLEN(L0812_pc_RenamedChampionString);
                                while (L0812_pc_RenamedChampionString[--AL0808_ui_CharacterIndex] == ' ') { /* Replace space characters on the right of the champion name by '\0' characters */
                                        L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex] = '\0';
                                }
                                for (AL0808_ui_ChampionIndex = C00_CHAMPION_FIRST; AL0808_ui_ChampionIndex < G0305_ui_PartyChampionCount - 1; AL0808_ui_ChampionIndex++) {
                                        if (!M546_STRCMP(M516_CHAMPIONS[AL0808_ui_ChampionIndex].Name, L0812_pc_RenamedChampionString)) /* If an existing champion already has the specified name for the new champion */
                                                goto T0281011_ContinueRename;
                                }
                                break;
                                T0281011_ContinueRename:
                                if (L0809_i_RenamedChampionString == C0_RENAME_CHAMPION_TITLE) {
                                        L0812_pc_RenamedChampionString = P0597_ps_Champion->Title;
                                }
                                M547_STRCPY(L0812_pc_RenamedChampionString = P0597_ps_Champion->Name, L0821_ac_ChampionNameBackupString); /* BUGX_XX L0812_pc_RenamedChampionString should be set to the champion name ONLY if L0809_i_RenamedChampionString != C0_RENAME_CHAMPION_TITLE. If the entered champion name is identical to the name of another champion already in the party and the title is being edited then an inconsistency appears: L0812_pc_RenamedChampionString points to the champion name whereas AL0808_ui_CharacterIndex contains the current character index in the champion title. If the title contains at least one character then this leads to the ability to use backspace past the beginning of the champion name and then overwrite data of the preceding champion in memory */
                                AL0808_ui_CharacterIndex = L0820_i_CharacterIndexBackup;
                        }
                        continue;
                }
                if (G2139_i_RenameCommand == C165_COMMAND_RENAME_BACKSPACE) {
                        if ((L0809_i_RenamedChampionString == C0_RENAME_CHAMPION_TITLE) || (AL0808_ui_CharacterIndex != 0)) {
                                if (!L0811_B_ChampionTitleIsFull) {
                                        F0077_MOUSE_EnableScreenUpdate_CPSE();
                                        F0052_TEXT_PrintToViewport(L0813_i_X, L0814_i_Y, C13_COLOR_LIGHTEST_GRAY, G0051_ac_Graphic562_UnderscoreCharacterString);
                                        F0097_DUNGEONVIEW_DrawViewport(C0_VIEWPORT_NOT_DUNGEON_VIEW);
                                        F0078_MOUSE_DisableScreenUpdate();
                                }
                                if (!AL0808_ui_CharacterIndex) {
                                        L0812_pc_RenamedChampionString = P0597_ps_Champion->Name;
                                        AL0808_ui_CharacterIndex = M544_STRLEN(L0812_pc_RenamedChampionString) - 1; /* BUGX_XX If L0812_pc_RenamedChampionString points to the champion name that was erased then AL0808_ui_CharacterIndex is set to -1, allowing to continue using backspace to decrease AL0808_ui_CharacterIndex and have L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex] pointing to memory area before the champion being renamed. Typing characters will then overwrite the previous champion data */
                                        L0809_i_RenamedChampionString = C1_RENAME_CHAMPION_NAME;
                                        L0813_i_X = L2267_i_X1 + (AL0808_ui_CharacterIndex * G2087_C6_TextCharacterWidth);
                                        L0814_i_Y = L2268_i_Y1;
                                } else {
                                        AL0808_ui_CharacterIndex--;
                                        L0813_i_X -= G2087_C6_TextCharacterWidth;
                                }
                                L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex] = '\0'; /* BUGX_XX If backspace is used while editing a non empty title (AL0808_ui_CharacterIndex != 0) and L0812_pc_RenamedChampionString points to the champion name, the champion name is erased in memory with '\0' characters (instead of the title itself) until AL0808_ui_CharacterIndex == 0 and the first character of the champion name is deleted */
                        }
                        continue;
                }
                if (G2139_i_RenameCommand == C167_COMMAND_RENAME_TITLE) {
                        if ((L0809_i_RenamedChampionString != C0_RENAME_CHAMPION_TITLE) && (AL0808_ui_CharacterIndex > 0)) {
                                F0077_MOUSE_EnableScreenUpdate_CPSE();
                                F0052_TEXT_PrintToViewport(L0813_i_X, L0814_i_Y, C13_COLOR_LIGHTEST_GRAY, G0051_ac_Graphic562_UnderscoreCharacterString);
                                F0097_DUNGEONVIEW_DrawViewport(C0_VIEWPORT_NOT_DUNGEON_VIEW);
                                F0078_MOUSE_DisableScreenUpdate();
                                T0281033_ProceedToTitle:
                                L0809_i_RenamedChampionString = C0_RENAME_CHAMPION_TITLE;
                                L0812_pc_RenamedChampionString = P0597_ps_Champion->Title;
                                L0813_i_X = L2269_i_X2;
                                L0814_i_Y = L2270_i_Y2;
                                AL0808_ui_CharacterIndex = 0;
                        }
                        continue;
                }
                L0810_i_Character = G2047_ac_ChampionRenameCharacters[G2139_i_RenameCommand - C168_COMMAND_RENAME_A];
                if (((L0810_i_Character == ' ') && (AL0808_ui_CharacterIndex == 0)) || L0811_B_ChampionTitleIsFull) {
                        continue;
                }
                G0052_ac_Graphic562_RenameChampionInputCharacterString[0] = L0810_i_Character;
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                F0052_TEXT_PrintToViewport(L0813_i_X, L0814_i_Y, C13_COLOR_LIGHTEST_GRAY, G0052_ac_Graphic562_RenameChampionInputCharacterString);
                F0097_DUNGEONVIEW_DrawViewport(C0_VIEWPORT_NOT_DUNGEON_VIEW);
                F0078_MOUSE_DisableScreenUpdate();
                L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex++] = L0810_i_Character;
                L0812_pc_RenamedChampionString[AL0808_ui_CharacterIndex] = '\0';
                L0813_i_X += G2087_C6_TextCharacterWidth;
                if ((L0809_i_RenamedChampionString != C0_RENAME_CHAMPION_TITLE) && (AL0808_ui_CharacterIndex == 7)) {
                        goto T0281033_ProceedToTitle;
                }
        };
        G0441_ps_PrimaryMouseInput = L2263_ps_PrimaryMouseInputBackup;
        G0442_ps_SecondaryMouseInput = L2264_ps_SecondaryMouseInputBackup;
        G0443_ps_PrimaryKeyboardInput = L2265_ps_PrimaryKeyboardInputBackup;
        G0444_ps_SecondaryKeyboardInput = L2266_ps_SecondaryKeyboardInputBackup;
#endif
}

void F0282_CHAMPION_ProcessCommands160To162_ClickInResurrectReincarnatePanel(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0598_i_Command)
#endif
int16_t P0598_i_Command FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned int16_t L0822_ui_ChampionIndex;
        REGISTER unsigned int16_t L0823_ui_Multiple;
        REGISTER unsigned int16_t L0824_ui_Multiple;
        REGISTER THING L0825_T_Thing;
#endif
#define AL0823_ui_SlotIndex      L0823_ui_Multiple
#define AL0823_ui_StatisticIndex L0823_ui_Multiple
#define AL0823_ui_Counter        L0823_ui_Multiple
#define AL0823_ui_ChampionColor  L0823_ui_Multiple
#define AL0824_ui_OneEighthOfCurrentStatistic L0824_ui_Multiple
#define AL0824_ui_StatisticIndex              L0824_ui_Multiple
        REGISTER CHAMPION* L0826_ps_Champion;
        REGISTER SENSOR* L0827_ps_Sensor;
#ifdef MEDIA724_I34E_I34M_A36M_A31M_A33M_A35E_A35M
        REGISTER char* L2000_PrefixString;
        char* L2001_SuffixString;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L0823_ui_Multiple;
        REGISTER THING L0825_T_Thing;
        REGISTER unsigned int16_t L0822_ui_ChampionIndex;
        REGISTER unsigned int16_t L0824_ui_Multiple;
        REGISTER int16_t L0828_i_MapX;
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0828_i_MapX;
#endif
        int16_t L0829_i_MapY;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        int16_t L0830_ai_Box[4];
#endif


        L0826_ps_Champion = &M516_CHAMPIONS[L0822_ui_ChampionIndex = G0305_ui_PartyChampionCount - 1];
        if (P0598_i_Command == C162_COMMAND_CLICK_IN_PANEL_CANCEL) {
                F0355_INVENTORY_Toggle_CPSE(C04_CHAMPION_CLOSE_INVENTORY);
                G0299_ui_CandidateChampionOrdinal = M000_INDEX_TO_ORDINAL(CM1_CHAMPION_NONE);
#ifdef MEDIA467_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
                if (G0305_ui_PartyChampionCount == 1) {
                        F0368_COMMAND_SetLeader(CM1_CHAMPION_NONE);
#ifdef MEDIA467_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        F0394_MENUS_SetMagicCasterAndDrawSpellArea(CM1_CHAMPION_NONE);
#endif
                }
                G0305_ui_PartyChampionCount--;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                M770_BOX_TOP(L0830_ai_Box) = 0;
                M771_BOX_BOTTOM(L0830_ai_Box) = 28;
                M769_BOX_RIGHT(L0830_ai_Box) = (M768_BOX_LEFT(L0830_ai_Box) = L0822_ui_ChampionIndex * C69_CHAMPION_STATUS_BOX_SPACING) + 66;
                G0578_B_UseByteBoxCoordinates = C0_FALSE;
#endif
#ifdef MEDIA018_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J
                F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                M524_FillScreenBox(L0830_ai_Box, C00_COLOR_BLACK);
                M524_FillScreenBox(&G0054_ai_Graphic562_Box_ChampionIcons[M026_CHAMPION_ICON_INDEX(L0826_ps_Champion->Cell, G0308_i_PartyDirection) << 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();
                F0733_FillZoneByIndex(L0822_ui_ChampionIndex + C151_ZONE_CHAMPION_0_STATUS_BOX_NAME_HANDS, C00_COLOR_BLACK);
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                F0733_FillZoneByIndex(M026_CHAMPION_ICON_INDEX(L0826_ps_Champion->Cell, G0308_i_PartyDirection) + C113_ZONE_CHAMPION_ICON_TOP_LEFT, C00_COLOR_BLACK);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0621_ClearChampionIconBox(M026_CHAMPION_ICON_INDEX(L0826_ps_Champion->Cell, G0308_i_PartyDirection));
#endif
                F0457_START_DrawEnabledMenus_CPSF();
                F0078_MOUSE_DisableScreenUpdate();
                return;
        }
        G0299_ui_CandidateChampionOrdinal = M000_INDEX_TO_ORDINAL(CM1_CHAMPION_NONE);
        L0828_i_MapX = G0306_i_PartyMapX;
        L0829_i_MapY = G0307_i_PartyMapY;
        L0828_i_MapX += G0233_ai_Graphic559_DirectionToStepEastCount[G0308_i_PartyDirection], L0829_i_MapY += G0234_ai_Graphic559_DirectionToStepNorthCount[G0308_i_PartyDirection];
        for (AL0823_ui_SlotIndex = C00_SLOT_READY_HAND; AL0823_ui_SlotIndex < C30_SLOT_CHEST_1; AL0823_ui_SlotIndex++) {
                if ((L0825_T_Thing = L0826_ps_Champion->Slots[AL0823_ui_SlotIndex]) != C0xFFFF_THING_NONE) {
                        F0164_DUNGEON_UnlinkThingFromList(L0825_T_Thing, 0, L0828_i_MapX, L0829_i_MapY);
                }
        }
        L0825_T_Thing = F0161_DUNGEON_GetSquareFirstThing(L0828_i_MapX, L0829_i_MapY);
        for (;;) { /*_Infinite loop_*/
                if (M012_TYPE(L0825_T_Thing) == C03_THING_TYPE_SENSOR) { /* BUG0_87 The same champion may be resurrected/reincarnated multiple times. When a champion is resurrected/reincarnated the engine disables the first sensor it finds on the champion mirror square but does not check that this is the champion portrait sensor. If another sensor is placed on the same square before the champion portrait sensor then it is disabled instead and the champion mirror remains available. The champion possessions are not cloned as they are removed the first time. This issue only affects custom dungeons. It does not exist in the original dungeons because there is a single sensor on champion mirror squares */
                        L0827_ps_Sensor = (SENSOR*)F0156_DUNGEON_GetThingData(L0825_T_Thing);
                        M044_SET_TYPE_DISABLED(L0827_ps_Sensor);
                        break;
                }
#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
                L0825_T_Thing = F0159_DUNGEON_GetNextThing(L0825_T_Thing);
        }
        if (P0598_i_Command == C161_COMMAND_CLICK_IN_PANEL_REINCARNATE) {
                F0281_CHAMPION_Rename(L0826_ps_Champion);
                F0008_MAIN_ClearBytes(M772_CAST_PC(L0826_ps_Champion->Skills), M543_BYTE_COUNT_INT(sizeof(L0826_ps_Champion->Skills)));
#ifdef MEDIA332_S20E_S21E_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_24_IMPROVEMENT New reincarnation rules: Health, Mana and Stamina values are halved. The current and maximum values of each statistic except Luck are decreased by 1/8th of their value without going below their minimum value */
                for (AL0823_ui_StatisticIndex = C1_STATISTIC_STRENGTH; AL0823_ui_StatisticIndex <= C6_STATISTIC_ANTIFIRE; AL0823_ui_StatisticIndex++) { /* This loop does not affect Luck. When the loop starts, the minimum value of each statistic C1_STATISTIC_STRENGTH to C6_STATISTIC_ANTIFIRE is 30 (as set by F0280_CHAMPION_AddCandidateChampionToParty). Current and maximum values are equal to the value from the champion definition */
                        AL0824_ui_OneEighthOfCurrentStatistic = L0826_ps_Champion->Statistics[AL0823_ui_StatisticIndex][C1_CURRENT] >> 3;
                        L0826_ps_Champion->Statistics[AL0823_ui_StatisticIndex][C1_CURRENT] = L0826_ps_Champion->Statistics[AL0823_ui_StatisticIndex][C0_MAXIMUM] = F0025_MAIN_GetMaximumValue(L0826_ps_Champion->Statistics[AL0823_ui_StatisticIndex][C2_MINIMUM], L0826_ps_Champion->Statistics[AL0823_ui_StatisticIndex][C1_CURRENT] - AL0824_ui_OneEighthOfCurrentStatistic);
                }
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_24_IMPROVEMENT New reincarnation rules: Health, Mana and Stamina values are halved. The current and maximum values of each statistic except Luck are decreased by 1/8th of their value without going below their minimum value */
                L0826_ps_Champion->CurrentHealth >>= 1;
                L0826_ps_Champion->MaximumHealth >>= 1;
                L0826_ps_Champion->CurrentStamina >>= 1;
                L0826_ps_Champion->MaximumStamina >>= 1;
                L0826_ps_Champion->CurrentMana >>= 1;
                L0826_ps_Champion->MaximumMana >>= 1;
#endif
#ifdef MEDIA629_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                L0826_ps_Champion->CurrentHealth >>= 2;
                L0826_ps_Champion->MaximumHealth >>= 2;
                L0826_ps_Champion->CurrentStamina >>= 2;
                L0826_ps_Champion->MaximumStamina >>= 2;
                L0826_ps_Champion->CurrentMana >>= 2;
                L0826_ps_Champion->MaximumMana >>= 2;
#endif
                for (AL0823_ui_Counter = 0; AL0823_ui_Counter < 12; AL0823_ui_Counter++) {
                        AL0824_ui_StatisticIndex = M002_RANDOM(7);
                        L0826_ps_Champion->Statistics[AL0824_ui_StatisticIndex][C1_CURRENT]++;
                        L0826_ps_Champion->Statistics[AL0824_ui_StatisticIndex][C0_MAXIMUM]++;
                }
        }
        if (G0305_ui_PartyChampionCount == 1) {
                G0362_l_LastPartyMovementTime = G0313_ul_GameTime;
#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
                F0368_COMMAND_SetLeader(C00_CHAMPION_FIRST);
                F0394_MENUS_SetMagicCasterAndDrawSpellArea(C00_CHAMPION_FIRST);
#endif
#ifdef MEDIA018_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J
        } else {
                F0393_MENUS_DrawSpellAreaControls(G0514_i_MagicCasterChampionIndex);
#endif
        }
#ifdef MEDIA724_I34E_I34M_A36M_A31M_A33M_A35E_A35M
        if (P0598_i_Command == C160_COMMAND_CLICK_IN_PANEL_RESURRECT) {
#ifdef MEDIA732_I34E_A35E
                L2000_PrefixString = "";
                L2001_SuffixString = " RESURRECTED.";
#endif
#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
                L2000_PrefixString = F0758_TranslateLanguage(C73_RESURRECTED_PREFIX);
                L2001_SuffixString = F0758_TranslateLanguage(C74_RESURRECTED_PREFIX);
#endif
        } else {
#ifdef MEDIA732_I34E_A35E
                L2000_PrefixString = "";
                L2001_SuffixString = " REINCARNATED.";
#endif
#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
                L2000_PrefixString = F0758_TranslateLanguage(C75_REINCARNATED_SUFFIX);
                L2001_SuffixString = F0758_TranslateLanguage(C76_REINCARNATED_SUFFIX);
#endif
        }
        AL0823_ui_ChampionColor = G0046_auc_Graphic562_ChampionColor[L0822_ui_ChampionIndex];
#endif
        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(AL0823_ui_ChampionColor = G0046_auc_Graphic562_ChampionColor[L0822_ui_ChampionIndex], L0826_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(AL0823_ui_ChampionColor, (P0598_i_Command == C160_COMMAND_CLICK_IN_PANEL_RESURRECT) ? " RESURRECTED." : " REINCARNATED.");
#endif
#ifdef MEDIA252_S12G /* CHANGE4_00_LOCALIZATION Translation to German language */
        F0047_TEXT_MESSAGEAREA_PrintMessage(AL0823_ui_ChampionColor, (P0598_i_Command == C160_COMMAND_CLICK_IN_PANEL_RESURRECT) ? " ZUM LEBEN ERWECKT." : " REINKARNIERT.");
#endif
#ifdef MEDIA446_A20G_A22G
        F0047_TEXT_MESSAGEAREA_PrintMessage(AL0823_ui_ChampionColor, (P0598_i_Command == C160_COMMAND_CLICK_IN_PANEL_RESURRECT) ? " VOM TODE ERWECKT." : " REINKARNIERT.");
#endif
#ifdef MEDIA261_S13FA_S13FB_A20F /* CHANGE5_00_LOCALIZATION Translation to French language */
        F0047_TEXT_MESSAGEAREA_PrintMessage(AL0823_ui_ChampionColor, (P0598_i_Command == C160_COMMAND_CLICK_IN_PANEL_RESURRECT) ? " RESSUSCITE." : " REINCARNE.");
#endif
#ifdef MEDIA571_F20J_X30J_P20JA_P20JB_F31J_X31J_P31J
        F0819_TEXT_MESSAGEAREA_PrintMessageAsJapanese(AL0823_ui_ChampionColor = G0046_auc_Graphic562_ChampionColor[L0822_ui_ChampionIndex], L0826_ps_Champion->Name);
        F0047_TEXT_MESSAGEAREA_PrintMessage(AL0823_ui_ChampionColor, (P0598_i_Command == C160_COMMAND_CLICK_IN_PANEL_RESURRECT) ? "は生き返った" : "は生まれ変わった");
#endif
#ifdef MEDIA724_I34E_I34M_A36M_A31M_A33M_A35E_A35M
        F0047_TEXT_MESSAGEAREA_PrintMessage(AL0823_ui_ChampionColor, L2000_PrefixString);
        F0047_TEXT_MESSAGEAREA_PrintMessage(AL0823_ui_ChampionColor, L0826_ps_Champion->Name);
        F0047_TEXT_MESSAGEAREA_PrintMessage(AL0823_ui_ChampionColor, L2001_SuffixString);
#endif
        F0355_INVENTORY_Toggle_CPSE(C04_CHAMPION_CLOSE_INVENTORY);
        F0457_START_DrawEnabledMenus_CPSF();
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
        F0067_MOUSE_SetPointerToNormal((G0411_i_LeaderIndex == CM1_CHAMPION_NONE) ? C0_POINTER_ARROW : C1_POINTER_HAND);
#endif
}

void F0283_CHAMPION_ViAltarRebirth(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0599_ui_ChampionIndex)
#endif
unsigned int16_t P0599_ui_ChampionIndex FINAL_SEPARATOR
{
        REGISTER CHAMPION* L0832_ps_Champion;
        REGISTER unsigned int16_t L0831_ui_Multiple;
#define AL0831_ui_Cell          L0831_ui_Multiple
#define AL0831_ui_MaximumHealth L0831_ui_Multiple
#define AL0831_ui_SlotIndex     L0831_ui_Multiple


        L0832_ps_Champion = &M516_CHAMPIONS[P0599_ui_ChampionIndex];
        if (F0285_CHAMPION_GetIndexInCell(L0832_ps_Champion->Cell) != CM1_CHAMPION_NONE) {
                AL0831_ui_Cell = C00_CELL_NORTHWEST;
                while (F0285_CHAMPION_GetIndexInCell(AL0831_ui_Cell) != CM1_CHAMPION_NONE) {
                        AL0831_ui_Cell++;
                }
                L0832_ps_Champion->Cell = AL0831_ui_Cell;
        }
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L0832_ps_Champion->Load = 0;
        for (AL0831_ui_SlotIndex = C00_SLOT_READY_HAND; AL0831_ui_SlotIndex < C30_SLOT_CHEST_1; AL0831_ui_SlotIndex++) {
                L0832_ps_Champion->Slots[AL0831_ui_SlotIndex] = C0xFFFF_THING_NONE;
        }
#endif
        AL0831_ui_MaximumHealth = L0832_ps_Champion->MaximumHealth;
        L0832_ps_Champion->CurrentHealth = (L0832_ps_Champion->MaximumHealth = F0025_MAIN_GetMaximumValue(25, AL0831_ui_MaximumHealth - (AL0831_ui_MaximumHealth >> 6) - 1)) >> 1;
        F0393_MENUS_DrawSpellAreaControls(G0514_i_MagicCasterChampionIndex);
        L0832_ps_Champion->Direction = G0308_i_PartyDirection;
        M008_SET(L0832_ps_Champion->Attributes, MASK0x8000_ACTION_HAND | MASK0x1000_STATUS_BOX | MASK0x0400_ICON);
#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(P0599_ui_ChampionIndex);
}

#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#include "CHAMPRST.C"
#endif
#endif
