Skip to content

Commit

Permalink
chore: Simplified validateInProgressConstructions
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Jan 19, 2025
1 parent 678df50 commit 159f2e5
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions core/src/com/unciv/logic/city/CityConstructions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -402,30 +402,30 @@ class CityConstructions : IsPartOfGameInfoSerialization {
val rejectionReasons =
(construction as INonPerpetualConstruction).getRejectionReasons(this)

if (rejectionReasons.any { it.hasAReasonToBeRemovedFromQueue() }) {
val workDone = getWorkDone(constructionName)
if (construction is Building) {
// Production put into wonders gets refunded
if (construction.isWonder && workDone != 0) {
city.civ.addGold(workDone)
city.civ.addNotification(
"Excess production for [$constructionName] converted to [$workDone] gold",
city.location,
NotificationCategory.Production,
NotificationIcon.Gold, "BuildingIcons/${constructionName}")
}
} else if (construction is BaseUnit) {
// Production put into upgradable units gets put into upgraded version
val cheapestUpgradeUnit = construction.getRulesetUpgradeUnits(city.state)
.map { city.civ.getEquivalentUnit(it) }
.filter { it.isBuildable(this) }
.minByOrNull { it.cost }
if (rejectionReasons.all { it.type == RejectionReasonType.Obsoleted } && cheapestUpgradeUnit != null) {
inProgressConstructions[cheapestUpgradeUnit.name] = (inProgressConstructions[cheapestUpgradeUnit.name] ?: 0) + workDone
}
if (!rejectionReasons.any { it.hasAReasonToBeRemovedFromQueue() }) continue

val workDone = getWorkDone(constructionName)
if (construction is Building) {
// Production put into wonders gets refunded
if (construction.isWonder && workDone != 0) {
city.civ.addGold(workDone)
city.civ.addNotification(
"Excess production for [$constructionName] converted to [$workDone] gold",
city.location,
NotificationCategory.Production,
NotificationIcon.Gold, "BuildingIcons/${constructionName}")
}
} else if (construction is BaseUnit) {
// Production put into upgradable units gets put into upgraded version
val cheapestUpgradeUnit = construction.getRulesetUpgradeUnits(city.state)
.map { city.civ.getEquivalentUnit(it) }
.filter { it.isBuildable(this) }
.minByOrNull { it.cost }
if (rejectionReasons.all { it.type == RejectionReasonType.Obsoleted } && cheapestUpgradeUnit != null) {
inProgressConstructions[cheapestUpgradeUnit.name] = (inProgressConstructions[cheapestUpgradeUnit.name] ?: 0) + workDone
}
inProgressConstructions.remove(constructionName)
}
inProgressConstructions.remove(constructionName)
}
}

Expand Down

0 comments on commit 159f2e5

Please sign in to comment.