#include "inc_misc_tools"
//Work in progress.
object GenerateDecor(object oObject);
//Sub Function of GenerateDecor.
object GenerateRubish(object oWP);

// New type of Dungeon decor generator.
void ConvertObject(object oObject);
// SubFunction of ConvertObject
void PlaceObject(string sResRef, location lLoc);

object GenerateDecor(object oWP)
    {
    return GenerateRubish(oWP);
    }

object GenerateRubish(object oWP)
    {
    string sResRef = "plc_garbage";
    int iRoll = d100();
    if (iRoll >= 95)            sResRef = "x0_fallentimber";
    else if (iRoll >= 90)       sResRef = "nw_pl_rubble001";
    else if (iRoll >= 85)       sResRef = "x0_cityrubble2";
    else if (iRoll >= 80)       sResRef = "x0_cityrubble1";
    else if (iRoll >= 75)       sResRef = "plc_rubble";
    else if (iRoll >= 70)       sResRef = "x0_desertboulde2";
    else if (iRoll >= 65)       sResRef = "x0_desertboulder";
    else if (iRoll >= 60)       sResRef = "x0_desertrocks";
    else if (iRoll >= 55)       sResRef = "x0_brokenfurnit";
    else if (iRoll >= 50)       sResRef = "x0_brokentable";
    else if (iRoll >= 45)       sResRef = "x0_brokentable2";
    else if (iRoll >= 40)       sResRef = "x0_brokenchair2";
    else if (iRoll >= 30)       sResRef = "x0_brokenchair1";
    else if (iRoll >= 25)       sResRef = "x0_brokenchair3";
    else if (iRoll >= 20)       sResRef = "x0_brokenchair4";
    else if (iRoll >= 15)       sResRef = "x0_brokenfurnit2";
    else if (iRoll >= 10)       sResRef = "x0_brokenfurnit1";
    else if (iRoll >= 5)        sResRef = "plc_waterdrip";
    object oObject = CreateObject(OBJECT_TYPE_PLACEABLE,sResRef,GetLocation(oWP));
    DestroyObject(oWP);
    return oObject;
    }

void ConvertObject(object oObject)
    {
    string sTag = GetTag(oObject);
    string sResRef;
    int iRoll = d100();
    location lLoc = GetLocation(oObject);
    if (GetPlotFlag(oObject))
        return;
    if (sTag == "Table")
        {
        if (iRoll <= 25)
            sResRef = "x0_brokentable";
        else if (iRoll <= 50)
            sResRef = "x0_brokentable2";
        }
    else if (sTag == "Chair")
        {
        if (iRoll <= 15)
            sResRef = "x0_brokenchair1";
        else if (iRoll <= 30)
            sResRef = "x0_brokenchair2";
        else if (iRoll <= 45)
            sResRef = "x0_brokenchair3";
        else if (iRoll <= 60)
            sResRef = "x0_brokenchair4";
       }
    if (sResRef != "") // Place the object if a new ResRef has been determined.
        {
        DestroyObject(oObject);
        DelayCommand(0.5,PlaceObject(sResRef,lLoc));
        }
    }

void PlaceObject(string sResRef, location lLoc)
    {
    object oObject = CreateObject(OBJECT_TYPE_PLACEABLE,sResRef,lLoc);
    AssignCommand(oObject,SetFacing(IntToFloat(Random(360))));
    }
