/////////////////////////////////////////////////////////////////////////////
// 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()
{
    int nSec=GetTimeSecond();
    object oPC;
    int nAlign;
    int nSecL=GetLocalInt(OBJECT_SELF,"nLastDelaySec");
    int nTime=GetLocalInt(GetModule(),GetTag(OBJECT_SELF)+"_timeup");
    if (nTime>0&&GetLocalInt(OBJECT_SELF,"nTimedUpgSet")!=TRUE)
    { // timed upgrade
      //SendMessageToPC(GetFirstPC(),"==DelayCommand set==");
      DelayCommand(HoursToSeconds(nTime),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);
    oPC=GetNearestCreature(CREATURE_TYPE_PERCEPTION,PERCEPTION_SEEN,OBJECT_SELF,1,CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC,CREATURE_TYPE_IS_ALIVE,TRUE);
    if (oPC!=OBJECT_INVALID)
    { // test
      nAlign=GetAlignmentGoodEvil(oPC);
      if (nAlign==ALIGNMENT_EVIL&&GetIsEnemy(oPC)!=TRUE&&GetLocalInt(oPC,"nMaskAlignment")!=TRUE)
      { // don't like this person
        AssignCommand(OBJECT_SELF,SpeakString("Foul evil one!"));
        AdjustReputation(oPC,OBJECT_SELF,-100);
        SetIsTemporaryEnemy(oPC,OBJECT_SELF);
        SetIsTemporaryEnemy(OBJECT_SELF,oPC);
      } // don't like this person
    } // test
}