//------------------------------------------------------------------------------
// ZZ> Jump over corpses
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsAlive
    tmpargument = [CHES]
    IfTargetHasID
      tmpargument = LATCHJUMP
      PressLatchButton
  Else
    tmpargument = LATCHJUMP
    PressLatchButton
  SetTargetToOldTarget


//------------------------------------------------------------------------------
tmpargument = 0
IfStateIsNot
  GetContent
  tmpx = tmpargument
  tmpy = 0
  IfXIsMoreThanY
    tmpargument = tmpx - 1
    SetContent


  // Check messages
  IfBumped
    tmpargument = 0
    IfContentIs
      IfStateIs2
        // "Good!"
        AddStat
        tmpargument = 8
        tmpdistance = 12000
        PlaySound
        tmpargument = 3
        SetState
        DropKeys
        tmpargument = 5
        SendMessageNear
        tmpargument = 30
        SetContent
      IfStateIs1
        // "So is it a deal?"
        tmpargument = 7
        tmpdistance = 12000
        PlaySound
        tmpargument = 2
        SetState
        tmpargument = 60
        SetContent
        tmpargument = 4
        SendMessageNear


//------------------------------------------------------------------------------
// ZZ> Move around...
IfTimeOut
  IfStateIs3
    tmpargument = 0
    IfContentIs
      SetTargetToSelf
      SetTargetToTargetLeftHand
        SetTargetToSelf
        SetTargetToTargetRightHand
          GetState // NOP
        Else
          tmpargument = LATCHPACKRIGHT
          PressLatchButton
      Else
        tmpargument = LATCHPACKLEFT
        PressLatchButton
      tmpargument = 100
      SetContent


    // Get in a fight
    tmpdistance = 250000
    SetTargetToDistantEnemy
      // Charge!
      tmpx = targetx
      tmpy = targety
      tmpdistance = 300
      tmpturn = targetturnto
      Compass
      ClearWaypoints
      AddWaypoint


      // Take a stab?
      tmpx = targetdistance
      tmpy = 120
      IfXIsLessThanY
        IfFacingTarget
          tmpargument = rand & 1 + 1
          PressLatchButton


      tmpargument = 10
      SetTime
    Else
      // Follow the Player around
      SetTargetToLeader
      tmpx = targetdistance
      tmpy = 200
      IfXIsLessThanY
        tmpx = targetx
        tmpy = targety
        tmpturn = targetturnto + 32768
        tmpdistance = 100
        Compass
        ClearWaypoints
        AddWaypoint
        tmpargument = 20
        SetTime
      Else
        tmpy = 600
        IfXIsLessThanY
          // Run after the player
          tmpx = targetx
          tmpy = targety
          tmpturn = targetturnto
          tmpdistance = 400
          Compass
          ClearWaypoints
          AddWaypoint
          tmpargument = 20
          SetTime
        Else
          // Walk around...
          tmpx = selfx
          tmpy = selfy
          tmpturn = selfturn + 8192
          tmpdistance = 200
          Compass
          ClearWaypoints
          AddWaypoint
          tmpargument = 20
          SetTime
  Else
    // How close is the player?
    tmpargument = [ROGU]
    tmpdistance = 6 // Friends and Enemies
    SetTargetToNearestBlahID
      tmpx = targetx - selfspawnx
      tmpy = targety - selfspawny
      tmpx = xydistance
      tmpy = 400
      IfXIsLessThanY
        tmpy = 200
        IfXIsLessThanY
          IfStateIs0
            // Talk to the player
            tmpargument = 90 // Delay
            SetContent

            tmpargument = 6
            tmpdistance = 12000
            PlaySound

            tmpargument = 3
            SendMessageNear

            tmpargument = 1
            SetState
          Else
            tmpx = selfspawnx
            tmpy = selfspawny
            tmpturn = targetturnto
            tmpdistance = 150
            Compass
            ClearWaypoints
            AddWaypoint
            tmpargument = 20
            SetTime
        Else
          // Approach the player
          tmpx = selfspawnx
          tmpy = selfspawny
          tmpturn = targetturnto
          tmpdistance = 150
          Compass
          ClearWaypoints
          AddWaypoint
          tmpargument = 20
          SetTime
      Else
        // Walk around in a circle
        tmpx = selfx
        tmpy = selfy
        tmpturn = selfturn + 8192
        tmpdistance = 200
        Compass
        ClearWaypoints
        AddWaypoint
        tmpargument = 20
        SetTime
    Else
      // Walk around in a circle
      tmpx = selfx
      tmpy = selfy
      tmpturn = selfturn + 8192
      tmpdistance = 200
      Compass
      ClearWaypoints
      AddWaypoint
      tmpargument = 20
      SetTime


//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  tmpargument = 2
  tmpdistance = rand & 1027 + 11000
  PlaySound
  tmpargument = 0
  IfTargetIsOnSameTeam
    tmpargument = 1
  SendMessage

  // Drop goodies
  tmpargument = 65535
  DropMoney

  // Make the character body
  tmpargument = 45
  SetBumpHeight


//------------------------------------------------------------------------------
// ZZ> Handle being attacked by blocking or countering or running away
IfAttacked
  SetTargetToWhoeverAttacked
  IfTargetIsOnSameTeam
    tmpargument = 5
    tmpdistance = rand & 1027 + 11000
    PlaySound
    tmpargument = 2
    SendMessageNear
  Else
    tmpargument = rand & 1 + 3
    tmpdistance = rand & 1027 + 11000
    PlaySound
  SetTargetToOldTarget


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