//----------------------------------------------------------------------------------
IfSpawned
  tmpargument = STATEGUARD
  SetState

//----------------------------------------------------------------------------------
//They got us in the back!
IfBackstabbed
  SetTargetToWhoeverAttacked
  tmpargument = 3
  SendMessageNear
  GetDamageType
  tmpdistance = tmpargument         //Same type of damage as last
  tmpargument = targetdex       //+1 damage per dex
  TargetDamageSelf

//----------------------------------------------------------------------------------
IfTimeOut
  tmpargument = rand & 15 + 30
  SetTime

  //Recharge gas attack
  tmpx = selfcontent
  tmpy = 0
  IfXIsMoreThanY
    tmpargument = selfcontent -1
    SetContent

  //Idle
  IfStateIsGuard
    SetTargetToNearbyEnemy
      IfFacingTarget                      //I see you!
        tmpargument = STATECOMBAT
        SetState
      Else
        tmpx = targetdex
        tmpy = rand % 1280 + selfwis
        IfXIsLessThanY
          tmpargument = STATECOMBAT
          SetState
    Else
      tmpx = selfspawnx
      tmpy = selfspawny
      ClearWaypoints
      AddWaypoint

  //Following enemy
  IfStateIsCombat
    IfTargetIsOnHatedTeam		//Attack?
      IfFacingTarget
        tmpx = targetdistance
        tmpy = 200
        IfXIsLessThanY
          tmpx = 35 + selfdex < 8
          tmpy = rand % 100
          IfXIsMoreThanY			//Check for attack skill
            tmpargument = ACTIONBA
            DoAction
      //Move towards the enemy
      tmpx = targetx
      tmpy = targety
      tmpdistance = 400
      tmpturn = targetturnto
      Compass
      ClearWaypoints
      AddWaypoint
    Else
      tmpargument = STATEGUARD
      SetState

//----------------------------------------------------------------------------------
//They died
IfTargetKilled
  tmpargument = STATEGUARD
  SetState
  
//----------------------------------------------------------------------------------
//Say ouch
IfAttacked
  tmpargument = rand & 1
  PlaySound
  SetTargetToWhoeverAttacked
    IfTargetIsOnHatedTeam
      tmpargument = STATECOMBAT
      SetState
    Else
      SetTargetToOldTarget

//----------------------------------------------------------------------------------
//Explode
IfKilled
  tmpargument = 3
  tmpdistance = selfz
  tmpx = selfx
  tmpy = selfy
  SpawnExactParticle
  IfTargetIsSelf			//Death message
    tmpargument = 1
  Else
    tmpargument = 0
  SendMessageNear

//----------------------------------------------------------------------------------
//Counter attack
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = ACTIONBA
      DoAction

      //Spew some paralysis gas
      tmpargument = 0
      IfContentIs
        tmpargument = selflevel*15 + 150
        SetTargetReloadTime		//Paralyse the target for 3 seconds + 0.3 seconds per level
        tmpargument = 4
        tmpx = targetx
        tmpy = targety
        tmpdistance = targetz
        SpawnExactParticle
        SpawnExactParticle		//Cloud
        tmpargument = rand & 3 + 5	//Recharge time
        SetContent
        tmpargument = 5			//Gass sound
        PlaySound
        tmpargument = 2
        SendMessageNear
  Else
    SetTargetToOldTarget

//----------------------------------------------------------------------------------
End					// All done
//----------------------------------------------------------------------------------
