//Different monster types determined by skin:
//0: Normal bat		(No special abillities)
//1: Vampyric bat	(Steals life)
//2: Undead bat		(Very tough, weak vs. holy)

//------------------------------------------------------------------------------
//Squeak if damaged
IfAttacked
  tmpargument = rand & 1 + 2		//Random ouch sound (sound 2 or 3)
  PlaySound
  GetDamageType
  tmpx = tmpargument
  tmpy = DAMAGEHOLY
  IfXIsEqualToY			//Holy damage is instant kill
    SetTargetToSelf
    KillTarget
    SetTargetToWhoeverAttacked
    tmpargument = 10		//Give some bonus xp
    tmpdistance = EXPREVENGE
    GiveExperienceToTarget
    tmpargument = 1		//Banishment sound
    PlaySound

//------------------------------------------------------------------------------
//Tell others its healed
IfHealed
  tmpargument = 2
  SendMessageNear

//------------------------------------------------------------------------------
//Handle death stuff
IfKilled
  SetTargetToWhoeverAttacked
  //Handle Messaging
  IfTargetIsOnSameTeam
    tmpargument = 1		//Killed self
  Else
    tmpargument = 0
    IfArmorIs
      tmpargument = 0		//Normal bat
    Else
      tmpargument = 1
      IfArmorIs
        tmpargument = 3		//Vampyric bat
      Else
        tmpargument = 4		//Killed normally
  SendMessageNear

  tmpargument = 1		//Bonus xp
  IfArmorIs
    tmpargument = 10
    GiveExperienceToTargetTeam

  tmpargument = 2		//Bonus xp
  IfArmorIs
    tmpargument = 25
    GiveExperienceToTargetTeam

  //Unbumpable body
  tmpargument = 0
  SetBumpHeight
  SetBumpSize
  
  //Crushable in passages now
  MakeCrushValid

  //Death sound
  tmpargument = 0
  PlaySound
  
//------------------------------------------------------------------------------
//Crush!
IfCrushed
  tmpargument = 6
  SendMessageNear
  GoPoof

//------------------------------------------------------------------------------
//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
    IfStateIs0
      IfTargetIsAlive				//Cant attack dead ones
        tmpargument = rand & 255 + 348		//1.50-2.50 damage
        tmpdistance = DAMAGEPOKE
        DamageTarget
        tmpargument = 1
        IfArmorIs
          tmpargument = rand & 127 + 64		//Heal 0.25 - 0.60 life
          SetTargetToSelf
          HealTarget
          SetTargetToOldTarget
        tmpargument = 1
        SetState                  //Don't loop biting

  //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

//------------------------------------------------------------------------------
//Leader stuff
IfLeaderKilled
  BecomeLeader
IfSpawned
  BecomeLeader		//Always have at least 1 leader

//------------------------------------------------------------------------------
//What to do each round
IfTimeOut
  tmpargument = rand & 15 + 40
  SetTime
  SetTargetToWideEnemy				//Locate enemy
    tmpx = targetx
    tmpy = targety
    tmpturn = rand & 4095 - 2048 + targetturnto
    tmpdistance = 700
    Compass
  Else						//No enemies, flock around leader
    SetTargetToSelf
    tmpx = rand % 1500 + selfspawnx - 750
    tmpy = rand % 1500 + selfspawny - 750
  tmpargument = 100				//Bats are fast
  SetSpeedPercent
  ClearWaypoints
  AddWaypoint

  //Random growl sound
  tmpx = rand % 900
  tmpy = 3
  IfXIsLessThanY
    tmpargument = 4
    PlaySound
  
  //Fly up and down towards enemies  
  tmpargument = 40
  IfTargetIsOnHatedTeam
    tmpx = targetz
    tmpy = selfz + 5
    IfXIsMoreThanY
      tmpargument = targetz + 5
  SetFlyHeight
    
  //Ready biting
  tmpargument = 0
  SetState

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