mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 22:37:02 -04:00
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:
parent
404a148cfb
commit
e5232494a0
@ -15,9 +15,9 @@ object CityLocationTileRanker {
|
|||||||
for (city in unit.civ.gameInfo.getCities()) {
|
for (city in unit.civ.gameInfo.getCities()) {
|
||||||
val center = city.getCenterTile()
|
val center = city.getCenterTile()
|
||||||
if (unit.civ.knows(city.civ) &&
|
if (unit.civ.knows(city.civ) &&
|
||||||
// If the CITY OWNER knows that the UNIT OWNER agreed not to settle near them
|
// If the CITY OWNER knows that the UNIT OWNER agreed not to settle near them
|
||||||
city.civ.getDiplomacyManager(unit.civ)
|
city.civ.getDiplomacyManager(unit.civ)
|
||||||
.hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs)
|
.hasFlag(DiplomacyFlags.AgreedToNotSettleNearUs)
|
||||||
) {
|
) {
|
||||||
yieldAll(
|
yieldAll(
|
||||||
center.getTilesInDistance(6)
|
center.getTilesInDistance(6)
|
||||||
@ -42,33 +42,29 @@ object CityLocationTileRanker {
|
|||||||
|
|
||||||
val distanceFromHome = if (unit.civ.cities.isEmpty()) 0
|
val distanceFromHome = if (unit.civ.cities.isEmpty()) 0
|
||||||
else unit.civ.cities.minOf { it.getCenterTile().aerialDistanceTo(unit.getTile()) }
|
else unit.civ.cities.minOf { it.getCenterTile().aerialDistanceTo(unit.getTile()) }
|
||||||
val range = (8 - distanceFromHome).coerceIn(
|
val range = (8 - distanceFromHome).coerceIn(1, 5) // Restrict vision when far from home to avoid death marches
|
||||||
1,
|
|
||||||
5
|
|
||||||
) // Restrict vision when far from home to avoid death marches
|
|
||||||
|
|
||||||
val possibleCityLocations = unit.getTile().getTilesInDistance(range)
|
val possibleCityLocations = unit.getTile().getTilesInDistance(range)
|
||||||
.filter { canUseTileForRanking(it, unit.civ) }
|
.filter { canUseTileForRanking(it, unit.civ) }
|
||||||
.filter {
|
.filter {
|
||||||
val tileOwner = it.getOwner()
|
val tileOwner = it.getOwner()
|
||||||
it.isLand && !it.isImpassible() && (tileOwner == null || tileOwner == unit.civ) // don't allow settler to settle inside other civ's territory
|
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))
|
&& (unit.currentTile == it || unit.movement.canMoveTo(it))
|
||||||
&& it !in tilesNearCities
|
&& it !in tilesNearCities
|
||||||
}
|
}
|
||||||
|
|
||||||
val luxuryResourcesInCivArea = getLuxuryResourcesInCivArea(unit.civ)
|
val luxuryResourcesInCivArea = getLuxuryResourcesInCivArea(unit.civ)
|
||||||
|
|
||||||
return possibleCityLocations
|
return possibleCityLocations
|
||||||
.map {
|
.map {
|
||||||
Pair(
|
it to
|
||||||
it,
|
|
||||||
rankTileAsCityCenterWithCachedValues(
|
rankTileAsCityCenterWithCachedValues(
|
||||||
it,
|
it,
|
||||||
nearbyTileRankings,
|
nearbyTileRankings,
|
||||||
luxuryResourcesInCivArea,
|
luxuryResourcesInCivArea,
|
||||||
unit.civ
|
unit.civ
|
||||||
),
|
)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.sortedByDescending { it.second }
|
.sortedByDescending { it.second }
|
||||||
}
|
}
|
||||||
@ -88,8 +84,10 @@ object CityLocationTileRanker {
|
|||||||
tile: Tile,
|
tile: Tile,
|
||||||
civ: Civilization
|
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(
|
private fun getNearbyTileRankings(
|
||||||
tile: Tile,
|
tile: Tile,
|
||||||
|
@ -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/ | ResourceTable | null | |
|
||||||
| WorldScreen/TopBar/ | RightAttachment | roundedEdgeRectangle | |
|
| WorldScreen/TopBar/ | RightAttachment | roundedEdgeRectangle | |
|
||||||
| WorldScreen/TopBar/ | StatsTable | null | |
|
| WorldScreen/TopBar/ | StatsTable | null | |
|
||||||
| WorldScreenMusicPopup/TrackList/ | Down", tintColor = skin.getColor("positive | null | |
|
| WorldScreenMusicPopup/TrackList/ | Down | null | |
|
||||||
| WorldScreenMusicPopup/TrackList/ | Over", tintColor = skin.getColor("highlight | null | |
|
| WorldScreenMusicPopup/TrackList/ | Over | null | |
|
||||||
| WorldScreenMusicPopup/TrackList/ | Up", tintColor = skin.getColor("color | null | |
|
| WorldScreenMusicPopup/TrackList/ | Up | null | |
|
||||||
<!--- DO NOT REMOVE OR MODIFY THIS LINE UI_ELEMENT_TABLE_REGION_END -->
|
<!--- DO NOT REMOVE OR MODIFY THIS LINE UI_ELEMENT_TABLE_REGION_END -->
|
||||||
|
|
||||||
## SkinConfig
|
## SkinConfig
|
||||||
|
Loading…
x
Reference in New Issue
Block a user