//------------------------------------------------------------------------------
//Angelic aura
tmpargument = 5
tmpx = selfx
tmpy = selfy
tmpdistance = selfz
SpawnExactParticle

//------------------------------------------------------------------------------
//Join the noble saviours!
IfOrdered
  tmpx = selforder
  tmpy = [FREE]
  IfXIsEqualToY
    JoinGoodTeam
    SetTargetToNearestFriend
    AddStat
    tmpargument = [PALA]		//Paladins
    IfTargetHasID
      tmpargument = 9
    Else
      tmpargument = [SOLD]		//soldiers
      IfTargetHasID
        tmpargument = 9
      Else
        tmpargument = [KNIG]		//and knights get special thanks
        IfTargetHasID
          tmpargument = 9
        Else
          tmpargument = [HEAL]		//Healers get a blessing =)
          IfTargetHasID
            tmpargument = 12
          Else
            tmpargument = [UNDE]
            IfTargetHasID
              tmpargument = 14    //Attack undead players
            Else
              tmpargument = 8		//Others get normal
    PlayFullSound
    SendMessage
    tmpargument = 3             //Follow mode
    SetState
    tmpargument = 70
    tmpdistance = EXPDARE
    GiveExperienceToGoodTeam
    SetOwnerToTarget            //Make the nearest saviour the new boss

    //She attacks Zombor or Undead players at sight
    tmpargument = [UNDE]
    IfTargetHasID
      tmpargument = TEAMH
      JoinTeam
      SetTargetToSelf
      SetOwnerToTarget
      tmpargument = 4
      SetState

//------------------------------------------------------------------------------
//Show where you are on the map
tmpx = selfstate
tmpy = 2
IfXIsMoreThanY
  tmpx = selfx
  tmpy = selfy
  tmpargument = 4
  ShowBlipXY

//------------------------------------------------------------------------------
//Main AI loop
IfTimeOut

  //Who won't help an angel in need?
  tmpx = selfstate
  tmpy = 3
  IfXIsLessThanY
    tmpargument = 250
    SetTime
    tmpdistance = 128*7
    SetTargetToDistantEnemy                //SetTargetToWhoeverIsInPassage
      IfTargetIsAPlayer
        IfStateIs0

//BAD: we are missing some voice acting here
//          tmpargument = [HEAL]
//          IfTargetHasID
//            tmpargument = 13		//Special healer greet
//          Else
//            tmpargument = [PALA]
//            IfTargetHasID
//              tmpargument = 12		//Special paladin greet
//            Else
//              tmpargument = 7		//Normal greet
          
          tmpargument = 7
          PlayFullSound
          SendMessage
          tmpargument = 1
          SetState
        Else
          IfStateIs1
            tmpargument = [HEAL]
            IfTargetHasID
              tmpargument = 14		//Special talk
            Else
              tmpargument = [PALA]
              IfTargetHasID
                tmpargument = 14		//Special talk
              Else
                tmpargument = [UNDE]
                IfTargetHasID
                  tmpargument = 14        //It's Zombor or something undeady!
                Else
                  tmpargument = rand % 3 + 5	//Normal random talk
            PlayFullSound
            SendMessage

            tmpargument = 0
            SetState
    Else
      IfStateIs1			//They are running away!
        tmpargument = 4
        PlaySound
        SendMessage
    SetTurnModeToWatchTarget

  //When not imprisoned, draw our gear
  Else
    IfHoldingMeleeWeapon
      DoNothing
    Else
      tmpargument = LATCHPACKRIGHT		//weapon
      PressLatchButton

  //Follow
  IfStateIs3
    tmpargument = rand & 15 + 35
    SetTime
    SetTargetToOwner
    tmpx = targetdistance
    tmpy = 1500
    IfXIsLessThanY                  //Follow player if he is far away
      SetTargetToWideEnemy
        tmpargument = [CUBE]
        IfTargetHasID			//Don't engage cubes
          SetTargetToOwner
        Else
          tmpargument = 4
          SetState

    tmpx = rand & 255 + ownerx - 128
    tmpy = rand & 255 + ownery - 128
    tmpdistance = 0 - 100
    tmpturn = targetturnto
    Compass
    ClearWaypoints
    AddWaypoint

  //Combat Mode
  IfStateIs4
    tmpargument = rand & 15 + 15
    SetTime
    tmpx = targetdistance
    tmpy = 250
    IfXIsMoreThanY              //Never run away from melee
      SetTargetToOwner
      tmpx = targetdistance
      tmpy = 700
      IfXIsMoreThanY            //See if we need to go after the player
        tmpargument = 3
        SetState

    //We are still in combat! Do the usual combat stuff
    IfStateIs4
      SetTargetToWideEnemy

        //Attack!
        IfHoldingMeleeWeapon
          IfFacingTarget
            IfTargetIsOnHatedTeam
              tmpx = targetdistance
              tmpy = 200
              IfXIsLessThanY
                PressLatchButton
        tmpargument = [CUBE]
        IfTargetHasID				//Keep away from cubes
          SetTargetToOwner
          tmpx = rand & 511 + ownerx - 256
          tmpy = rand & 511 + ownery - 256
          tmpturn = targetturnto
          tmpdistance = 700
          Compass
          ClearWaypoints
          AddWaypoint
        Else
          tmpx = rand & 511 + targetx - 256
          tmpy = rand & 511 + targety - 256
          tmpturn = targetturnto
          tmpdistance = 700
          Compass
          ClearWaypoints
          AddWaypoint

      //No more enemies around
      Else
        tmpargument = 3
        SetState

  //First priority is to heal allies
  tmpx = selfmana
  tmpy = 255
  IfXIsMoreThanY
    tmpx = selfstate
    tmpy = 2
    IfXIsMoreThanY
      SetOldTarget
      SetTargetToNearestFriend
        IfTargetIsHurt
          tmpx = targetx
          tmpy = targety
          ClearWaypoints
          AddWaypoint
          IfFacingTarget
            tmpx = targetdistance
            tmpy = 150
            IfXIsLessThanY
              tmpargument = LATCHLEFT
              PressLatchButton
        Else
          SetTargetToOldTarget

  //Ressurect friends
  tmpx = selfmana
  tmpy = 255
  IfXIsMoreThanY
    tmpdistance = 5			//Dead'n friends
    tmpargument = [HUMA]
    SetTargetToWideBlahID
      IfTargetIsAlive
        SetTargetToOldTarget			//Dont ressurect alive friends!
      Else
        IfTargetIsOnSameTeam
          GetContent
          tmpy = 1024
          tmpx = tmpargument
          IfXIsMoreThanY			//Finished charging?
            RespawnTarget
              tmpargument = 0
              SetContent
              tmpargument = 13
              PlayFullSound
              SendMessage
          Else				//Charge
            tmpx = targetx
            tmpy = targety
            tmpdistance = targetz
            tmpargument = 6
            SpawnExactParticle
            SetOldTarget
            SetTargetToSelf
            tmpargument = 5
            CostTargetMana
            GetContent
            tmpargument = tmpargument + 5
            SetContent
            SetTargetToOldTarget
            tmpargument = 1
            SetTime
    Else
      tmpargument = 0				//abort casting
      SetContent

//------------------------------------------------------------------------------
//Handle death by sending a message and other stuff
IfKilled
  tmpargument = 1
  PlaySound			//death cry

  tmpargument = 0
  IfTargetIsOnSameTeam
    tmpargument = 1
    IfTargetIsSelf
      tmpargument = 2
  SendMessage

  // Drop goodies
  tmpargument = selfmoney
  DropItems
  DropMoney
  DropKeys

  // Make the character body
  tmpargument = 45
  SetBumpHeight

  //Make no body! (for ressurections)
  GoPoof
  SpawnPoof

//------------------------------------------------------------------------------
//Say ouch
IfAttacked
  SetTargetToWhoeverAttacked
  tmpdistance = 1
  IfTargetIsOnSameTeam
    tmpdistance = 0
    IfTargetIsFemale		//Friendly get special ouch
      tmpargument = 10		//Sister
    Else
      tmpargument = 11		//Sir
    PlaySound
    SendMessageNear

  tmpturn = 0
  IfDistanceIsMoreThanTurn		//Normal ouch
    tmpargument = rand & 1 + 1
    PlaySound

//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
