//-------------------------------------------------------------------------
//Scream and shout
IfAttacked
  SetTargetToWhoeverAttacked
  tmpargument = 2
  PlaySound

//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  // Spit out text
  tmpargument = 0
  IfTargetIsOnSameTeam
    tmpargument = 1
    IfTargetIsSelf
      tmpargument =3
  SendMessage

  // Drop goodies
  tmpargument = 65535
  DropMoney
  DropKeys

  // Make the character body
  tmpargument = 45
  SetBumpHeight

  // Stop flying
  tmpargument = 0
  SetFlyHeight

  //Sound
  tmpargument = 1
  PlaySound

  // Tell the wings to stop flappin'
  SetTargetToRider // The wings are on gripleft, so this works
  tmpargument = [DEAD]
  OrderTarget

//---------------------------------------------------------
//Attack the enemy if BUMPED
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = LATCHRIGHT
      PressLatchButton
    Else
      tmpargument = 2 //Guard
      SetState  
  Else
    SetTargetToOldTarget

//--------------------------------------------------------
//What to do if enemies are defeated
IfTargetKilled
  SetTargetToNearestEnemy
    tmpargument = 1
    SetState
  Else
    tmpargument = 0
    SetState

//------------------------------------------------------------------------------
IfTimeOut
  // Wait for the good guys to barge in...
  IfStateIs0
    tmpargument = 20
    SetTime
    SetTargetToNearbyEnemy
      tmpargument = 1
      SetState
    Else
      tmpargument = 20
      SetTime      

  // Follow through
  IfStateIs3
    tmpargument = rand & 31 + 90
    SetTime
    tmpargument = 1
    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...
      IfTargetIsOnHatedTeam
        IfHoldingMeleeWeapon
          PressLatchButton
          tmpargument = 3
          SetState
        Else
          tmpargument = 0
          SetState
          tmpargument = [SKEL]
          IfTargetHasID
            PressLatchButton
          SetTargetToWideEnemy
         
    Else
      // Fall through to next...
      tmpargument = 1
      SetState

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

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