//selfstate is rage counter
//If content = 1 then rage is active

//Announce the beast has arrived
IfSpawned
  SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      SetOwnerToTarget
      JoinTargetTeam
      MakeNameKnown
  IfNameIsKnown
    DoNothing
  Else
    tmpargument = 16
    SendMessage
    tmpargument = 5
    PlayFullSound
    JoinNullTeam
    
//Say ouch
IfAttacked
  tmpargument = 3
  PlaySound
  SetTargetToWhoeverAttacked
  
//Say hello
IfGrabbed
  IfNameIsKnown
    SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      SetOldTarget
      SetTargetToOwner
      IfTargetIsOldTarget
        tmpargument = 10
      Else
        tmpargument = 9
      SendMessageNear
  Else
    SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      SetOwnerToTarget
      JoinTargetTeam
      MakeNameKnown
      tmpargument = 12
      SendMessageNear
      tmpargument = 13
      SendMessageNear
      
  //Lose all rage
  tmpargument = 0
  SetState
  UndoEnchant
  tmpargument = 0
  SetContent

//Let the player know what this is
IfTakenOut
  SetTargetToWhoeverIsHolding
    IfTargetIsAPlayer
      tmpargument = 11
      SendMessageNear 

//Display stats or make crunch noise
IfUsed
  SetTargetToWhoeverIsHolding
    tmpargument = 50
    SetTargetReloadTime
    
  IfTargetIsAPlayer
    // Print =NAME=
    SetTargetToSelf
    tmpargument = 1
    SendMessageNear      

    // Level
    tmpx = targetlevel+1
    tmpargument = 2
    SendMessageNear

    // Physical Stats
    tmpx = targetlife > 9
    tmpy = 2
    IfXIsMoreThanY
      tmpx = 3
    tmpargument = 4 + tmpx
    tmpx = selfstr > 8
    tmpy = selfwis > 8
    SendMessageNear

    // Mental Stats
    tmpdistance = targetexp
    tmpx = targetint > 8
    tmpy = targetwis > 8
    tmpargument = 8
    SendMessageNear

//Ressurection
IfCleanedUp				
  IfTargetIsAlive			  
    tmpx = 1100				  
    tmpy = targetdistance		 
    IfXIsLessThanY			 
      RespawnCharacter			     
  Else					 
    RespawnCharacter	

//Goodbye!
IfDropped
  SetTargetToWhoeverIsHolding
  IfTargetIsAPlayer
    tmpargument = 3
    SendMessageNear
    
  //Prepeare for roaming around!
  SetTargetToSelf
  StopTargetMovement
  UnkeepAction
  

//Death stuff
IfKilled			
  tmpargument = 0
  SendMessageNear
  tmpargument = 30			 
  SetBumpHeight
  
  //Death sound
  tmpargument = 2
  PlaySound
  
//Get out of the way
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnSameTeam  
    tmpx = rand & 1023 + targetx - 512
    tmpy = rand & 1023 + targety - 512
    ClearWaypoints
    AddWaypoint

//Main AI loop
IfTimeOut

  //Baah!			
  tmpx = rand & 63
  tmpy = 0
  IfXIsEqualToY                  
    tmpargument = rand & 1
    PlaySound
  
  tmpargument = 1
  IfContentIs
    tmpargument = 12        //Double reaction in rage
    SetTime
  Else
    tmpargument = 25
    SetTime
    
  //Reduce rage
  tmpx = selfstate
  tmpy = 0
  IfXIsMoreThanY
    tmpargument = selfstate - 1
    SetState
  
  //Become enraged!
  tmpx = selfstate
  tmpy = 11                     //Rage treshold
  IfXIsMoreThanY
    tmpargument = 0
    IfContentIs
      SetTargetToSelf
      EnchantTarget
      tmpargument = 5
      PlaySound
      tmpargument = 14
      SendMessageNear
      tmpargument = 1
      SetContent
  Else
    UndoEnchant
    tmpargument = 0
    SetContent

  IfHeld
    DoNothing
  Else
    SetTargetToOwner
    IfTargetIsSelf                              //No owner yet, wander
      tmpx = rand & 1023 - 512 + selfspawnx
      tmpy = rand & 1023 - 512 + selfspawny
    Else
      tmpargument = 0
      IfContentIs
        SetTargetToNearbyEnemy              //Act normally
      Else
        SetTargetToWideEnemy                //In rage more agressive
      IfTargetIsOnHatedTeam
        tmpx = targetdistance
        tmpy = 150
        IfXIsLessThanY
          IfFacingTarget
            tmpargument = ACTIONUA              //Bite
            DoAction
            tmpargument = rand & selfstr > 1
            DamageTarget
            tmpargument = selfstate + 5         //3 bites in a row should do the trick
            SetState                           //Build some rage
            tmpargument = 4
            PlaySound
            tmpargument = 1
            tmpx = targetx
            tmpy = targety
            tmpdistance = targetz
            SpawnExactParticle
            
        //Move towards the prey
        tmpx = targetx
        tmpy = targety
        tmpturn = targetturnto
        tmpdistance = 800
        Compass
      Else                          //No enemies, follow
        tmpx = ownerx
        tmpy = ownery
        tmpargument = 1
        IfContentIs
          tmpdistance = 600
          tmpturn = targetturnto
          Compass
    ClearWaypoints			
    AddWaypoint		
		
End					
