Trigger resource recalculation upon gaining a unit that requires resources

This commit is contained in:
Yair Morgenstern 2023-06-01 11:43:55 +03:00
parent fcd309781d
commit a7107fa04d
2 changed files with 5 additions and 2 deletions

View File

@ -70,10 +70,13 @@ class UnitManager(val civInfo:Civilization) {
fun placeUnitNearTile(location: Vector2, unitName: String): MapUnit? { fun placeUnitNearTile(location: Vector2, unitName: String): MapUnit? {
val unit = civInfo.gameInfo.tileMap.placeUnitNearTile(location, unitName, civInfo) val unit = civInfo.gameInfo.tileMap.placeUnitNearTile(location, unitName, civInfo)
if (unit != null) if (unit != null) {
for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponGainingUnit)) for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponGainingUnit))
if (unit.matchesFilter(unique.params[0])) if (unit.matchesFilter(unique.params[0]))
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo)
if (unit.baseUnit.getResourceRequirementsPerTurn().isNotEmpty())
civInfo.cache.updateCivResources()
}
return unit return unit
} }
fun getCivUnitsSize(): Int = unitList.size fun getCivUnitsSize(): Int = unitList.size

View File

@ -278,7 +278,7 @@ class CivInfoTransientCache(val civInfo: Civilization) {
for (city in civInfo.cities) newDetailedCivResources.add(city.getCityResources()) for (city in civInfo.cities) newDetailedCivResources.add(city.getCityResources())
for (resourceSupply in newDetailedCivResources) for (resourceSupply in newDetailedCivResources)
if(resourceSupply.amount > 0) if (resourceSupply.amount > 0)
resourceSupply.amount = (resourceSupply.amount * civInfo.getResourceModifier(resourceSupply.resource)).toInt() resourceSupply.amount = (resourceSupply.amount * civInfo.getResourceModifier(resourceSupply.resource)).toInt()
if (!civInfo.isCityState()) { if (!civInfo.isCityState()) {