//------------------------------------------------------------------------------
//Jumping over corpses
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsAlive
    tmpargument = [CHES]
    IfTargetHasID
      tmpargument = LATCHJUMP
      PressLatchButton
  Else
    tmpargument = LATCHJUMP
    PressLatchButton
  SetTargetToOldTarget

//------------------------------------------------------------------------------
tmpargument = 0
IfStateIsNot
  GetContent
  tmpx = tmpargument
  tmpy = 0
  IfXIsMoreThanY
    tmpargument = tmpx - 1
    SetContent

//Joining the soldier
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsAPlayer
    IfTargetIsOnOtherTeam
      JoinGoodTeam
      SetTargetToLeader
      tmpargument = 6
      PlaySound
      tmpargument = 5
      SendMessage
      tmpargument = 40
      tmpdistance = EXPQUEST
      GiveExperienceToGoodTeam
      tmpargument = 3
      SetState
      DropKeys			//Drop boss key
      AddStat			//Show stats

//-----------------------------------------------------------------------------
//Footstep sound
IfHitGround
  tmpargument = 0
  PlaySound

//----------------------------------------------------------------------------
//Using his shield
IfTargetIsAttacking
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = [SHIE]
      IfHoldingItemID
        tmpargument = LATCHLEFT
        PressLatchButton

//------------------------------------------------------------------------------
//Moving around...
IfTimeOut
  IfStateIs3
    tmpargument = 0
    IfContentIs
      SetTargetToSelf
      SetTargetToTargetLeftHand
        SetTargetToSelf
        SetTargetToTargetRightHand
          DoNothing
        Else
          tmpargument = LATCHPACKRIGHT
          PressLatchButton
      Else
        tmpargument = LATCHPACKLEFT
        PressLatchButton
      tmpargument = 100
      SetContent

    //Get in a fight!
    tmpdistance = 128*5
    SetTargetToDistantEnemy
      // Charge!
      tmpx = targetx
      tmpy = targety
      tmpdistance = 300
      tmpturn = targetturnto
      Compass
      ClearWaypoints
      AddWaypoint

      // Take a stab?
      tmpx = targetdistance
      tmpy = 120
      IfXIsLessThanY
        IfFacingTarget
          tmpargument = rand & 1 + 1
          PressLatchButton

      tmpargument = 10
      SetTime
    Else

      //Following the player
      SetTargetToLeader
      tmpx = targetdistance
      tmpy = 400
      IfXIsLessThanY
        tmpx = targetx
        tmpy = targety
        tmpturn = targetturnto + 32768
        tmpdistance = 100
        Compass
        ClearWaypoints
        AddWaypoint
        tmpargument = 20
        SetTime
      Else
      
        //Run to the player
        tmpy = 1200
        IfXIsLessThanY
          tmpx = targetx
          tmpy = targety
          tmpturn = targetturnto
          tmpdistance = 400
          Compass
          ClearWaypoints
          AddWaypoint
          tmpargument = 20
          SetTime
        Else

          //Walking around, player too far away
          tmpx = selfx
          tmpy = selfy
          tmpturn = selfturn + 8192
          tmpdistance = 200
          Compass
          ClearWaypoints
          AddWaypoint
          tmpargument = 20
          SetTime

  //Still a prisoner...
  Else
      //How close is the player?
    tmpargument = [SOLD]
    tmpdistance = 6 // Friends and Enemies
    SetTargetToNearestBlahID
      tmpx = targetx - selfspawnx
      tmpy = targety - selfspawny
      tmpx = xydistance
      tmpy = 400
      IfXIsLessThanY
        tmpy = 200
        IfXIsLessThanY
          IfStateIs0

            //Talk to the player...
            tmpargument = 90 // Delay
            SetContent

            tmpargument = 1
            SetState
          Else
            tmpx = selfspawnx
            tmpy = selfspawny
            tmpturn = targetturnto
            tmpdistance = 150
            Compass
            ClearWaypoints
            AddWaypoint
            tmpargument = 20
            SetTime
        Else
          //Approach the player
          tmpx = selfspawnx
          tmpy = selfspawny
          tmpturn = targetturnto
          tmpdistance = 150
          Compass
          ClearWaypoints
          AddWaypoint
          tmpargument = 20
          SetTime
      Else
        //Walk around in a circle
        tmpx = selfx
        tmpy = selfy
        tmpturn = selfturn + 8192
        tmpdistance = 200
        Compass
        ClearWaypoints
        AddWaypoint
        tmpargument = 20
        SetTime
    Else
      //If blah is not, Move around in a circle
      tmpx = selfx
      tmpy = selfy
      tmpturn = selfturn + 8192
      tmpdistance = 200
      Compass
      ClearWaypoints
      AddWaypoint
      tmpargument = 20
      SetTime

//------------------------------------------------------------------------------
//If the lord is killed
IfKilled
  tmpargument = 7
  PlaySound
  tmpargument = 0
  IfTargetIsOnSameTeam
    tmpargument = 1
  SendMessage

  //Drop all his items
  tmpargument = selfmoney
  DropMoney
  DropKeys
  DropItems

  //Create the body
  tmpargument = 45
  SetBumpHeight

//------------------------------------------------------------------------------
//What happens if the Lord is attacked?
IfAttacked
  SetTargetToWhoeverAttacked
  IfTargetIsOnSameTeam
    tmpargument = 1
    PlaySound
    tmpargument = 2
    SendMessageNear
  Else
    tmpargument = rand & 3 + 4
    PlaySound
  SetTargetToOldTarget

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