//---------------------------------------------------------
//Better fighting tactics
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsAMount
    tmpargument = LATCHJUMP
    PressLatchButton
    tmpargument = 1
    SetState
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = LATCHRIGHT
      PressLatchButton
    Else
      SetTargetToNearestEnemy
      tmpargument = 0
      SetTime
  Else
    SetTargetToOldTarget


IfAttacked
  SetTargetToWhoeverAttacked
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = LATCHRIGHT
      PressLatchButton
    Else
      tmpargument = 1 //Guard
      SetState  
  Else
    SetTargetToOldTarget

IfTargetIsAttacking
  IfHitFromFront
    IfTargetIsOnHatedTeam   
      IfFacingTarget
        tmpargument = [SHIE]
        IfHoldingItemID
          tmpargument = LATCHLEFT
          PressLatchButton

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


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


  // Drop goodies
  tmpargument = 65535
  DropMoney
  DropKeys
  DropItems



  // Make the character body
  tmpargument = 0
  SetBumpHeight

//------------------------------------------------------------------------------
IfTimeOut
  // Return to normal
  IfStateIs4
    tmpargument = 1
    SetState

  // Wait for the good guys to barge in...
  IfStateIs0
    tmpargument = 20
    SetTime
      SetTargetToWideEnemy
    IfTargetIsAPlayer
      tmpargument = rand & 15 + 8
      SetTime
      Run
      SetTurnModeToVelocity
      tmpx = targetx
      tmpy = targety
      tmpargument = 4
      SetState
    Else
      Run
      tmpx = rand & 255 + targetx - 128	    
      tmpy = rand & 255 + targety - 128	    
      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
        IfTargetIsOnHatedTeam
          PressLatchButton
          tmpargument = 3
          SetState
        Else
          SetTargetToOldTarget
    Else
      // Fall through to next...
      tmpargument = 1
      SetState

  // Rush the enemy
  IfStateIs1
    SetTurnModeToVelocity
    tmpx = targetdistance
    tmpy = 1400
    IfXIsMoreThanY
      // Find a new enemy
      SetTargetToNearbyEnemy
        tmpargument = 5
      Else
        tmpargument = 0
        SetState
        tmpargument = 5
      SetTime
    Else
      IfTargetIsOnHatedTeam
        // 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
  SetTargetToWhoeverAttacked
  IfTargetIsOnHatedTeam
    Run
    tmpargument = 1
    SetState
    SetTurnModeToVelocity
    tmpargument = 4
    PlaySound
  Else
    tmpargument = 3
    PlaySound   
    SetTargetToOldTarget 

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