//------------------------------------------------------------------------------
//STATUE AI
IfSpawned
  tmpargument = 1
  ChangeArmor
  KeepAction
  tmpx = selfspawnx
  tmpy = selfspawny
  ClearWaypoints
  AddWaypoint
  tmpargument = 0
  SetFlyHeight

//------------------------------------------------------------------------------
//BOSS AI
tmpargument = 1
IfArmorIs
  IfOrdered
    tmpx = [DKNI]           //Become alive?
    tmpy = selforder
    IfXIsEqualToY
      tmpargument = 0
      ChangeArmor
      UnkeepAction
      tmpargument = 20
      SetFlyHeight
      SetTargetToSelf
      EnchantTarget  // Enchant self...

      // Darkknight has a dyna light particle
      tmpargument = 2
      tmpdistance = SPAWNORIGIN
      SpawnAttachedParticle

Else
  IfTargetKilled
    tmpdistance = 128*10
    SetTargetToDistantEnemy
      tmpargument = 1
      SetState
    Else
      tmpargument = 0
      SetState


  //------------------------------------------------------------------------------
  // ZZ> Handle death by sending a message and other stuff
  IfKilled
    tmpargument = 2
    PlaySound

    //Get rid of the darkness
    DisaffirmCharacter

    // Drop goodies
    tmpargument = selfmoney
    DropMoney
    DropKeys


    tmpargument = 0
    SendMessageNear


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

    //Tell the dracolich we are dead
    tmpargument = [BDIE]
    IssueOrder


  //------------------------------------------------------------------------------
  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
      SetTargetToSelf
      tmpdistance = 128*10
      SetTargetToDistantEnemy
        tmpargument = rand & 15 + 50
        SetTime
        Run
        SetTurnModeToVelocity
        tmpx = targetx
        tmpy = targety
        tmpargument = 4
        SetState
      Else
        Stop
        tmpx = selfx
        tmpy = selfy
        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
      IfTargetIsOnHatedTeam
        tmpx = targetdistance
      Else
        tmpx = 1500
      tmpy = 1400
      IfXIsMoreThanY
        // Find a new enemy
        tmpdistance = 128*10
        SetTargetToDistantEnemy
          DoNothing
        Else
          tmpargument = 0
          SetState
        tmpargument = 5
        SetTime
      Else
        // Charge the enemy
        tmpx = targetx
        tmpy = targety
        tmpturn = targetturnto
        tmpdistance = 200
        Compass
        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
    PlaySound

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