//------------------------------------------------------------------------------
// ZZ> Set up when spawned
IfSpawned
  tmpargument = 8  // sleeping
  SetState

//------------------------------------------------------------------------------
//Content > 0 means we got poisoned by eating a kursed item
tmpx = selfcontent
tmpy = 0
IfXIsMoreThanY
  tmpargument = selfcontent - 1
  SetContent
  
  //Deal 4 posion damage to ourselves each update
  SetTargetToOwner
  tmpargument = 4
  tmpdistance = DAMAGEEVIL
  TargetDamageSelf
  HealSelf
  
  //Make us green
  tmpargument = 2
  SetGreenShift
  tmpargument = -2
  SetRedShift
  SetBlueShift
  
  //End poison effect?
  tmpargument = 0
  IfContentIs
    tmpargument = 2
    SetGreenShift
    tmpargument = -2
    SetRedShift
    SetBlueShift

//------------------------------------------------------------------------------
// ZZ> Shhh.... I'm sleeping
IfStateIs8
  IfTimeOut
    tmpargument = ACTIONMK
    DoAction   
    KeepAction

    // Sleepy Z's
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz
    tmpargument = 6
    SpawnExactParticle

    // Snore...
    tmpargument = rand & 3 + 4
    PlaySound
    tmpargument = 100
    SetTime

    tmpdistance = 128*7
    SetTargetToDistantEnemy
      IfTargetIsSneaking
        //don't wake up
      Else
        tmpargument = 1
        SetState
        UnkeepAction
        tmpargument = 1
        SendMessage
        tmpargument = 50
        SetTime

//------------------------------------------------------------------------------
// ZZ> Attack enemy
IfBumped				// Attack whoever it bumped
  SetTargetToWhoeverBumped		  //
  IfTargetIsOnHatedTeam			  // Make sure it's an enemy
    tmpargument = LATCHLEFT		    // Bite 'em
    PressLatchButton			    //
  
  //Zefz: I have no idea what this is for...
  tmpargument = [RUST]
  IfTargetHasID
    tmpargument = 512
    HealSelf

IfScoredAHit
  SetTargetToWhoeverWasHit
    SetTargetToTargetLeftHand           //Look for Metal to eat
      tmpargument = [RUST]
      IfTargetHasVulnerabilityID
        tmpargument = 3
        SendMessage
        
        //We get poisoned if we eat kursed stuff
        IfTargetIsKursed
          tmpargument = 1500            //30 seconds
          SetContent
          tmpargument = 4
          SendMessage
          SetOldTarget                  //Make them the poisoner
          SetTargetToWhoeverWasHit
          SetOwnerToTarget
          SetTargetToOldTarget
          
        PoofTarget
        tmpx = selfx
        tmpy = selfy
        tmpdistance = selfz
        tmpargument = 5
        SpawnExactParticle
      Else
        SetTargetToWhoeverWasHit
        SetTargetToTargetRightHand
          tmpargument = [RUST]
          IfTargetHasVulnerabilityID
            tmpargument = 3
            SendMessage
            
            //We get poisoned if we eat kursed stuff
            IfTargetIsKursed
              tmpargument = 1500            //30 seconds
              SetContent
              tmpargument = 4
              SendMessage
              SetOldTarget                  //Make them the poisoner
              SetTargetToWhoeverWasHit
              SetOwnerToTarget
              SetTargetToOldTarget
              
            PoofTarget
            tmpx = selfx
            tmpy = selfy
            tmpdistance = selfz
            tmpargument = 5
            SpawnExactParticle
    Else
      SetTargetToWhoeverWasHit
      SetTargetToTargetRightHand
        tmpargument = [RUST]
        IfTargetHasVulnerabilityID
          tmpargument = 3
          SendMessage
          PoofTarget
          tmpx = selfx
          tmpy = selfy
          tmpdistance = selfz
          tmpargument = 5
          SpawnExactParticle
    
    //Deal extra damage to metal armored folks
    IfTargetIsDressedUp
      tmpargument = rand % 512 + 512    //2-4 extra damage
      DamageTarget
      EnchantTarget           //Make their armor less effective from now on
      
    SetTargetToOldTarget

IfAttacked
  SetTargetToNearbyEnemy
    tmpargument = rand % 5
    tmpx = tmpargument
    tmpy = 2
    IfXIsLessThanY
      SetTargetToTargetLeftHand           //Look for Metal to eat
        tmpargument = [RUST]
        IfTargetHasVulnerabilityID
          tmpargument = 3
          SendMessage
          PoofTarget
          tmpx = selfx
          tmpy = selfy
          tmpdistance = selfz
          tmpargument = 5
          SpawnExactParticle
        Else
          SetTargetToOldTarget
          SetTargetToTargetRightHand
            tmpargument = [RUST]
            IfTargetHasVulnerabilityID
              tmpargument = 3
              SendMessage
              PoofTarget
              tmpx = selfx
              tmpy = selfy
              tmpdistance = selfz
              tmpargument = 5
              SpawnExactParticle
      Else
        SetTargetToOldTarget
        SetTargetToTargetRightHand
          tmpargument = [RUST]
          IfTargetHasVulnerabilityID
            tmpargument = 3
            SendMessage
            PoofTarget
            tmpx = selfx
            tmpy = selfy
            tmpdistance = selfz
            tmpargument = 5
            SpawnExactParticle
      SetTargetToOldTarget
  tmpturn = selfturn + 32768
  tmpdistance = 500
  tmpx = selfx
  tmpy = selfy
  Compass
  ClearWaypoints
  AddWaypoint

//------------------------------------------------------------------------------
//Death
IfKilled
  tmpargument = 34
  SetBumpHeight
  IfTargetIsOnHatedTeam
    tmpargument = 0
    SendMessageNear

//------------------------------------------------------------------------------
// ZZ> Handle wandering around
IfStateIs1
  // Wander around
  IfTimeOut				// This is done every so often
    tmpdistance = 128*7
    SetTargetToDistantEnemy
      tmpx = rand & 511 - 256 + targetx	    //
      tmpy = rand & 511 - 256 + targety	    //
      tmpargument = rand & 63 + 50		  // Wait a while and try again
    Else					  // Wander around home position
      tmpx = rand & 1023 - 512 + selfspawnx   //
      tmpy = rand & 1023 - 512 + selfspawny   //
      tmpargument = rand % 20 + 10		  // Wait a while and try again
    ClearWaypoints			  //
    AddWaypoint				  //
    SetTime				  //

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