// Parent spawner state
IfTimeOut
  // See if the board need to be cleared
  GetContent
  tmpx = tmpargument
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 1
    SetContent


    // Reset the board...
    tmpx = 60 < 7
    tmpy = 9 < 7
    tmpargument = 187
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY


    tmpx = 60 < 7
    tmpy = tmpy + 128
    tmpargument = 187
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY


    tmpx = 60 < 7
    tmpy = tmpy + 128
    tmpargument = 187
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY


    tmpx = 60 < 7
    tmpy = tmpy + 128
    tmpargument = 187
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY


  tmpargument = 3
  SetTime


  SetTargetToNearestFriend


  IfTargetIsAPlayer
    // See if the target is on the ground
    tmpx = targetaltitude
    tmpy = 20
    IfXIsLessThanY
      // See if the target is in the play area
      tmpx = targetx
      tmpy = 60 < 7
      IfXIsMoreThanY
        tmpy = 64 < 7
        IfXIsLessThanY
          tmpy = targety
          tmpx = 9 < 7
          IfYIsMoreThanX
            tmpx = 13 < 7
            IfYIsLessThanX
              // See if the target is standing in the center
              tmpx = targetx - 32 & 64
              tmpy = 0
              IfXIsEqualToY
                tmpx = targety - 32 & 64
                IfXIsEqualToY
                  // Change a tile
                  tmpx = targetx
                  tmpy = targety
                  GetTileXY
                  tmpx = tmpargument
                  tmpy = 187
                  IfXIsEqualToY		//The tile is unused yet
                    GetContent
                    tmpargument = tmpargument & 1 + 188
                    tmpx = targetx
                    tmpy = targety
                    SetTileXY


                    // Remember which ones have are Red
                    tmpx = tmpargument & 1
                    tmpy = 0
                    IfXIsEqualToY
                      tmpx = targetx > 7 - 60
                      tmpy = targety > 7 - 9 < 2
                      tmpx = tmpx + tmpy
                      tmpturn = 1 < tmpx
                      tmpargument = 0
                      GetXY
                      tmpx = tmpx + tmpturn
                      SetXY
                      tmpargument = tmpx
                      SetState
                      

                    // Increase the count
                    GetContent
                    tmpargument = tmpargument + 1
                    SetContent
                    tmpx = tmpargument
                    tmpy = 17
                    IfXIsEqualToY			//The number of tiles pressed
                      // We are done...
                      tmpargument = 0
                      GetXY
                      tmpy = 60072 //38505	//The answer (Two snakes)
                      IfXIsEqualToY
                        // The player won...
                        tmpargument = 0
                        SendMessageNear

                        // Play the "found a secret" sound
                        tmpargument = 2
                        PlayFullSound

                        //Award some xp
                        tmpargument = 50
                        tmpdistance = EXPSECRET
                        GiveExperienceToGoodTeam

                        //Spawn the gift key
                        tmpargument = 63		//Slot number
                        tmpx = 62 < 7			//X
                        tmpy = 11 < 7			//Y
                        tmpdistance = 700		//Z
                        SpawnExactCharacterXYZ

                        //Also spawn some random treasure loot
                        tmpargument = rand % 6
                        SetState
                        IfStateIs0
                          tmpargument = 61	//Scroll of identify
                        IfStateIs1
                          tmpargument = 69	//Silver scimitar
                        IfStateIs2
                          tmpargument = 59	//Life potion
                        IfStateIs3
                          tmpargument = 37	//Levitation potion
                        IfStateIs4
                          tmpargument = 77	//Rune of Combat bless
                        IfStateIs5
                          tmpargument = 78	//Rune of Holy Bolt
                         
                        tmpx = 61 < 7			//X
                        tmpy = 10 < 7			//Y
                        tmpdistance = 700		//Z
                        SpawnExactCharacterXYZ

			//Second item
                        tmpargument = rand % 6
                        SetState
                        IfStateIs0
                          tmpargument = 61	//Scroll of identify
                        IfStateIs1
                          tmpargument = 69	//Silver scimitar
                        IfStateIs2
                          tmpargument = 59	//Life potion
                        IfStateIs3
                          tmpargument = 37	//Levitation potion
                        IfStateIs4
                          tmpargument = 77	//Rune of Combat bless
                        IfStateIs5
                          tmpargument = 78	//Rune of Holy Bolt

                        tmpx = 61 < 7			//X
                        tmpy = 12 < 7			//Y
                        SpawnExactCharacterXYZ

			//Third item
                        tmpargument = rand % 6
                        SetState
                        IfStateIs0
                          tmpargument = 61	//Scroll of identify
                        IfStateIs1
                          tmpargument = 69	//Silver scimitar
                        IfStateIs2
                          tmpargument = 59	//Life potion
                        IfStateIs3
                          tmpargument = 37	//Levitation potion
                        IfStateIs4
                          tmpargument = 77	//Rune of Combat bless
                        IfStateIs5
                          tmpargument = 78	//Rune of Holy Bolt

                        tmpx = 63 < 7			//X
                        tmpy = 10 < 7			//Y
                        SpawnExactCharacterXYZ

			//Last and fourth item
                        tmpargument = rand % 6
                        SetState
                        IfStateIs0
                          tmpargument = 61	//Scroll of identify
                        IfStateIs1
                          tmpargument = 69	//Silver scimitar
                        IfStateIs2
                          tmpargument = 59	//Life potion
                        IfStateIs3
                          tmpargument = 37	//Levitation potion
                        IfStateIs4
                          tmpargument = 77	//Rune of Combat bless
                        IfStateIs5
                          tmpargument = 78	//Rune of Holy Bolt

                        tmpx = 63 < 7			//X
                        tmpy = 12 < 7			//Y
                        SpawnExactCharacterXYZ


                        // Open a master passage
                        tmpargument = passage
                        OpenPassage
                        GoPoof
                      Else
                        // The player lost...
                        tmpargument = rand & 3 + 1
                        SendMessageNear


                        // Play the failed sound
                        tmpargument = 1
                        PlayFullSound


                        // Start it over in a second
                        tmpargument = 0
                        SetContent
                        tmpx = 0
                        SetXY
                        tmpargument = 50
                        SetTime
                    Else
                      // Play the button press sound
                      tmpargument = 0
                      PlaySound


End					// Finished with this character
