// Generates goods as per table 7-4
void GenerateGoods(object oContainer,int iCR, int iGoods);
// Sub function of Generate Goods
void GenerateGems(int iNumber, object oContainer = OBJECT_SELF, int iGoods = 1);
// Sub function of Generate Goods
void GenerateArt(int iNumber, object oContainer = OBJECT_SELF, int iMulti = 1);

void GenerateGoods(object oMonster,int iCR, int iGoods)
    {
    int iRoll = d100();
    int iGem,iArt;
    if (iCR > 20)
        iCR = 20;
    switch (iCR)
        {
        case 1:
            {
            if (iRoll <= 90) break;
            else if (iRoll <= 95) {iGem = 1;break;}
            else {iArt = 1;break;}
            }
        case 2:
            {
            if (iRoll <= 81) break;
            else if (iRoll <= 95) {iGem = d3();break;}
            else {iArt = d3();break;}
            }
        case 3:
            {
            if (iRoll <= 77) break;
            else if (iRoll <= 95) {iGem = d3();break;}
            else {iArt = d3();break;}
            }
        case 4:
            {
            if (iRoll <= 70) break;
            else if (iRoll <= 95) {iGem = d4();break;}
            else {iArt = d3();break;}
            }
        case 5:
            {
            if (iRoll <= 60) break;
            else if (iRoll <= 95) {iGem = d4();break;}
            else {iArt = d4();break;}
            }
        case 6:
            {
            if (iRoll <= 56) break;
            else if (iRoll <= 92) {iGem = d4();break;}
            else {iArt = d4();break;}
            }
        case 7:
            {
            if (iRoll <= 48) break;
            else if (iRoll <= 88) {iGem = d4();break;}
            else {iArt = d4();break;}
            }
        case 8:
            {
            if (iRoll <= 45) break;
            else if (iRoll <= 85) {iGem = d6();break;}
            else {iArt = d4();break;}
            }
        case 9:
            {
            if (iRoll <= 40) break;
            else if (iRoll <= 80) {iGem = d8();break;}
            else {iArt = d4();break;}
            }
        case 10:
            {
            if (iRoll <= 35) break;
            else if (iRoll <= 79) {iGem = d8();break;}
            else {iArt = d6();break;}
            }
        case 11:
            {
            if (iRoll <= 24) break;
            else if (iRoll <= 74) {iGem = d10();break;}
            else {iArt = d6();break;}
            }
        case 12:
            {
            if (iRoll <= 17) break;
            else if (iRoll <= 70) {iGem = d10();break;}
            else {iArt = d8();break;}
            }
        case 13:
            {
            if (iRoll <= 11) break;
            else if (iRoll <= 66) {iGem = d12();break;}
            else {iArt = d10();break;}
            }
        case 14:
            {
            if (iRoll <= 11) break;
            else if (iRoll <= 66) {iGem = d8(2);break;}
            else {iArt = d6(2);break;}
            }
        case 15:
            {
            if (iRoll <= 9) break;
            else if (iRoll <= 65) {iGem = d10(2);break;}
            else {iArt = d8(2);break;}
            }
        case 16:
            {
            if (iRoll <= 7) break;
            else if (iRoll <= 64) {iGem = d6(4);break;}
            else {iArt = d10(2);break;}
            }
        case 17:
            {
            if (iRoll <= 4) break;
            else if (iRoll <= 63) {iGem = d8(4);break;}
            else {iArt = d8(3);break;}
            }
        case 18:
            {
            if (iRoll <= 4) break;
            else if (iRoll <= 54) {iGem = d12(3);break;}
            else {iArt = d10(3);break;}
            }
        case 19:
            {
            if (iRoll <= 3) break;
            else if (iRoll <= 50) {iGem = d6(6);break;}
            else {iArt = d6(6);break;}
            }
        case 20:
            {
            if (iRoll <= 2) break;
            else if (iRoll <= 38) {iGem = d10(4);break;}
            else {iArt = d6(7);break;}
            }
        };
    if (iGem)
        GenerateGems(iGem , oMonster, iGoods);
    else if (iArt)
        GenerateArt(iArt , oMonster, iGoods);
    }

void GenerateGems(int iNumber, object oContainer, int iMulti)
    {
    int i,iRoll;
    string sResRef;
    for (i = 1; i <= iNumber * iMulti; i++)
        {
        iRoll = d100();
        if (iRoll <= 25)        sResRef = "rdg_gem101";
        else if (iRoll <= 50)   sResRef = "rdg_gem201";
        else if (iRoll <= 70)   sResRef = "rdg_gem301";
        else if (iRoll <= 90)   sResRef = "rdg_gem401";
        else if (iRoll <= 99)   sResRef = "rdg_gem501";
        else                    sResRef = "rdg_gem601";
        // Designed for future expandability.
        CreateItemOnObject(sResRef, oContainer);
        }
    }

void GenerateArt(int iNumber, object oContainer, int iMulti)
    {
    int i,iRoll;
    string sResRef;
    for (i = 1; i <= iNumber * iMulti; i++)
        {
        iRoll = d100();
        if (iRoll <= 10)        sResRef = "rdg_art101";
        else if (iRoll <= 25)   sResRef = "rdg_art201";
        else if (iRoll <= 40)   sResRef = "rdg_art301";
        else if (iRoll <= 50)   sResRef = "rdg_art401";
        else if (iRoll <= 60)   sResRef = "rdg_art501";
        else if (iRoll <= 70)   sResRef = "rdg_art601";
        else if (iRoll <= 80)   sResRef = "rdg_art701";
        else if (iRoll <= 85)   sResRef = "rdg_art801";
        else if (iRoll <= 90)   sResRef = "rdg_art901";
        else if (iRoll <= 95)   sResRef = "rdg_art1001";
        else if (iRoll <= 99)   sResRef = "rdg_art1101";
        else                    sResRef = "rdg_art1201";
        // Designed for future expandability.
        CreateItemOnObject(sResRef, oContainer);
        }
    }

