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

//------------------------------------------------------------------------------
tmpargument = 0
IfStateIsNot
  Sneak				//33% speed
  GetContent
  tmpx = tmpargument
  tmpy = 0
  IfXIsMoreThanY
    tmpargument = tmpx - 1
    SetContent

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

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

    // Get in a fight
    tmpdistance = 128*6
    SetTargetToDistantEnemy
      // Charge!
      Run					//100% speed
      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
        Walk					//66% speed
        tmpx = targetx
        tmpy = targety
        tmpturn = targetturnto + 32768
        tmpdistance = 100
        Compass
        ClearWaypoints
        AddWaypoint
        tmpargument = 20
        SetTime
      Else
        tmpy = 600
        IfXIsLessThanY
          // Run after the player
          Run					//100% speed
          tmpx = targetx
          tmpy = targety
          tmpturn = targetturnto
          tmpdistance = 400
          Compass
          ClearWaypoints
          AddWaypoint
          tmpargument = 20
          SetTime
        Else
          // Walk around...
          Sneak					//66% speed
          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 = targetdistance
      tmpy = 400
      IfXIsLessThanY
        tmpy = 200
        IfXIsLessThanY
          IfStateIs0
            // Talk to the player
            tmpargument = 90 		// Delay
            SetContent

            tmpargument = 6
            PlaySound

            tmpargument = 3
            SendMessageNear

            tmpargument = 1
            SetState
          Else
            Walk					//66% speed
            tmpx = selfspawnx
            tmpy = selfspawny
            tmpturn = targetturnto
            tmpdistance = 150
            Compass
            ClearWaypoints
            AddWaypoint
            tmpargument = 20
            SetTime
        Else
          // Approach the player
          Walk					//66% speed
          tmpx = selfspawnx
          tmpy = selfspawny
          tmpturn = targetturnto
          tmpdistance = 150
          Compass
          ClearWaypoints
          AddWaypoint
          tmpargument = 20
          SetTime
      Else
        // Walk around in a circle
        Sneak					//33% speed
        tmpx = selfx
        tmpy = selfy
        tmpturn = selfturn + 8192
        tmpdistance = 200
        Compass
        ClearWaypoints
        AddWaypoint
        tmpargument = 20
        SetTime
    Else
      // Walk around in a circle
      Sneak					//33% speed
      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
  PlaySound
  tmpargument = 0
  IfTargetIsOnSameTeam
    tmpargument = 1
  SendMessage

  // Drop goodies
  tmpargument = selfmoney
  DropMoney

  // Make the character body
  tmpargument = 45
  SetBumpHeight

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

//------------------------------------------------------------------------------
// ZZ> Display mini map location if befriended

IfStateIs3
  tmpx = selfx
  tmpy = selfy
  tmpargument = BLUE
  ShowBlipXY

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