#include "inc_misc_tools"
void main()
    {
    // DETERMINE THE PC
    object oPC = GetClickingObject();
    if (!GetIsObjectValid(oPC))
        oPC = GetEnteringObject();
    if (!GetIsObjectValid(oPC))
        oPC = GetLastUsedBy();
    // DETERMINE THE DESTINATION
    object oDest = GetLocalObject(OBJECT_SELF,"Dest");
    object oDoor;
    if (GetIsObjectValid(oDest))
        AssignCommand(oPC,Transition(oDest));
    else if (GetLocalInt(OBJECT_SELF,"DeadEnd"))
        FloatingTextStringOnCreature("Dead End",oPC);
    else
        {
        // FIND A TRANSITION TO LINK
        if (GetTag(OBJECT_SELF) == "RDG_PIT")
            oDest = DetermineDestination(TRUE,FALSE);
        else if (GetTag(OBJECT_SELF) == "rdg_secret_door")
            {
            oDest = DetermineDestination(FALSE,TRUE);
            if (GetIsObjectValid(oDest))
                {
                oDoor = CreateObject(OBJECT_TYPE_PLACEABLE,"rdg_secret_door",GetLocation(oDest),FALSE);
                AssignCommand(oDoor,SetFacing(GetFacing(oDest)));
                LinkTransitions (oDoor,oDest); //Marks far side secret door wp as used.
                oDest = oDoor;
                }
            }
        else
            oDest = DetermineDestination();
        if (GetIsObjectValid(oDest))
            {
            LinkTransitions(oDest);
            AssignCommand(oPC,Transition(oDest));
            }
        else
            {
            SetLocalInt(OBJECT_SELF,"DeadEnd",TRUE);
            FloatingTextStringOnCreature("Dead End",oPC);
            }
        }
    }


