public static int GetTileNeighborByDirection6WayInt(this WorldGrid grid, int tileID, int dir) { grid.GetTileNeighbors(tileID, tmpNeighbors); foreach (int tile2 in tmpNeighbors) { if (grid.GetDirection6WayIntFromTo(tileID, tile2) == dir) { return(tile2); } } return(tileID); }
/*public static int?[] GetTileNeighborsSorted(this WorldGrid wg, int tileID) * { * int?[] sortedNeighbors = new int?[] { null, null, null, null, null, null }; * wg.GetTileNeighbors(tileID, tmpNeighbors); * foreach (int tile2 in tmpNeighbors) * { * int dir = wg.GetDirection6WayIntFromTo(tileID, tile2); * sortedNeighbors[dir] = tile2; * } * return sortedNeighbors; * }*/ /*public static void GetTileDirsOfNeighborsWithSameBiome(this WorldGrid wg, int tileID, List<int> outNeighborDirs, List<int> outAdjacentIds) * { * BiomeDef biome = wg[tileID].biome; * wg.GetTileNeighbors(tileID, tmpNeighbors); * for (int i = 0; i < tmpNeighbors.Count; i++) * { * if (wg[tmpNeighbors[i]].biome == biome) * { * outNeighborDirs.Add(wg.GetDirection6WayIntFromTo(tileID, tmpNeighbors[i])); * outAdjacentIds.Add(i); * } * } * }*/ public static void GetTileDirsOfNeighborsByValidator(this WorldGrid wg, int tileID, List <int> outNeighborDirs, List <int> outAdjacentIds, TileNeightborPredicate validator) { Tile tile = wg[tileID]; wg.GetTileNeighbors(tileID, tmpNeighbors); for (int i = 0; i < tmpNeighbors.Count; i++) { if (validator(tile, wg[tmpNeighbors[i]])) { outNeighborDirs.Add(wg.GetDirection6WayIntFromTo(tileID, tmpNeighbors[i])); outAdjacentIds.Add(i); } } }