#include "inc_misc_tools"
// Randomly Generates Scroll IDs for ResRefs
// iType 1 = Minor Wand
// iType 2 = Medium Wand
// iType 3 = Major Wand
// No other value will work.
object Table827(int iType);

int Table827a();
int Table827b();
int Table827c();

object Table827(int iType)
    {
    int iRoll,i,iArcane;
    string sResRef;
    if (d100() <= 1)
        iArcane = TRUE;
    if (iType == 1)
        i = Table827a();
    else if (iType == 2)
        i = Table827b();
    else if (iType == 3)
        i = Table827c();
    if (i < 1000)
        sResRef = "wand" + Convert(i);
    else
        sResRef = "wand" + IntToString(i);
    return CreateItemOnObject(sResRef);
    }

int Table827a()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 5) {iResult = Table827a();}        //Reroll
    else if (iRoll <=10) {iResult = SPELL_LIGHT;}
    else if (iRoll <=15) {iResult = Table827a();}   //Reroll
    else if (iRoll <=20) {iResult = SPELL_COLOR_SPRAY;}
    else if (iRoll <=25) {iResult = SPELL_BURNING_HANDS;}
    else if (iRoll <=30) {iResult = SPELL_CHARM_PERSON;}
    else if (iRoll <=35) {iResult = Table827a();}   //Reroll
    else if (iRoll <=40) {iResult = SPELL_MAGIC_MISSILE;}
    else if (iRoll <=45) {iResult = Table827a();}   //Reroll
    else if (iRoll <=50) {iResult = SPELL_SUMMON_CREATURE_I;}
    else if (iRoll <=55) {iResult = SPELL_CURE_LIGHT_WOUNDS;}
    else if (iRoll <=58) {iResult = 2000 + SPELL_MAGIC_MISSILE;}
    else if (iRoll <=59) {iResult = 3000 + SPELL_MAGIC_MISSILE;}
    else if (iRoll <=63) {iResult = Table827a();}   //Reroll
    else if (iRoll <=66) {iResult = SPELL_SUMMON_CREATURE_II;}
    else if (iRoll <=69) {iResult = SPELL_SILENCE;}
    else if (iRoll <=72) {iResult = SPELL_KNOCK;}
    else if (iRoll <=75) {iResult = Table827a();}   //Reroll
    else if (iRoll <=78) {iResult = SPELL_INVISIBILITY;}
    else if (iRoll <=81) {iResult = Table827a();}   //Reroll
    else if (iRoll <=84) {iResult = SPELL_BULLS_STRENGTH;}
    else if (iRoll <=87) {iResult = Table827a();}   //Reroll
    else if (iRoll <=90) {iResult = SPELL_GHOUL_TOUCH;}
    else if (iRoll <=93) {iResult = SPELL_CURE_MODERATE_WOUNDS;}
    else if (iRoll <=96) {iResult = SPELL_HOLD_PERSON;}
    else if (iRoll <=98) {iResult = SPELL_MELFS_ACID_ARROW;}
    else if (iRoll <=99) {iResult = SPELL_WEB;}
    else {iResult = SPELL_DARKNESS;}
    return iResult;
    }

int Table827b()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <=3)       {iResult = SPELL_CHARM_PERSON;}
    else if (iRoll <=6)  {iResult = Table827b();}   //Reroll
    else if (iRoll <=9) {iResult = SPELL_MAGIC_MISSILE;}
    else if (iRoll <=12) {iResult = Table827b();}   //Reroll
    else if (iRoll <=15) {iResult = SPELL_SUMMON_CREATURE_I;}
    else if (iRoll <=18) {iResult = SPELL_CURE_LIGHT_WOUNDS;}
    else if (iRoll <=21) {iResult = 2000 + SPELL_MAGIC_MISSILE;}
    else if (iRoll <=23) {iResult = 3000 + SPELL_MAGIC_MISSILE;}
    else if (iRoll <=26) {iResult = Table827b();}   //Reroll
    else if (iRoll <=29) {iResult = SPELL_SUMMON_CREATURE_II;}
    else if (iRoll <=32) {iResult = SPELL_SILENCE;}
    else if (iRoll <=35) {iResult = SPELL_KNOCK;}
    else if (iRoll <=38) {iResult = Table827b();}   //Reroll
    else if (iRoll <=41) {iResult = SPELL_INVISIBILITY;}
    else if (iRoll <=44) {iResult = Table827b();}   //Reroll
    else if (iRoll <=48) {iResult = SPELL_BULLS_STRENGTH;}
    else if (iRoll <=50) {iResult = Table827b();}   //Reroll
    else if (iRoll <=53) {iResult = SPELL_GHOUL_TOUCH;}
    else if (iRoll <=60) {iResult = SPELL_CURE_MODERATE_WOUNDS;}
    else if (iRoll <=63) {iResult = SPELL_HOLD_PERSON;}
    else if (iRoll <=66) {iResult = SPELL_MELFS_ACID_ARROW;}
    else if (iRoll <=69) {iResult = SPELL_WEB;}
    else if (iRoll <=71) {iResult = SPELL_DARKNESS;}
    else if (iRoll <=72) {iResult = 4000 + SPELL_MAGIC_MISSILE;}
    else if (iRoll <=75) {iResult = SPELL_FIREBALL;}
    else if (iRoll <=80) {iResult = SPELL_LIGHTNING_BOLT;}
    else if (iRoll <=82) {iResult = SPELL_SUMMON_CREATURE_III;}
    else if (iRoll <=84) {iResult = Table827b();}   //Reroll
    else if (iRoll <=86) {iResult = Table827b();}   //Reroll
    else if (iRoll <=88) {iResult = SPELL_SLOW;}
    else if (iRoll <=90) {iResult = Table827b();}   //Reroll
    else if (iRoll <=92) {iResult = SPELL_DISPEL_MAGIC;}
    else if (iRoll <=94) {iResult = SPELL_CURE_SERIOUS_WOUNDS;}
    else if (iRoll <=95) {iResult = SPELL_CONTAGION;}
    else if (iRoll <=96) {iResult = 2000+SPELL_CHARM_PERSON;}
    else if (iRoll <=97) {iResult = 2000+SPELL_FIREBALL;}
    else if (iRoll <=99) {iResult = SPELL_SEARING_LIGHT;}
    else iResult = 2000+SPELL_LIGHTNING_BOLT;
    return iResult;
    }

int Table827c()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <=02) {iResult = 3000 + SPELL_MAGIC_MISSILE;}
    else if (iRoll <=3) {iResult = Table827b();}   //Reroll
    else if (iRoll <=4) {iResult = SPELL_SUMMON_CREATURE_II;}
    else if (iRoll <=5) {iResult = SPELL_SILENCE;}
    else if (iRoll <=6) {iResult = SPELL_KNOCK;}
    else if (iRoll <=7) {iResult = Table827b();}   //Reroll
    else if (iRoll <=10) {iResult = SPELL_INVISIBILITY;}
    else if (iRoll <=12) {iResult = Table827b();}   //Reroll
    else if (iRoll <=15) {iResult = SPELL_BULLS_STRENGTH;}
    else if (iRoll <=17) {iResult = Table827b();}   //Reroll
    else if (iRoll <=19) {iResult = SPELL_GHOUL_TOUCH;}
    else if (iRoll <=21) {iResult = SPELL_CURE_MODERATE_WOUNDS;}
    else if (iRoll <=23) {iResult = SPELL_HOLD_PERSON;}
    else if (iRoll <=25) {iResult = SPELL_MELFS_ACID_ARROW;}
    else if (iRoll <=27) {iResult = SPELL_WEB;}
    else if (iRoll <=30) {iResult = SPELL_DARKNESS;}
    else if (iRoll <=33) {iResult = 4000 + SPELL_MAGIC_MISSILE;}
    else if (iRoll <=36) {iResult = 5000 + SPELL_MAGIC_MISSILE;}
    else if (iRoll <=39) {iResult = SPELL_FIREBALL;}
    else if (iRoll <=41) {iResult = SPELL_LIGHTNING_BOLT;}
    else if (iRoll <=43) {iResult = SPELL_SUMMON_CREATURE_III;}
    else if (iRoll <=45) {iResult = Table827b();}   //Reroll
    else if (iRoll <=47) {iResult = Table827b();}   //Reroll
    else if (iRoll <=49) {iResult = SPELL_SLOW;}
    else if (iRoll <=51) {iResult = Table827b();}   //Reroll
    else if (iRoll <=53) {iResult = SPELL_DISPEL_MAGIC;}
    else if (iRoll <=55) {iResult = SPELL_CURE_SERIOUS_WOUNDS;}
    else if (iRoll <=57) {iResult = SPELL_CONTAGION;}
    else if (iRoll <=58) {iResult = 2000+SPELL_CHARM_PERSON;}
    else if (iRoll <=59) {iResult = 2000+SPELL_FIREBALL;}
    else if (iRoll <=61) {iResult = SPELL_SEARING_LIGHT;}
    else if (iRoll <=63) {iResult = 2000+SPELL_LIGHTNING_BOLT;}

    else if (iRoll <=65) {iResult = 3000+SPELL_FIREBALL;}
    else if (iRoll <=67) {iResult = 3000+SPELL_LIGHTNING_BOLT;}
    else if (iRoll <=69) {iResult = SPELL_CHARM_MONSTER;}
    else if (iRoll <=71) {iResult = SPELL_FEAR;}
    else if (iRoll <=73) {iResult = SPELL_IMPROVED_INVISIBILITY;}
    else if (iRoll <=75) {iResult = SPELL_POLYMORPH_SELF;}
    else if (iRoll <=77) {iResult = Table827b();}   //Reroll
    else if (iRoll <=79) {iResult = SPELL_ICE_STORM;}
    else if (iRoll <=81) {iResult = SPELL_SUMMON_CREATURE_IV;}
    else if (iRoll <=83) {iResult = Table827b();}   //Reroll
    else if (iRoll <=84) {iResult = SPELL_WALL_OF_FIRE;}
    else if (iRoll <=85) {iResult = SPELL_RAY_OF_ENFEEBLEMENT;}

    else if (iRoll <=86) {iResult = SPELL_POISON;}
    else if (iRoll <=87) {iResult = Table827b();}   //Reroll
    else if (iRoll <=89) {iResult = SPELL_NEUTRALIZE_POISON;}
    else if (iRoll <=90) {iResult = SPELL_INFLICT_CRITICAL_WOUNDS;}
    else if (iRoll <=92) {iResult = SPELL_CURE_CRITICAL_WOUNDS;}
    else if (iRoll <=93) {iResult = SPELL_RESTORATION;}
    else if (iRoll <=94) {iResult = 4000+SPELL_FIREBALL;}
    else if (iRoll <=95) {iResult = 4000+SPELL_LIGHTNING_BOLT;}
    else if (iRoll <=96) {iResult = Table827b();}   //Reroll
    else if (iRoll <=97) {iResult = Table827b();}   //Reroll
    else if (iRoll <=98) {iResult = Table827b();}   //Reroll
    else if (iRoll <=99) {iResult = Table827b();}   //Reroll
    else iResult = SPELL_STONESKIN;
    return iResult;
    }
