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

int Table824a1();
int Table824a2();
int Table824a3();
int Table824a4();
int Table824a5();
int Table824a6();
int Table824a7();
int Table824a8();
int Table824a9();
int Table824d1();
int Table824d2();
int Table824d3();
int Table824d4();
int Table824d5();
int Table824d6();
int Table824d7();
int Table824d8();
int Table824d9();
object Table821(int iType)
    {
    int iRoll,i,iArcane;
    string sResRef;
    if (d100() <= 70)
        iArcane = TRUE;
    if (iType == 1)
        {
        iRoll = d100();
        if      (iRoll <= 50 && iArcane)    {sResRef = "scroll" + Convert(Table824a1());}
        else if (iRoll <= 50)               {sResRef = "scroll" + Convert(Table824d1());}
        else if (iRoll <= 95 && iArcane)    {sResRef = "scroll" + Convert(Table824a2());}
        else if (iRoll <= 95)               {sResRef = "scroll" + Convert(Table824d2());}
        else if (iArcane)                   {sResRef = "scroll" + Convert(Table824a3());}
        else                                {sResRef = "scroll" + Convert(Table824d3());}
        }
    else if (iType == 2)
        {
        iRoll = d100();
        if (iRoll <= 5 && iArcane)          {sResRef = "scroll" + Convert(Table824a2());}
        else if (iRoll <= 5)                {sResRef = "scroll" + Convert(Table824d2());}
        else if (iRoll <= 65 && iArcane)    {sResRef = "scroll" + Convert(Table824a3());}
        else if (iRoll <= 65)               {sResRef = "scroll" + Convert(Table824d3());}
        else if (iRoll <= 95 && iArcane)    {sResRef = "scroll" + Convert(Table824a4());}
        else if (iRoll <= 95)               {sResRef = "scroll" + Convert(Table824d4());}
        else if (iArcane)                   {sResRef = "scroll" + Convert(Table824a5());}
        else                                {sResRef = "scroll" + Convert(Table824d5());}
        }
    else if (iType == 3)
        {
        iRoll = d100();
        if (iRoll <= 5 && iArcane)          {sResRef = "scroll" + Convert(Table824a4());}
        else if (iRoll <= 5)                {sResRef = "scroll" + Convert(Table824d4());}
        else if (iRoll <= 50 && iArcane)    {sResRef = "scroll" + Convert(Table824a5());}
        else if (iRoll <= 50)               {sResRef = "scroll" + Convert(Table824d5());}
        else if (iRoll <= 70 && iArcane)    {sResRef = "scroll" + Convert(Table824a6());}
        else if (iRoll <= 70)               {sResRef = "scroll" + Convert(Table824d6());}
        else if (iRoll <= 85 && iArcane)    {sResRef = "scroll" + Convert(Table824a7());}
        else if (iRoll <= 85)               {sResRef = "scroll" + Convert(Table824d7());}
        else if (iRoll <= 95 && iArcane)    {sResRef = "scroll" + Convert(Table824a8());}
        else if (iRoll <= 95)               {sResRef = "scroll" + Convert(Table824d8());}
        else if (iArcane)                   {sResRef = "scroll" + Convert(Table824a9());}
        else                                {sResRef = "scroll" + Convert(Table824d9());}
        }
    return CreateItemOnObject(sResRef);
    }

int Table824a1()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 5) {iResult = SPELL_BURNING_HANDS;}
    else if (iRoll <=10) {iResult = SPELL_ACID_SPLASH;}
    else if (iRoll <=15) {iResult = SPELL_CHARM_PERSON;}
    else if (iRoll <=18) {iResult = SPELL_COLOR_SPRAY;}
    else if (iRoll <=22) {iResult = SPELL_DAZE;}
    else if (iRoll <=25) {iResult = SPELL_ELECTRIC_JOLT;}
    else if (iRoll <=28) {iResult = SPELL_FLARE;}
    else if (iRoll <=31) {iResult = SPELL_LIGHT;}
    else if (iRoll <=36) {iResult = SPELL_RAY_OF_FROST;}
    else if (iRoll <=39) {iResult = SPELL_GREASE;}
    else if (iRoll <=44) {iResult = SPELL_IDENTIFY;}
    else if (iRoll <=47) {iResult = SPELL_RESISTANCE;}
    else if (iRoll <=51) {iResult = SPELL_MAGE_ARMOR;}
    else if (iRoll <=54) {iResult = SPELL_MAGIC_MISSILE;}
    else if (iRoll <=57) {iResult = SPELL_NEGATIVE_ENERGY_RAY;}
    else if (iRoll <=60) {iResult = SPELL_RAY_OF_ENFEEBLEMENT;}
    else if (iRoll <=63) {iResult = SPELL_PROTECTION_FROM_EVIL;}
    else if (iRoll <=66) {iResult = SPELL_SHIELD;}
    else if (iRoll <=69) {iResult = SPELL_SCARE;}
    else if (iRoll <=73) {iResult = SPELL_TRUE_STRIKE;}
    else if (iRoll <=78) {iResult = SPELL_SLEEP;}
    else if (iRoll <=81) {iResult = SPELL_EXPEDITIOUS_RETREAT;}
    else if (iRoll <=84) {iResult = SPELL_SUMMON_CREATURE_I;}
    else if (iRoll <=87) {iResult = SPELL_CURE_MINOR_WOUNDS;}
    else if (iRoll <=92) {iResult = SPELL_LESSER_DISPEL;}
    else if (iRoll <=95) {iResult = Table824a1();}
    else {iResult = Table824a1();} //Reroll
    return iResult;
    }

int Table824a2()
    {
    /*
    Bard spells not in this list:
    SPELL_CLARITY
    SPELL_CURE_MODERATE_WOUNDS
    SPELL_HOLD_PERSON
    SPELL_SILENCE
    SPELL_SOUND_BURST
    SPELL_GHOUL_TOUCH
    */
    int iResult;
    int iRoll = d100();
    if (iRoll <= 3) {iResult = SPELL_GHOSTLY_VISAGE;}
    else if (iRoll <= 8) {iResult = SPELL_BLINDNESS_AND_DEAFNESS;}
    else if (iRoll <=13) {iResult = SPELL_DARKNESS;}
    else if (iRoll <=18) {iResult = SPELL_BULLS_STRENGTH;}
    else if (iRoll <=22) {iResult = SPELL_CATS_GRACE;}
    else if (iRoll <=25) {iResult = SPELL_EAGLE_SPLEDOR;}
    else if (iRoll <=30) {iResult = SPELL_ENDURANCE;}
    else if (iRoll <=33) {iResult = SPELL_FOXS_CUNNING;}
    else if (iRoll <=38) {iResult = SPELL_INVISIBILITY;}
    else if (iRoll <=41) {iResult = SPELL_KNOCK;}
    else if (iRoll <=46) {iResult = SPELL_GHOSTLY_VISAGE;}
    else if (iRoll <=51) {iResult = SPELL_GHOUL_TOUCH;}
    else if (iRoll <=54) {iResult = SPELL_MELFS_ACID_ARROW;}
    else if (iRoll <=59) {iResult = SPELL_LESSER_DISPEL;}
    else if (iRoll <=64) {iResult = SPELL_OWLS_WISDOM;}
    else if (iRoll <=69) {iResult = SPELL_RESIST_ELEMENTS;}
    else if (iRoll <=72) {iResult = SPELL_TASHAS_HIDEOUS_LAUGHTER;}
    else if (iRoll <=77) {iResult = SPELL_SEE_INVISIBILITY;}
    else if (iRoll <=80) {iResult = SPELL_CONTINUAL_FLAME;}
    else if (iRoll <=83) {iResult = SPELL_STINKING_CLOUD;}
    else if (iRoll <=87) {iResult = SPELL_SUMMON_CREATURE_II;}
    else if (iRoll <=92) {iResult = SPELL_BALAGARNSIRONHORN;}
    else if (iRoll <=95) {iResult = SPELL_WEB;}
    else iResult = Table824a2(); //Reroll
    return iResult;
    }

int Table824a3()
    {
    /*
    Bard spells not in this list:
    SPELL_BESTOW_CURSE
    SPELL_CHARM_MONSTER
    SPELL_CONFUSION
    SPELL_CURE_SERIOUS_WOUNDS
    SPELL_FEAR
    SPELL_FIND_TRAPS
    SPELL_REMOVE_CURSE
    SPELL_REMOVE_DISEASE
    */
    int iResult;
    int iRoll = d100();
    if (iRoll <= 5) {iResult = SPELL_ANIMATE_DEAD;}
    else if (iRoll <=10) {iResult = SPELL_CLAIRAUDIENCE_AND_CLAIRVOYANCE;}
    else if (iRoll <=15) {iResult = SPELL_DISPEL_MAGIC;}
    else if (iRoll <=20) {iResult = SPELL_DISPLACEMENT;}
    else if (iRoll <=25) {iResult = SPELL_FIREBALL;}
    else if (iRoll <=28) {iResult = SPELL_FLAME_ARROW;}
    else if (iRoll <=31) {iResult = SPELL_CLARITY;}
    else if (iRoll <=33) {iResult = SPELL_FIND_TRAPS;}
    else if (iRoll <=36) {iResult = SPELL_NEGATIVE_ENERGY_BURST;}
    else if (iRoll <=39) {iResult = SPELL_PROTECTION_FROM_ELEMENTS;}
    else if (iRoll <=42) {iResult = SPELL_HASTE;}
    else if (iRoll <=45) {iResult = SPELL_HOLD_PERSON;}
    else if (iRoll <=47) {iResult = SPELL_INVISIBILITY_SPHERE;}
    else if (iRoll <=53) {iResult = SPELL_LIGHTNING_BOLT;}
    else if (iRoll <=57) {iResult = SPELL_MAGIC_CIRCLE_AGAINST_CHAOS;}// Actually works for all circle prot.
    else if (iRoll <=60) {iResult = SPELL_STINKING_CLOUD;}
    else if (iRoll <=65) {iResult = SPELL_SLOW;}
    else if (iRoll <=70) {iResult = SPELL_GUST_OF_WIND;}
    else if (iRoll <=75) {iResult = SPELL_DISPLACEMENT;}
    else if (iRoll <=79) {iResult = SPELL_SUMMON_CREATURE_III;}
    else if (iRoll <=84) {iResult = SPELL_WOUNDING_WHISPERS;}
    else if (iRoll <=87) {iResult = SPELL_VAMPIRIC_TOUCH;}
    else if (iRoll <=90) {iResult = Table824a3();} //Reroll
    else iResult = Table824a3(); //Reroll
    return iResult;
    }

int Table824a4()
    {
    /*
    Bard spells not in this list:
    SPELL_CURE_CRITICAL_WOUNDS
    SPELL_DISMISSAL
    SPELL_DOMINATE_PERSON
    SPELL_NEUTRALIZE_POISON
    */
    int iResult;
    int iRoll = d100();
    if (iRoll <= 5) {iResult = SPELL_CHARM_MONSTER;}
    else if (iRoll <=10) {iResult = SPELL_CONFUSION;}
    else if (iRoll <=15) {iResult = SPELL_CONTAGION;}
    else if (iRoll <=20) {iResult = SPELL_BESTOW_CURSE;}
    else if (iRoll <=23) {iResult = SPELL_LESSER_SPELL_BREACH;}
    else if (iRoll <=28) {iResult = SPELL_PHANTASMAL_KILLER;}
    else if (iRoll <=33) {iResult = SPELL_REMOVE_BLINDNESS_AND_DEAFNESS;}
    else if (iRoll <=36) {iResult = SPELL_ENERVATION;}
    else if (iRoll <=39) {iResult = SPELL_EVARDS_BLACK_TENTACLES;}
    else if (iRoll <=44) {iResult = SPELL_FEAR;}
    else if (iRoll <=47) {iResult = SPELL_ISAACS_LESSER_MISSILE_STORM;}
    else if (iRoll <=50) {iResult = SPELL_ICE_STORM;}
    else if (iRoll <=55) {iResult = SPELL_IMPROVED_INVISIBILITY;}
    else if (iRoll <=58) {iResult = SPELL_HOLD_MONSTER;}
    else if (iRoll <=61) {iResult = SPELL_MINOR_GLOBE_OF_INVULNERABILITY;}
    else if (iRoll <=67) {iResult = SPELL_PHANTASMAL_KILLER;}
    else if (iRoll <=70) {iResult = SPELL_LEGEND_LORE;}
    else if (iRoll <=73) {iResult = SPELL_POLYMORPH_SELF;}
    else if (iRoll <=76) {iResult = SPELL_REMOVE_CURSE;}
    else if (iRoll <=79) {iResult = SPELL_SHADOW_CONJURATION_DARKNESS;}// All shadow conjurations
    else if (iRoll <=82) {iResult = SPELL_STONESKIN;}
    else if (iRoll <=84) {iResult = SPELL_SUMMON_CREATURE_IV;}
    else if (iRoll <=87) {iResult = SPELL_WALL_OF_FIRE;}
    else if (iRoll <=90) {iResult = SPELL_WAR_CRY;}
    else iResult = Table824a4(); //Reroll
    return iResult;
    }

int Table824a5()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 4) {iResult = SPELL_BIGBYS_INTERPOSING_HAND;}
    else if (iRoll <=8) {iResult = SPELL_CLOUDKILL;}
    else if (iRoll <=13) {iResult = SPELL_CONE_OF_COLD;}
    else if (iRoll <=17) {iResult = SPELL_DISMISSAL;}
    else if (iRoll <=21) {iResult = SPELL_DOMINATE_PERSON;}
    else if (iRoll <=24) {iResult = SPELL_FEEBLEMIND;}
    else if (iRoll <=27) {iResult = SPELL_GREATER_SHADOW_CONJURATION_ACID_ARROW;} // All greater Shadow conjurations
    else if (iRoll <=31) {iResult = SPELL_HOLD_MONSTER;}
    else if (iRoll <=35) {iResult = SPELL_ELEMENTAL_SHIELD;}
    else if (iRoll <=40) {iResult = SPELL_MIND_FOG;}
    else if (iRoll <=44) {iResult = SPELL_ENERGY_BUFFER;}
    else if (iRoll <=49) {iResult = SPELL_LESSER_MIND_BLANK;}
    else if (iRoll <=53) {iResult = SPELL_LESSER_PLANAR_BINDING;}
    else if (iRoll <=56) {iResult = SPELL_LESSER_SPELL_MANTLE;}
    else if (iRoll <=60) {iResult = SPELL_SUMMON_CREATURE_V;}
    else if (iRoll <=64) {iResult = SPELL_FIREBRAND;}
    else if (iRoll <=69) {iResult = SPELL_ETHEREAL_VISAGE;}
    else if (iRoll <=73) {iResult = SPELL_GREATER_DISPELLING;}
    else if (iRoll <=77) {iResult = SPELL_HEALING_CIRCLE;}
    else if (iRoll <=81) {iResult = Table824a5();} //Reroll
    else if (iRoll <=86) {iResult = Table824a5();} //Reroll
    else if (iRoll <=90) {iResult = Table824a5();} //Reroll
    else iResult = Table824a5(); //Reroll
    return iResult;
    }

int Table824a6()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 4) {iResult = SPELL_ACID_FOG;}
    else if (iRoll <=7) {iResult = SPELL_ETHEREAL_VISAGE;}
    else if (iRoll <=11) {iResult = SPELL_GREATER_DISPELLING;}
    else if (iRoll <=15) {iResult = SPELL_BIGBYS_FORCEFUL_HAND;}
    else if (iRoll <=19) {iResult = SPELL_CHAIN_LIGHTNING;}
    else if (iRoll <=23) {iResult = SPELL_CIRCLE_OF_DEATH;}
    else if (iRoll <=26) {iResult = SPELL_GREATER_SPELL_BREACH;}
    else if (iRoll <=30) {iResult = SPELL_GREATER_STONESKIN;}
    else if (iRoll <=33) {iResult = SPELL_LEGEND_LORE;}
    else if (iRoll <=37) {iResult = SPELL_FLESH_TO_STONE;}
    else if (iRoll <=41) {iResult = SPELL_GLOBE_OF_INVULNERABILITY;}
    else if (iRoll <=45) {iResult = SPELL_MASS_HASTE;}
    else if (iRoll <=49) {iResult = SPELL_PLANAR_BINDING;}
    else if (iRoll <=52) {iResult = SPELL_TENSERS_TRANSFORMATION;}
    else if (iRoll <=57) {iResult = SPELL_ISAACS_GREATER_MISSILE_STORM;}
    else if (iRoll <=61) {iResult = SPELL_DIRGE;}
    else if (iRoll <=65) {iResult = SPELL_ENERGY_BUFFER;}
    else if (iRoll <=70) {iResult = SPELL_ICE_STORM;}
    else if (iRoll <=75) {iResult = Table824a6();} //Reroll
    else if (iRoll <=78) {iResult = SPELL_SHADES_CONE_OF_COLD;}   // All shades spells
    else if (iRoll <=82) {iResult = SPELL_STONE_TO_FLESH;}
    else if (iRoll <=86) {iResult = SPELL_SUMMON_CREATURE_VI;}
    else if (iRoll <=90) {iResult = SPELL_TRUE_SEEING;}
    else iResult = Table824a6(); //Reroll
    return iResult;
    }

int Table824a7()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 5) {iResult = SPELL_BIGBYS_GRASPING_HAND;}
    else if (iRoll <=10) {iResult = SPELL_CONTROL_UNDEAD;}
    else if (iRoll <=15) {iResult = SPELL_DELAYED_BLAST_FIREBALL;}
    else if (iRoll <=20) {iResult = SPELL_PROTECTION_FROM_SPELLS;}
    else if (iRoll <=25) {iResult = SPELL_FINGER_OF_DEATH;}
    else if (iRoll <=30) {iResult = SPELL_SHADOW_SHIELD;}
    else if (iRoll <=35) {iResult = SPELL_SPELL_MANTLE;}
    else if (iRoll <=40) {iResult = SPELL_BANISHMENT;}
    else if (iRoll <=45) {iResult = SPELL_MORDENKAINENS_SWORD;}
    else if (iRoll <=50) {iResult = SPELL_POWER_WORD_STUN;}
    else if (iRoll <=55) {iResult = SPELL_PRISMATIC_SPRAY;}
    else if (iRoll <=60) {iResult = Table824a7();} //Reroll
    else if (iRoll <=65) {iResult = Table824a7();} //Reroll
    else if (iRoll <=70) {iResult = Table824a7();} //Reroll
    else if (iRoll <=75) {iResult = SPELL_SUMMON_CREATURE_VII;}
    else if (iRoll <=80) {iResult = Table824a7();} //Reroll
    else if (iRoll <=85) {iResult = Table824a7();} //Reroll
    else if (iRoll <=90) {iResult = Table824a7();} //Reroll
    else iResult = Table824a7(); //Reroll
    return iResult;
    }

int Table824a8()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 3) {iResult = SPELL_CREATE_UNDEAD;}
    else if (iRoll <=8) {iResult = SPELL_BIGBYS_CLENCHED_FIST;}
    else if (iRoll <=13) {iResult = SPELL_GREATER_PLANAR_BINDING;}
    else if (iRoll <=18) {iResult = SPELL_MASS_BLINDNESS_AND_DEAFNESS;}
    else if (iRoll <=23) {iResult = SPELL_HORRID_WILTING;}
    else if (iRoll <=28) {iResult = SPELL_INCENDIARY_CLOUD;}
    else if (iRoll <=33) {iResult = SPELL_MASS_CHARM;}
    else if (iRoll <=38) {iResult = SPELL_MIND_BLANK;}
    else if (iRoll <=43) {iResult = SPELL_PREMONITION;}
    else if (iRoll <=48) {iResult = SPELL_ETHEREALNESS;} // Greater Sanctuary
    else if (iRoll <=53) {iResult = Table824a8();} //Reroll
    else if (iRoll <=58) {iResult = Table824a8();} //Reroll
    else if (iRoll <=63) {iResult = Table824a8();} //Reroll
    else if (iRoll <=68) {iResult = Table824a8();} //Reroll
    else if (iRoll <=73) {iResult = Table824a8();} //Reroll
    else if (iRoll <=78) {iResult = Table824a8();} //Reroll
    else if (iRoll <=83) {iResult = SPELL_SUMMON_CREATURE_VII;}
    else if (iRoll <=88) {iResult = SPELL_SUNBURST;}
    else if (iRoll <=90) {iResult = Table824a8();} //Reroll
    else iResult = Table824a8(); //Reroll
    return iResult;
    }

int Table824a9()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 7) {iResult = SPELL_BIGBYS_CRUSHING_HAND;}
    else if (iRoll <=14) {iResult = SPELL_ENERGY_DRAIN;}
    else if (iRoll <=21) {iResult = SPELL_DOMINATE_MONSTER;}
    else if (iRoll <=28) {iResult = SPELL_METEOR_SWARM;}
    else if (iRoll <=35) {iResult = SPELL_MORDENKAINENS_DISJUNCTION;}
    else if (iRoll <=49) {iResult = SPELL_GATE;}
    else if (iRoll <=56) {iResult = SPELL_SHAPECHANGE;}
    else if (iRoll <=63) {iResult = SPELL_SUMMON_CREATURE_IX;}
    else if (iRoll <=69) {iResult = SPELL_POWER_WORD_KILL;}
    else if (iRoll <=76) {iResult = SPELL_WAIL_OF_THE_BANSHEE;}
    else if (iRoll <=83) {iResult = SPELL_WEIRD;}
    else if (iRoll <=90) {iResult = SPELL_GREATER_SPELL_MANTLE;}
    else iResult = Table824a9(); //Reroll
    return iResult;
    }
/*




*/
int Table824d1()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 5) {iResult = SPELL_BLESS;}
    else if (iRoll <=10) {iResult = SPELL_PROTECTION_FROM_EVIL;}
    else if (iRoll <=14) {iResult = SPELL_REMOVE_FEAR;}
    else if (iRoll <=19) {iResult = SPELL_CURE_LIGHT_WOUNDS;}
    else if (iRoll <=22) {iResult = SPELL_SCARE;}
    else if (iRoll <=25) {iResult = SPELL_CURE_MINOR_WOUNDS;}
    else if (iRoll <=28) {iResult = SPELL_LIGHT;}
    else if (iRoll <=31) {iResult = SPELL_RESISTANCE;}
    else if (iRoll <=34) {iResult = SPELL_FIND_TRAPS;} // Supposed to be detect snares and and pits.
    else if (iRoll <=39) {iResult = SPELL_DOOM;}
    else if (iRoll <=44) {iResult = SPELL_ENTANGLE;}
    else if (iRoll <=49) {iResult = SPELL_VIRTUE;}
    else if (iRoll <=54) {iResult = SPELL_INFLICT_LIGHT_WOUNDS;}
    else if (iRoll <=59) {iResult = SPELL_MAGIC_FANG;}
    else if (iRoll <=64) {iResult = SPELL_CAMOFLAGE;}
    else if (iRoll <=67) {iResult = SPELL_MAGIC_FANG;}
    else if (iRoll <=70) {iResult = SPELL_ENDURE_ELEMENTS;}
    else if (iRoll <=73) {iResult = SPELL_DIVINE_FAVOR;}
    else if (iRoll <=77) {iResult = SPELL_SANCTUARY;}
    else if (iRoll <=82) {iResult = SPELL_ENTANGLE;}
    else if (iRoll <=86) {iResult = SPELL_SUMMON_CREATURE_I;}
    else if (iRoll <=90) {iResult = SPELL_SUMMON_CREATURE_I;}
    else iResult = Table824d1(); //Reroll
    return iResult;
    }
/*
Spells not in this table
SPELL_RESIST_ELEMENTS
SPELL_SOUND_BURST
SPELL_FLAME_LASH
SPELL_PROTECTION_FROM_ELEMENTS
SPELL_SLEEP
SPELL_ONE_WITH_THE_LAND
SPELL_AURAOFGLORY
SPELL_BLOOD_FRENZY
*/
int Table824d2()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 5) {iResult = SPELL_AID;}
    else if (iRoll <=10) {iResult = SPELL_DARKNESS;}
    else if (iRoll <=15) {iResult = SPELL_BARKSKIN;}
    else if (iRoll <=20) {iResult = SPELL_BULLS_STRENGTH;}
    else if (iRoll <=25) {iResult = SPELL_CHARM_PERSON_OR_ANIMAL;}
    else if (iRoll <=28) {iResult = SPELL_EAGLE_SPLEDOR;}
    else if (iRoll <=31) {iResult = SPELL_CURE_MODERATE_WOUNDS;}
    else if (iRoll <=36) {iResult = SPELL_ENDURANCE;}
    else if (iRoll <=39) {iResult = SPELL_FIND_TRAPS;}
    else if (iRoll <=42) {iResult = SPELL_FOXS_CUNNING;}
    else if (iRoll <=47) {iResult = SPELL_LESSER_DISPEL;}
    else if (iRoll <=50) {iResult = SPELL_HOLD_ANIMAL;}
    else if (iRoll <=55) {iResult = SPELL_HOLD_PERSON;}
    else if (iRoll <=58) {iResult = SPELL_INFLICT_MODERATE_WOUNDS;}
    else if (iRoll <=63) {iResult = SPELL_LESSER_RESTORATION;}
    else if (iRoll <=67) {iResult = SPELL_SILENCE;}
    else if (iRoll <=70) {iResult = SPELL_NEGATIVE_ENERGY_RAY;}
    else if (iRoll <=75) {iResult = SPELL_OWLS_WISDOM;}
    else if (iRoll <=79) {iResult = SPELL_SUMMON_CREATURE_II;}
    else if (iRoll <=83) {iResult = SPELL_SUMMON_CREATURE_II;}
    else if (iRoll <=85) {iResult = SPELL_REMOVE_PARALYSIS;}
    else if (iRoll <=90) {iResult = SPELL_SILENCE;}
    else iResult = Table824d2(); //Reroll
    return iResult;
    }
/*
Spells not in this list
SPELL_CURE_MODERATE_WOUNDS
SPELL_POISON
*/
int Table824d3()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 2) {iResult = SPELL_CALL_LIGHTNING;}
    else if (iRoll <=9) {iResult = SPELL_CURE_SERIOUS_WOUNDS;}
    else if (iRoll <=13) {iResult = SPELL_DISPEL_MAGIC;}
    else if (iRoll <=15) {iResult = SPELL_DOMINATE_ANIMAL;}
    else if (iRoll <=17) {iResult = SPELL_GREATER_MAGIC_FANG;}
    else if (iRoll <=19) {iResult = SPELL_INFLICT_SERIOUS_WOUNDS;}
    else if (iRoll <=22) {iResult = SPELL_INVISIBILITY_PURGE;}
    else if (iRoll <=26) {iResult = SPELL_ANIMATE_DEAD;}
    else if (iRoll <=28) {iResult = SPELL_MAGIC_CIRCLE_AGAINST_CHAOS;}
    else if (iRoll <=30) {iResult = SPELL_MAGIC_CIRCLE_AGAINST_EVIL;}
    else if (iRoll <=32) {iResult = SPELL_MAGIC_CIRCLE_AGAINST_GOOD;}
    else if (iRoll <=34) {iResult = SPELL_MAGIC_CIRCLE_AGAINST_LAW;}
    else if (iRoll <=38) {iResult = SPELL_NEGATIVE_ENERGY_PROTECTION;}
    else if (iRoll <=41) {iResult = SPELL_NEUTRALIZE_POISON;}
    else if (iRoll <=43) {iResult = SPELL_BESTOW_CURSE;}
    else if (iRoll <=46) {iResult = SPELL_PRAYER;}
    else if (iRoll <=51) {iResult = SPELL_PROTECTION_FROM_ELEMENTS;}
    else if (iRoll <=53) {iResult = SPELL_REMOVE_BLINDNESS_AND_DEAFNESS;}
    else if (iRoll <=56) {iResult = SPELL_REMOVE_CURSE;}
    else if (iRoll <=59) {iResult = SPELL_REMOVE_DISEASE;}
    else if (iRoll <=62) {iResult = SPELL_SEARING_LIGHT;}
    else if (iRoll <=65) {iResult = SPELL_BLINDNESS_AND_DEAFNESS;}
    else if (iRoll <=67) {iResult = SPELL_SPIKE_GROWTH;}
    else if (iRoll <=72) {iResult = SPELL_CLARITY;}
    else if (iRoll <=75) {iResult = SPELL_SUMMON_CREATURE_III;}
    else if (iRoll <=78) {iResult = SPELL_SUMMON_CREATURE_III;}
    else if (iRoll <=80) {iResult = SPELL_CONTAGION;}
    else if (iRoll <=90) {iResult = SPELL_CONTINUAL_FLAME;}
    else iResult = Table824d3(); //Reroll
    return iResult;
    }
/*
Spells not in this table

*/
int Table824d4()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 2) {iResult = SPELL_DEATH_WARD;}
    else if (iRoll <=5) {iResult = SPELL_DISMISSAL;}
    else if (iRoll <=12) {iResult = SPELL_CURE_CRITICAL_WOUNDS;}
    else if (iRoll <=19) {iResult = SPELL_POISON;}
    else if (iRoll <=24) {iResult = SPELL_DISPEL_MAGIC;}
    else if (iRoll <=27) {iResult = SPELL_DIVINE_POWER;}
    else if (iRoll <=34) {iResult = SPELL_FLAME_STRIKE;}
    else if (iRoll <=41) {iResult = SPELL_FREEDOM_OF_MOVEMENT;}
    else if (iRoll <=47) {iResult = SPELL_MASS_CAMOFLAGE;}
    else if (iRoll <=50) {iResult = SPELL_HAMMER_OF_THE_GODS;}
    else if (iRoll <=53) {iResult = SPELL_INFLICT_CRITICAL_WOUNDS;}
    else if (iRoll <=55) {iResult = SPELL_HOLD_MONSTER;}
    else if (iRoll <=62) {iResult = SPELL_NEUTRALIZE_POISON;}
    else if (iRoll <=66) {iResult = SPELL_STONESKIN;}
    else if (iRoll <=68) {iResult = SPELL_RESTORATION;}
    else if (iRoll <=71) {iResult = SPELL_POLYMORPH_SELF;}
    else if (iRoll <=74) {iResult = SPELL_CURE_SERIOUS_WOUNDS;}
    else if (iRoll <=76) {iResult = Table824d4();} //Reroll
    else if (iRoll <=80) {iResult = SPELL_SUMMON_CREATURE_IV;}
    else if (iRoll <=82) {iResult = SPELL_SUMMON_CREATURE_IV;}
    else if (iRoll <=90) {iResult = Table824d4();} //Reroll
    else iResult = Table824d4(); //Reroll
    return iResult;
    }
/*
Spells not in this list
SPELL_SUMMON_SHADOW  //Unable to make a scroll of this spell

*/
int Table824d5()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 7) {iResult = SPELL_AWAKEN;}
    else if (iRoll <=13) {iResult = SPELL_DEATH_WARD;}
    else if (iRoll <=15) {iResult = SPELL_SPELL_RESISTANCE;}
    else if (iRoll <=22) {iResult = SPELL_CURE_CRITICAL_WOUNDS;}
    else if (iRoll <=26) {iResult = SPELL_CIRCLE_OF_DOOM;}
    else if (iRoll <=29) {iResult = SPELL_INFERNO;}
    else if (iRoll <=35) {iResult = SPELL_FLAME_STRIKE;}
    else if (iRoll <=38) {iResult = SPELL_GREATER_OWLS_WISDOM;}
    else if (iRoll <=40) {iResult = Table824d5();} //Reroll
    else if (iRoll <=43) {iResult = SPELL_HEALING_CIRCLE;}
    else if (iRoll <=45) {iResult = SPELL_ICE_STORM;}
    else if (iRoll <=50) {iResult = Table824d5();} //Reroll
    else if (iRoll <=57) {iResult = SPELL_RAISE_DEAD;}
    else if (iRoll <=60) {iResult = Table824d5();} //Reroll
    else if (iRoll <=63) {iResult = SPELL_SLAY_LIVING;}
    else if (iRoll <=65) {iResult = SPELL_SPELL_RESISTANCE;}
    else if (iRoll <=67) {iResult = SPELL_SUMMON_CREATURE_V;}
    else if (iRoll <=69) {iResult = SPELL_SUMMON_CREATURE_V;}
    else if (iRoll <=72) {iResult = Table824d5();} //Reroll
    else if (iRoll <=74) {iResult = SPELL_TRUE_SEEING;}
    else if (iRoll <=75) {iResult = Table824d5();} //Reroll
    else if (iRoll <=78) {iResult = SPELL_WALL_OF_FIRE;}
    else if (iRoll <=80) {iResult = Table824d5();} //Reroll
    else if (iRoll <=90) {iResult = Table824d5();} //Reroll
    else iResult = Table824d5(); //Reroll
    return iResult;
    }

int Table824d6()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 8) {iResult = SPELL_CREATE_UNDEAD;}
    else if (iRoll <=14) {iResult = SPELL_BLADE_BARRIER;}
    else if (iRoll <=19) {iResult = SPELL_GREATER_DISPELLING;}
    else if (iRoll <=23) {iResult = SPELL_ENERGY_BUFFER;}
    else if (iRoll <=28) {iResult = SPELL_GREATER_STONESKIN;}
    else if (iRoll <=34) {iResult = SPELL_HARM;}
    else if (iRoll <=41) {iResult = SPELL_HEAL;}
    else if (iRoll <=47) {iResult = SPELL_HEALING_CIRCLE;}
    else if (iRoll <=55) {iResult = SPELL_PLANAR_ALLY;}
    else if (iRoll <=57) {iResult = SPELL_REGENERATE;}
    else if (iRoll <=60) {iResult = SPELL_BANISHMENT;}
    else if (iRoll <=68) {iResult = SPELL_SUMMON_CREATURE_VI;}
    else if (iRoll <=71) {iResult = SPELL_ETHEREALNESS;}
    else if (iRoll <=77) {iResult = SPELL_DROWN;}
    else if (iRoll <=80) {iResult = Table824d6();} //Reroll
    else if (iRoll <=90) {iResult = Table824d6();} //Reroll
    else iResult = Table824d6(); //Reroll
    return iResult;
    }

int Table824d7()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 11) {iResult = 0;}
    else if (iRoll <=18) {iResult = SPELL_CREEPING_DOOM;}
    else if (iRoll <=25) {iResult = SPELL_DESTRUCTION;}
    else if (iRoll <=32) {iResult = SPELL_WORD_OF_FAITH;}
    else if (iRoll <=36) {iResult = SPELL_FIRE_STORM;}
    else if (iRoll <=40) {iResult = SPELL_GREATER_RESTORATION;}
    else if (iRoll <=47) {iResult = SPELL_AURA_OF_VITALITY;}
    else if (iRoll <=54) {iResult = SPELL_REGENERATE;}
    else if (iRoll <=61) {iResult = SPELL_FIRE_STORM;}
    else if (iRoll <=68) {iResult = SPELL_RESURRECTION;}
    else if (iRoll <=72) {iResult = SPELL_SUMMON_CREATURE_VII;}
    else if (iRoll <=76) {iResult = SPELL_HARM;}
    else if (iRoll <=80) {iResult = SPELL_TRUE_SEEING;}
    else if (iRoll <=90) {iResult = SPELL_HEAL;}
    else iResult = Table824d7(); //Reroll
    return iResult;
    }
/*
Aura vs Alignment was unable to find this spell....
*/
int Table824d8()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 6) {iResult = SPELL_CREATE_GREATER_UNDEAD;}
    else if (iRoll <=12) {iResult = SPELL_CREEPING_DOOM;}
    else if (iRoll <=18) {iResult = SPELL_SUNBEAM;}
    else if (iRoll <=25) {iResult = SPELL_EARTHQUAKE;}
    else if (iRoll <=30) {iResult = SPELL_FINGER_OF_DEATH;}
    else if (iRoll <=35) {iResult = SPELL_FIRE_STORM;}
    else if (iRoll <=44) {iResult = SPELL_HOLY_AURA;}
    else if (iRoll <=50) {iResult = SPELL_MASS_HEAL;}
    else if (iRoll <=56) {iResult = SPELL_NATURES_BALANCE;}
    else if (iRoll <=62) {iResult = SPELL_PREMONITION;}
    else if (iRoll <=68) {iResult = SPELL_SUMMON_CREATURE_VIII;}
    else if (iRoll <=74) {iResult = SPELL_SUNBURST;}
    else if (iRoll <=80) {iResult = SPELL_UNHOLY_AURA;}
    else if (iRoll <=90) {iResult = SPELL_BOMBARDMENT;}
    else iResult = Table824d8(); //Reroll
    return iResult;
    }
/*
Spells not in this list
SPELL_MASS_HEAL
SPELL_UNDEATHS_ETERNAL_FOE
*/
int Table824d9()
    {
    int iResult;
    int iRoll = d100();
    if (iRoll <= 7) {iResult = SPELL_EARTHQUAKE;}
    else if (iRoll <=14) {iResult = SPELL_ELEMENTAL_SWARM;}
    else if (iRoll <=26) {iResult = SPELL_ENERGY_DRAIN;}
    else if (iRoll <=38) {iResult = SPELL_IMPLOSION;}
    else if (iRoll <=50) {iResult = SPELL_GATE;}
    else if (iRoll <=57) {iResult = SPELL_SHAPECHANGE;}
    else if (iRoll <=68) {iResult = SPELL_STORM_OF_VENGEANCE;}
    else if (iRoll <=80) {iResult = SPELL_SUMMON_CREATURE_IX;}
    else if (iRoll <=90) {iResult = SPELL_RESURRECTION;}
    else iResult = Table824d9(); //Reroll
    return iResult;
    }
