Quick win for #7491 - only update resources after trade/unit if resources are relevant

This commit is contained in:
Yair Morgenstern 2022-07-22 09:26:40 +03:00
parent ae187f4f85
commit 858c7bc256
2 changed files with 9 additions and 5 deletions

View File

@ -483,7 +483,7 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
// exception will happen), also rearrange existing units so that
// 'nextPotentiallyDueAt' becomes 0. This way new units are always last to be due
// (can be changed as wanted, just have a predictable place).
var newList = getCivUnitsStartingAtNextDue().toMutableList()
val newList = getCivUnitsStartingAtNextDue().toMutableList()
newList.add(mapUnit)
units = newList
nextPotentiallyDueAt = 0
@ -492,19 +492,21 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
// Not relevant when updating TileInfo transients, since some info of the civ itself isn't yet available,
// and in any case it'll be updated once civ info transients are
updateStatsForNextTurn() // unit upkeep
updateDetailedCivResources()
if (mapUnit.baseUnit.getResourceRequirements().isNotEmpty())
updateDetailedCivResources()
}
}
fun removeUnit(mapUnit: MapUnit) {
// See comment in addUnit().
var newList = getCivUnitsStartingAtNextDue().toMutableList()
val newList = getCivUnitsStartingAtNextDue().toMutableList()
newList.remove(mapUnit)
units = newList
nextPotentiallyDueAt = 0
updateStatsForNextTurn() // unit upkeep
updateDetailedCivResources()
if (mapUnit.baseUnit.getResourceRequirements().isNotEmpty())
updateDetailedCivResources()
}
fun getIdleUnits() = getCivUnits().filter { it.isIdle() }

View File

@ -580,7 +580,9 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
else civInfo.addNotification("[${offer.name}] to [$otherCivName] has ended", otherCivName, NotificationIcon.Trade)
civInfo.updateStatsForNextTurn() // if they were bringing us gold per turn
civInfo.updateDetailedCivResources() // if they were giving us resources
if (trade.theirOffers.union(trade.ourOffers) // if resources were involved
.any { it.type == TradeType.Luxury_Resource || it.type == TradeType.Strategic_Resource })
civInfo.updateDetailedCivResources()
}
}
}