//The definition of the diffrent states:
//0: Follow master
//1: Combat

//Manage some flashy start things and set some values
IfSpawned
  JoinGoodTeam

//How often can it attack?
IfUsed
  tmpargument = 75
  SetReloadTime

IfKilled				// This reduces the height of the char
  tmpdistance = rand & 1023 + 11000
  tmpargument = 3
  PlaySound
  tmpargument = 0			  // Last words...
  SetState				  //
  SendMessageNear				  //
  GoPoof


IfAttacked				// Attacked
  SetTargetToWhoeverAttacked		  //
    IfTargetIsAlive			    //
      IfTargetIsOnHatedTeam		      // Go after 'em
        tmpargument = 1			        //
        SetState			        //  
        tmpdistance = rand & 2047 + 11000       // Ouch!
        tmpargument = 2
        PlaySound			        //
    Else				    //Attacker died already
      SetTargetToOldTarget		      //


IfTargetKilled				// Return to follow mode
  tmpargument = 0			  // State 0 ( Follow )
  SetState				  //


IfTimeOut				// This is done every so often
  SetTargetToNearbyEnemy		  // Look out for enemies
    tmpargument = 1			      //
    SetState				      // Change to combat mode
    tmpargument = selfhateid		      //
    IfTargetHasID			      // Battle cry versus hate group
      IfTargetIsOldTarget		        //
        tmpargument = 0			          // NOP
      Else				        //
        tmpargument = 2			          //
        SendMessageNear			          //
        tmpargument = 1			          //
        tmpdistance = rand & 2047 + 11000         //
        PlaySound			          //

  tmpargument = 0			  // Check state
  IfStateIs				  // State 0 ( Follow )
    tmpx = leaderx			    //
    tmpy = leadery			    //
    tmpturn = 16384 + leaderturn	    // Stand to side
    tmpdistance = 100			    //
    Compass				    //
  Else					  // State 1 ( Combat )
    tmpx = targetdistance		    // Close enough to attack?
    tmpy = 200				    //
    IfXIsLessThanY			    //
      tmpargument = LATCHRIGHT		      // Right Attack == 2
      PressLatchButton	
      tmpx = rand & 60
      tmpy = 0
      IfXIsEqualToY                //See if monster is charged up
        tmpargument = 0       //part0.txt
        tmpx = selfx            // x
        tmpy = selfy            // y
        tmpdistance = selfz     // z
        SpawnExactParticle      //Unleash the power!!
        tmpargument = 3
        SendMessageNear

    tmpx = targetdistance
    tmpy = 700
    IfXIsMoreThanY
      tmpargument = 0
      SetState
    tmpx = leaderdistance
    IfXIsMoreThanY
      tmpargument = 0
      SetState
    tmpx = targetx			    // Move towards enemy
    tmpy = targety			    //
    tmpturn = targetturnto		    //
    tmpdistance = 200			    //
    Compass				    //

  ClearWaypoints			  //
  AddWaypoint				  //
  tmpargument = rand&20			  // Try again later
  SetTime				  //

IfBumped				// Bumped
  SetTargetToWhoeverBumped		  //
  IfTargetIsOnHatedTeam			  // Try to counter
    tmpargument = LATCHRIGHT		    //
    PressLatchButton			    //
  Else					  // Get around other character
    tmpargument = 0			    // Return to follow state
    SetTargetToNearbyEnemy		    // Look out for enemies
      tmpargument = 1			      // Stay in combat state
    Else				    // Revert
      SetTargetToOldTarget		      //
    SetState				    //
    tmpx = rand&511+selfx-256		    //
    tmpy = rand&511+selfy-256		    //
    ClearWaypoints			    //
    AddWaypoint				    //
    tmpargument = 40			    // Try again soon
    SetTime				    //

//Spell effects
IfSpawned
  tmpargument = 0       //part0.txt
  tmpx = selfx            // x
  tmpy = selfy            // y
  tmpdistance = selfz     // z
  SpawnExactParticle      //Unleash the power!!
  SpawnExactParticle      //Unleash the power - twice!!
  tmpargument = 3
  PlaySound
  
End					// Finished with this character
