public static WorldChunkController ChunkOfDefaultTerrain(Coords chunkCoords) { WorldChunkController controller = new WorldChunkController(chunkCoords); controller.WorldChunkModel.grid = new WorldCellController[WorldChunkModel.ChunkSize, WorldChunkModel.ChunkSize]; for (int i = 0; i < Math.Pow(WorldChunkModel.ChunkSize, 2); i++) { // Calculate chunk-relative X and Y (between 0 and ChunkSize) int relXIndex = (int)i % WorldChunkModel.ChunkSize; int relYIndex = (int)Math.Floor(i / (double)WorldChunkModel.ChunkSize); WorldCellController cellController = WorldCellFactory.GetNewCell( new Structs.FloatCoords { x = chunkCoords.x * WorldChunkModel.ChunkSize + relXIndex, y = chunkCoords.y * WorldChunkModel.ChunkSize + relYIndex }); cellController.worldCellModel.ParentChunk = controller.WorldChunkModel; controller.WorldChunkModel.grid[relXIndex, relYIndex] = cellController; } return(controller); }
// Checks if Diagonal move is possible/not blocked public bool IsDiagonalPathBlocked(Coords originCoords, Coords destinationCoords, LocationModel unitLocationModel) { CoordsCalculator coordsCalculator = new CoordsCalculator((FloatCoords)originCoords); if (!coordsCalculator.GetNeighbours().Contains((FloatCoords)destinationCoords)) { throw new ArgumentException("destinationCoords must be neighbouring originCoords"); } //checks if coords are next to each other if (coordsCalculator.GetNonDiagonalNeighbours().Contains((FloatCoords)destinationCoords)) { return(false); } Coords commonNeighbour1 = new Coords { x = originCoords.x, y = destinationCoords.y }; Coords commonNeighbour2 = new Coords { x = destinationCoords.x, y = originCoords.y }; WorldCellController cell1 = worldController.GetCellFromCoords(commonNeighbour1); WorldCellController cell2 = worldController.GetCellFromCoords(commonNeighbour2); //Checks if both coords are blocked by an obstacle return(cell1 != null && IsCellImpassable(cell1.worldCellModel, unitLocationModel) || cell2 != null && IsCellImpassable(cell2.worldCellModel, unitLocationModel)); }
public void AddStructure(IStructure <IStructureDef> building) { foreach (Coords coords in building.Def.BuildingShape) { Coords actual = coords + building.StartCoords; WorldCellController cell = GetCellFromCoords(actual); // add building to the cells its on cell.worldCellModel.BuildingOnTop = building; // add cells to the building building.OccupiedCells.Add(cell.worldCellModel); } // add building to buildinglist WorldModel.Structures.Add(building); }
/// <summary> /// sets everything within viewrange from the coords to the specified viewmode /// </summary> /// <param name="mode"></param> /// <param name="viewrange"></param> /// <param name="coords"></param> public void UpdateViewMode(ViewMode mode, int viewrange, FloatCoords coords) { // loop from -viewrange to + viewrange for (int x = (viewrange) * -1; x <= viewrange; x++) { for (int y = (viewrange) * -1; y <= viewrange; y++) { // set coords relative to the given coords Coords tempcoords = (Coords) new FloatCoords { x = x + coords.x, y = y + coords.y }; // check if the coords are within viewrange if (!(DistanceCalculator.DiagonalDistance((FloatCoords)tempcoords, coords) < viewrange)) { continue; } // get the cell from the tempcoords WorldCellController cellController = worldController.GetCellFromCoords(tempcoords); // check if the cellcontroller exists if (cellController == null) { continue; } // set the viewmode cellController.ChangeViewMode(mode); // check if there is a building in the cell if (cellController.worldCellModel.BuildingOnTop == null) { continue; } // set viewmode of the building on the cell if (cellController.worldCellModel.BuildingOnTop.GetType() == typeof(BuildingController)) { ((BuildingController)cellController.worldCellModel.BuildingOnTop).BuildingView.ViewMode = mode; } // set viewmode of the ConstructingBuilding on the cell if (cellController.worldCellModel.BuildingOnTop.GetType() == typeof(ConstructingBuildingController)) { ((ConstructingBuildingController)cellController.worldCellModel.BuildingOnTop).ConstructingBuildingView.ViewMode = mode; } } } }