//Tactics: Wait until enemy show up, when he does, always follow it until it is
//defeated

//Randomize ghost skin
IfSpawned
  tmpargument = rand % 4
  ChangeArmor

//This makes ghosts fly up and down
tmpx = targetz
tmpy = selfz
IfXIsMoreThanY
  IfTargetIsOnHatedTeam
    tmpargument = rand & 30 - 15 + targetz
    SetFlyHeight
Else
  tmpargument = 38
  SetFlyHeight		//Reset to normal

//------------------------------------------------------------------------------
//New round
IfTimeOut
  tmpargument = rand & 20 +  32
  SetTime				//Redo timer

  tmpx = rand & 100			//Moaning sound?
  tmpy = rand & 1
  IfXIsLessThanY
    tmpargument = 3
    IfContentIs			//Dont if timer is short becuase
      tmpargument = rand % 5 + 3		//of attacking
      tmpdistance = rand & 4000 + 6000
      PlaySound
    Else
      GetContent			
      tmpx = tmpargument
      tmpy = 3
      IfXIsLessThanY
        tmpargument = 3
        SetContent


  //Dorment
  IfStateIs0			
    SetTargetToWideEnemy
      tmpx = targetx
      tmpy = targety
      tmpargument = 1
      IfTargetIsAlive
        SetState
        tmpx = selfspawnx
        tmpy = selfspawny
    Else
      tmpx = selfspawnx
      tmpy = selfspawny
    ClearWaypoints
    AddWaypoint

  //Hunting
  IfStateIs1
    tmpx = targetx
    tmpy = targety			//Move towards enemy
    ClearWaypoints
    AddWaypoint
    tmpx = rand & 100			//Sometimes charge instead
    tmpy = 10				//10%
    IfXIsLessThanY
      tmpargument = 100				//charges are fast
      SetSpeedPercent
      tmpx = targetx
      tmpy = targety
      tmpturn = targetturnto
      tmpdistance = 700
      ClearWaypoints
      AddWaypoint

    //Dont flock
    SetOldTarget			//Remember enemy
    SetTargetToNearestFriend
    tmpx = targetdistance
    tmpy = 90
    IfXIsLessThanY			//To close to friend?
      tmpx = rand & 500 + targetx - 250
      tmpy = rand & 500 + targety - 250
      SetTargetToOldTarget		//Enemy
      tmpturn = targetturnto
      tmpdistance = rand & 1000
      Compass
      ClearWaypoints
      AddWaypoint			//Move randomly away from him
      tmpargument = rand & 30 + 30
      SetTime
    Else
      SetTargetToOldTarget		//Set target back to enemy

//Attack enemy
IfStateIs1
  IfTargetIsOnHatedTeam
    tmpx = targetdistance		//Close enough?
    tmpy = 150
    IfXIsLessThanY
      tmpargument = rand % 2		//Randomize attack left or right hand
      SetContent
      tmpargument = 1
      IfContentIs			//Attack right
        tmpargument = LATCHRIGHT
      Else				//Attack left
        tmpargument = LATCHLEFT
      IfTargetIsAlive
        PressLatchButton
      tmpargument = 0
      SetTime


//------------------------------------------------------------------------------
//Hit by silver
IfHitVulnerable
  tmpargument = rand & 1280 + 1024	//4-9 damage
  tmpdistance = DAMAGEHOLY
  SetTargetToSelf
  DamageTarget
  tmpargument = 9
  tmpdistance = rand & 8000 + 11000
  PlaySound			//Special feared sound
  tmpargument = 3
  SendMessageNear

//------------------------------------------------------------------------------
//Return to dorment state when enemy is defeated
IfTargetIsAlive
  DoNothing
Else
  tmpargument = 0
  SetState

//------------------------------------------------------------------------------
//Holy damage makes ghosts scared
IfAttacked
  GetDamageType
  tmpy = tmpargument
  tmpx = DAMAGEHOLY
  IfXIsEqualToY
    tmpx = targetx
    tmpy = targety
    tmpturn = targetturnto + 36780		//TargetTurnAway
    tmpdistance = 12000
    Compass
    ClearWaypoints
    AddWaypoint
    tmpargument = rand & 80 + 50
    SetTime
    tmpargument = 9
    tmpdistance = rand & 8000 + 11000
    PlaySound			//Special feared sound
    tmpargument = 3
    SendMessageNear
  Else						//Normal ouch
    tmpargument = rand & 1
    tmpdistance = rand & 8000 + 11000
    PlaySound			//Ouch sound

//------------------------------------------------------------------------------
//Death stuff
IfKilled
  tmpargument = 2
  tmpdistance = rand & 8000 + 11000
  PlaySound			//death sound
  tmpargument = 0
  IfTargetIsOnSameTeam
    tmpargument = 1
  SendMessageNear
  tmpargument = 4
  SpawnPoof
  tmpargument = 2
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  SpawnExactParticle
  GoPoof

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