//Set correct wing collor
IfSpawned
  SetTargetToRider
  tmpargument = 1
  IfArmorIs
    ChangeTargetArmor
  tmpargument = 2
  IfArmorIs
    ChangeTargetArmor

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

  // Drop goodies
  tmpargument = 65535
  DropMoney

  // 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

//------------------------------------------------------------------------------
//Enemy target has been defeated
IfTargetKilled
  SetTargetToNearestEnemy
    tmpargument = 1 //Follow
    SetState
  Else
    tmpargument = 0 //Guard
    SetState

//------------------------------------------------------------------------------
IfTimeOut

  //Guard in a circle
  IfStateIs0
    tmpargument = 20
    SetTime    
    SetTargetToNearbyEnemy	//Enemy found, target him
      tmpargument = 1 
      SetState 		//and charge
    Else			//Circle around
      Run
      SetTurnModeToWatch
      tmpx = selfx
      tmpy = selfy
      tmpturn = selfturn + 6192
      tmpdistance = 200
      Compass
      ClearWaypoints
      AddWaypoint		       

  //Move towards enemy
  IfStateIs1
    SetTurnModeToVelocity
    tmpx = targetdistance
    tmpy = 250
    IfXIsLessThanY
      tmpargument = 2
      SetState		//Melee
      tmpargument = 5
      SetTime
    Else				//Move towards enemy in a
      tmpx = rand & 340 + targetx - 170	//random direction pattern
      tmpy = rand & 340 + targety - 170
      tmpturn = targetturnto
      tmpdistance = 500
      Compass
      ClearWaypoints
      AddWaypoint
      tmpargument = 35
      SetTime
  SetTargetToWideEnemy	//Enemy to far away?
    DoNothing		//Nope
  Else
    tmpargument = 0 		//Yep return to guarding
    SetState    
    tmpargument = 20
    SetTime

  //Combat
  IfStateIs2
    tmpx = targetdistance
    tmpy = 120
    IfXIsLessThanY             // Close enough to swing...
      IfFacingTarget            // If he is facing his enemy
        tmpargument = LATCHRIGHT
        PressLatchButton
        tmpargument = 15
        SetTime

    //Enemy to far away?
    tmpx = targetdistance
    tmpy = 250
    IfXIsMoreThanY    
       tmpargument = 1 		//Retry attack position
       SetState    
       tmpargument = 0
       SetTime

    //Move directly towards target
    tmpx = targetx
    tmpy = targety
    ClearWaypoints
    AddWaypoint

  //Dont flock
  SetOldTarget			//Remember enemy
  SetTargetToNearestFriend
  tmpx = targetdistance
  tmpy = 150
  IfXIsLessThanY			//To close to friend?
    tmpx = rand & 500 + targetx - 250
    tmpy = rand & 500 + targety - 250
    SetTargetToOldTarget		//Enemy
    tmpturn = targetturnto
    tmpdistance = rand & 1000
    Compass
    ClearWaypoints
    AddWaypoint			//Move randomly away from him
    tmpargument = rand & 30 + 30
    SetTime
  Else
    SetTargetToOldTarget		//Set target back to enemy

//------------------------------------------------------------------------------
//Handle being attacked by countering
IfAttacked
  SetTargetToWhoeverAttacked
  IfTargetIsOnHatedTeam
    Run
    IfStateIs0		//If not already, engage in combat
      tmpargument = 1
      SetState
    tmpargument = 2
    PlaySound		//Ouch sound
  Else
    SetTargetToOldTarget

//------------------------------------------------------------------------------
//Slash and bite (Okay forget the biting part)
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = LATCHRIGHT
      PressLatchButton
  Else
    SetTargetToOldTarget	//Oops, friendly xD

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