// Get mean if characters wanna be bad
IfAttacked
  CallForHelp
  JoinEvilTeam
IfCalledForHelp
  JoinEvilTeam

//------------------------------------------------------------------------------
// ZZ> Setup shop...
IfSpawned
  tmpargument = passage
  AddShopPassage


  // Make the border
  tmpargument = 2
  tmpdistance = 0


  // Top
  tmpx = selfx - 192
  tmpy = selfy - 384
  SpawnExactParticle
  tmpx = tmpx + 128
  SpawnExactParticle
  tmpx = tmpx + 128
  SpawnExactParticle
  tmpx = tmpx + 128
  SpawnExactParticle


  // Bottom
  tmpy = selfy + 384
  SpawnExactParticle
  tmpx = tmpx - 128
  SpawnExactParticle
  tmpx = tmpx - 128
  SpawnExactParticle
  tmpx = tmpx - 128
  SpawnExactParticle


  // Left
  tmpx = selfx - 384
  tmpy = selfy - 192
  SpawnExactParticle
  tmpy = tmpy + 128
  SpawnExactParticle
  tmpy = tmpy + 128
  SpawnExactParticle
  tmpy = tmpy + 128
  SpawnExactParticle


  // Right
  tmpx = selfx + 384
  SpawnExactParticle
  tmpy = tmpy - 128
  SpawnExactParticle
  tmpy = tmpy - 128
  SpawnExactParticle
  tmpy = tmpy - 128
  SpawnExactParticle


  // Show the area
  //tmpdistance = 255
  //FlashPassage


  // Add some random goodies
  tmpdistance = 0
  tmpx = selfx - 128
  tmpy = selfy - 128
  tmpturn = rand
  tmpargument = tmpturn & 15 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx
  tmpturn = rand
  tmpargument = tmpturn & 15 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx + 128
  tmpturn = rand
  tmpargument = tmpturn & 15 + 60
  SpawnExactCharacterXYZ

  tmpy = selfy
  tmpturn = rand
  tmpargument = tmpturn & 15 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx - 128
  tmpturn = rand
  tmpargument = tmpturn & 15 + 60 
  SpawnExactCharacterXYZ

  tmpy = selfy + 128
  tmpturn = rand
  tmpargument = tmpturn & 15 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx
  tmpturn = rand
  tmpargument = tmpturn & 15 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx + 128
  tmpturn = rand
  tmpargument = tmpturn & 15 + 60
  SpawnExactCharacterXYZ


  // Add some random chests ( West side )
  tmpturn = rand & 8191 + 28768
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx - 256
  tmpy = selfy - 128
  SpawnExactCharacterXYZ


  tmpturn = rand & 8191 + 28768
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx - 256
  tmpy = selfy
  SpawnExactCharacterXYZ


  tmpturn = rand & 8191 + 28768
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx - 256
  tmpy = selfy + 128
  SpawnExactCharacterXYZ


  // Add some random chests ( East side )
  tmpturn = rand & 8191 + 61535
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx + 256
  tmpy = selfy - 128
  SpawnExactCharacterXYZ


  tmpturn = rand & 8191 + 61535
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx + 256
  tmpy = selfy
  SpawnExactCharacterXYZ


  tmpturn = rand & 8191 + 61535
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx + 256
  tmpy = selfy + 128
  SpawnExactCharacterXYZ


//------------------------------------------------------------------------------
// ZZ> Handle orders ( purchases )
IfOrdered
  // Counter specifies transaction ( 0, 1, or 2 )
  // Order specifies price
  tmpx = selforder
  tmpy = 0
  IfXIsEqualToY
    tmpx = selfcounter
    tmpy = 0
    IfXIsEqualToY
      // I'm not payin' for that!
      tmpargument = 8
      SendMessageNear
  Else
    // Buy/Sell
    tmpx = selfcounter
    tmpy = 3
    IfXIsLessThanY
      tmpy = 0 - 1
      IfXIsMoreThanY
        tmpargument = tmpx + 5
        tmpx = selforder
        SendMessageNear


//------------------------------------------------------------------------------
// ZZ> Move around...  Start at state 0
IfTimeOut
  IfStateIs0
    tmpx = rand & 255 - 128 + selfspawnx
    tmpy = rand & 255 - 128 + selfspawny
    ClearWaypoints
    AddWaypoint
  tmpargument = rand & 31 + 15
  SetTime


//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  JoinEvilTeam
  tmpargument = 3
  tmpdistance = rand & 1027 + 11000
  PlaySound
  tmpargument = MESSAGEDEATH
  IfTargetIsOnSameTeam
    tmpargument = MESSAGEFRAG
    IfTargetIsSelf
      tmpargument = MESSAGEACCIDENT
  SendMessage

  // Drop goodies
  tmpargument = 65535
  DropMoney

  // Make the character body
  tmpargument = 45
  SetBumpHeight

  // Tell the chests that they've been looted ( need differing IDSZ for
  // multiple shops on the same level... )
  tmpdistance = [SHOP]
  tmpargument = 983  // The unique code for a looted shop
  OrderSpecialID


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



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