//------------------------------------------------------------------------------
// ZZ> Most undead have an enchantment sustaining them
IfSpawned
  EnchantTarget  // Enchant self...


//------------------------------------------------------------------------------
IfTargetKilled
  SetTargetToNearestEnemy
    tmpargument = 1
    SetState
  Else
    tmpargument = 0
    SetState


//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  tmpargument = 2
  tmpdistance = rand & 2047 + 10000
  PlaySound


  // Drop goodies
  tmpargument = 65535
  DropMoney
  DropKeys


  // Boss stuff...
  tmpx = selfmorale
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 1
    OpenPassage
    ClearEndMessage
    tmpargument = 2
    AddEndMessage
    tmpargument = 3
    AddEndMessage
    tmpargument = 1
  Else
    tmpargument = 0
  SendMessageNear


  // Make the character body
  tmpargument = 0
  SetBumpHeight
  tmpargument = 0
  SetFlyHeight


//------------------------------------------------------------------------------
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnSameTeam
    tmpx = selfx
    tmpy = selfy
    tmpturn = targetturnto + 32768
    tmpdistance = 256
    Compass
    ClearWaypoints
    AddWaypoint
    SetTargetToOldTarget


//------------------------------------------------------------------------------
IfTimeOut
  // Return to normal
  IfStateIs4
    tmpargument = 1
    SetState
  // Wait for the good guys to barge in...
  IfStateIs0
    tmpargument = 20
    SetTime
    tmpargument = passage
    SetTargetToSelf
    SetTargetToWhoeverIsInPassage
      GetState
    Else
      SetTargetToWideEnemy
    IfTargetIsOnHatedTeam
      tmpargument = rand & 15 + 50
      SetTime
      Run
      SetTurnModeToVelocity
      tmpx = targetx
      tmpy = targety
      tmpargument = 4
      SetState
    Else
      Stop
      SetTurnModeToWatch
      tmpx = selfx
      tmpy = selfy + 200
      ClearWaypoints
      AddWaypoint
  // Follow through
  IfStateIs3
    tmpargument = rand & 31 + 90
    SetTime
    tmpargument = 4
    SetState
    tmpx = selfx
    tmpy = selfy
    tmpturn = selfturn
    tmpdistance = 200
    Compass
    ClearWaypoints
    AddWaypoint
  // Chop the enemy
  IfStateIs2
    tmpargument = rand & 31 + 30
    SetTime
    tmpx = targetdistance
    tmpy = 180
    IfXIsLessThanY
      // Close enough to swing...
      IfHoldingMeleeWeapon
        PressLatchButton
        tmpargument = 3
        SetState
    Else
      // Fall through to next...
      tmpargument = 1
      SetState
  // Rush the enemy
  IfStateIs1
    SetTurnModeToVelocity
    tmpx = targetdistance
    tmpy = 1400
    IfXIsMoreThanY
      // Find a new enemy
      SetTargetToNearestEnemy
        tmpargument = 5
      Else
        tmpargument = 0
        SetState
        tmpargument = 5
      SetTime
    Else
      // Charge the enemy
      tmpx = targetx
      tmpy = targety
      tmpturn = targetturnto
      tmpdistance = 200
      Compass
      SetOldTarget
      SetTargetToNearestFriend
        tmpdistance = 500 - targetdistance > 1
        tmpturn = targetturnto + 32768
        Compass
        SetTargetToOldTarget
      ClearWaypoints
      AddWaypoint
      tmpargument = 2
      SetState
      tmpargument = rand & 3 + 6
      SetTime



//------------------------------------------------------------------------------
// ZZ> Handle being attacked by blocking or countering or running away
IfAttacked
  Run
  tmpargument = 1
  SetState
  SetTurnModeToVelocity
  SetTargetToWhoeverAttacked
  tmpargument = rand & 1
  tmpdistance = rand & 2047 + 10000
  PlaySound



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