//------------------------------------------------------------------------------
//STATUE AI
IfSpawned
  tmpargument = 1
  ChangeArmor
  SetTargetToSelf
  SetTargetToTargetLeftHand
  ChangeTargetArmor
  SetTargetToTargetRightHand
  ChangeTargetArmor
  KeepAction
  tmpx = selfspawnx
  tmpy = selfspawny
  ClearWaypoints
  AddWaypoint

//------------------------------------------------------------------------------
//BOSS BATTLE AI
tmpargument = 1
IfArmorIs
  IfOrdered
    tmpx = [SCOR]           //Become alive?
    tmpy = selforder
    IfXIsEqualToY
      tmpargument = 0
      ChangeArmor
      UnkeepAction
Else

  // ZZ> Make the scorpion run away
  IfScoredAHit
    tmpx = selfx
    tmpy = selfy
    tmpturn = selfturn + 32768
    tmpdistance = 700
    Compass
    ClearWaypoints
    AddWaypoint

    tmpargument = 20
    SetTime


  //------------------------------------------------------------------------------
  // ZZ> Handle death by sending a message and other stuff
  IfKilled
    // Spit out text
    tmpargument = 0
    IfTargetIsOnHatedTeam
      tmpargument = 1
    SendMessage


    // Make noises
    tmpargument = 1
    PlaySound


    // Make the character body
    tmpargument = 45
    SetBumpHeight
    tmpargument = 30
    SetBumpSize

    //Tell the dracolich we are dead
    tmpargument = [BDIE]
    IssueOrder

  //------------------------------------------------------------------------------
  // ZZ> Let the character walk around
  IfTimeOut
    tmpargument = 20
    SetTime

    tmpdistance = 128*10
    SetTargetToDistantEnemy
      Run
      SetTurnModeToWatchTarget
      IfFacingTarget
        tmpx = targetdistance
        tmpy = 300
        IfXIsLessThanY
          tmpy = 100
          IfXIsLessThanY
            // Do tail attack
            tmpargument = ACTIONMC // Tail strike
            DoAction
              // Spawn particle on tip of the tail to do damage
              tmpargument = 0
              tmpdistance = 60
              SpawnAttachedParticle
              tmpargument = 20
              SetReloadTime


            // Back up
            tmpx = selfx
            tmpy = selfy
            tmpturn = selfturn + 32768
            tmpdistance = 300
            Compass
          Else
            tmpx = rand & 255
            IfXIsMoreThanY
              // Do claw attack
              tmpargument = rand & 1 + 1
              PressLatchButton
            Else
              // Do tail attack
              tmpargument = ACTIONMC // Tail strike
              DoAction
                // Spawn particle on tip of the tail to do damage
                tmpargument = 0
                tmpdistance = 60
                SpawnAttachedParticle
                tmpargument = 20
                SetReloadTime
            tmpx = targetx
            tmpy = targety
        Else
          tmpy = 600
          IfXIsLessThanY
            tmpx = rand & 511
            tmpy = 410
            IfXIsLessThanY
              // Circle left or right ( depending on life )
              tmpturn = selflife & 256 < 6 + selfturn
              tmpdistance = 800
              tmpx = selfx
              tmpy = selfy
              Compass
            Else
              // Rush attack
              tmpargument = rand & 1 + 1
              PressLatchButton

              // Play a sound
              tmpargument = 2
              tmpdistance = 22050
              PlaySound

              tmpturn = targetturnto
              tmpdistance = 1600
              tmpx = selfx
              tmpy = selfy
              Compass
          Else
            // Do approach
            tmpx = targetx
            tmpy = targety
      Else
        // Walk to find target
        tmpx = selfx
        tmpy = selfy
        tmpturn = selfturn
        tmpdistance = 800
        Compass
        tmpx = tmpx + targetx + targetx + targetx > 2
        tmpy = tmpy + targety + targety + targety > 2
        tmpx = tmpx - selfx < 1 + selfx
        tmpy = tmpy - selfy < 1 + selfy
    Else
      // Circle to guard terrain
      Sneak
      SetTurnModeToVelocity
      tmpx = selfspawnx
      tmpy = selfspawny
      tmpturn = xyturnto + 16384
      tmpdistance = 1000
      Compass
      tmpargument = 5
      SetTime
    ClearWaypoints
    AddWaypoint


  //------------------------------------------------------------------------------
  // ZZ> Handle being attacked by making a sound...  Drop claws...
  IfAttacked
    tmpargument = 0
    PlaySound


    GetDamageType
    tmpx = tmpargument
    tmpy = DAMAGESLASH
    IfXIsEqualToY
      tmpx = rand & 255
      tmpy = 128
      IfXIsMoreThanY          //50%
        // Drop a claw
        tmpargument = tmpx > 2 & 1 + ACTIONMA
        DoActionOverride


  //------------------------------------------------------------------------------
  IfBumped
    SetTargetToWhoeverBumped
    IfTargetIsOnHatedTeam
      IfFacingTarget
        tmpargument = ACTIONMC // Tail strike
        DoAction
          // Spawn particle on tip of the tail to do damage
          tmpargument = 0
          tmpdistance = 60
          SpawnAttachedParticle
          tmpargument = 20
          SetReloadTime
      Else
        tmpx = targetx
        tmpy = targety
        tmpdistance = 300
        tmpturn = rand
        Compass
        ClearWaypoints
        AddWaypoint
        tmpargument = 30
        SetTime
    Else
      SetTargetToOldTarget
      tmpx = rand & 511 - 256 + selfx
      tmpy = rand & 511 - 256 + selfy
      ClearWaypoints
      AddWaypoint
      tmpargument = 10
      SetTime


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