# HG changeset patch # User Quintillus # Date 1712245555 14400 # Thu Apr 04 11:45:55 2024 -0400 # Node ID d96f15c954c82532c7d899207c94f4670598b921 # Parent cfa4f571e14bab36c51e53da4f6f4c2dd95718a7 Add a utility method to grab a tile based on its coordinates. Kind of surprised one of these didn't already exist. diff --git a/src/main/java/com/civfanatics/civ3/biqFile/IO.java b/src/main/java/com/civfanatics/civ3/biqFile/IO.java --- a/src/main/java/com/civfanatics/civ3/biqFile/IO.java +++ b/src/main/java/com/civfanatics/civ3/biqFile/IO.java @@ -6655,6 +6655,21 @@ } /** + * Convenience method that returns the tile at a given index. Wraps around + * the world if need be. + * @param xPos The xlocation + * @param yPos The ylocation + * @return The tile at that location, or null if the location is not valid + */ + public TILE getTileAt(int xPos, int yPos) { + int tileIndex = calculateTileIndex(xPos, yPos); + if (tileIndex == -1) { + return null; + } + return tile.get(tileIndex); + } + + /** * Returns the 8 surrounding tiles. * If some of them are off the map, it returns fewer. * May be expanded to the 21 tiles cross at one point.