Пример #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);
        }
    }
Пример #2
0
    /**
     * Obtain a world coordinate for a vertex from a grid coordinate.
     */
    public Vector3 GetPositionOfVertexCoordinate(int col, int row, BoardGrid.VertexSpecifier vertexSpec)
    {
        Vector3 pos = GetPositionOfFaceCoordinate(col, row);

        switch (vertexSpec)
        {
        case BoardGrid.VertexSpecifier.L:
            pos = pos + new Vector3(-gridHeight / 2, 0, 0.28f * gridHeight);
            break;

        case BoardGrid.VertexSpecifier.R:
            pos = pos + new Vector3(gridHeight / 2, 0, -0.28f * gridHeight);
            break;
        }

        return(pos);
    }
Пример #3
0
    /**
     * Can only place cities the player has the resources, and only to upgrade an existing settlement.
     */
    public bool CanPlaceCity(Player player, int col, int row, BoardGrid.VertexSpecifier vertexSpec)
    {
        // Check if cost requirements met (there is no such thing as a free city)
        if (!player.CanAffordResourceTransaction(0, 0, 2, 0, 3))
        {
            return(false);
        }

        Vertex vertex = boardGrid.GetVertex(col, row, vertexSpec);

        // Check to see if vertex contains a settlement and have enough cities in store
        if (vertex.settlement != null && !vertex.settlement.isCity && vertex.settlement.ownerId.Equals(player.GetId()) && player.storeCityNum > 0) // If it is this player's settlement
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }