public static HashSet <Tile> ComputeTileInRange(Tile startTile, int rangeMax, bool blockingTile) { if (rangeMax >= 0) { HashSet <Tile> TileInRange = new HashSet <Tile> (); HashSet <Tile> OpenTiles = new HashSet <Tile> (); OpenTiles.Add(startTile); for (int range = 0; range <= rangeMax; range++) { HashSet <Tile> OpenTilesTemp = new HashSet <Tile> (OpenTiles); foreach (Tile Tile in OpenTilesTemp) { OpenTiles.Remove(Tile); TileInRange.Add(Tile); //foreach(GameObject TileNeighboor in Tile.GetComponent<Tile>().GetNeighboors(startTile.GetComponent<Tile>().GetClearance())) foreach (Tile TileNeighboor in Tile.GetNeighboors()) { if (TileNeighboor.GetFree() == true || blockingTile == false) { OpenTiles.Add(TileNeighboor); } } } } TileInRange.Remove(startTile); return(TileInRange); } else { Debug.LogError("invalid argument"); return(null); } }
public static HashSet <Tile> ComputeTileInRange(SpaceObject ship, bool blockingTile) { Tile startTile = ship.GetReferenceTile(); List <Tile> shipTiles = ship.GetTiles(); if (startTile.GetComponent <Tile> () == null || ship.GetMoveRange() < 0) { Debug.LogError("invalid argument"); return(null); } HashSet <Tile> TilesInRange = new HashSet <Tile> (); HashSet <Tile> TilesInRangeTemp = new HashSet <Tile> (); HashSet <Tile> OpenTiles = new HashSet <Tile> (); /*foreach (GameObject shipTile in shipTiles) * OpenTiles.Add (shipTile);*/ OpenTiles.Add(startTile); for (int range = 0; range <= ship.GetMoveRange(); range++) { HashSet <Tile> OpenTilesTemp = new HashSet <Tile> (OpenTiles); foreach (Tile currentOpenTile in OpenTilesTemp) { List <Tile> currentOpenTileNeighboors = currentOpenTile.GetNeighboors(ship.GetClearance()); OpenTiles.Remove(currentOpenTile); TilesInRange.Add(currentOpenTile); //Debug.Log("TilesInRange.count = " +TilesInRange.Count); //Debug.Log("currentOpenTileNeighboors.count = " +currentOpenTileNeighboors.Count); foreach (Tile TileNeighboor in currentOpenTileNeighboors) { if ((TileNeighboor.GetFree() == true || TileNeighboor.GetSpaceObjectOnTile() == ship || blockingTile == false) && OpenTiles.Contains(TileNeighboor) == false) { OpenTiles.Add(TileNeighboor); } } } } TilesInRangeTemp = new HashSet <Tile> (TilesInRange); foreach (Tile rangeTile in TilesInRangeTemp) { if (ship.GetClearance() > 1) { foreach (Tile boxTile in Utilities.RecoverBox(rangeTile, ship.GetClearance())) { if (TilesInRange.Contains(boxTile) == false && (boxTile.GetFree() == true || blockingTile == false)) { TilesInRange.Add(boxTile); } } } else { TilesInRange.Add(rangeTile); } } return(TilesInRange); }