Exemple #1
0
    // Placement

    /**
     * Can place settlements only when there are no neighbouring settlements, and if connected to a road that player already owns.
     * In setup mode, can place settlements not connected to a road.
     */
    public bool CanPlaceSettlement(Player player, int col, int row, BoardGrid.VertexSpecifier vertexSpec)
    {
        // Check if there are any adjacent building -- Spacing requirement
        List <Vertex> adjacentVertices = boardGrid.GetAdjacentVerticesFromVertex(col, row, vertexSpec);

        foreach (Vertex adjacentVertex in adjacentVertices)
        {
            if (adjacentVertex.settlement != null)
            {
                return(false);
            }
        }

        // Check if connected to a road owned by this player
        bool        validRoadNearby = false;
        List <Edge> adjacentEdges   = boardGrid.GetAdjacentEdgesFromVertex(col, row, vertexSpec);

        foreach (Edge adjacentEdge in adjacentEdges)
        {
            if (adjacentEdge.road != null)
            {
                if (adjacentEdge.road.ownerId == player.GetId())
                {
                    validRoadNearby = true;
                }
            }
        }
        if (!validRoadNearby && player.freeSettlements <= 0)
        {
            return(false);
        }

        // Check if cost requirements met
        if (!player.CanAffordResourceTransaction(1, 1, 1, 1, 0) && player.freeSettlements <= 0)
        {
            return(false);
        }

        // Check to see if tile contains a building and have enough settlements in store
        if (boardGrid.GetVertex(col, row, vertexSpec).settlement == null && player.storeSettlementNum > 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }