#include "inc_room_decor"
#include "inc_gen_enc"

//Sets up contents of areas.
void SetUpContents(object oPartyMember, int iPartyLevel);
// Sets up room encounters
void SetUpEncounters(int iPartyLevel);
// Sets up wandering monster encounters
// They will apear at the second nearest Transition WP.
// If that is not available they will spawn at the nearest.
void SetUpWanderingEncounter(object oPC);

//Sets up Starting positions and conditions of doors.
void SetUpDoor(object oDoor);
void SetUpDoor(object oDoor)
    {
    if (d100() <= DOOR_LOCKED_PERCENTAGE)
        {
        if (GetIsOpen(oDoor) && GetIsTrapped(oDoor))
            AssignCommand(oDoor,ActionCloseDoor(oDoor));
        SetLocked(oDoor,TRUE);
        }
    else if (d100() <= DOOR_OPEN_PERCENTAGE)
        AssignCommand(oDoor,ActionOpenDoor(oDoor));
    else if (d100() <= NO_DOOR_PERCENTAGE
        && !GetIsTrapped(oDoor))
        DestroyObject(oDoor);
    SetLocalInt(oDoor,"Set",TRUE);
    }

void SetUpContents(object oPartyMember, int iPartyLevel)
    {
    location lLoc;
    int iType;
    object oObject = GetFirstObjectInArea(OBJECT_SELF);
    string sTag;
    effect eStone = EffectPetrify();
    while (GetIsObjectValid(oObject))
        {
        iType = GetObjectType(oObject);
        lLoc = GetLocation(oObject);
        sTag = GetTag(oObject);
        switch (iType)
            {
            case OBJECT_TYPE_DOOR:
                {
                if (!GetLocalInt(oObject,"Set"))
                    SetUpDoor(oObject);
                break;
                }
            case OBJECT_TYPE_ITEM:
            case OBJECT_TYPE_PLACEABLE:
                {
                if (d100() > ROOM_DECOR)
                    {
                    if (!GetPlotFlag(oObject))
                        DestroyObject(oObject);
                    }
                else
                    ConvertObject(oObject);
                break;
                }
            case OBJECT_TYPE_WAYPOINT:
                {
                if (sTag == "Decor") // Decor
                    {
                    if (d100() <= ROOM_DECOR)
                        {
                        GenerateDecor(oObject);
                        break;
                        }
                    else
                        DestroyObject(oObject);
                    break;
                    }
                }
            };
        oObject = GetNextObjectInArea(OBJECT_SELF);
        }
    }

void SetUpEncounters(int iPartyLevel)
    {
    string sString,sTag;
    object oWP = GetFirstObjectInArea(OBJECT_SELF);
    while(GetIsObjectValid(oWP))
        {
        if (GetTag(oWP) == "MON_"
         && !GetLocalInt(oWP,"DoOnce")
         && d100() <= ROOM_MONSTER_CHANCE)
            {
            GenerateEncounter(iPartyLevel,oWP);
            break;
            }
        oWP = GetNextObjectInArea(OBJECT_SELF);
        }
    }

void SetUpWanderingEncounter(object oPC)
    {
    int iPartyLevel = PartyLevel(oPC);
    object oWP = GetNearestObjectByTag("Transition",oPC,2);
    if (!GetIsObjectValid(oWP) || GetArea(oWP)!=OBJECT_SELF)
        oWP = GetNearestObjectByTag("Transition",oPC,1);
    if (GetIsObjectValid(oWP))
        GenerateEncounter(iPartyLevel,oWP,TRUE);
    }

//void main(){}
