// Check for a kill order
IfOrdered
  tmpx = selforder
  tmpy = [UNDO]
  IfXIsEqualToY
    UndoEnchant


//------------------------------------------------------------------------------
// Undead are sustained by magic
IfSpawned
  EnchantTarget // target is self...
  Walk


//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  tmpargument = MESSAGEDEATH
  IfTargetIsOnSameTeam
    tmpargument = MESSAGEFRAG
    IfTargetIsSelf
      tmpargument = MESSAGEACCIDENT
  SendMessageNear

  // Drop goodies
  tmpargument = 65535
  DropMoney

  // Respawn the team
//  tmpx = selfmorale
//  tmpy = 1
//  IfXIsLessThanY
//    CleanUp

  // Make the character body
  tmpargument = 45
  SetBumpHeight



//------------------------------------------------------------------------------
// ZZ> For helper AIs
IfLeaderKilled
  BecomeLeader



//------------------------------------------------------------------------------
// ZZ> Respawn the character
//IfCleaned
//  DropWeapons
//  SpawnPoof
//  RespawnCharacter
//  BecomeLeader


IfTimeOut
  tmpx = rand & 255
  tmpy = 235
  IfXIsMoreThanY
    tmpargument = tmpx & 1 + 2
    tmpdistance = rand & 2047 + 10000
    PlaySound
    // Randomize the frames...
    tmpargument = tmpx & 1 + LATCHLEFT
    PressLatchButton
  SetTargetToNearbyEnemy
    tmpx = targetdistance
    tmpy = 110
    IfXIsLessThanY
      IfFacingTarget
        tmpargument = rand & 1 + LATCHLEFT
        PressLatchButton
    tmpargument = 20
    SetTime
    tmpx = targetx
    tmpy = targety
    tmpdistance = 200
    tmpturn = targetturnto
    Compass
  Else
    tmpargument = rand & 31 + 120
    SetTime
    tmpx = rand & 1023 - 512 + selfspawnx
    tmpy = rand & 1023 - 512 + selfspawny
  ClearWaypoints
  AddWaypoint
IfAtLastWaypoint
  tmpargument = 0
  SetTime


//------------------------------------------------------------------------------
// ZZ> Handle being attacked by blocking or countering or running away
IfAttacked
  // Image changes with damage

  // Chase the attacker
  SetTargetToWhoeverAttacked
  IfTargetIsOnHatedTeam
    tmpx = targetx
    tmpy = targety
    tmpdistance = 200
    tmpturn = targetturnto
    Compass
    ClearWaypoints
    AddWaypoint
    tmpargument = 30
    SetTime


//------------------------------------------------------------------------------
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = rand & 1 + LATCHLEFT
      PressLatchButton
    Else
      tmpx = targetx
      tmpy = targety
      tmpdistance = 200
      tmpturn = targetturnto
      Compass
      ClearWaypoints
      AddWaypoint
      tmpargument = 30
      SetTime
  Else
    tmpargument = 0
    SetTime
    SetTargetToOldTarget


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