#include "prc_x2_itemprop"
object RandomizeArmorColor(object oArmor);
// Returns a randomized appearance suit of armor.
object RandomizeArmor(object oArmor);
// Random Armor Type Table
object Table84();
// Random Shield Type Table
object Table85();
//Minor Armor and Shields Table
object Table83a(int iSpecial = 0, object oArmor =OBJECT_INVALID,int iEnc = 0);
//Medium Armor and Shields Table
object Table83b(int iSpecial = 0, object oArmor =OBJECT_INVALID,int iEnc = 0);
//Major Armor and Shields Table
object Table83c(int iSpecial = 0, object oArmor =OBJECT_INVALID,int iEnc = 0);

int Table86a(int iSpecial, object oArmor, int iEnc);
int Table87a(int iSpecial, object oArmor, int iEnc);
int Table86b(int iSpecial, object oArmor, int iEnc);
int Table87b(int iSpecial, object oArmor, int iEnc);
int Table86c(int iSpecial, object oArmor, int iEnc);
int Table87c(int iSpecial, object oArmor, int iEnc);

object Table88b();
object Table88c();

object Table89b();
object Table89c();

object Table83a(int iSpecial, object oArmor, int iEnc)
    {
    int iRoll = d100();
    string sString;
    object oArmor;
    int iSpecial, iType;
    if (iRoll <= 60) {iEnc += 1;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(1));}
    else if (iRoll <= 80){iEnc += 1;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(1));}
    else if (iRoll <= 85){iEnc += 2;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(2));}
    else if (iRoll <= 87){iEnc += 2;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(2));}
    else
        {
        oArmor = Table83a(iSpecial+=1,oArmor,iEnc);
        iSpecial = 0;// Reset varible to zero as special properties were set in the subfunction.
        }
    if (iSpecial)
        {
        iType = GetBaseItemType(oArmor);
        if (iType == BASE_ITEM_LARGESHIELD
         || iType == BASE_ITEM_SMALLSHIELD
         || iType == BASE_ITEM_TOWERSHIELD)
            iEnc = Table87a(iSpecial,oArmor,iEnc);
        else
            iEnc = Table86a(iSpecial,oArmor,iEnc);
        }
    SetLocalInt(oArmor,"Enc",iEnc);
    SetLocalInt(oArmor,"MW",TRUE);
    return oArmor;
    }

object Table83b(int iSpecial,object oArmor, int iEnc)
    {
    int iRoll = d100();
    string sString;
    int iSpecial, iType;
    if (iRoll <= 5)         {iEnc += 1;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(1));}
    else if (iRoll <= 10)   {iEnc += 1;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(1));}
    else if (iRoll <= 20)   {iEnc += 2;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(2));}
    else if (iRoll <= 30)   {iEnc += 2;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(2));}
    else if (iRoll <= 40)   {iEnc += 3;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(3));}
    else if (iRoll <= 50)   {iEnc += 3;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(3));}
    else if (iRoll <= 55)   {iEnc += 4;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(4));}
    else if (iRoll <= 57)   {iEnc += 4;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(4));}
    else if (iRoll <= 88)   {oArmor = Table88b();iSpecial = 0;}
    else if (iRoll <= 89)   {oArmor = Table89b();iSpecial = 0;}
    else
        {
        oArmor = Table83b(iSpecial+=1,oArmor,iEnc);
        iSpecial = 0;
        }
    if (iSpecial)
        {
        iType = GetBaseItemType(oArmor);
        if (iType == BASE_ITEM_LARGESHIELD
         || iType == BASE_ITEM_SMALLSHIELD
         || iType == BASE_ITEM_TOWERSHIELD)
            iEnc = Table87b(iSpecial,oArmor,iEnc);
        else
            iEnc = Table86b(iSpecial,oArmor,iEnc);
        }
    SetLocalInt(oArmor,"Enc",iEnc);
    SetLocalInt(oArmor,"MW",TRUE);
    return oArmor;
    }

object Table83c(int iSpecial, object oArmor, int iEnc)
    {
    int iRoll = d100();
    string sString;
    int iSpecial, iType;
    if (iRoll <= 8)         {iEnc += 3;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(3));}
    else if (iRoll <= 16)   {iEnc += 3;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(3));}
    else if (iRoll <= 27)   {iEnc += 4;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(4));}
    else if (iRoll <= 38)   {iEnc += 4;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(4));}
    else if (iRoll <= 49)   {iEnc += 5;IPSafeAddItemProperty(oArmor = Table85(),ItemPropertyACBonus(5));}
    else if (iRoll <= 57)   {iEnc += 5;IPSafeAddItemProperty(oArmor = Table84(),ItemPropertyACBonus(5));}
    else if (iRoll <= 60)   {oArmor = Table88c();iSpecial = 0;}
    else if (iRoll <= 63)   {oArmor = Table89c();iSpecial = 0;}
    else
        {
        oArmor = Table83c(iSpecial+=1,oArmor,iEnc);
        iSpecial = 0;
        }
    if (iSpecial)
        {
        iType = GetBaseItemType(oArmor);
        if (iType == BASE_ITEM_LARGESHIELD
         || iType == BASE_ITEM_SMALLSHIELD
         || iType == BASE_ITEM_TOWERSHIELD)
            iEnc = Table87c(iSpecial,oArmor,iEnc);
        else
            iEnc = Table86c(iSpecial,oArmor,iEnc);
        }
    SetLocalInt(oArmor,"Enc",iEnc);
    SetLocalInt(oArmor,"MW",TRUE);
    return oArmor;
    }

object Table84()
    {
    int iRoll = d100();
    string sString;
    object oArmor;
    if (iRoll <= 1)       sString = "nw_aarcl009";
    else if (iRoll <= 2)  sString = "nw_aarcl001";
    else if (iRoll <= 12) sString = "nw_aarcl008";
    else if (iRoll <= 27) sString = "nw_aarcl002";
    else if (iRoll <= 42) sString = "nw_aarcl012";
    else if (iRoll <= 43) sString = "nw_aarcl003";
    else if (iRoll <= 44) sString = "nw_aarcl004";
    else if (iRoll <= 57) sString = "nw_aarcl010";
    else if (iRoll <= 58) sString = "nw_aarcl005";
    else if (iRoll <= 59) sString = "nw_aarcl011";
    else if (iRoll <= 60) sString = "nw_aarcl006";
    else sString = "nw_aarcl007";
    oArmor = CreateItemOnObject(sString);
    oArmor = RandomizeArmor(oArmor);
    return oArmor;
    }

object Table85()
    {
    int iRoll = d100();
    string sString;
    if (iRoll <= 20) sString = "nw_ashsw001";
    else if (iRoll <= 95) sString = "nw_ashlw001";
    else sString = "nw_ashto001";
    object oItem = CreateItemOnObject(sString);
    SetLocalInt(oItem,"BaseValue",GetGoldPieceValue(oItem));
    return oItem;
    }

int Table86a(int iSpecial, object oArmor, int iEnc)
    {
    int i,iRoll,iTemp;
    for (i = 1; i<= iSpecial; i+=1)
        {
        iRoll = d100();
        if (iRoll <= 30)
            {
            iEnc += 1;
            switch(Random(7)+1)
                {
                case 1: {iTemp = IP_CONST_LIGHTCOLOR_BLUE;break;}
                case 2: {iTemp = IP_CONST_LIGHTCOLOR_GREEN;break;}
                case 3: {iTemp = IP_CONST_LIGHTCOLOR_ORANGE;break;}
                case 4: {iTemp = IP_CONST_LIGHTCOLOR_PURPLE;break;}
                case 5: {iTemp = IP_CONST_LIGHTCOLOR_RED;break;}
                case 6: {iTemp = IP_CONST_LIGHTCOLOR_WHITE;break;}
                case 7: {iTemp = IP_CONST_LIGHTCOLOR_YELLOW;break;}
                };
            IPSafeAddItemProperty(oArmor,ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_BRIGHT,iTemp));
            }
        else if (iRoll <= 52)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_TUMBLE,10));
            }
        else if (iRoll <= 74)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_HIDE,10));
            }
        else if (iRoll <= 96)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_MOVE_SILENTLY,10));
            }
        else if (iRoll <= 98)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
            }
        else
            iSpecial += 2;
        }
    return iEnc;
    }

int Table86b(int iSpecial, object oArmor, int iEnc)
    {
    int i,iRoll,iTemp;
    for (i = 1; i<= iSpecial; i+=1)
        {
        iRoll = d100();
        if (iRoll <= 2)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB));
            }
        else if (iRoll <= 7)
            {
            iEnc += 1;
            switch(Random(7)+1)
                {
                case 1: {iTemp = IP_CONST_LIGHTCOLOR_BLUE;break;}
                case 2: {iTemp = IP_CONST_LIGHTCOLOR_GREEN;break;}
                case 3: {iTemp = IP_CONST_LIGHTCOLOR_ORANGE;break;}
                case 4: {iTemp = IP_CONST_LIGHTCOLOR_PURPLE;break;}
                case 5: {iTemp = IP_CONST_LIGHTCOLOR_RED;break;}
                case 6: {iTemp = IP_CONST_LIGHTCOLOR_WHITE;break;}
                case 7: {iTemp = IP_CONST_LIGHTCOLOR_YELLOW;break;}
                };
            IPSafeAddItemProperty(oArmor,ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_BRIGHT,iTemp));
            }
        else if (iRoll <= 19)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_TUMBLE,10));
            }
        else if (iRoll <= 30)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_HIDE,10));
            }
        else if (iRoll <= 49)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_MOVE_SILENTLY,10));
            }
        else if (iRoll <= 50)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14));
            }
        else if (iRoll <= 60)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyTrueSeeing());
            }
        else if (iRoll <= 65)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
            }
        else if (iRoll <= 66)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16));
            }
        else if (iRoll <= 71)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ACID,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 76)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_COLD,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 81)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_FIRE,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 86)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ELECTRICAL,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 91)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_SONIC,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 94)
            {
            iEnc += 4;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18));
            }
        else if (iRoll <= 95)
            {
            iEnc += 5;
            IPSafeAddItemProperty(oArmor,ItemPropertyCastSpell(SPELL_ETHEREALNESS,IP_CONST_CASTSPELL_NUMUSES_1_USE_PER_DAY));
            }
        else if (iRoll <= 98)
            {
            iEnc += 5;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB));
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_KNOCKDOWN));
            }
        else
            iSpecial += 2;
        }
    return iEnc;
    }

int Table86c(int iSpecial, object oArmor, int iEnc)
    {
    int i,iRoll,iTemp;
    for (i = 1; i<= iSpecial; i+=1)
        {
        iRoll = d100();
        if (iRoll <= 2)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB));
            }
        else if (iRoll <= 8)
            {
            iEnc += 1;
            switch(Random(7)+1)
                {
                case 1: {iTemp = IP_CONST_LIGHTCOLOR_BLUE;break;}
                case 2: {iTemp = IP_CONST_LIGHTCOLOR_GREEN;break;}
                case 3: {iTemp = IP_CONST_LIGHTCOLOR_ORANGE;break;}
                case 4: {iTemp = IP_CONST_LIGHTCOLOR_PURPLE;break;}
                case 5: {iTemp = IP_CONST_LIGHTCOLOR_RED;break;}
                case 6: {iTemp = IP_CONST_LIGHTCOLOR_WHITE;break;}
                case 7: {iTemp = IP_CONST_LIGHTCOLOR_YELLOW;break;}
                };
            IPSafeAddItemProperty(oArmor,ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_BRIGHT,iTemp));
            }
        else if (iRoll <= 9)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_TUMBLE,10));
            }
        else if (iRoll <= 11)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_HIDE,10));
            }
        else if (iRoll <= 14)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertySkillBonus(SKILL_MOVE_SILENTLY,10));
            }
        else if (iRoll <= 16)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14));
            }
        else if (iRoll <= 21)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyTrueSeeing());
            }
        else if (iRoll <= 23)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageReduction(IP_CONST_DAMAGEREDUCTION_1,IP_CONST_DAMAGESOAK_5_HP));
            }
        else if (iRoll <= 27)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
            }
        else if (iRoll <= 29)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16));
            }
        else if (iRoll <= 31)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ACID,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 41)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_COLD,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 51)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_FIRE,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 61)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ELECTRICAL,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 64)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_SONIC,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 67)
            {
            iEnc += 4;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18));
            }
        else if (iRoll <= 69)
            {
            iEnc += 5;
            IPSafeAddItemProperty(oArmor,ItemPropertyCastSpell(SPELL_ETHEREALNESS,IP_CONST_CASTSPELL_NUMUSES_1_USE_PER_DAY));
            }
        else if (iRoll <= 72)
            {
            iEnc += 5;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB));
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_KNOCKDOWN));
            }
        else if (iRoll <= 74)
            {
            iEnc += 4;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_20));
            }
        else
            iSpecial += 2;
        }
    return iEnc;
    }

int Table87a(int iSpecial, object oArmor, int iEnc)
    {
    int i,iRoll,iTemp;
    for (i = 1; i<= iSpecial; i+=1)
        {
        iRoll = d100();
        if (iRoll <= 30)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusFeat(IP_CONST_FEAT_KNOCKDOWN));
            }
        else if (iRoll <= 50)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertyOnHitCastSpell(SPELL_BLINDNESS_AND_DEAFNESS,4));
            }
        else if (iRoll <= 60)
            {
            iEnc += 1;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB));
            }
        else if (iRoll <= 99)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_PIERCING,IP_CONST_DAMAGESOAK_5_HP));
            }
        else
            iSpecial += 2;
        }
    return iEnc;
    }

int Table87b(int iSpecial, object oArmor, int iEnc)
    {
    int i,iRoll,iTemp;
    for (i = 1; i<= iSpecial; i+=1)
        {
        iRoll = d100();
        if (iRoll <= 10)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_PIERCING,IP_CONST_DAMAGESOAK_5_HP));
            }
        else if (iRoll <= 16)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_PIERCING,IP_CONST_DAMAGESOAK_10_HP));
            }
        else if (iRoll <= 20)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14));
            }
        else if (iRoll <= 25)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyTrueSeeing());
            }
        else if (iRoll <= 30)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
            }
        else if (iRoll <= 40)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ACID,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 50)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_COLD,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 60)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_FIRE,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 70)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ELECTRICAL,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 80)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_SONIC,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 90)
            {
            iEnc += 5;
            IPSafeAddItemProperty(oArmor,ItemPropertyCastSpell(IP_CONST_CASTSPELL_SPELL_MANTLE_13,IP_CONST_CASTSPELL_NUMUSES_1_USE_PER_DAY));
            }
        else
            iSpecial += 2;
        }
    return iEnc;
    }

int Table87c(int iSpecial, object oArmor, int iEnc)
    {
    int i,iRoll,iTemp;
    for (i = 1; i<= iSpecial; i+=1)
        {
        iRoll = d100();
        if (iRoll <= 15)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_PIERCING,IP_CONST_DAMAGESOAK_10_HP));
            }
        else if (iRoll <= 20)
            {
            iEnc += 2;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14));
            }
        else if (iRoll <= 25)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyTrueSeeing());
            }
        else if (iRoll <= 35)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
            }
        else if (iRoll <= 38)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ACID,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 41)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_COLD,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 44)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_FIRE,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 47)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ELECTRICAL,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 50)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_SONIC,IP_CONST_DAMAGERESIST_10));
            }
        else if (iRoll <= 55)
            {
            iEnc += 3;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16));
            }
        else if (iRoll <= 60)
            {
            iEnc += 4;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18));
            }
        else if (iRoll <= 65)
            {
            iEnc += 5;
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB));
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
            IPSafeAddItemProperty(oArmor,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_KNOCKDOWN));
            }
        else if (iRoll <= 70)
            {
            iEnc += 5;
            IPSafeAddItemProperty(oArmor,ItemPropertyCastSpell(IP_CONST_CASTSPELL_SPELL_MANTLE_13,IP_CONST_CASTSPELL_NUMUSES_1_USE_PER_DAY));
            }
        else if (iRoll <= 80)
            {
            iEnc += 4;
            IPSafeAddItemProperty(oArmor,ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_20));
            }
        else
            iSpecial += 2;
        }
    return iEnc;
    }

object Table88b()
    {
    int iRoll = d100();
    string sString;
    if (iRoll <= 10)
        sString = "chains601";
    else if (iRoll <= 25)
        sString = "chain601";
    else if (iRoll <= 35)
        sString = "hide601";
    else if (iRoll <= 45)
        sString = "breast601";
    else if (iRoll <= 70)
        sString = "fplate601";
    else if (iRoll <= 80)
        sString = "fplate602";
    else if (iRoll <= 90)
        sString = "banded601";
    else if (iRoll <= 100)
        sString = "breast602";
    return CreateItemOnObject(sString);
    }

object Table88c()
    {
    int iRoll = d100();
    string sString;
    if (iRoll <= 10)
        sString = "fplate602";
    else if (iRoll <= 40)
        sString = "banded601";
    else if (iRoll <= 60)
        sString = "breast602";
    else if (iRoll <= 80)
        return Table88c();//Reroll
    else if (iRoll <= 100)
        return Table88c();//Reroll
    return CreateItemOnObject(sString);
    }

object Table89b()
    {
    int iRoll = d100();
    string sString;
    if (iRoll <= 10)
        sString = "sshield601";
    else if (iRoll <= 18)
        sString = "lshield601";
    else if (iRoll <= 25)
        sString = "lshield602";
    else if (iRoll <= 45)
        sString = "lshield603";
    else if (iRoll <= 65)
        sString = "sshield602";
    else if (iRoll <= 90)
        sString = "lshield604";
    else if (iRoll <= 100)
        sString = "lshield605";
    return CreateItemOnObject(sString);
    }

object Table89c()
    {
    int iRoll = d100();
    string sString;
    if (iRoll <= 20)
        sString = "lshield603";
    else if (iRoll <= 40)
        sString = "sshield602";
    else if (iRoll <= 60)
        sString = "lshield604";
    else if (iRoll <= 80)
        sString = "lshield605";
    else if (iRoll <= 100)
        sString = "lshield606";
    return CreateItemOnObject(sString);
    }

object RandomizeArmor(object oArmor)
    {
    int iLow,iHigh;
    int iAC = GetItemACValue(oArmor);
    object oArmor2;
    switch (iAC)
        {
        case 0: {iLow = 0; iHigh = 10;break;}
        case 1: {iLow = 11; iHigh = 13;break;}
        case 2: {iLow = 14; iHigh = 20;break;}
        case 3: {iLow = 21; iHigh = 24;break;}
        case 4: {iLow = 25; iHigh = 31;break;}
        case 5: {iLow = 32; iHigh = 36;break;}
        case 6: {iLow = 37; iHigh = 41;break;}
        case 7: {iLow = 42; iHigh = 46;break;}
        case 8: {iLow = 47; iHigh = 51;break;}
        };
    int iRange = iHigh - iLow +1;
    int iNum = (Random(iRange)+iLow);
    oArmor2 = CopyItemAndModify(oArmor,ITEM_APPR_TYPE_ARMOR_MODEL,ITEM_APPR_ARMOR_MODEL_TORSO ,iNum,TRUE);
    DestroyObject(oArmor);
    oArmor = RandomizeArmorColor(oArmor2);
    return oArmor;
    }

object RandomizeArmorColor(object oArmor)
    {
    int i,iColor;
    object oArmor2;
    for (i = 1; i <= 6; i++)
        {
        switch (i)
            {
            case 1:{iColor = ITEM_APPR_ARMOR_COLOR_CLOTH1;break;}
            case 2:{iColor = ITEM_APPR_ARMOR_COLOR_CLOTH2;break;}
            case 3:{iColor = ITEM_APPR_ARMOR_COLOR_LEATHER1;break;}
            case 4:{iColor = ITEM_APPR_ARMOR_COLOR_LEATHER2;break;}
            case 5:{iColor = ITEM_APPR_ARMOR_COLOR_METAL1;break;}
            case 6:{iColor = ITEM_APPR_ARMOR_COLOR_METAL2;break;}
            };
        oArmor2 = CopyItemAndModify(oArmor,ITEM_APPR_TYPE_ARMOR_COLOR,iColor,Random(64),TRUE);
        DestroyObject(oArmor);
        oArmor = oArmor2;
        }
    return oArmor;
    }
