//------------------------------------------------------------------------------
// Jump over barriers, onto mounts
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsAlive
    IfTargetIsAPlatform
      // Jump over some stuff
      tmpargument = LATCHJUMP
      PressLatchButton
    IfTargetIsAMount
      // Jump onto mounts
      tmpx = targetx
      tmpy = targety
      ClearWaypoints
      AddWaypoint
      tmpargument = 30
      SetTime
  Else
    // Jump over corpses
    tmpargument = LATCHJUMP
    PressLatchButton
  SetTargetToOldTarget

//------------------------------------------------------------------------------
IfKilled
  // Tell the players
    tmpargument = 0
    IfTargetIsOnSameTeam
      tmpargument = 1
    SendMessage
    
  // Give bonus points
  tmpargument = 90
  tmpdistance = EXPQUEST
  GiveExperienceToGoodTeam

  //Death cry
  tmpargument = 1
  PlaySound

  // Drop goodies
  tmpargument = selfmoney
  DropMoney
  DropItems
  DropKeys
  
  // Make the character body
  tmpargument = 40
  SetBumpHeight
  
  //Win the module
  tmpargument = [BEAT]
  AddIDSZ
  BeatModule
  EnableExport
  tmpargument = [COBO]
  tmpdistance = 1
  AddQuestAllPlayers
  
  //Victory tune
  tmpargument = 14
  PlayMusic
  
  //End text
  ClearEndMessage
  tmpargument = 6
  AddEndMessage
  tmpargument = 7
  AddEndMessage
  tmpargument = 8
  AddEndMessage
  tmpargument = 9
  AddEndMessage

//------------------------------------------------------------------------------
IfAttacked
  SetTargetToWhoeverAttacked
    IfTargetIsOnHatedTeam

      // Check for backstab
      IfBackstabbed
        // Allow Rogues to backstab 
        tmpargument = 3
        SendMessageNear

        //Some bonus xp
        tmpargument = 20
        tmpdistance = EXPMURDER
        GiveExperienceToTarget

        // extra damage (every 4 dex gives +1 damage)
        tmpargument = targetdex > 3
        SetTargetToSelf
        DamageTarget
    Else
      // Friendly fire, get out of the way
      tmpx = rand & 511 - 256 + selfx
      tmpy = rand & 511 - 256 + selfy
      ClearWaypoints
      AddWaypoint
      SetTargetToOldTarget

    // Tell everyone to charge
    CallForHelp

    //Ouch
    tmpargument = rand & 1 + 2
    PlaySound
    
    tmpargument = selfcontent + 12
    SetContent

//------------------------------------------------------------------------------
//Increase rage
IfScoredAHit
  tmpargument = selfcontent + 16
  SetContent
  
  //Go in berserker mode?
  tmpargument = 2
  IfStateIsNot
    tmpx = selfcontent
    tmpy = 50            //Need 50 rage points to engage
    IfXIsMoreThanY
      tmpargument = 2
      SetState
      SetTargetToSelf
      SetOwnerToTarget
      EnchantTarget
      SetTargetToWhoeverWasHit
      tmpargument = 5
      SendMessageNear
      PlaySound

//------------------------------------------------------------------------------
IfTimeOut
  tmpargument = rand & 7 + 10
  SetTime
 
  //Reduce rage
  tmpx = selfcontent
  tmpy = 0
  IfXIsMoreThanY
    tmpargument = selfcontent - 1
    SetContent
  Else
    IfStateIs2
      UndoEnchant
      tmpargument = 1
      SetState

  //Throne sitter
  IfStateIs0
    SetTurnModeToVelocity
    tmpx = selfspawnx
    tmpy = selfspawny
    ClearWaypoints
    AddWaypoint
    tmpdistance = 128*12          //Look at enemy
    SetTargetToDistantEnemy
      SetTurnModeToWatchTarget
      tmpx = targetdistance
      tmpy = 128*6
      IfXIsLessThanY
        tmpy = 128*3
        IfXIsLessThanY
          tmpargument = 1   //Charge!
          SetState
        CallForHelp     //Order guards to charge
       
  //Charge!
  IfStateIs1
    SetTurnModeToVelocity
    SetTargetToWideEnemy
      tmpx = targetx
      tmpy = targety
      tmpdistance = 500
      tmpturn = targetturnto
      Compass
      ClearWaypoints
      AddWaypoint
    Else
      tmpargument = 0
      SetState
      
  //Rage!
  IfStateIs2
    tmpdistance = 128*12
    SetTargetToDistantEnemy         //Long aggro range
      SetTurnModeToWatchTarget
      tmpx = targetx
      tmpy = targety
      tmpdistance = 1500
      tmpturn = targetturnto
      Compass
    Else
      tmpargument = selfcontent - 5     //Drain away fast if nothing to attack
      SetContent
      tmpx = rand & 1023 + selfx - 512
      tmpy = rand & 1023 + selfy - 512
    ClearWaypoints
    AddWaypoint
      
  //Make him a trigger happy fiend
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpx = targetdistance
      tmpy = 210
      IfXIsLessThanY
        IfHoldingMeleeWeapon
          tmpx = selfstate*10     //Double attack rage in berserk
          tmpy = rand % 35
          IfXIsMoreThanY
            tmpargument = ACTIONBC
            DoAction
          //PressLatchButton        //BUG!! DOESNT WORK?!
       
//------------------------------------------------------------------------------
//healing... only good for removing rage
IfHealed
  tmpargument = 2
  SendMessageNear
  
  //Remove rage
  tmpargument = 0
  SetContent
  UndoEnchant
  tmpargument = 1
  SetState
//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
