diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 2dda7490..a12ff3bb 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -213,8 +213,14 @@ class GameInfo { } for (civInfo in civilizations){ + // Since this depends on the cities of ALL civilizations, + // we need to wait until we've set the transients of all the cities before we can run this. + // Hence why it's not in CivInfo.setTransients(). + civInfo.setCitiesConnectedToCapitalTransients() + // We need to determine the GLOBAL happiness state in order to determine the city stats for(cityInfo in civInfo.cities) cityInfo.cityStats.updateCityHappiness() + for (cityInfo in civInfo.cities) cityInfo.cityStats.update() } } diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index bb7d98e4..a40321f7 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -39,6 +39,7 @@ class CivilizationInfo { @Transient private var units=listOf() @Transient var viewableTiles = setOf() @Transient var viewableInvisibleUnitsTiles = setOf() + /** Contains cities from ALL civilizations connected by trade routes to the capital */ @Transient var citiesConnectedToCapital = listOf() @@ -437,7 +438,6 @@ class CivilizationInfo { cityInfo.civInfo = this // must be before the city's setTransients because it depends on the tilemap, that comes from the currentPlayerCivInfo cityInfo.setTransients() } - setCitiesConnectedToCapitalTransients() updateViewableTiles() updateHasActiveGreatWall() updateDetailedCivResources() @@ -550,8 +550,9 @@ class CivilizationInfo { val citiesReachedToMediums = HashMap>() var citiesToCheck = mutableListOf(getCapital()) citiesReachedToMediums[getCapital()] = arrayListOf("Start") + val allCivCities = gameInfo.civilizations.flatMap { it.cities } - while(citiesToCheck.isNotEmpty() && citiesReachedToMediums.size() for(cityToConnectFrom in citiesToCheck){ val reachedMediums = citiesReachedToMediums[cityToConnectFrom]!! @@ -561,7 +562,7 @@ class CivilizationInfo { val roadBfs = BFS(cityToConnectFrom.getCenterTile()){it.roadStatus!=RoadStatus.None} roadBfs.stepToEnd() - val reachedCities = cities.filter { roadBfs.tilesReached.containsKey(it.getCenterTile())} + val reachedCities = allCivCities.filter { roadBfs.tilesReached.containsKey(it.getCenterTile())} for(reachedCity in reachedCities){ if(!citiesReachedToMediums.containsKey(reachedCity)){ newCitiesToCheck.add(reachedCity) @@ -578,7 +579,7 @@ class CivilizationInfo { && cityToConnectFrom.cityConstructions.containsBuildingOrEquivalent("Harbor")){ val seaBfs = BFS(cityToConnectFrom.getCenterTile()){it.isWater || it.isCityCenter()} seaBfs.stepToEnd() - val reachedCities = cities.filter { seaBfs.tilesReached.containsKey(it.getCenterTile())} + val reachedCities = allCivCities.filter { seaBfs.tilesReached.containsKey(it.getCenterTile())} for(reachedCity in reachedCities){ if(!citiesReachedToMediums.containsKey(reachedCity)){ newCitiesToCheck.add(reachedCity) diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index eda4736a..d7d56f18 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -75,7 +75,7 @@ class TileMap { fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit? { val unit = GameBasics.Units[unitName]!!.getMapUnit() val tilesInDistance = getTilesInDistance(position, 2) - unit.assignOwner(civInfo) // both the civ name and actual civ need to be in here in order to calculate the canMoveTo...Darn + unit.assignOwner(civInfo,false) // both the civ name and actual civ need to be in here in order to calculate the canMoveTo...Darn var unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) && (unit.type.isWaterUnit() || it.isLand) } if (unitToPlaceTile==null) unitToPlaceTile = tilesInDistance.firstOrNull { unit.canMoveTo(it) } @@ -88,6 +88,10 @@ class TileMap { // Only once we add the unit to the civ we can activate addPromotion, because it will try to update civ viewable tiles for(promotion in unit.baseUnit.promotions) unit.promotions.addPromotion(promotion,true) + + // And update civ stats, since the new unit changes both unit upkeep and resource consumption + civInfo.updateStatsForNextTurn() + civInfo.updateDetailedCivResources() } else { civInfo.removeUnit(unit) // since we added it to the civ units in the previous assignOwner