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
  tmpdistance = 22050
  PlaySound


IfKilled
  tmpargument = 0
  SendMessageNear
  tmpargument = 40
  SetBumpHeight
  tmpargument = 1
  tmpdistance = rand & 4095 + 11000
  PlaySound


IfAttacked
  SetTargetToWhoeverAttacked
    tmpargument = 0
    tmpdistance = rand & 4095 + 11000
    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
        tmpx = selfaccel
        tmpy = 1
        IfXIsMoreThanY
          tmpargument = LATCHJUMP
          PressLatchButton
          tmpx = targetx - selfx > 4
          tmpy = targety - selfy > 4
          SetOldTarget
          SetTargetToSelf
          AccelerateTarget
          SetTargetToOldTarget

          // Play the sound
          tmpargument = 2
          tmpdistance = rand & 1023 + 10500
          PlaySound
      tmpx = targetx
      tmpy = targety
    Else
      tmpx = selfx
      tmpy = selfy
      tmpturn = selfturn
      tmpdistance = 500
      Compass
      tmpx = tmpx + targetx + targetx + targetx > 2
      tmpy = tmpy + targety + targety + targety > 2
    ClearWaypoints
    AddWaypoint
  Else
    tmpx = selfx
    tmpy = selfy
    tmpturn = selfturn
    tmpdistance = 500
    Compass
    tmpturn = rand & 1023 - 512 + selfx
    tmpx = tmpx + tmpturn + tmpturn + tmpturn > 2
    tmpturn = rand & 1023 - 512 + selfy
    tmpy = tmpy + tmpturn + tmpturn + tmpturn > 2
    ClearWaypoints
    AddWaypoint
  tmpargument = rand & 31 + 25
  SetTime


// All done
End
