Improved AI city location picking

Done by ignoring tiles already belonging to another civ / within work range of another city
This commit is contained in:
Yair Morgenstern 2023-06-12 10:27:21 +03:00
parent 404a148cfb
commit e5232494a0
2 changed files with 16 additions and 18 deletions

View File

@ -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,

View File

@ -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 | |
<!--- DO NOT REMOVE OR MODIFY THIS LINE UI_ELEMENT_TABLE_REGION_END -->
## SkinConfig