//------------------------------------------------------------------------------
// This function makes the character recognize a master
IfSpawned
  MakeCrushValid
  SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      SetOwnerToTarget
      JoinTargetTeam
      MakeNameKnown
      
//------------------------------------------------------------------------------
IfDropped
  UnkeepAction
            
//------------------------------------------------------------------------------
//Say hello
IfGrabbed
  MakeCrushInvalid
  IfNameIsKnown
    SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      SetOldTarget
      SetTargetToOwner
      IfTargetIsOldTarget
        tmpargument = 5             //ello' boss
      Else
        tmpargument = 6             //You're not the boss!
      SendMessageNear
  Else
    SetTargetToWhoeverIsHolding     //New boss =)
    IfTargetIsAPlayer
      SetOwnerToTarget
      JoinTargetTeam
      MakeNameKnown
      tmpargument = 3
      SendMessageNear
      tmpargument = 4
      SendMessageNear

//------------------------------------------------------------------------------
//Display stats
IfUsed
  SetTargetToWhoeverIsHolding
  tmpargument = 25
  SetTargetReloadTime
  IfTargetIsAPlayer
    // =name=
    SetTargetToSelf
    tmpargument = 7
    SendMessageNear

    // Level
    tmpx = targetlevel
    tmpy = 3
    IfXIsMoreThanY
      tmpx = 3
    tmpargument = 8 + tmpx
    tmpx = targetlevel              //To display levels above 3 properly
    SendMessageNear

    // Stats
    tmpx = targetlife > 9
    tmpy = 2
    IfXIsMoreThanY
      tmpx = 3
    tmpargument = 12 + tmpx
    tmpx = selfstr > 8
    tmpy = selfwis > 8
    SendMessageNear

    // Stats
    tmpx = selfint > 8
    tmpy = selfdex > 8
    tmpdistance = targetexp
    tmpargument = 16
    SendMessageNear
    
//------------------------------------------------------------------------------
//Tell others its healed
IfHealed
  tmpargument = 17
  SendMessageNear
  
//------------------------------------------------------------------------------
//Respawn
IfCleanedUp				
  IfTargetIsAlive			  // Make sure killer is away
    tmpx = 1100				    //
    tmpy = targetdistance		    //
    IfXIsLessThanY			    //
      RespawnCharacter			      //
  Else					  // Killer is far away
    RespawnCharacter			    //
    
//------------------------------------------------------------------------------
//Mooshed in a passage
IfCrushed
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  tmpargument = 4
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  GoPoof
  tmpargument = 2
  SendMessageNear

//------------------------------------------------------------------------------
//Handle death stuff
IfKilled
  SetTargetToWhoeverAttacked
  IfNameIsKnown
    SetOldTarget
    SetTargetToOwner
    IfTargetIsAlive
      tmpargument = 0
      SendMessageNear
    SetTargetToOldTarget
  Else
    tmpargument = 1
    SendMessageNear

  //Unbumpable body
  tmpargument = 0
  SetBumpHeight
  SetBumpSize

  //Death sound
  tmpargument = 0
  PlaySound

//------------------------------------------------------------------------------
//What to do if bumped
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    tmpargument = rand & 75 + 74
    SetTime
    tmpx = rand & 1500 + targetx - 750
    tmpy = rand & 1500 + targety - 750
    ClearWaypoints
    AddWaypoint

    //Bite the enemy				//Must look at him
    IfTargetIsAlive				//Cant attack dead ones
      tmpargument = rand & 255 + selfstr
      tmpdistance = DAMAGEPOKE
      DamageTarget
        SetOldTarget
        SetTargetToOwner
        tmpargument = 1+selflevel*64
        HealTarget
        SetTargetToOldTarget      //Lifesteal goes to the boss

  //Move out of way of friends
  IfTargetIsOnSameTeam
    tmpx = rand & 511 - 256 + targetx
    tmpy = rand & 511 - 256 + targety 
    ClearWaypoints
    AddWaypoint
    SetTargetToOldTarget
    tmpargument = rand % 20 + 20
    SetTime

//------------------------------------------------------------------------------
//What to do each round
IfTimeOut
  tmpargument = rand & 15 + 40
  SetTime
  
  IfHeld
    DoNothing
  Else
    tmpx = ownerdistance
    tmpy = 1000
    IfXIsLessThanY
      SetTargetToWideEnemy				//Locate enemy
        tmpx = targetx
        tmpy = targety
        tmpturn = rand & 4095 - 2048 + targetturnto
        tmpdistance = 700
        Compass
      Else						//No enemies, flock around boss
        tmpx = rand & 1500 + ownerx - 750
        tmpy = rand & 1500 + ownery - 750
    Else
      tmpx = rand & 1500 + ownerx - 750
      tmpy = rand & 1500 + ownery - 750
    tmpargument = 100				//Bats are fast
    SetSpeedPercent
    ClearWaypoints
    AddWaypoint

    //Random growl sound
    tmpx = rand & 511
    tmpy = 5
    IfXIsLessThanY
      tmpargument = 4
      PlaySound

//------------------------------------------------------------------------------
End					// Finished with this character
//------------------------------------------------------------------------------