/////////////////////////////////////////////////////////////////////////////
// Real Time Strategy - NWN - Heartbeat kicker
//===========================================================================
// By Deva Bryson Winblood. 02/24/2003
/////////////////////////////////////////////////////////////////////////////
/* This heartbeat just makes sure the DelayCommand() for the NPC fired off
   recently.  If it has not then it will start it up again */
// If no AI has been processed for 12 seconds it will launch the script
void main()
{
    object oMe=OBJECT_SELF;
    object oMod=GetModule();
    object oAProxy;
    string sID=GetLocalString(oMe,"sTeamID");
    string sS=GetLocalString(oMod,"sIsAlliedTo"+sID);
    int nSec=GetTimeSecond();
    int nSecL=GetLocalInt(OBJECT_SELF,"nLastDelaySec");
    int nTime=GetLocalInt(GetModule(),GetTag(OBJECT_SELF)+"_timeup");
    int nInstanceID=GetLocalInt(oMod,"nInstanceID");
    int nIID=GetLocalInt(oMe,"nIID");
    if (nIID!=nInstanceID)
    { // clear from game loaded from save
/* //Qlippoth removed, doesn't fix movement stuttering//       SetLocalInt(oMe,"nIID",nInstanceID);
        AssignCommand(oMe,ClearAllActions(TRUE));
        ExecuteScript("unit_fromsave",oMe);*/
    } // clear from game loaded from save
    if (GetStringLength(sS)>0&&GetLocalInt(oMod,"bIsAllianceLeader"+sID)!=TRUE)
    { // make sure allied
      oAProxy=GetObjectByTag(sS+"_PROXY");
      if(GetIsEnemy(oAProxy,oMe)) ChangeFaction(oMe,oAProxy);
    } // make sure allied
    if (nTime>0&&GetLocalInt(OBJECT_SELF,"nTimedUpgSet")!=TRUE)
    { // timed upgrade
      //SendMessageToPC(GetFirstPC(),"==DelayCommand set==");
      DelayCommand(18.0,ExecuteScript("rts_timed_upg",OBJECT_SELF));
      SetLocalInt(OBJECT_SELF,"nTimedUpgSet",TRUE);
    } // timed upgrade
    if (nSecL>nSec) nSec=nSec+60;
    if ((nSec-nSecL)>12) ExecuteScript("rts_unit_ai",OBJECT_SELF);
}