// v2.1.0 - Updated to new version of AI.
// v2.0.0 -
//::////////////////////////////////////////////////////////////////////////////
//:: FileName:  hark_ace_blocked
//::////////////////////////////////////////////////////////////////////////////
/*
   This will cause blocked creatures to open or smash down doors depending on
  int and str.
*/
//::////////////////////////////////////////////////////////////////////////////
#include "hark_i0_henshout"
#include "hark_i0_ace"
//::////////////////////////////////////////////////////////////////////////////
void main()
{
  if (!preEvent()) { return; }

  object oDoor = GetBlockingDoor();
  object oMaster = GetRealMaster();
  if (GetObjectType(oDoor) == OBJECT_TYPE_DOOR && GetIsObjectValid(oMaster) &&
     !GetLocalInt(OBJECT_SELF, "Scouting") &&
     !IsOnOppositeSideOfDoor(oDoor, oMaster, OBJECT_SELF))
    {
     ClearAllActions();
     ClearForceOptions();
     if (GetAssociate(ASSOCIATE_TYPE_HENCHMAN, GetMaster()) == OBJECT_SELF &&
        (GetIsObjectValid(GetLocalObject(OBJECT_SELF, "LastTarget")) ||
         GetLocalInt(OBJECT_SELF, "LastSeenOrHeard")))
       {
        DeleteLocalObject(OBJECT_SELF, "LastTarget");
        ClearEnemyLocation();
        if (!GetLocalInt(oDoor, "tkDoorWarning"))
          {
           SpeakString(MON_NEAR);
           SetLocalInt(oDoor, "tkDoorWarning", TRUE);
          }
       }
     ActionForceFollowObject(oMaster, GetFollowDistance());
    }
  else if (GetIsDoorActionPossible(oDoor, DOOR_ACTION_OPEN) && GetAbilityScore(OBJECT_SELF, ABILITY_INTELLIGENCE) >= 3)
    { DoDoorAction(oDoor, DOOR_ACTION_OPEN); }
  else if (GetIsDoorActionPossible(oDoor, DOOR_ACTION_UNLOCK))
    { DoDoorAction(oDoor, DOOR_ACTION_UNLOCK); }
  else if (GetIsDoorActionPossible(oDoor, DOOR_ACTION_BASH) && GetAbilityScore(OBJECT_SELF, ABILITY_STRENGTH) >= 15)
    { DoDoorAction(oDoor, DOOR_ACTION_BASH); }

  if (GetSpawnInCondition(NW_FLAG_EVENT_BLOCKED))
    { SignalEvent(OBJECT_SELF, EventUserDefined(1012)); }

  postEvent();
}
//::////////////////////////////////////////////////////////////////////////////
