//------------------------------------------------------------------------------
//Die truly
IfKilled
  tmpargument = 0
  SendMessageNear
  
  //Bloody death
  tmpargument = 0
  tmpdistance = 0
  tmpx = selfx
  tmpy = selfy
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  GoPoof
  
//------------------------------------------------------------------------------
//Figure out how often we have split and change size accordingly
IfSpawned  
  tmpargument = 0
  IfContentIs
    DoNothing
  Else
    SetTargetToSelf
    
    tmpargument = 1
    IfContentIs
      tmpargument = 75
      SetTargetSize
    
    tmpargument = 2
    IfContentIs
      tmpargument = 60
      SetTargetSize
      
    tmpargument = 3
    IfContentIs
      tmpargument = 40
      SetTargetSize
    
    tmpargument = -targetmaxlife > selfcontent
    GiveLifeToTarget
    
//------------------------------------------------------------------------------
IfAttacked
  SetTargetToWhoeverAttacked
  tmpargument = 0
  PlaySound
  
  //Make up to three children!
  tmpx = selfcontent
  tmpy = 3
  IfXIsLessThanY
    tmpdistance = 0
    tmpturn = 0
    GetDamageType
    tmpx = tmpargument
    tmpy = DAMAGESLASH
    IfXIsEqualToY
      tmpdistance = 1
    tmpy = DAMAGEPOKE
    IfXIsEqualToY
      tmpdistance = 1
 
    //Split if they do the correct type of damage
    IfDistanceIsMoreThanTurn 
      tmpargument = selfcontent + 1
      SetContent
      
      //Reduce our size
      SetTargetToSelf
      tmpargument = 75
      SetTargetSize

      //And our child
      tmpx = selfx
      tmpy = selfy
      tmpturn = selfturn
      tmpdistance = 0
      SpawnCharacter

      tmpargument = selfcontent
      SetChildContent

      //Halve our max life
      SetTargetToSelf
      tmpargument = -targetmaxlife > 1
      GiveLifeToTarget

      //Halve the life for the child as well
      SetTargetToChild
      tmpargument = -selflife > 1
      GiveLifeToTarget

//------------------------------------------------------------------------------
//Move around
IfTimeOut
  tmpargument = 40
  SetTime
  
  SetTargetToWideEnemy
    tmpx = targetx
    tmpy = targety
    tmpdistance = 600
    tmpturn = rand % 16360 + targetturnto - 8190
    Compass
    ClearWaypoints
    AddWaypoint
  Else  
    tmpx = rand & 511 + selfx - 256
    tmpy = rand & 511 + selfy - 256
    ClearWaypoints
    AddWaypoint

//------------------------------------------------------------------------------
//Deal damage or scuttle
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpturn = rand % 3 - selfcontent
      tmpargument = tmpturn * 256 + 512
      DamageTarget
      
      //Look alive!
      tmpargument = ACTIONME
      DoAction
      
      /Acid sizzle
      tmpargument = 1
      PlaySound
  Else
    //Scuttle around
    tmpx = rand & 511 + targetx - 256
    tmpy = rand & 511 + targety - 256
    ClearWaypoints
    AddWaypoint
  
//------------------------------------------------------------------------------
End					// Finished with this character
//------------------------------------------------------------------------------
