//------------------------------------------------------------------------------
// 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

  // Open the boss passage
  tmpargument = passage
  OpenPassage

  // Set the "forgot something" ending
  ClearEndMessage
  tmpargument = 2
  AddEndMessage
  tmpargument = 3
  AddEndMessage

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

  SetTargetToWideEnemy
    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
            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
  
    //Play boss music
    tmpargument = 25
    tmpdistance = 400
    PlayMusic  
  Else
    // Circle to guard terrain
    Sneak
    SetTurnModeToVelocity
    tmpx = selfspawnx
    tmpy = selfspawny
    tmpturn = xyturnto + 16384
    tmpdistance = 1000
    Compass
    tmpargument = 5
    SetTime
    
    //Play normal music
    tmpargument = 4
    tmpdistance = 1500
    PlayMusic

  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
      // 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
//------------------------------------------------------------------------------
