/** * Obtains a world coordinate for an edge at a grid coordinate. */ public Vector3 GetPositionOfEdgeCoordinate(int col, int row, BoardGrid.EdgeSpecifier edgeSpec) { Vector3 pos = GetPositionOfFaceCoordinate(col, row); switch (edgeSpec) { case BoardGrid.EdgeSpecifier.N: pos = pos + new Vector3(gridHeight / 4, 0, gridWidth / 2); break; case BoardGrid.EdgeSpecifier.W: pos = pos + new Vector3(-gridHeight / 4, 0, gridWidth / 2); break; case BoardGrid.EdgeSpecifier.E: pos = pos + new Vector3(gridHeight / 2, 0, 0); break; } return(pos); }
/** * Roads must be connected to a settlement or another road. */ public bool CanPlaceRoad(Player player, int col, int row, BoardGrid.EdgeSpecifier edgeSpec) { // Check if connected to a settlement of the same player bool validbuildingWithNoRoadsNearby = false; bool validbuildingNearby = false; List <Vertex> adjacentVertices = boardGrid.GetConnectedVerticesFromEdge(col, row, edgeSpec); foreach (Vertex vertex in adjacentVertices) { Settlement buildingObject = vertex.settlement; if (buildingObject != null) { if (buildingObject != null) { if (buildingObject.ownerId == player.GetId()) { validbuildingNearby = true; int[] vertexPos = boardGrid.GetVertexPosition(vertex); if (vertexPos != null) { List <Edge> edgesTemp = boardGrid.GetAdjacentEdgesFromVertex(vertexPos[0], vertexPos[1], (BoardGrid.VertexSpecifier)vertexPos[2]); int roadCount = 0; foreach (Edge edgeTemp in edgesTemp) { if (edgeTemp.road != null) { roadCount++; } } if (roadCount == 0) { validbuildingWithNoRoadsNearby = true; } } } } } } // Check if connected to a road of the same player bool validRoadNearby = false; List <Edge> adjacentEdges = boardGrid.GetConnectedEdgesFromEdge(col, row, edgeSpec); foreach (Edge adjacentEdge in adjacentEdges) { if (adjacentEdge.road != null) { if (adjacentEdge.road.ownerId == player.GetId()) { // Check that if the road is connected, that it is not interrupted by an enemy settlement int[] adjacentEdgeCoords = boardGrid.GetEdgeCoordinates(adjacentEdge); Vertex vertexBetweenRoads = boardGrid.GetVertexBetweenTwoConnectedEdges(col, row, edgeSpec, adjacentEdgeCoords[0], adjacentEdgeCoords[1], (BoardGrid.EdgeSpecifier)adjacentEdgeCoords[2]); if (vertexBetweenRoads.settlement != null) { if (vertexBetweenRoads.settlement.ownerId == player.GetId()) { validRoadNearby = true; } } else { validRoadNearby = true; } } } } // If it's the second turn, only let the player place next to the settlement with no road if (GameManager.Instance.GetTurnCycle() == 2 && !validbuildingWithNoRoadsNearby) { return(false); } if (!validRoadNearby && !validbuildingNearby) { return(false); } // Check if cost requirements met if (!player.CanAffordResourceTransaction(1, 0, 0, 1, 0) && player.freeRoads <= 0) { return(false); } // Check to see if tile is empty and have enough roads in store Edge edge = boardGrid.GetEdge(col, row, edgeSpec); if (edge.road == null && player.storeRoadNum > 0) { return(true); } else { return(false); } }