From e5232494a0e7775a95c7c4ab4ca4c12df1c27704 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 12 Jun 2023 10:27:21 +0300 Subject: [PATCH] Improved AI city location picking Done by ignoring tiles already belonging to another civ / within work range of another city --- .../automation/unit/CityLocationTileRanker.kt | 28 +++++++++---------- docs/Modders/Creating-a-UI-skin.md | 6 ++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/CityLocationTileRanker.kt b/core/src/com/unciv/logic/automation/unit/CityLocationTileRanker.kt index 077de11da8..32bef7ab90 100644 --- a/core/src/com/unciv/logic/automation/unit/CityLocationTileRanker.kt +++ b/core/src/com/unciv/logic/automation/unit/CityLocationTileRanker.kt @@ -15,9 +15,9 @@ object CityLocationTileRanker { for (city in unit.civ.gameInfo.getCities()) { val center = city.getCenterTile() if (unit.civ.knows(city.civ) && - // If the CITY OWNER knows that the UNIT OWNER agreed not to settle near them - city.civ.getDiplomacyManager(unit.civ) - .hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs) + // If the CITY OWNER knows that the UNIT OWNER agreed not to settle near them + city.civ.getDiplomacyManager(unit.civ) + .hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs) ) { yieldAll( center.getTilesInDistance(6) @@ -42,33 +42,29 @@ object CityLocationTileRanker { val distanceFromHome = if (unit.civ.cities.isEmpty()) 0 else unit.civ.cities.minOf { it.getCenterTile().aerialDistanceTo(unit.getTile()) } - val range = (8 - distanceFromHome).coerceIn( - 1, - 5 - ) // Restrict vision when far from home to avoid death marches + val range = (8 - distanceFromHome).coerceIn(1, 5) // Restrict vision when far from home to avoid death marches val possibleCityLocations = unit.getTile().getTilesInDistance(range) .filter { canUseTileForRanking(it, unit.civ) } .filter { val tileOwner = it.getOwner() it.isLand && !it.isImpassible() && (tileOwner == null || tileOwner == unit.civ) // don't allow settler to settle inside other civ's territory - && (unit.currentTile == it || unit.movement.canMoveTo(it)) - && it !in tilesNearCities + && (unit.currentTile == it || unit.movement.canMoveTo(it)) + && it !in tilesNearCities } val luxuryResourcesInCivArea = getLuxuryResourcesInCivArea(unit.civ) return possibleCityLocations .map { - Pair( - it, + it to rankTileAsCityCenterWithCachedValues( it, nearbyTileRankings, luxuryResourcesInCivArea, unit.civ - ), - ) + ) + } .sortedByDescending { it.second } } @@ -88,8 +84,10 @@ object CityLocationTileRanker { tile: Tile, civ: Civilization ) = - // The AI is allowed to cheat and act like it knows the whole map. - tile.isExplored(civ) || civ.isAI() + + (tile.isExplored(civ) || civ.isAI()) // The AI is allowed to cheat and act like it knows the whole map. + && (tile.getOwner() == null || + tile.getOwner() == civ && tile.getTilesInDistance(3).none { it.isCityCenter() }) private fun getNearbyTileRankings( tile: Tile, diff --git a/docs/Modders/Creating-a-UI-skin.md b/docs/Modders/Creating-a-UI-skin.md index 12cf466d5d..751c425008 100644 --- a/docs/Modders/Creating-a-UI-skin.md +++ b/docs/Modders/Creating-a-UI-skin.md @@ -127,9 +127,9 @@ These shapes are used all over Unciv and can be replaced to make a lot of UI ele | WorldScreen/TopBar/ | ResourceTable | null | | | WorldScreen/TopBar/ | RightAttachment | roundedEdgeRectangle | | | WorldScreen/TopBar/ | StatsTable | null | | -| WorldScreenMusicPopup/TrackList/ | Down", tintColor = skin.getColor("positive | null | | -| WorldScreenMusicPopup/TrackList/ | Over", tintColor = skin.getColor("highlight | null | | -| WorldScreenMusicPopup/TrackList/ | Up", tintColor = skin.getColor("color | null | | +| WorldScreenMusicPopup/TrackList/ | Down | null | | +| WorldScreenMusicPopup/TrackList/ | Over | null | | +| WorldScreenMusicPopup/TrackList/ | Up | null | | ## SkinConfig