//::///////////////////////////////////////////////
//:: nw_i0_ochrejelly
//:: Copyright (c) 2004 Bioware Corp.
//:://////////////////////////////////////////////
/*
    An include file for handling the "Split"
    functionality of the Ochre Jellies.
*/
//:://////////////////////////////////////////////
//::///////////////////////////////////////////////
//:: nw_i0_ochrejelly
//:: Copyright (c) 2004 Bioware Corp.
//:://////////////////////////////////////////////
/*
    An include file for handling the "Split"
    functionality of the Ochre Jellies.
*/
//:://////////////////////////////////////////////
//:: Created By: Keith K2 Hayward
//:: Created On: July, 2004
//:: Modified On: January, 2006
//:://////////////////////////////////////////////
/*
    Updated for Project Q IV by Pstemarie 31 Jan 2022: Level down effect now only occurs on EASY game difficulty, added parameters for Q oozes

*/

void SplitCreature(object oCreature, int iHP);

void SplitCreature(object oCreature, int iHP)
{
    string sClone;

    int iHitDice = GetHitDice(oCreature);
    int iDifficulty = GetGameDifficulty();
    int iDamage;

    effect ePoof1 = EffectVisualEffect(VFX_COM_CHUNK_GREEN_MEDIUM);
    effect ePoof2 = EffectVisualEffect(VFX_COM_CHUNK_GREEN_SMALL);
    effect eLevelDown, eDamage;

    object oClone1, oClone2;

    location lSpawn = GetLocation(oCreature);
    string sResRef = GetResRef(oCreature);

    // Find the correct type
    if (sResRef == "nw_ochrejellylrg")
    {
        sClone = "nw_ochrejellymed";
    }
    else if ((sResRef == "nw_ochrejellymed") && (iDifficulty >= GAME_DIFFICULTY_NORMAL))
    {
        sClone = "nw_ochrejellysml";
        iHitDice -= 4; // no level down
    }

//***** PRJECT Q IV APPEARANCES ****/////

    else if (sResRef == "q_blkpuddinglrg")
    {
        sClone = "q_blkpuddingmed";
    }
    else if ((sResRef == "q_blkpuddingmed") && (iDifficulty >= GAME_DIFFICULTY_NORMAL))
    {
        sClone = "q_blkpuddingsml";
        iHitDice -= 6; // no level down
    }
    else if (sResRef == "q_whtpuddinglrg")
    {
        sClone = "q_whtpuddingmed";
    }
    else if ((sResRef == "q_whtpuddingmed") && (iDifficulty >= GAME_DIFFICULTY_NORMAL))
    {
        sClone = "q_whtpuddingsml";
        iHitDice -= 4; // no level down
    }
    else if (sResRef == "q_dunpuddinglrg")
    {
        sClone = "q_dunpuddingmed";
    }
    else if ((sResRef == "q_dunpuddingmed") && (iDifficulty >= GAME_DIFFICULTY_NORMAL))
    {
        sClone = "q_dunpuddingsml";
        iHitDice -= 6; // no level down
    }
    else if (sResRef == "q_brwnpuddinglrg")
    {
        sClone = "q_brwnpuddingmed";
    }
    else if ((sResRef == "q_brwnpuddingmed") && (iDifficulty >= GAME_DIFFICULTY_NORMAL))
    {
        sClone = "q_brwnpuddingsml";
        iHitDice -= 6; // no level down
    }
    else if (sResRef == "q_mustrdjellylrg")
    {
        sClone = "q_mustrdjellymed";
    }
    else if ((sResRef == "q_mustrdjellymed") && (iDifficulty >= GAME_DIFFICULTY_NORMAL))
    {
        sClone = "q_mustrdjellysml";
        iHitDice -= 3; // no level down
    }

    // Create the clones
    oClone1 = CreateObject(OBJECT_TYPE_CREATURE, sClone, lSpawn, TRUE);
    oClone2 = CreateObject(OBJECT_TYPE_CREATURE, sClone, lSpawn, TRUE);

    if ((GetIsObjectValid(oClone1))&&(GetIsObjectValid(oClone2)))
    {
        iDamage = GetCurrentHitPoints(oClone1) - (iHP/2);
        eDamage = EffectDamage(iDamage);

        ApplyEffectAtLocation(DURATION_TYPE_INSTANT, ePoof1, lSpawn);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, ePoof2, oClone1);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, ePoof2, oClone2);

        // Reduce the hitpoints of the Jellies and take away a level
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oClone1);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oClone2);

        // If the Level of the monster is greater then 1 reduce it by a level
        if (GetGameDifficulty() < GAME_DIFFICULTY_NORMAL )
        {
            eLevelDown = EffectNegativeLevel(iHitDice, TRUE);
            if (iHitDice > 0)
            {
                ApplyEffectToObject(DURATION_TYPE_INSTANT, eLevelDown, oClone1);
                ApplyEffectToObject(DURATION_TYPE_INSTANT, eLevelDown, oClone2);
            }
        }
        AssignCommand(oCreature, ClearAllActions(TRUE));
        DestroyObject(oCreature);
    }
}

