// get all buildings from selectionbox public List <IGameActionHolder> SelectBuildings() { List <IGameActionHolder> selected; if (DistanceCalculator.DiagonalDistance(topLeft, bottomRight) < 0.5) { selected = new List <IGameActionHolder>(); WorldCellModel cell = Game.GameModel.World.GetCellFromCoords((Coords)topLeft).worldCellModel; if (cell.BuildingOnTop != null) { selected.Add(cell.BuildingOnTop); } } else { // TODO optimise selected = (from item in Game.PlayerFaction.FactionModel.Buildings where topLeft.x <= item.StartCoords.x + (item.Width / 2) && topLeft.y <= item.StartCoords.y + (item.Height / 2) && bottomRight.x >= item.StartCoords.x + (item.Width / 2) && bottomRight.y >= item.StartCoords.y + (item.Height / 2) select item).Cast <IGameActionHolder>().ToList(); } return(selected); }
// check if coords-range contains building or illegal terrain public bool AreTerrainCellsLegal(IEnumerable <Coords> coordsList, List <TerrainType> whiteList) { foreach (Coords coords in coordsList) { WorldCellModel cell = GetCellFromCoords(coords).worldCellModel; if (cell.BuildingOnTop != null) { return(false); } if (!whiteList.Contains(cell.Terrain)) { return(false); } } return(true); }
// checks if a cell is an obstacle for the specifeid unit private bool CellIsObstacle(WorldCellModel cell, LocationModel unit) => unit.UnwalkableTerrain.Contains(cell.Terrain) || cell.BuildingOnTop != null;
/// <summary> /// Checks if cell is impassible by unit /// </summary> /// <param name="cell">Cell in question</param> /// <param name="unit">Unit that tries to pass</param> /// <returns>Impassibility</returns> private bool IsCellImpassable(WorldCellModel cell, LocationModel unit) { CoordsCalculator coordsCalculator = new CoordsCalculator((FloatCoords)cell.RealCoords); return(coordsCalculator.DistanceToFloatCoords((FloatCoords)unit.Coords) > SearchLimit || CellIsObstacle(cell, unit)); }