//------------------------------------------------------------------------------
// ZZ> Animate the character
IfStateIs2
  // Full of blood
  GetContent
  tmpargument = tmpargument + 2 & 15 + 40
  SetContent
IfStateIs1
  // Filling up with blood
  IfTimeOut
    tmpargument = 2
    SetState
    tmpargument = 32
    SetTime
  GetContent
  tmpargument = tmpargument + 2 & 15 + 20
  SetContent
IfStateIs0
  // Normal
  IfSpawned
    MakeCrushValid
    tmpargument = 1
    PlaySoundLooped
  GetContent
  tmpargument = tmpargument + 2 & 15
  SetContent
SetFrame



//------------------------------------------------------------------------------
// Adjust the buzzing volume
SetTargetToLeader
IfTargetIsSelf
  tmpargument = 1
  tmpdistance = 0
  SetVolumeNearestTeammate



//------------------------------------------------------------------------------
// ZZ> Do movement AI
IfTimeOut
  tmpargument = 32
  SetTime


  // Find someone to poke
  SetTargetToWideEnemy
    IfStateIs2
      tmpx = rand & 1023 - 512 + leaderx
      tmpy = rand & 1023 - 512 + leadery
    Else
      BecomeLeader
      tmpx = targetx
      tmpy = targety
      tmpturn = rand & 4095 - 2048 + targetturnto
      tmpdistance = 700
      Compass
  Else
    // Swarm around leader
    tmpx = rand & 511 - 256 + leaderx
    tmpy = rand & 511 - 256 + leadery
  ClearWaypoints
  AddWaypoint


//------------------------------------------------------------------------------
// ZZ> Handle doors crushing
IfCrushed
  // Sound
  tmpargument = 0
  tmpdistance = rand & 2047 + 10000
  PlaySound


  // Die or Pop?
  IfStateIs2
    // Particle spawn
    SpawnPoof
  Else
    // Particle spawn
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz
    tmpargument = 0
    SpawnExactParticle


  // Message
  tmpargument = 3
  SendMessageNear
  GoPoof


  // Check sound
  tmpx = selfmorale
  tmpy = 1
  IfXIsLessThanY
    tmpargument = 1
    StopSound


//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff...
IfKilled
  // Sound
  tmpargument = 0
  tmpdistance = rand & 2047 + 10000
  PlaySound


  // Die or Pop?
  IfStateIs2
    // Pop
    tmpargument = ACTIONKB
    DoActionOverride
    // Particle spawn
    SpawnPoof
    tmpargument = 1
  Else
    // Die
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz
    tmpargument = 0
    SpawnExactParticle
    tmpargument = ACTIONKA
    DoActionOverride
    tmpargument = 0


  // Message
  SendMessageNear


  // Check sound
  tmpx = selfmorale
  tmpy = 1
  IfXIsLessThanY
    tmpargument = 1
    StopSound


  // Don't move
  SetTargetToSelf
  StopTargetMovement


//------------------------------------------------------------------------------
// ZZ> Handle blood sucking
IfBumped
  IfStateIs0
    SetTargetToWhoeverBumped
    IfTargetIsOnHatedTeam
      IfTargetIsDefending
        // Check incoming direction
        tmpx = targetturnto + 49152 - targetturn & 65535
        tmpy = 32768
        IfXIsMoreThanY
          tmpx = 1 // Hit
        Else
          tmpx = 0 // Miss
      Else
        tmpx = 1 // Hit        


      tmpy = 1
      IfXIsEqualToY
        // Start fill animation
        tmpargument = 1
        SetState
        tmpargument = 8
        SetTime
        tmpargument = 14
        SetContent

        // Turn red
        tmpargument = 1
        ChangeArmor

        // Tell the target
        tmpargument = 2
        SendMessageNear

        // Do some damage
        tmpargument = 1024 // 4
        DamageTarget
      Else
        // Bounce off the character
        tmpx = selfx - targetx < 4 + selfx
        tmpy = selfy - targety < 4 + selfy
        ClearWaypoints
        AddWaypoint
        tmpargument = 16
        SetTime


//------------------------------------------------------------------------------
// ZZ> For swarm AI
IfLeaderKilled
  BecomeLeader


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