//------------------------------------------------------------------------------
// Setup character
IfSpawned
  Walk
  BecomeLeader		//Bossy guy eh?

  //Sustained by magic
  SetTargetToSelf
  EnchantTarget

//------------------------------------------------------------------------------
//New round
IfTimeOut
  tmpargument = 25
  SetTime

  SetTargetToWideEnemy
    tmpx = targetdistance
    tmpy = 128*3
    IfXIsMoreThanY
      tmpargument = STATECHARGE
    Else
      tmpargument = STATECOMBAT
    SetState
  
  IfStateIsCharge
    Run							//Random approach
    tmpx = rand % 512 + targetx - 256
    tmpy = rand % 512 + targety - 256
    tmpdistance = rand % 550 - 100
    tmpturn = rand % 12000 + targetturnto - 6000
    Compass
    ClearWaypoints
    AddWaypoint
    tmpargument = 75
    SetTime

  IfStateIsCombat
    Walk
    tmpx = targetx				//Cling to enemy and try to hit
    tmpy = targety
    tmpdistance = 500
    tmpturn = targetturnto
    Compass
    ClearWaypoints
    AddWaypoint
  
    tmpx = targetdistance			//Attack stuff
    tmpy = 200
    IfXIsLessThanY
      IfFacingTarget
        IfTargetIsOnHatedTeam
          tmpargument = LATCHRIGHT
          PressLatchButton

  //Return to spawn when enemy is killed
  IfStateIsRetreat
    SetTargetToNearbyEnemy
      tmpargument = STATECHARGE
      SetState
    Else
      tmpx = selfspawnx
      tmpy = selfspawny
      ClearWaypoints
      AddWaypoint
      tmpargument = 250
      SetTime

//------------------------------------------------------------------------------
//Run away if hit enemy and then prepare to reapproach
IfScoredAHit
  Run
  tmpx = targetx
  tmpy = targety
  tmpdistance = rand % 2400 - 1200
  tmpturn = rand
  Compass
  ClearWaypoints
  AddWaypoint
  tmpargument = 90
  SetTime

//------------------------------------------------------------------------------
//Return to start
IfTargetKilled
  tmpargument = STATERETREAT
  SetState

//------------------------------------------------------------------------------
//Someone is mean!
IfAttacked
  SetTargetToWhoeverAttacked
  tmpargument = STATECOMBAT
  SetState
  
//------------------------------------------------------------------------------
//Spawn burning footsteps
tmpx = selfcontent
tmpy = 6			//Step timer/space between steps
IfXIsMoreThanY
  tmpx = selfaccel
  tmpy = 15			//Only if moving
  IfXIsMoreThanY
    tmpargument = 3
    IfStateIsNot		//Don't do if not in combat
      tmpargument = 4
      tmpx = selfx
      tmpy = selfy
      tmpdistance = selfz
      SpawnExactParticle	//Create the step
    tmpargument = 0
    SetContent			//Reset step timer
Else
  tmpargument = tmpargument +1
  SetContent			//Increase step timer by 1

//------------------------------------------------------------------------------
//Do victory stuff and drop loot
IfKilled
  tmpargument = selfmoney
  DropMoney
  DropItems
  DropKeys
  tmpargument = 0		//Tell them what happened
  SendMessageNear

  tmpargument = 50		//award some quest xp
  tmpdistance = EXPQUEST
  GiveExperienceToGoodTeam

  //Death cry
  tmpargument = 3
  PlaySound

  //Make the body
  tmpargument = 15
  SetBumpHeight
  
  //Spawn the portal to the first level of the abyss!
  tmpargument = 101
  tmpx = selfspawnx
  tmpy = selfspawny
  tmpdistance = selfz
  SpawnExactCharacterXYZ
  
//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
