IfSpawned
  MakeCrushValid

IfCrushed
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  tmpargument = 1
  SpawnExactParticle
  SpawnExactParticle
  GoPoof
  tmpargument = 1
  SendMessageNear

IfDropped
  // Popped out of a chest
  tmpargument = 3
  PlaySound

IfKilled
  IfTargetIsSelf
    tmpargument = 2
  Else
    tmpargument = 0
  SendMessageNear
  tmpargument = 40
  SetBumpHeight
  tmpargument = 1
  PlaySound

IfAttacked
  SetTargetToWhoeverAttacked
    tmpargument = 0
    PlaySound

IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = LATCHLEFT
      PressLatchButton
  Else
    tmpx = rand & 1023 - 512 + selfx
    tmpy = rand & 1023 - 512 + selfy
    ClearWaypoints
    AddWaypoint
    SetTargetToOldTarget

// Look for enemies
IfTimeOut
  SetTargetToNearestEnemy
    IfFacingTarget
      tmpx = targetdistance
      tmpy = 800
      IfXIsLessThanY

        //Growl
        tmpx = rand % 2048
        tmpy = 0
        IfXIsEqualToY
          tmpargument = 3
          PlaySound

        //Attack
        tmpx = targetdistance
        tmpy = 450
        IfXIsLessThanY
          tmpx = selfaccel
          tmpy = 1
          IfXIsMoreThanY
            tmpargument = LATCHJUMP
            PressLatchButton
            tmpx = targetx - selfx > 4
            tmpy = targety - selfy > 4
            SetOldTarget
            SetTargetToSelf
            AccelerateTarget
            SetTargetToOldTarget
            // Play the attack sound
            tmpargument = 2
            PlaySound

      tmpx = targetx
      tmpy = targety
      tmpturn = targetturnto
      tmpdistance = 1500
      Compass
    Else
      tmpx = targetx
      tmpy = targety
      tmpturn = targetturnto
      tmpdistance = 0 - 100
      Compass
    ClearWaypoints
    AddWaypoint
  Else
    tmpx = selfx
    tmpy = selfy
    tmpturn = selfturn
    tmpdistance = 500
    Compass
    tmpturn = rand & 1023 - 512 + selfspawnx
    tmpx = tmpx + tmpturn + tmpturn + tmpturn > 2
    tmpturn = rand & 1023 - 512 + selfspawny
    tmpy = tmpy + tmpturn + tmpturn + tmpturn > 2
    ClearWaypoints
    AddWaypoint
  tmpargument = rand & 31 + 25
  SetTime

// All done
End
