private IHexCell BuildCell( CellTerrain terrain = CellTerrain.Grassland, CellShape shape = CellShape.Flatlands, CellVegetation vegetation = CellVegetation.None, CellFeature feature = CellFeature.None, bool hasRoads = false, bool hasRiver = false, ICity city = null ) { var mockCell = new Mock <IHexCell>(); mockCell.SetupAllProperties(); var newCell = mockCell.Object; newCell.Terrain = terrain; newCell.Shape = shape; newCell.Vegetation = vegetation; newCell.Feature = feature; newCell.HasRoads = hasRoads; MockRiverCanon.Setup(canon => canon.HasRiver(newCell)).Returns(hasRiver); MockCityLocationCanon.Setup(canon => canon.GetPossessionsOfOwner(newCell)) .Returns(city != null ? new List <ICity>() { city } : new List <ICity>()); return(newCell); }
private void RenderCell(CellShape cellShape, int x, int y) { if (CellManager.Instance.cellShape == CellShape.SquareWithWall) { var cell = CellManager.Instance.GetCellByCoordinates(x, y) as SquareCellWithWall; if (cell == null) { return; } // 显示墙 cell.RefreshDirWall(SquareDirection.W); cell.RefreshDirWall(SquareDirection.S); if (x == MapManager.Instance.MapWidth - 1) { cell.RefreshDirWall(SquareDirection.E); } if (y == MapManager.Instance.MapHeight - 1) { cell.RefreshDirWall(SquareDirection.N); } cell.RefreshIsBlock(); } }
// 将触碰位置转换为六边形坐标 public BaseCell GetCellByPos(CellShape shape, Vector3 position) { if (shape == CellShape.Hexagon) { position = transform.InverseTransformPoint(position); Coordinates coordinates = Coordinates.HexCoordinatesFromPosition(position, gridSize); // 首先将单元坐标转换为合适的数组索引,对于一个正方形网格就是X加Z乘以宽度 // 还需要加入半-Z偏移量 int index = coordinates.GetX() + coordinates.GetZ() * width + coordinates.GetZ() / 2; BaseCell cell = CellManager.Instance.cells[index]; return(cell); } else if (shape == CellShape.Square || shape == CellShape.SquareWithWall) { position = transform.InverseTransformPoint(position); Coordinates coordinates = Coordinates.SquareCoordinatesFromPosition(position, gridSize); // 首先将单元坐标转换为合适的数组索引,对于一个正方形网格就是X加Z乘以宽度 // 还需要加入半-Z偏移量 int index = coordinates.GetX() + coordinates.GetZ() * width; BaseCell cell = CellManager.Instance.cells[index]; return(cell); } return(null); }
public void SetActiveShape(int index) { IsPainting = index >= 0; if (IsPainting) { ActiveShape = (CellShape)index; } }
public void GenerateMap(CellShape shape, int width, int height, float gridSize) { MapManager.Instance.SetMapSize(width, height, gridSize); MapManager.Instance.SetCellShape(shape); CreateCells(shape, width, height); RenderCells(shape); }
private IHexCell BuildCell(CellShape shape) { var mockCell = new Mock <IHexCell>(); mockCell.Setup(cell => cell.Shape).Returns(shape); return(mockCell.Object); }
private IHexCell BuildCell(CellTerrain terrain, CellShape shape, CellVegetation vegetation) { var mockCell = new Mock <IHexCell>(); mockCell.Setup(cell => cell.Terrain).Returns(terrain); mockCell.Setup(cell => cell.Shape).Returns(shape); mockCell.Setup(cell => cell.Vegetation).Returns(vegetation); return(mockCell.Object); }
public CellYieldModificationData(CellVegetation featureRequired, YieldSummary bonusYield) { _propertyConsidered = CellPropertyType.Vegetation; _vegetationRequired = featureRequired; _bonusYield = bonusYield; _terrainRequired = CellTerrain.Grassland; _shapeRequired = CellShape.Flatlands; _mustBeUnderwater = false; }
private void CreateCells(CellShape cellShape, int width, int height) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { CreateCell(cellShape, x, y); } } }
private void ResetNeightbors(CellShape cellShape) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { ResetNeightbor(cellShape, x, y); } } }
private void RenderCells(CellShape cellShape) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { RenderCell(cellShape, x, y); } } }
public CellYieldModificationData(bool mustBeUnderwater, YieldSummary bonusYield) { _propertyConsidered = CellPropertyType.CellIsUnderwater; _mustBeUnderwater = mustBeUnderwater; _bonusYield = bonusYield; _terrainRequired = CellTerrain.Grassland; _shapeRequired = CellShape.Flatlands; _vegetationRequired = CellVegetation.None; }
public int GetTreePlacementCostForShape(CellShape shape) { switch (shape) { case CellShape.Flatlands: return(TreesOnFlatlandsCrawlCost); case CellShape.Hills: return(TreesOnHillsCrawlCost); default: return(-1000); } }
public float GetShapeDefensiveness(CellShape shape) { var index = (int)shape; if (index >= ShapeDefensiveness.Count) { return(0); } else { return(ShapeDefensiveness[index]); } }
private IHexCell BuildCell(CellTerrain terrain, CellShape shape, params IImprovement[] improvements) { var mockCell = new Mock <IHexCell>(); mockCell.Setup(cell => cell.Terrain).Returns(terrain); mockCell.Setup(cell => cell.Shape).Returns(shape); var newCell = mockCell.Object; MockImprovementLocationCanon.Setup(canon => canon.GetPossessionsOfOwner(newCell)).Returns(improvements); return(newCell); }
public YieldSummary GetYieldOfShape(CellShape shape) { switch (shape) { case CellShape.Flatlands: return(YieldSummary.Empty); case CellShape.Hills: return(HillsYield); case CellShape.Mountains: return(MountainsYield); default: throw new NotImplementedException(); } }
public int GetBaseMoveCostOfShape(CellShape shape) { switch (shape) { case CellShape.Flatlands: return(0); case CellShape.Hills: return(HillsMoveCost); case CellShape.Mountains: return(MountainsMoveCost); default: throw new NotImplementedException(); } }
public int GetWeightFromShape(CellShape shape) { switch (shape) { case CellShape.Flatlands: return(FlatlandWeight); case CellShape.Hills: return(HillsWeight); case CellShape.Mountains: return(-1000); default: throw new NotImplementedException(); } }
private IHexCell BuildCell( CellTerrain terrain = CellTerrain.Grassland, CellShape shape = CellShape.Flatlands, CellVegetation vegetation = CellVegetation.None, CellFeature feature = CellFeature.None ) { var mockCell = new Mock <IHexCell>(); mockCell.Setup(cell => cell.Terrain).Returns(terrain); mockCell.Setup(cell => cell.Shape).Returns(shape); mockCell.Setup(cell => cell.Vegetation).Returns(vegetation); mockCell.Setup(cell => cell.Feature).Returns(feature); return(mockCell.Object); }
public void ChangeShapeOfCell(IHexCell cell, CellShape shape) { if (!CanChangeShapeOfCell(cell, shape)) { throw new InvalidOperationException("CanChangeShapeOfCell must return true on the given arguments"); } cell.Shape = shape; if (shape != CellShape.Flatlands) { if (cell.Terrain == CellTerrain.FloodPlains) { ChangeTerrainOfCell(cell, CellTerrain.Desert); } if (cell.Vegetation == CellVegetation.Marsh) { ChangeVegetationOfCell(cell, CellVegetation.None); } if (cell.Terrain.IsWater()) { ChangeTerrainOfCell(cell, CellTerrain.Grassland); } if (cell.Vegetation != CellVegetation.None && shape == CellShape.Mountains) { ChangeVegetationOfCell(cell, CellVegetation.None); } if (cell.Feature == CellFeature.Oasis) { ChangeFeatureOfCell(cell, CellFeature.None); } if (shape == CellShape.Mountains && cell.HasRoads) { ChangeHasRoadsOfCell(cell, false); } } cell.SuppressSlot = CityLocationCanon.GetPossessionsOfOwner(cell).Any() || cell.Shape == CellShape.Mountains; }
protected void UpdateSelfPos() { CellShape shape = CellManager.Instance.cellShape; Coordinates coordinates; if (shape == CellShape.SquareWithWall) { Transform mapTrans = MapManager.Instance.GridSystem.transform; if (mapTrans == null) { return; } var position = mapTrans.InverseTransformPoint(transform.position); coordinates = Coordinates.SquareCoordinatesFromPosition(position, MapManager.Instance.GridSize); m_CurrentCellId = CellManager.Instance.GetCellByCoordinates(coordinates.GetX(), coordinates.GetZ()).ID; } }
private void ResetNeightbors() { CellShape cellShape = CellManager.Instance.cellShape; ResetNeightbors(cellShape); }
public bool CanChangeShapeOfCell(IHexCell cell, CellShape shape) { return(true); }
public bool DoesShapeConsumeFullMovement(CellShape shape) { return(ShapesConsumingFullMovement.Contains(shape)); }
private void CreateCell(CellShape cellShape, int x, int y) { Vector2 position; CellManager.Instance.cellShape = cellShape; BaseCell cell; if (CellManager.Instance.cellShape == CellShape.Hexagon) { // 相邻六边形单元X方向的距离是内径的2倍 // 每一行沿着X方向都有一个内径大小的偏移,需要取消一部分的偏移 position.x = (x + y * 0.5f - y / 2) * (HexMetrics.innerRadius * 2f) * gridSize; // 到下一行的距离应该是1.5倍的外径 position.y = y * (HexMetrics.outerRadius * 1.5f) * gridSize; // 将单元保存在数组中,因为默认平面是10*10单位,将每个单元偏移那么多 cell = Instantiate <HexCell>(hexCellPrefab); if (cell == null) { Debug.LogError("生成了个空的"); } // 调整HexGrid.CreateCell来配合新坐标 cell.coordinates = Coordinates.HexCoordinatesFromOffset(x, y); } else if (CellManager.Instance.cellShape == CellShape.Square) { position.x = x * SquareMetrics.sideLength * gridSize; position.y = y * SquareMetrics.sideLength * gridSize; // 将单元保存在数组中,因为默认平面是10*10单位,将每个单元偏移那么多 cell = Instantiate <SquareCell>(squareCellPrefab); if (cell == null) { Debug.LogError("生成了个空的"); } cell.coordinates = Coordinates.SquareCoordinatesFromOffset(x, y); } else if (CellManager.Instance.cellShape == CellShape.SquareWithWall) { position.x = x * SquareMetrics.sideLength * gridSize; position.y = y * SquareMetrics.sideLength * gridSize; // 将单元保存在数组中,因为默认平面是10*10单位,将每个单元偏移那么多 cell = Instantiate <SquareCellWithWall>(squareCellWithWallPrefab); if (cell == null) { Debug.LogError("生成了个空的"); } SquareCellWithWall sqCell = cell as SquareCellWithWall; if (sqCell != null) { sqCell.InitWall(); } cell.coordinates = Coordinates.SquareCoordinatesFromOffset(x, y); } else { Debug.Log(string.Format("网格形状 {cellShape} 不符合要求")); return; } CellManager.Instance.AddCell(cell); int id = CellManager.Instance.GetIdByCoordinates(x, y); cell.SetID(id); cell.transform.SetParent(transform, false); cell.transform.localScale *= gridSize; cell.transform.localPosition = position; ResetNeightbor(cellShape, x, y); }
private void RenderCells() { CellShape cellShape = CellManager.Instance.cellShape; RenderCells(cellShape); }
private void ResetNeightbor(CellShape cellShape, int x, int y) { int id = x + MapManager.Instance.MapWidth * y; if (cellShape == CellShape.Hexagon) { HexCell cell = CellManager.Instance.GetCellByCoordinates(x, y) as HexCell; if (cell == null) { return; } // 初始化 东-西方向 邻居关系 if (x > 0) { cell.SetNeighbor(HexDirection.W, CellManager.Instance.cells[id - 1] as HexCell); } // 有另外两个双向的连接需要完成。由于它们在不同行之间,我们只能连接之前的行。 // 需要跳过整个第一行。 if (y > 0) { // 偶数行 if ((y & 1) == 0) { // 所有单元都有东南方向的邻居。 cell.SetNeighbor(HexDirection.SE, CellManager.Instance.cells[id - width] as HexCell); // 除了第一个单元,都有西南邻居。 if (x > 0) { cell.SetNeighbor(HexDirection.SW, CellManager.Instance.cells[id - width - 1] as HexCell); } } // 奇数行 else { cell.SetNeighbor(HexDirection.SW, CellManager.Instance.cells[id - width] as HexCell); if (x < width - 1) { cell.SetNeighbor(HexDirection.SE, CellManager.Instance.cells[id - width + 1] as HexCell); } } } } else if (cellShape == CellShape.Square) { SquareCell cell = CellManager.Instance.GetCellByCoordinates(x, y) as SquareCell; if (cell == null) { return; } // 初始化 东-西方向 邻居关系 if (x > 0) { cell.SetNeighbor(SquareDirection.W, CellManager.Instance.cells[id - 1] as SquareCell); } // 有另外两个双向的连接需要完成。由于它们在不同行之间,我们只能连接之前的行。 // 需要跳过整个第一行。 if (y > 0) { cell.SetNeighbor(SquareDirection.S, CellManager.Instance.cells[id - width] as SquareCell); } } else if (cellShape == CellShape.SquareWithWall) { SquareCellWithWall cell = CellManager.Instance.GetCellByCoordinates(x, y) as SquareCellWithWall; if (cell == null) { return; } // 初始化 东-西方向 邻居关系 if (x > 0) { cell.SetNeighbor(SquareDirection.W, CellManager.Instance.cells[id - 1] as SquareCellWithWall); } if (y > 0) { cell.SetNeighbor(SquareDirection.S, CellManager.Instance.cells[id - width] as SquareCellWithWall); } } else { Debug.LogError("No Such Shape."); } }
public bool IsCostIgnoredOnShape(CellShape shape) { return(ShapesWithIgnoredCosts.Contains(shape)); }
public void SetCellShape(CellShape shape) { m_Shape = shape; }