public void SowVeg(IServerSocket serverSocket)
 {
     for (int x = 0; x < TileAreaWidth; x++)
     {
         for (int y = 0; y < TileAreaHeight; y++)
         {
             if (ForestSpaces[x, y] == TileTypes.Field)
             {
                 ForestSpaces[x, y] = TileTypes.Field2Veg;
                 serverSocket.SetPlayerTileType(new Vector2(x, y), GetTileType(new Vector2(x, y), true), false);
                 return;
             }
         }
     }
 }
 public void SetBuildingTileAt(IServerSocket serverSocket, Vector2 position, string buildingType)
 {
     CaveSpaces[(int)position.x, (int)position.y] = buildingType;
     serverSocket.SetPlayerTileType(position, GetTileType(position, false), true);
 }
        public void SetTileAt(IServerSocket serverSocket, Vector2 position, bool isForest, bool isExpedition, out int foodGain, out int pigsGain, out int rubyGain)
        {
            foodGain = 0;
            pigsGain = 0;
            rubyGain = 0;

            if (TilesToPlace.First() == TileTypes.SmallFence)
            {
                if (isExpedition)
                {
                    //already paid for
                }
                else
                {
                    int woodCost = 2;
                    if (HasTile(BuildingTypes.Carpenter))
                    {
                        woodCost --;
                    }
                    _player.Wood -= woodCost;
                }
            }
            if (TilesToPlace.First() == TileTypes.BigFence1)
            {
                if (isExpedition)
                {
                    //already paid for
                }
                else
                {
                    int woodCost = 4;
                    if (HasTile(BuildingTypes.Carpenter))
                    {
                        woodCost--;
                    }
                    _player.Wood -= woodCost;
                }
            }
            if (TilesToPlace.First() == TileTypes.Stable)
            {
                //pay for the stable
                if (!HasTile(BuildingTypes.StoneCarver) && !isExpedition)
                {
                    _player.Stone--;
                }

                int x = (int)position.x;
                int y = (int)position.y;
                StableSpaces[x, y] = TileTypes.Stable;
                TilesToPlace.RemoveAt(0);
                _isPlacingSecondPartOfTile = TilesToPlace.Count > 0;
                if (_isPlacingSecondPartOfTile)
                {
                    _firstPartOfDouble = position;
                }
                else
                {
                    _firstPartOfDouble = new Vector2(-1, -1);
                }
                serverSocket.SetPlayerTileType(position, GetTileType(position, isForest), !isForest);
                return;
            }
            string[,] tileArea;
            if (isForest)
                tileArea = ForestSpaces;
            else
                tileArea = CaveSpaces;

            string oldTile = tileArea[(int)position.x, (int)position.y];
            string newTile = TilesToPlace.First();

            tileArea[(int)position.x, (int)position.y] = newTile;
            TilesToPlace.RemoveAt(0);

            //if this was a double fenced pasture, record it
            if (_isPlacingSecondPartOfTile && newTile == TileTypes.BigFence2)
            {
                _doubleFencedPastures.Add(_firstPartOfDouble);
                _doubleFencedPastures.Add(position);
            }

            _isPlacingSecondPartOfTile = TilesToPlace.Count > 0;
            if (_isPlacingSecondPartOfTile)
            {
                _firstPartOfDouble = position;
            }
            else
            {
                _firstPartOfDouble = new Vector2(-1, -1);
            }

            //apply any bonuses from this tile
            if (isForest)
            {
                if ((int)position.x == 1 && (int)position.y == 0)
                    foodGain++;
                if ((int)position.x == 0 && (int)position.y == 1)
                    pigsGain++;
                if ((int)position.x == 2 && (int)position.y == 3)
                    pigsGain++;
            }
            else
            {
                if (oldTile == TileTypes.DeepTunnel && newTile == TileTypes.RubyMine)
                    rubyGain++;
                if ((int)position.x == 1 && (int)position.y == 0)
                    foodGain++;
                if ((int)position.x == 2 && (int)position.y == 3)
                    foodGain += 2;
            }

            serverSocket.SetPlayerTileType(position, GetTileType(position, isForest), !isForest);
        }
        public void FieldPhase(IServerSocket _serverSocket, out int harvestedGrain, out int harvestedVeg)
        {
            harvestedGrain = 0;
            harvestedVeg = 0;
            List<Vector2> updatedFields = new List<Vector2>();

            //replace each 1 corn or 1 veg with zero, 2 with 1, 3 with 2, etc
            for (int x = 0; x < TileAreaWidth; x++)
            {
                for (int y = 0; y < TileAreaHeight; y++)
                {
                    if (ForestSpaces[x, y] == TileTypes.Field1Grain)
                    {
                        ForestSpaces[x, y] = TileTypes.Field;
                        harvestedGrain++;
                        updatedFields.Add(new Vector2(x, y));
                    }
                    if (ForestSpaces[x, y] == TileTypes.Field2Grain)
                    {
                        ForestSpaces[x, y] = TileTypes.Field1Grain;
                        harvestedGrain++;
                        updatedFields.Add(new Vector2(x, y));
                    }
                    if (ForestSpaces[x, y] == TileTypes.Field3Grain)
                    {
                        ForestSpaces[x, y] = TileTypes.Field2Grain;
                        harvestedGrain++;
                        updatedFields.Add(new Vector2(x, y));
                    }
                    if (ForestSpaces[x, y] == TileTypes.Field1Veg)
                    {
                        ForestSpaces[x, y] = TileTypes.Field;
                        harvestedVeg++;
                        updatedFields.Add(new Vector2(x, y));
                    }
                    if (ForestSpaces[x, y] == TileTypes.Field2Veg)
                    {
                        ForestSpaces[x, y] = TileTypes.Field1Veg;
                        harvestedVeg++;
                        updatedFields.Add(new Vector2(x, y));
                    }
                }
            }

            foreach (Vector2 position in updatedFields)
            {
                _serverSocket.SetPlayerTileType(position, GetTileType(position, true), false);
            }
        }