

#include "inc_gen_loot"
//Generates an encounter that should be challenging to the party.
// If iWander is set true the monsters will hunt a PC in the area.
void GenerateEncounter(int iCR, object oWP,int iWander = FALSE);
// Creates the primary or secondary foe.
// If iCR > 0 loot for the encounter will be generated on that monster.
// If iWander is set true the monster will hunt a PC in the area.
object  CreateBoss(string sResRef, location lLoc, int iCR = 0, int iWander = FALSE);
// Creates a bunch of peons based on iCR.
// If a second type of Peon is determined both will be used.
// The second Peons should only be used for archer variants.
// If iWander is set true the monsters will hunt a PC in the area.
void CreatePeons (string sPeon1, location lLoc, float fCCR, string sPeon2 = "", int iWander = FALSE);
// Finds out the resref of the peons to be spawned by the CreatePeon function.
string GetPeonResRef(string sResRef);
// Generates an encounter Level
int GetEncounterLevel (int iPartyLevel);
// Causes the caller to walk around the area looking for a PC.
void Hunt();

int GetEncounterLevel (int iPartyLevel)// Good
    {
    int iScaler = iPartyLevel/2;
    if (iScaler < 1)
        iScaler = 1;
    int i = (Random(iScaler*2+1)) - iScaler;
    int  iEncounterLevel = iPartyLevel + i; // Adds the randomized number to the party level.
    if (iEncounterLevel >= 40)         iEncounterLevel = 40;
    else if (iEncounterLevel <= 1)     iEncounterLevel = 1;
    return iEncounterLevel;
    }

void GenerateEncounter(int iPartyLevel, object oWP, int iWander)
    {
    if (GetTag(oWP) == "MON_")// Set the waypoint so that it is not used again.
        {
        if (GetLocalInt(oWP,"DoOnce"))
            return;
        SetLocalInt(oWP,"DoOnce",TRUE);
        }
    location lLoc = GetLocation(oWP);
    int i, iEncNumber, iNum, iRoll;
    float fCCR,fCR;
    string sBoss,sLT,sPeon1,sPeon2;
    object oMonster;
    int iEncounterLevel = GetEncounterLevel (iPartyLevel);
    // Generate Encounter.
    switch (iEncounterLevel)
        {
        case 40:
            {
            switch(Random(1)+1)
                {
                case 1: {sBoss = "x2_dracolich001";break;}//Level 43
                }
            break;
            }
        case 39:
        case 38:
        case 37:
        case 36:
        case 35://Allow above 20 to turn on.
            {
            switch(Random(1)+1)
                {
                case 1: {sBoss = "x2_golem001";break;}//Add Peons
                }
            break;
            }
        case 34:
        case 33:
        case 32:
            {
            switch(Random(1)+1)
                {
                case 1: {sBoss = "x2_golem002";break;}//Add Peons
                };
            break;
            }
        case 31:
        case 30:
        case 29:
        case 28://Allow above 20 to turn on.
            {
            switch(Random(2)+1)
                {
                case 1: {sBoss = "x2_drider005";break;}//Add Peons
                case 2: {sBoss = "nw_lich001";break;}//Add Peons
                };
            break;
            }
        case 26:
        case 25://Allow above 20 to turn on.
            {
            switch(Random(2)+1)
                {
                case 1: {sBoss = "nw_goldmflesh001";break;}
                case 2: {sBoss = "x2_slaadwhite001"; sPeon1 =  "nw_slaaddeth";break;}
                };
            break;
            }
        case 24:
            {
            switch(Random(2)+1)
                {
                case 1: {sBoss = "nw_drgred003";break;}
                case 2: {sBoss = "x2_demilich001";break;}
                };
            break;
            }
        case 23://Allow above 20 to turn on.
            {
            switch(Random(2)+1)
                {
                case 1: {sBoss = "x2_drider004";                    sPeon1 =  "x2_drider003";break;}
                case 2: {sBoss = "nw_drgblue003";break;}
                };
            break;
            }
        case 22:
            {
            switch(Random(2)+1)
                {
                case 1: {sBoss = "x2_dragonshad001";break;}
                case 2: {sBoss =  "nw_drggreen003"; break;}         //None
                };
            break;
            }
        case 21://Allow above 20 to turn on.
            {
            switch(Random(3)+1)
                {
                case 1: {sBoss = "x2_goliron_huge";break;}
                case 2: {sBoss =  "nw_drgblack003"; break;}         //None
                case 3: {sBoss =  "nw_lichboss";                    sPeon1 = "nw_doomkght";break;}
                };
            break;
            }
        case 20:
            {
            switch(Random(3)+1)
                {
                case 1: {sBoss =  "nw_airelder";                    sLT = "nw_airgreat";   sPeon1 ="nw_airhuge";break;}
                case 2: {sBoss =  "nw_drgwhite003"; break;}         //None
                case 3: {sBoss =  "x2_mindfveneratr";               sPeon1 =  "x2_mindflayer001";break;}
                case 4: {sBoss =  "x0_form_queen";                  sLT =  "x0_form_myrmarch";                  sPeon1 =  "x0_form_taskmast";             sPeon2 = "x0_form_warrior";break;}
                };
            break;
            }
       case 19:
            {
            switch(Random(1)+1)
                {
                case 1: {sBoss =  "nw_drgred002"; break;}           //None
                case 2: {sBoss =  "x2_mindflayer002";       sPeon1 =  "x2_mindflayer001";break;}
                };
            break;
            }
        case 18:
            {
            switch(Random(3)+1)
                {
                case 1: {sBoss =  "nw_airgreat";                    sLT = "nw_airhuge";   sPeon1 ="nw_air";break;}
                case 2: {sBoss =  "nw_ogremageboss";                sPeon1 = "nw_ogre01";   break;}
                case 3:
                    {
                    switch(Random(2)+1)// Dragons
                        {
                        case 1: {sBoss =  "nw_drggreen002"; break;}         //None
                        case 2: {sBoss =  "nw_drgblue002"; break;}          //None           //None
                        }
                    break;
                    }

                }
            break;
            }
        case 17:
            {
            switch(Random(5)+1)
                {
                case 1: {sBoss =  "nw_eartheld";                    sLT = "nw_earthgreat";   sPeon1 ="nw_earthhuge";break;}
                case 2: {sBoss =  "nw_fireelder";                   sLT = "nw_firegreat";   sPeon1 ="nw_firehuge";break;}
                case 3: {sBoss =  "nw_lich003";                     sPeon1 = "nw_doomkght";break;}
                case 4: {sBoss =  "nw_drgblack002"; break;}         //None
                case 5: {sBoss =  "x2_drider003";                   sPeon1 = "x2_drider002";break;}
                };
            break;
            }
        case 16:
            {
            switch(Random(6)+1)
                {
                case 1: {sBoss =  "nw_goliron"; break;}             //None
                case 2: {sBoss =  "nw_watelder";                    sLT = "nw_watergreat";   sPeon1 ="nw_waterhuge";break;}
                case 3: {sBoss =  "nw_balorboss";                   sLT = "nw_dmsucubus";   sPeon1 = "nw_slaadred";break;}
                case 4: {sBoss =  "nw_vampire003";                  sPeon1 = "nw_vampire004";;break;}
                case 5: {sBoss =  "nw_drgwhite002"; break;}         //None
                case 6: {sBoss =  "x2_mindfdarkener";               sPeon1 =  "x2_mindflayer001";break;}
                };
            break;
            }
        case 15:
            {
            switch(Random(11)+1)
                {
                case 1: {sBoss =  "nw_earthgreat";                  sLT = "nw_earthhuge";   sPeon1 ="nw_earth";break;}
                case 2: {sBoss =  "nw_firegreat";                   sLT = "nw_firehuge";    sPeon1 ="nw_fire";break;}
                case 3: {sBoss =  "nw_demon";                       sLT = "nw_dmsucubus";   sPeon1 = "nw_slaadred";break;}
                case 4: {sBoss =  "nw_devil001"; break;             sLT = "nw_dmsucubus";   sPeon1 = "nw_slaadred";break;}
                case 5: {sBoss =  "nw_slaaddthboss";                sPeon1 = "nw_slaadred";break;}
                case 6: {sBoss =  "nw_slaaddeth";                   sPeon1 = "nw_slaadred";break;}
                case 7: {sBoss =  "nw_doomkghtboss";                sPeon1 = "nw_doomkght";break;}
                case 8: {sBoss =  "nw_drgred001"; break;}           //None
                case 9: {sBoss =  "nw_beardireboss"; break;}        //None
                case 10: {sBoss =  "nw_duecler020";                  sLT = "nw_duemage005";      sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                case 11: // Drow Elves
                    {
                    switch(d2())
                        {
                        case 1: {sBoss =  "nw_drowmage020";             sPeon1 = "nw_drowfight005"; sPeon2 = "nw_drowrogue005";break;}
                        case 2: {sBoss =  "nw_drowfight020";            sPeon1 = "nw_drowfight005"; break;}
                        }
                    break;
                    }
                case 12: {sBoss = "x2_beholder003";break;}
                };
            break;
            }
        case 14:
            {
            switch(Random(5)+1)
                {
                case 1: {sBoss =  "nw_watergreat";                  sLT = "nw_waterhuge";   sPeon1 ="nw_water";break;}
                case 2: {sBoss =  "nw_drgblue001"; break;}         //None
                case 3: {sBoss =  "nw_drggreen001"; break;}        //None
                case 4: // Duergar Dwarves
                    {
                    switch(d2())
                        {
                        case 1: {sBoss =  "nw_duemage020";             sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                        case 2: {sBoss =  "nw_duefight020";            sLT = "nw_duecler005";      sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                        }
                    break;
                    }
                case 5: {sBoss =  "nw_spiderboss";                      sPeon1 = "nw_spiddire";break;}
                };
            break;
            }
        case 13:
            {
            switch(Random(8)+1)
                {
                case 1: {sBoss =  "nw_bathorror";               sPeon1 = "nw_helmhorr";break;}
                case 2: {sBoss =  "nw_airhuge";                 sPeon1 = "nw_air";break;}
                case 3: {sBoss =  "nw_vampire002";              sPeon1 = "rdg_vampire";break;}
                case 4: {sBoss =  "nw_vampire004";              sPeon1 = "rdg_vampire";break;}
                case 5: {sBoss =  "nw_skeldevour"; break;}      //None
                case 6: {sBoss =  "nw_drgblack001"; break;}     //None
                case 7: {sBoss =  "nw_duerogue020";            sLT = "nw_duecler005";  sPeon1 = "nw_duefight005";  sPeon2 = "nw_duerogue005";break;}
                case 8: {sBoss =  "nw_drowrogue020";          sPeon1 = "nw_drowfight005"; sPeon2 = "nw_drowrogue005";break;}
                };
            break;
            }
        case 12:
            {
            switch(Random(6)+1)
                {
                case 1: {sBoss =  "nw_golstone"; break;}        //None
                case 2: {sBoss =  "nw_firehuge";                sPeon1 = "nw_fire";break;}
                case 3: {sBoss =  "nw_gntfire";                 sLT = "x0_gntfirefem"; sPeon1 = "nw_ogre01";break;}
                case 4: {sBoss =  "nw_vampire001";              sPeon1 = "rdg_vampire";break;}
                case 5: {sBoss =  "nw_mohrg";                   sPeon1 = "nw_zombie01";     sPeon2 = "nw_zombie02"; break;}
                case 6: {sBoss =  "nw_drgwhite001"; break;}     //None
                };
            break;
            }
        case 11:
            {
            switch(Random(13)+1)
                {
                case 1: {sBoss =  "nw_golbone"; break;}           //None
                case 2: {sBoss =  "nw_earthhuge";               sPeon1 = "nw_earth"; break;}
                case 3: {sBoss =  "nw_helmhorr"; break;}          //None
                case 4: {sBoss =  "nw_slaadgryboss";            sPeon1 = "nw_slaadred";break;}
                case 5: {sBoss =  "nw_waterhuge";               sPeon1 = "nw_water"; break;}
                case 6: {sBoss =  "nw_mummyboss";               sLT = "nw_mumcleric";   sPeon1 = "nw_mummy"; break;}
                case 7: {sBoss =  "nw_goblinboss";              sLT = "nw_gobwizb";     sPeon1 = "nw_goblinb";      sPeon2 ="nw_goblina"; break;}
                case 8: {sBoss =  "nw_wolfdireboss";            sLT = "nw_direwolf";    sPeon1 = "nw_worg";  break;}
                case 9: {sBoss =  "nw_diretiger"; break;}
                case 10: // Duergar Dwarves
                    {
                    switch(d3())
                        {
                        case 1: {sBoss =  "nw_duemage015";             sLT = "nw_duecler005";      sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                        case 2: {sBoss =  "nw_duefight015";            sLT = "nw_duecler005";      sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                        case 3: {sBoss =  "nw_duecler015";             sLT = "nw_duemage005";      sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                        }
                    break;
                    }
                case 11: // Drow Elves
                    {
                    switch(d3())
                        {
                        case 1: {sBoss =  "nw_drowcler015";             sLT = "nw_drowmage005";     sPeon1 = "nw_drowfight005"; sPeon2 = "nw_drowrogue005";break;}
                        case 2: {sBoss =  "nw_drowmage015";             sPeon1 = "nw_drowfight005"; sPeon2 = "nw_drowrogue005";break;}
                        case 3: {sBoss =  "nw_drowfight015";            sPeon1 = "nw_drowfight005"; break;}
                        }
                    break;
                    }
                case 12: {sBoss =  "x2_beholder001";break;}
                case 13: {sBoss =  "x0_form_myrmarch";                  sLT =  "x0_form_taskmast";             sPeon1 = "x0_form_warrior";break;}
                };
            break;
            }
        case 10:
            {
            switch(Random(14)+1)
                {
                case 1: {sBoss =  "nw_golclay"; break;}         //None
                case 2: {sBoss =  "nw_slaadgray";               sPeon1 = "nw_slaadred";break;}
                case 3: {sBoss =  "nw_dmvrock"; break;}         //None
                case 4: {sBoss =  "nw_gnthill";                 sPeon1 = "nw_ogre01";break;}
                case 5: {sBoss =  "nw_gntmount";                sPeon1 = "nw_ogre01";break;}
                case 6: {sBoss =  "x0_gntfirefem";              sPeon1 = "nw_ogre01";break;}
                case 7: {sBoss =  "nw_mumcleric";               sPeon1 = "nw_mummy"; break;}
                case 8: {sBoss =  "nw_gntfrost";                sLT = "x0_gntfrostfem"; sPeon1 = "nw_ogre01";       sPeon2 = "nw_wolfwint"; break;}
                case 9: {sBoss =  "nw_mumfight";                sPeon1 = "nw_mummy"; break;}
                case 10: {sBoss =  "nw_doomkght";               sLT = "nw_skelchief";   sPeon1 = "nw_skelwarr01";break;}
                case 11: {sBoss =  "nw_orcboss";                sLT = "nw_orcwizb";     sPeon1 = "nw_orcb";         sPeon2 = "nw_orca"; break;}
                case 12: {sBoss =  "nw_bugbearboss";            sLT = "nw_bugchiefb";   sPeon1 = "nw_bugbearb";     sPeon2 = "nw_bugbeara";break;}
                case 13: {sBoss =  "nw_duerogue015";            sLT = "nw_duecler005";  sPeon1 = "nw_duefight005";  sPeon2 = "nw_duerogue005";break;}
                case 14: // Drow Elves & Driders
                    {
                    switch(d2())
                        {
                        case 1: {sBoss =  "nw_drowrogue015";           sPeon1 = "nw_drowfight005"; sPeon2 = "nw_drowrogue005";break;}
                        case 2: {sBoss = "x2_drider002";               sPeon1 = "x2_drider001";break;}
                        }
                    break;
                    }
                };
            break;
            }
        case 9:
            {
            switch(Random(6)+1)
                {
                case 1: {sBoss =  "nw_umberhulk"; break;}       //None
                case 2: {sBoss =  "x0_gntfrostfem";             sPeon1 = "nw_ogre01";   sPeon2 = "nw_wolfwint"; break;}
                case 3: {sBoss =  "nw_slaadgrn";                sPeon1 = "nw_slaadred";break;}
                case 4: {sBoss =  "nw_bodak"; break;}           //None
                case 5: {sBoss =  "nw_halfdra001";              sPeon1 = "nw_tiefling02";break;}
                case 6: {sBoss =  "x2_mindflayer001";break;}
                };
            break;
            }
        case 8:
            {
            switch(Random(10)+1)
                {
                case 1: {sBoss =  "nw_ettin";                   sPeon1 = "nw_ogre01";break;}
                case 2: {sBoss =  "nw_halffnd001";              sPeon1 = "nw_tiefling02";break;}
                case 3: {sBoss =  "nw_golflesh"; break;}        //None
                case 4: {sBoss =  "nw_grayrend"; break;}        //None
                case 5: {sBoss =  "nw_minchief";                sPeon1 = "nw_minotaur"; break;}
                case 6: {sBoss =  "nw_minogon"; break;}         //None
                case 7: {sBoss =  "nw_willowisp"; break;}       //None
                case 8: {sBoss =  "nw_zombieboss";              sPeon1 = "nw_zombtyrant";break;}
                case 9: {sBoss =  "nw_duecler010";              sLT = "nw_duemage005";      sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                case 10: // Drow Elves & Driders
                    {
                    switch(d3())
                        {
                        case 1: {sBoss =  "nw_drowcler010";     sLT = "x2_drider001";        sPeon1 = "nw_drowfight005"; sPeon2 = "nw_drowrogue005";break;}
                        case 2: {sBoss =  "nw_drowfight010";                                 sPeon1 = "nw_drowfight005"; break;}
                        case 3: {sBoss = "x2_driderw01";        sPeon1 = "x2_drider001";break;}
                        }
                    break;
                    }
                };
            break;
            }
        case 7:
            {
            switch(Random(17)+1)
                {
                case 1: {sBoss =  "nw_rakshasa"; break;}          //None
                case 2: {sBoss =  "nw_dmsucubus"; break;}         //None
                case 3: {sBoss =  "nw_devour"; break;}            //None
                case 4: {sBoss =  "nw_slaadbl";                 sPeon1 = "nw_slaadred";break;}
                case 5: {sBoss =  "nw_trollchief";              sPeon1 = "nw_troll";break;}
                case 6: {sBoss =  "nw_btlstag";                 sPeon1 = "nw_btlbomb";break;}
                case 7: {sBoss =  "nw_trollwiz";                sPeon1 = "nw_troll";break;}
                case 8: {sBoss =  "nw_spiddire"; break;         sPeon1 = "nw_spidgiant";break;}
                case 9: {sBoss =  "x0_gorgon"; break;}            //None
                case 10: {sBoss =  "nw_shfiend";                sPeon1 = "nw_shadow";break;}
                case 11: {sBoss =  "nw_skelchief";              sPeon1 = "nw_skelwarr01";break;}
                case 12: {sBoss =  "nw_revenant001"; break;}      //None
                case 13: {sBoss =  "nw_beastmalar001"; break;}
                case 14: // Duergar Dwarves
                    {
                    switch(d3())
                        {
                        case 1: {sBoss =  "nw_duemage010";             sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                        case 2: {sBoss =  "nw_duefight010";            sLT = "nw_duecler005";      sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                        case 3: {sBoss =  "nw_duerogue010";            sLT = "nw_duecler005";      sPeon1 = "nw_duefight005"; sPeon2 = "nw_duerogue005";break;}
                        }
                    break;
                    }
                case 15: // Drow Elves & Driders
                    {
                    switch(d3())
                        {
                        case 1: {sBoss =  "nw_drowmage010";             sPeon1 = "nw_drowfight005"; sPeon2 = "nw_drowrogue005";break;}
                        case 2: {sBoss =  "nw_drowrogue010";            sPeon1 = "nw_drowfight005"; sPeon2 = "nw_drowrogue005";break;}
                        case 3: {sBoss =  "x2_fdrider002";              sPeon1 = "x2_drider001";break;}
                        }
                    break;
                    }
                case 16: {sBoss =  "x0_stinger_chief"; sLT =  "x0_stinger_mage"; sPeon1 = "x0_stinger";break;}
                case 17: {sBoss =  "x0_form_taskmast";             sPeon1 = "x0_form_warrior"; sPeon2 = "x0_form_worker";break;}

                };
            break;
            }
        case 6:
            {
            switch(Random(12)+1)
                {
                case 1: {sBoss =  "nw_invstalk"; break;}        //None
                case 2: {sBoss =  "nw_slaadred"; break;}        //None
                case 3: {sBoss =  "nw_ogrechief01";             sPeon1 = "nw_ogre01";   break;}
                case 4: {sBoss =  "x0_manticore"; break;}       //None
                case 5: {sBoss =  "nw_skelwarr01";              sPeon1 = "nw_skeleton"; break;}
                case 6: {sBoss =  "nw_skelwarr02";              sPeon1 = "nw_skeleton"; break;}
                case 7: {sBoss =  "rdg_vampire";                sPeon1 = "nw_tiefling02";break;}
                case 8: {sBoss =  "nw_curst002"; break;}        //None
                case 9: {sBoss =  "nw_curst004"; break;}        //None
                case 10: {sBoss =  "nw_spectre"; break;}        //None
                case 11:
                    {
                    switch (Random(2)+1)
                        {
                        case 1: {sBoss =  "x2_fdrider001";break;}
                        case 2: {sBoss = "x2_drider001";break;}
                        };
                    break;
                    }
                };
            break;
            }
        case 5:
            {
            switch(Random(22)+1)
                {
                case 1: {sBoss =  "x0_basilisk"; break;}        //None
                case 2: {sBoss =  "nw_beastxvim"; break;}       //None
                case 3: {sBoss =  "x0_cockatrice"; break;}      //None
                case 4: {sBoss =  "nw_ettercap";                sPeon1 = "nw_spidgiant";break;}
                case 5: {sBoss =  "nw_ghoullord";               sPeon1 = "nw_ghoul"; break;}
                case 6: {sBoss =  "nw_horror"; break;}          //None
                case 8: {sBoss =  "nw_ogremage01";              sPeon1 = "rdg_orc2";         sPeon2 = "rdg_orc"; break;}
                case 9: {sBoss =  "nw_troll"; break;            sPeon1 = "rdg_orc2";         sPeon2 = "rdg_orc"; break;}
                case 10: {sBoss =  "nw_werecat"; break;}        //None
                case 11: {sBoss =  "x0_wyrmling_blu"; break;}   //None
                case 12: {sBoss =  "x0_wyrmling_red"; break;}   //None
                case 13: {sBoss =  "nw_curst001"; break;}       //None
                case 14: {sBoss =  "rdg_curst_ranger"; break;}  //None
                case 15: {sBoss =  "nw_mummy";                  sPeon1 = "nw_zombie01";     sPeon2 = "nw_zombie02"; break;}
                case 16: {sBoss =  "nw_wraith"; break;}         //None
                case 17: {sBoss =  "nw_bugchiefa";              sPeon1 = "nw_bugbearb";     sPeon2 = "nw_bugbeara";break;}
                case 18: {sBoss =  "nw_bugchiefb";              sPeon1 = "nw_bugbearb";     sPeon2 = "nw_bugbeara";break;}
                case 19: {sBoss =  "nw_direwolf";               sPeon1 = "nw_worg"; break;}
                case 20: {sBoss =  "nw_wolfwint"; break;}       //None
                case 21:
                    {
                    switch(d2())
                        {
                        case 1: {sBoss =  "x0_stinger_mage"; sPeon1 = "x0_stinger"; break;}
                        case 2: {sBoss =  "x0_stinger_war"; sPeon1 = "x0_stinger"; break;}
                        }
                    break;
                    }
                case 22: {sBoss =  "x2_harpy001"; break;}       //None
                };
            break;
            }
        case 4:
            {
            switch(Random(25)+1)
                {
                case 1: {sBoss =  "nw_air"; break;}             //None
                case 2: {sBoss =  "nw_earth"; break;}           //None
                case 3: {sBoss =  "nw_ghast";                   sPeon1 = "nw_ghoul"; break;}
                case 4: {sBoss =  "nw_hellhound"; break;}       //None
                case 5: {sBoss =  "nw_minotaur";                sPeon1 = "rdg_orc";         sPeon2 = "rdg_orc"; break;}
                case 6: {sBoss =  "nw_shmastif"; break;}        //None
                case 7: {sBoss =  "nw_spidwra";                 sPeon1 = "nw_spidgiant";break;}
                case 8: {sBoss =  "nw_spidswrd";                sPeon1 = "nw_spidgiant";break;}
                case 9: {sBoss =  "nw_water"; break;}           //None
                case 10: {sBoss =  "x0_wyrmling_grn"; break;}   //None
                case 11: {sBoss =  "nw_yuan_ti001";             sPeon1 = "nw_zombie01";     sPeon2 = "nw_zombie02"; break;}
                case 12: {sBoss =  "nw_skelpriest";             sPeon1 = "nw_skeleton"; break;}
                case 13: {sBoss =  "nw_skelmage"; break;        sPeon1 = "nw_skeleton"; break;}
                case 14: {sBoss =  "nw_wight"; break;}          //None
                case 15: {sBoss =  "nw_zombwarr01";             sPeon1 = "nw_zombie01";     sPeon2 = "nw_zombie02"; break;}
                case 16: {sBoss =  "nw_zombwarr02";             sPeon1 = "nw_zombie01";     sPeon2 = "nw_zombie02"; break;}
                case 17: {sBoss =  "nw_gobchiefa";              sPeon1 = "nw_goblinb";      sPeon2 = "nw_goblina"; break;}
                case 18: {sBoss =  "nw_orcwiza";                sPeon1 = "rdg_orc2";         sPeon2 = "rdg_orc"; break;}
                case 19: {sBoss =  "nw_orcwizb";                sPeon1 = "rdg_orc2";         sPeon2 = "rdg_orc"; break;}
                case 20: {sBoss =  "nw_bugwiza";                sPeon1 = "nw_bugbearb";     sPeon2 = "nw_bugbeara";break;}
                case 21: {sBoss =  "nw_bugwizb";                sPeon1 = "nw_bugbearb";     sPeon2 = "nw_bugbeara";break;}
                case 22: // Duergar Dwarves
                    {
                    switch(d4())
                        {
                        case 1: {sBoss =  "nw_duecler005";             sLT = "nw_duemage001";      sPeon1 = "nw_duefight001"; sPeon2 = "nw_duerogue001";break;}
                        case 2: {sBoss =  "nw_duemage005";             sLT = "nw_duecler001";      sPeon1 = "nw_duefight001"; sPeon2 = "nw_duerogue001";break;}
                        case 3: {sBoss =  "nw_duefight005";            sLT = "nw_duecler001";      sPeon1 = "nw_duefight001"; sPeon2 = "nw_duerogue001";break;}
                        case 4: {sBoss =  "nw_duerogue005";            sLT = "nw_duecler001";      sPeon1 = "nw_duefight001"; sPeon2 = "nw_duerogue001";break;}
                        }
                    break;
                    }
                case 23: // Drow Elves
                    {
                    switch(d3())
                        {
                        case 1: {sBoss =  "nw_drowcler005";             sPeon1 = "nw_drowfight001"; sPeon2 = "nw_drowrogue001";break;}
                        case 2: {sBoss =  "nw_drowmage005";             sPeon1 = "nw_drowfight001"; sPeon2 = "nw_drowrogue001";break;}
                        case 3: {sBoss =  "nw_drowfight005";            sPeon1 = "nw_drowfight001"; break;}
                        }
                    break;
                    }
                case 24: {sBoss =  "snw_seahag";                        sLT = "snw_seahag";      sPeon1 = "x0_asabi_warrior";break;}
                case 25: {sBoss =  "x0_form_warrior";                   sPeon1 = "x0_form_worker"; break;}
                };
            break;
            }
        case 3:
            {
            switch(Random(24)+1)
                {
                case 1: {sBoss =  "nw_btlbomb";                 sPeon1 = "nw_btlfire";break;}
                case 2: {sBoss =  "nw_btlfire02";               sPeon1 = "nw_btlfire";break;}
                case 3: {sBoss =  "nw_btlstink";                sPeon1 = "nw_btlfire";break;}
                case 4: {sBoss =  "nw_fire"; break;}            //None
                case 5: {sBoss =  "rdg_gargoyle"; break;}        //None
                case 6: {sBoss =  "nw_ogre01";                  sPeon1 = "nw_orcb";         sPeon2 = "nw_orca"; break;}
                case 7: {sBoss =  "nw_spidgiant"; break;}       //None
                case 8: {sBoss =  "nw_spidphase"; break;}       //None
                case 9: {sBoss =  "x0_wyrmling_blk"; break;}    //None
                case 10: {sBoss =  "x0_wyrmling_wht"; break;}   //None
                case 11: // Mephits
                    {
                    switch(Random(12)+1)
                        {
                        case 1: {sBoss =  "nw_mepice"; break;}          //None
                        case 2: {sBoss =  "nw_mepooze"; break;}         //None
                        case 3: {sBoss =  "nw_mepwater"; break;}        //None
                        case 4: {sBoss =  "nw_mepsteam"; break;}        //None
                        case 5: {sBoss =  "nw_imp"; break;}             //None
                        case 6: {sBoss =  "nw_mepmagma"; break;}        //None
                        case 7: {sBoss =  "nw_mepfire"; break;}         //None
                        case 8: {sBoss =  "nw_mepsalt"; break;}         //None
                        case 9: {sBoss =  "nw_dmquasit"; break;}        //None
                        case 10: {sBoss =  "nw_mepearth"; break;}       //None
                        case 11: {sBoss =  "nw_mepdust"; break;}        //None
                        case 12: {sBoss =  "nw_mepair"; break;}         //None
                        }
                    break;
                    }
                case 12: {sBoss =  "nw_shadow"; break;}         //None
                case 13: {sBoss =  "nw_zombtyrant";             sPeon1 =  "nw_zombie01";    sPeon2 = "nw_zombie02"; break;}
                case 14: {sBoss =  "nw_allip"; break;}          //None
                case 15: {sBoss =  "nw_gobchiefb";              sPeon1 = "nw_goblinb";      sPeon2 ="nw_goblina"; break;}
                case 16: {sBoss =  "nw_gobwiza";                sPeon1 = "nw_goblinb";      sPeon2 ="nw_goblina"; break;}
                case 17: {sBoss =  "nw_gobwizb";                sPeon1 = "nw_goblinb";      sPeon2 ="nw_goblina"; break;}
                case 18: {sBoss =  "nw_orcchiefa";              sPeon1 = "rdg_orc2";         sPeon2 = "rdg_orc"; break;}
                case 19: {sBoss =  "nw_orcchiefb";              sPeon1 = "rdg_orc2";         sPeon2 = "rdg_orc"; break;}
                case 20: {sBoss =  "nw_worg";                   sPeon1 = "nw_goblinb";      sPeon2 ="nw_goblina"; break;}
                case 21: {sBoss =  "nw_drowrogue005";           sPeon1 = "nw_drowfight001"; sPeon2 = "nw_drowrogue001";break;}
                case 22: {sBoss =  "x2_beholder002";break;}     //None
                case 23: {sBoss =  "x0_stinger";break;}         //None
                case 24: {sBoss =  "x2_gelcube";break;}         //None

                };
            break;
            }
        case 2:
            {
            switch(Random(9) + 1)
                {
                case 1: {sBoss =  "x0_asabi_warrior";           sPeon1 = "nw_kobold001";    sPeon2 = "nw_kobold002";break;}
                case 2: {sBoss =  "nw_bugbearb";                sPeon1 = "nw_bugbeara";     sPeon2 ="nw_goblinb"; break;}
                case 3: {sBoss =  "nw_oldwara";                 sPeon1 = "nw_kobold001";    sPeon2 = "nw_kobold002";break;}
                case 4: {sBoss =  "nw_ghoul"; break;}           //None
                case 5: {sBoss =  "nw_krenshar"; break;}        //None
                case 6: {sBoss =  "nw_werewolf"; break;}        //None
                case 7: {sBoss =  "nw_hobgoblin002";            sPeon1 = "nw_goblinb";      sPeon2 = "nw_hobgoblin001"; break;}
                case 8: // Kobold Bosses
                    {
                    switch(Random(12)+1)
                        {
                        case 8: {sBoss =  "nw_kobold003";               sPeon1 = "nw_kobold001";    sPeon2 = "nw_kobold002";break;}
                        case 9: {sBoss =  "nw_kobold004";               sPeon1 = "nw_kobold001";    sPeon2 = "nw_kobold002";break;}
                        case 10: {sBoss = "nw_kobold005";               sPeon1 = "nw_kobold001";    sPeon2 = "nw_kobold002";break;}
                        case 11: {sBoss = "nw_kobold006";               sPeon1 = "nw_kobold001";    sPeon2 = "nw_kobold002";break;}
                        }
                    break;
                    }
                case 9: {sBoss = "rdg_wererat";                sPeon1 = "nw_ratdire001";   sPeon2 = "nw_rat001";break;}
                };
            break;
            }
        case 1:
            {
            switch(Random(16) + 1)
                {
                case 1: {sBoss =  "nw_gnoll001"; break;}        //None
                case 2: {sBoss =  "nw_zombie01";                sPeon1 = "nw_zombie02"; break;}
                case 3: {sBoss =  "nw_skeleton"; break;}        //None
                case 4: {sBoss =  "nw_tiefling02"; break;}      //None
                case 5: {sBoss =  "rdg_bat"; break;}             //None
                case 6: {sBoss =  "nw_hobgoblin001"; break;}    //None
                case 7: {sBoss =  "nw_kobold001";               sPeon1 = "nw_kobold002"; break;}
                case 8: {sBoss =  "nw_stirge"; break;}          //None
                case 9: {sBoss =  "nw_btlfire"; break;}         //None
                case 10: {sBoss =  "nw_goblinb";                sPeon1 = "nw_goblina"; break;}
                case 11: {sBoss =  "rdg_orc2";                  sPeon1 = "rdg_orc"; break;}
                case 12: {sBoss =  "nw_rat001"; break;}         //None
                case 13: {sBoss =  "nw_ratdire001";             sPeon1 = "nw_ratdire001";    sPeon2 = "nw_rat001";break;}
                case 14: // Duergar Dwarves
                    {
                    switch(d4())
                        {
                        case 1: {sBoss =  "nw_duecler001";             sLT = "nw_duemage001";      sPeon1 = "nw_duefight001"; sPeon2 = "nw_duerogue001";break;}
                        case 2: {sBoss =  "nw_duemage001";             sLT = "nw_duecler001";      sPeon1 = "nw_duefight001"; sPeon2 = "nw_duerogue001";break;}
                        case 3: {sBoss =  "nw_duefight001";            sLT = "nw_duecler001";      sPeon1 = "nw_duefight001"; sPeon2 = "nw_duerogue001";break;}
                        case 4: {sBoss =  "nw_duerogue001";            sLT = "nw_duecler001";      sPeon1 = "nw_duefight001"; sPeon2 = "nw_duerogue001";break;}
                        }
                    break;
                    }
                case 15: // Drow Elves
                    {
                    switch(d4())
                        {
                        case 1: {sBoss =  "nw_drowcler001";             sPeon1 = "nw_drowfight001"; sPeon2 = "nw_drowrogue001";break;}
                        case 2: {sBoss =  "nw_drowmage001";             sPeon1 = "nw_drowfight001"; sPeon2 = "nw_drowrogue001";break;}
                        case 3: {sBoss =  "nw_drowfight001";            sPeon1 = "nw_drowfight001"; break;}
                        case 4: {sBoss =  "nw_drowrogue001";            sPeon1 = "nw_drowfight001"; sPeon2 = "nw_drowrogue001";break;}
                        }
                    break;
                    }
                case 16: {sBoss =  "x0_form_worker"; break;}
                }
            break;
            }
        };
    oMonster = CreateBoss(sBoss,lLoc,iPartyLevel,iWander);          // Create the first monster. This monster will be carrying the loot.
    fCR = IntToFloat(iPartyLevel) - GetChallengeRating(oMonster);        // Adjust the remaining CR left for other monsters.
    if (fCR > 0.00 && sLT != "")                               // Create a leutenant for the encounter.
        {
        oMonster = CreateBoss(sLT,lLoc,0,iWander);
        fCR -= GetChallengeRating(oMonster);
        }
    if (fCR > 0.00)                                            // Create Peons
        {
        if (sPeon1 == "")
            sPeon1 = sBoss;
        CreatePeons(sPeon1,lLoc,fCR,sPeon2,iWander);
        }
    }

object CreateBoss(string sResRef, location lLoc, int iCR, int iWander)
    {
    object oMonster = CreateObject(OBJECT_TYPE_CREATURE,sResRef,lLoc,FALSE,"Boss");
    if (iCR > 0)
        {
        if (iCR > 40)
            iCR = 40;
        if (iCR > 0)
            {
            AssignCommand(oMonster,GenerateLoot(oMonster,iCR));// Found an error that was causing this to spawn items on PCs if triggered by one.
            SetLocalInt(oMonster,"Boss",iCR);
            }
        }
    if (iWander)
        AssignCommand(oMonster,DelayCommand(6.0,Hunt()));
    return oMonster;
    }

void CreatePeons (string sPeon1, location lLoc, float fCCR, string sPeon2, int iWander)
    {
    int i,j,iNum;
    object oMonster = CreateObject(OBJECT_TYPE_CREATURE,sPeon1,lLoc);  // Create the first Peon
    float fCR = GetChallengeRating(oMonster); // Determine CR of the Peons
    if (fCR > 0.0)
        {
        if (fCR < 1.0)
            iNum = FloatToInt(fCCR/fCR);
        else if (fCR >= 1.0)
            {
            i = FloatToInt(fCCR/fCR);
            if (i < 1)
                i = 1;
            else if (i >= 6)
                i = 5; //CPU SAFETY CAP DO NOT CHANGE UNDER PAIN OF LAG!
            switch (i)
                {
                case 1: {iNum = 2;break;}
                case 2: {iNum = 4;break;}
                case 3: {iNum = 8;break;}
                case 4: {iNum = 16;break;}  // WARNING! MAY HICKUP!
                case 5: {iNum = 32; break;} // WARNING! MAY CAUSE LAG!
                case 6: {iNum = 64; break;} // WARNING WILL CAUSE LAG!
                case 7: {iNum = 128; break;} // THIS SHOULD COMPLETELY STOP YOUR SYSTEM FOR A FEW SECONDS!
                case 8: {iNum = 256; break;} // Forget it your hopeless.
                };
            }
       if (iNum > 0)
            {
            if (sPeon2 =="")    j = 1;
            else                j = 2;
            for (i = 1; i <= iNum; i+=j)
                {
                oMonster = CreateObject(OBJECT_TYPE_CREATURE,sPeon1,lLoc);
                if (iWander)
                    AssignCommand(oMonster,Hunt());
                if (j == 2)
                    {
                    oMonster = CreateObject(OBJECT_TYPE_CREATURE,sPeon2,lLoc);
                    if (iWander)
                        AssignCommand(oMonster,Hunt());
                    }
                }
            }
        }
    }

void Hunt()
    {
    ClearAllActions();
    ActionMoveToLocation(GetLocation(GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC)));
    }
