// v2.0.0 -
//::////////////////////////////////////////////////////////////////////////////
//:: FileName:  hark_o0_tracking
//::////////////////////////////////////////////////////////////////////////////
/*
   The Henchman will attempt to find tracks of creatures on the ground and will
  begin following the tracks to the closest creature.
*/
//::////////////////////////////////////////////////////////////////////////////
#include "hark_i0_henshout"
//::////////////////////////////////////////////////////////////////////////////
int TrackCheck(object oTarget)
{
  if (GetIsObjectValid(oTarget))
    {
     // Determine the DC for the check.
     object oTrackDC = GetNearestObjectByTag(HS_TRACK_DC);
     int nTrackDC = GetWillSavingThrow(oTrackDC);
     int nWeather = GetWeather(GetArea(OBJECT_SELF));
     if (nWeather == WEATHER_RAIN || nWeather == WEATHER_SNOW)
       { nTrackDC += 2; }
     else
       { nTrackDC -= 2; }
     if (GetIsAreaNatural(GetArea(OBJECT_SELF)) == AREA_NATURAL)
       { nTrackDC -= 2; }
     else
       { nTrackDC += 2; }
     float fDis = GetDistanceToObject(oTarget);
     int nAdj = nTrackDC + FloatToInt(fDis / 10.0);
     int nCheck = d20() + GetLevelByClass(CLASS_TYPE_RANGER);

     // Return the result.
     return (nCheck >= nAdj && !GetHasFeat(FEAT_TRACKLESS_STEP, oTarget));
    }
  return FALSE;
}
//::////////////////////////////////////////////////////////////////////////////
void TrackStop()
{
  ClearAllActions();
  SetAssociateState(NW_ASC_IS_BUSY, FALSE);
  DeleteLocalObject(OBJECT_SELF, HS_TRACK_TARGET);
}
//::////////////////////////////////////////////////////////////////////////////
void main()
{
  object oTarget = GetLocalObject(OBJECT_SELF, HS_TRACK_TARGET);
  if (GetIsObjectValid(oTarget))
    {
     ClearAllActions();
     ActionPlayAnimation(ANIMATION_LOOPING_LOOK_FAR, 1.0, 2.0);
     ActionMoveToObject(oTarget);

     if (TrackCheck(oTarget))
       {
        if (GetObjectSeen(oTarget))
          {
           DelayCommand(6.1, SpeakString(TRACK_FOUND));
           DelayCommand(6.2, TrackStop());
          }
        else
          { DelayCommand(6.1, ExecuteScript(sTrackingScript, OBJECT_SELF)); }
       }
     else
       {
        DelayCommand(6.1, SpeakString(TRACK_LOST));
        DelayCommand(6.2, TrackStop());
       }
    }
  else
    {
     TrackStop();
    }
}
//::////////////////////////////////////////////////////////////////////////////
