//------------------------------------------------------------------------------
//STATUE AI
IfSpawned
  tmpargument = 2
  ChangeArmor
  KeepAction
  tmpx = selfspawnx
  tmpy = selfspawny
  ClearWaypoints
  AddWaypoint
  tmpargument = 255
  SetLight

//------------------------------------------------------------------------------
//BOSS AI
tmpargument = 2
IfArmorIs
  IfOrdered
    tmpx = [YETI]           //Become alive?
    tmpy = selforder
    IfXIsEqualToY
      tmpargument = 0
      ChangeArmor
      UnkeepAction
      tmpargument = 230
      SetLight
      tmpargument = 37
      ClosePassage
Else

  //The different states:
  //0: Guard
  //1: Combat
  //2: Turned to rock
  //------------------------------------------------------------------------------
  //Combat/Guard
  IfTimeOut
    tmpargument = rand & 15 + 25
    SetTime

    //Spawn meteors
    tmpargument = 0
    IfStateIsNot
      tmpx = rand & 1
      tmpy = 0
      IfXIsEqualToY         //50%
        tmpargument = 49
        tmpdistance = 450
        tmpx = rand & 255 + targetx - 128
        tmpx = rand & 240 + tmpx	- 120	//lessen the randomness
        tmpy = rand & 255 + targety - 256
        tmpy = rand & 240 + tmpy	- 120    //lessen the randomness
        tmpturn = rand % 65535
        SpawnExactCharacterXYZ
          tmpargument = 1
          SetChildState

    //Guard mode
    IfStateIs0
      tmpx = rand & 1023 + selfx - 512
      tmpy = rand & 1023 + selfy - 512
      ClearWaypoints
      AddWaypoint

      //Close the exit!
      SetTargetToWideEnemy
        tmpargument = 1
        SetState
        tmpargument = 1		//Roar!
        SendMessageNear
        tmpargument = 6
        PlaySound

    //Combat mode
    IfStateIs1
      SetTargetToWideEnemy
        DoNothing
      Else
        tmpargument = 0
        SetState
      tmpdistance = 200				//For Compass later
      tmpx = targetdistance
      tmpy = 1600
      IfXIsLessThanY
        tmpy = 650
        IfXIsLessThanY
          tmpy = 200
          IfXIsLessThanY                     //Close enough to attack?
            IfFacingTarget
              tmpx = rand % 3			//33% kick, 33% smash, 33% nothing
              tmpy = 0
              IfXIsEqualToY
                tmpargument = ACTIONUA         //Smash
                DoAction
              tmpy = 1
              IfXIsEqualToY
                tmpargument = ACTIONUB         //Kick
                DoAction

          //Jump bash them
          Else
            tmpx = rand % 55
            tmpy = 8
            IfXIsLessThanY              //Chance
              tmpargument = ACTIONJA
              DoAction
                tmpargument = 7
                PlaySound
                tmpdistance = selfz + 15
                tmpx = selfx
                tmpy = selfy
                SpawnExactParticle	//Spawn 8 balls of fire
                SpawnExactParticle
                SpawnExactParticle
                SpawnExactParticle
                SpawnExactParticle
                SpawnExactParticle
                SpawnExactParticle
                SpawnExactParticle
        Else
          tmpdistance = 1500		//Charge!
          Run
        tmpx = targetx			//Move towards enemy
        tmpy = targety
        tmpturn = targetturnto
        Compass
        ClearWaypoints
        AddWaypoint
      Else
        tmpargument = 0			//Return to guard
        SetState

    //What to do if rock solid
    IfStateIs2
      SetTargetToSelf
      tmpargument = 50
      HealTarget		//Remove poison and regenerate extra
      tmpx = selflife
      tmpy = 3000
      IfXIsMoreThanY	//Keep regeneration in rock form
        tmpargument = 0	//until you gain 20 life again
        ChangeArmor
        tmpargument = 0
        SetState
        tmpargument = ACTIONMK
        UnkeepAction
        tmpargument = 230
        SetLight

  //------------------------------------------------------------------------------
  //Handle death by sending a message and other stuff
  IfKilled
    tmpargument = 1		//Sound number
    PlaySound

    UnkeepAction

    //Messaging
    tmpargument = MESSAGEDEATH
    IfTargetIsOnSameTeam
      tmpargument = MESSAGEFRAG
      IfTargetIsSelf
        tmpargument = MESSAGEACCIDENT
    SendMessageNear

    // Drop goodies
    tmpargument = selfmoney	//All of it
    DropMoney

    //Destroyed fire blast...
    SpawnPoof
    SpawnPoof
    SpawnPoof

    //Spawn a golden chest reward
    tmpargument = 86
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz + 600
    tmpturn = rand
    SpawnExactCharacterXYZ

    tmpargument = 2		//Randomize the chest type
    tmpx = rand % 100		//55% chance for artifact
    tmpy = 55
    IfXIsMoreThanY		//35% for armor chest
      tmpargument = 1
      tmpy = 90
      IfXIsMoreThanY		//10% for mere gold & treasure
        tmpargument = 0
    SetChildState

    //Open the exit!
    tmpargument = 37
    OpenPassage

  //------------------------------------------------------------------------------
  //Handle being attacked by blocking or countering or running away
  IfAttacked

    // Turn to rock if life is less than 6 blocks
    tmpargument = 2
    IfStateIsNot
      tmpx = selflife
      tmpy = 1800
      IfXIsLessThanY
        tmpargument = 2		//Rock form
        SetState
        tmpargument = 1		//Look like rock
        ChangeArmor
        tmpargument = ACTIONMK	//rock mode
        DoActionOverride
        KeepAction
        tmpargument = 5		//rock sound
        PlaySound
        tmpargument = 255
        SetLight

      //Ice Bonus damage
      Else
        GetDamageType
        tmpx = tmpargument
        tmpy = DAMAGEICE
        IfXIsEqualToY
          // Permanent life loss from ice
          SetOldTarget
          SetTargetToSelf
          tmpargument = 0 - 1024		//Lose 4 permanent life
          GiveLifeToTarget
          SetTargetToOldTarget
          tmpargument = 5
          SendMessageNear

        //Ouch sound
        tmpargument = 2
        PlaySound

    //Hit while rock form, spawn a dust cloud and clink
    Else
      tmpargument = 4
      PlaySound

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