IfSpawned
  // Hide out until players come
  tmpargument = ACTIONHA
  DoActionOverride
  KeepAction
  tmpargument = 2
  SetState
  SetTurnModeToWatchTarget



IfScoredAHit
  // Make a small splash
  tmpargument = 6
  tmpdistance = GRIPLEFT
  SpawnAttachedParticle



IfKilled
  // Tell the players
  tmpargument = 1
  IfTargetIsOnHatedTeam
    tmpargument = 0
  SendMessage


  // Handle boss stuff
  tmpargument = passage
  OpenPassage
  ClearEndMessage
  tmpargument = 2
  AddEndMessage
  tmpargument = 3
  AddEndMessage


  // Make a noise
  tmpargument = 2
  tmpdistance = 11025
  PlaySound


  // Do splash...
  tmpargument = 1
  tmpdistance = 8
  SpawnAttachedParticle
  tmpdistance = 14
  SpawnAttachedParticle
  tmpdistance = 20
  SpawnAttachedParticle
  tmpdistance = 26
  SpawnAttachedParticle
  tmpdistance = 32
  SpawnAttachedParticle
  tmpdistance = 38
  SpawnAttachedParticle
  tmpdistance = 44
  SpawnAttachedParticle
  tmpdistance = 50
  SpawnAttachedParticle
  tmpdistance = 56
  SpawnAttachedParticle
  tmpdistance = 62
  SpawnAttachedParticle
  tmpdistance = 68
  SpawnAttachedParticle
  tmpdistance = 72
  SpawnAttachedParticle



IfAttacked
  // Just in case it was in the middle of a throw
  SetTurnModeToWatchTarget


  // Do splash
  tmpargument = 1
  tmpdistance = 8
  SpawnAttachedParticle
  tmpdistance = 14
  SpawnAttachedParticle
  tmpdistance = 20
  SpawnAttachedParticle
  tmpdistance = 26
  SpawnAttachedParticle
  tmpdistance = 32
  SpawnAttachedParticle
  tmpdistance = 38
  SpawnAttachedParticle
  tmpdistance = 44
  SpawnAttachedParticle
  tmpdistance = 50
  SpawnAttachedParticle
  tmpdistance = 56
  SpawnAttachedParticle
  tmpdistance = 62
  SpawnAttachedParticle
  tmpdistance = 68
  SpawnAttachedParticle
  tmpdistance = 72
  SpawnAttachedParticle


  // Teleport away...  State 1 is waiting to teleport
  tmpargument = 1
  SetState
  tmpargument = 24
  SetTime
  KeepAction


  // Give it limited invincibility
  tmpargument = 35
  SetDamageTime


  // Make a noise
  tmpargument = 0
  tmpdistance = rand & 2047 + 10000
  PlaySound


IfBumped
  IfStateIs0
    SetTargetToWhoeverBumped
    IfTargetIsOnHatedTeam
      tmpargument = ACTIONUA
      DoAction
        // Make a noise
        tmpargument = 1
        tmpdistance = rand & 4095 + 8000
        PlaySound
    Else
      tmpx = rand & 255 + targetx - 128
      tmpy = rand & 255 + targety - 128
      ClearWaypoints
      AddWaypoint
      SetTargetToOldTarget



// Make the bottom fade out
tmpturn = 0		// Use this intensity
tmpx = 1200		// Below this height,
tmpdistance = 255	// Use this intensity
tmpy = 5000		// Above this height,
FlashVariableHeight	// Interpolate between




IfTimeOut
  // Ready the boss music
  tmpargument = 21
  tmpturn = IGCOMBAT
  tmpdistance = 1
  SetMusicPassage



  // Throw the target
  IfStateIs3
    tmpx = 0
    tmpy = 0
    tmpturn = selfturn
    tmpdistance = 30
    Compass
    AccelerateTarget
    tmpargument = 0
    SetState
    tmpargument = rand & 1023 + 1024  // 4-8 damage
    DamageTarget
    SetTurnModeToWatchTarget



  // Hide until an enemy is nearby and the door is open
  IfStateIs2
    tmpargument = 30
    SetDamageTime
    tmpargument = 20
    IfPassageOpen
      SetTargetToNearestEnemy
        tmpx = targetdistance
        tmpy = 800
        IfXIsLessThanY
          // Ready to appear, so teleport
          tmpargument = 1
          SetState
    tmpargument = 20 // Time


  // Teleport...
  IfStateIs1
    // Teleport ready
    tmpx = rand & 511 - 256 + selfspawnx
    tmpy = rand & 511 - 256 + selfspawny
    tmpargument = 0 // Time
    Teleport
      tmpargument = ACTIONMJ
      DoActionOverride
      UnkeepAction
      tmpargument = 0
      SetState

      // Make a noise
      tmpargument = 1
      tmpdistance = rand & 2047 + 10000
//      PlaySound


  // Find an enemy
  IfStateIs0
    SetTargetToSelf
    SetTargetToTargetLeftHand
      // There's an in hand enemy...  Throw 'im
      tmpx = selfx
      tmpy = selfy
      tmpargument = ACTIONUC
      DoAction
        tmpargument = 3
        SetState
        SetTurnModeToSpin

        // Make a noise
        tmpargument = 1
        tmpdistance = rand & 4095 + 8000
        PlaySound
      tmpargument = 23  // Time before accel
    Else
      // Look for other enemies
      SetTargetToNearestEnemy
        // Close enough to attack?
        tmpx = targetdistance
        tmpy = 200
        IfXIsLessThanY
          // Choose grab or smash...
          tmpx = rand & 511
          IfXIsLessThanY
            // Grab
            tmpargument = ACTIONUA
            DoAction
              // Make a noise
              tmpargument = 1
              tmpdistance = rand & 4095 + 8000
              PlaySound
          Else
            // Smash
            tmpargument = rand & 2 + ACTIONUB
            DoAction
              // Make a noise
              tmpargument = 1
              tmpdistance = rand & 4095 + 8000
              PlaySound

              // Do damage
              tmpargument = 0
              tmpdistance = GRIPLEFT
              SpawnAttachedParticle
        // Follow the enemy
        tmpx = targetx
        tmpy = targety
      Else
        // No enemies around...
        tmpx = rand & 511 - 256 + selfspawnx
        tmpy = rand & 511 - 256 + selfspawny
        // Return to hiding...
        tmpargument = ACTIONHA
        DoActionOverride
        KeepAction
        tmpargument = 30
        SetDamageTime
        tmpargument = 2
        SetState
      tmpargument = rand & 15 + 10  // Time
    ClearWaypoints
    AddWaypoint



  // Wait a while, tmpargument should be set
  SetTime



  // Water wierd heals itself if water is high...
  GetWaterLevel
  tmpx = tmpargument
  tmpy = 600
  IfXIsMoreThanY
    SetTargetToSelf
    tmpargument = 64
    HealTarget



// All done
End

