mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Fixed bug where units could still be purchased if they used a depleted resource (#4798)
This commit is contained in:
parent
0c1a21f6ae
commit
6d5fe2ff7a
@ -365,12 +365,11 @@ class CityConstructions {
|
|||||||
val inProgressSnapshot = inProgressConstructions.keys.filter { it != currentConstructionFromQueue }
|
val inProgressSnapshot = inProgressConstructions.keys.filter { it != currentConstructionFromQueue }
|
||||||
for (constructionName in inProgressSnapshot) {
|
for (constructionName in inProgressSnapshot) {
|
||||||
val construction = getConstruction(constructionName)
|
val construction = getConstruction(constructionName)
|
||||||
val rejectionReason: String =
|
// Perpetual constructions should always still be valid (I hope)
|
||||||
when (construction) {
|
if (construction is PerpetualConstruction) continue
|
||||||
is Building -> construction.getRejectionReason(this)
|
|
||||||
is BaseUnit -> construction.getRejectionReason(this)
|
val rejectionReason =
|
||||||
else -> ""
|
(construction as INonPerpetualConstruction).getRejectionReason(this)
|
||||||
}
|
|
||||||
|
|
||||||
if (rejectionReason.endsWith("lready built")
|
if (rejectionReason.endsWith("lready built")
|
||||||
|| rejectionReason.startsWith("Cannot be built with")
|
|| rejectionReason.startsWith("Cannot be built with")
|
||||||
|
@ -22,6 +22,7 @@ interface INonPerpetualConstruction : IConstruction, INamed {
|
|||||||
|
|
||||||
fun getProductionCost(civInfo: CivilizationInfo): Int
|
fun getProductionCost(civInfo: CivilizationInfo): Int
|
||||||
fun getStatBuyCost(cityInfo: CityInfo, stat: Stat): Int?
|
fun getStatBuyCost(cityInfo: CityInfo, stat: Stat): Int?
|
||||||
|
fun getRejectionReason(cityConstructions: CityConstructions): String
|
||||||
|
|
||||||
private fun getMatchingUniques(uniqueTemplate: String): Sequence<Unique> {
|
private fun getMatchingUniques(uniqueTemplate: String): Sequence<Unique> {
|
||||||
return uniqueObjects.asSequence().filter { it.placeholderText == uniqueTemplate }
|
return uniqueObjects.asSequence().filter { it.placeholderText == uniqueTemplate }
|
||||||
@ -41,6 +42,13 @@ interface INonPerpetualConstruction : IConstruction, INamed {
|
|||||||
) return true
|
) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if the construction should be purchasable, not whether it can be bought with a stat at all */
|
||||||
|
fun isPurchasable(cityConstructions: CityConstructions): Boolean {
|
||||||
|
val rejectionReason = getRejectionReason(cityConstructions)
|
||||||
|
return rejectionReason == ""
|
||||||
|
|| rejectionReason == "Can only be purchased"
|
||||||
|
}
|
||||||
|
|
||||||
fun canBePurchasedWithAnyStat(cityInfo: CityInfo): Boolean {
|
fun canBePurchasedWithAnyStat(cityInfo: CityInfo): Boolean {
|
||||||
return Stat.values().any { canBePurchasedWithStat(cityInfo, it) }
|
return Stat.values().any { canBePurchasedWithStat(cityInfo, it) }
|
||||||
@ -107,7 +115,7 @@ open class PerpetualConstruction(override var name: String, val description: Str
|
|||||||
|
|
||||||
override fun isBuildable(cityConstructions: CityConstructions): Boolean =
|
override fun isBuildable(cityConstructions: CityConstructions): Boolean =
|
||||||
throw Exception("Impossible!")
|
throw Exception("Impossible!")
|
||||||
|
|
||||||
override fun postBuildEvent(cityConstructions: CityConstructions, wasBought: Boolean) =
|
override fun postBuildEvent(cityConstructions: CityConstructions, wasBought: Boolean) =
|
||||||
throw Exception("Impossible!")
|
throw Exception("Impossible!")
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
|||||||
|| rejectionReason == "Can only be purchased"
|
|| rejectionReason == "Can only be purchased"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRejectionReason(construction: CityConstructions): String {
|
override fun getRejectionReason(construction: CityConstructions): String {
|
||||||
if (construction.isBuilt(name)) return "Already built"
|
if (construction.isBuilt(name)) return "Already built"
|
||||||
// for buildings that are created as side effects of other things, and not directly built
|
// for buildings that are created as side effects of other things, and not directly built
|
||||||
// unless they can be bought with faith
|
// unless they can be bought with faith
|
||||||
|
@ -240,7 +240,7 @@ class BaseUnit : INamed, INonPerpetualConstruction, CivilopediaText() {
|
|||||||
|| rejectionReason == "Can only be purchased"
|
|| rejectionReason == "Can only be purchased"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRejectionReason(cityConstructions: CityConstructions): String {
|
override fun getRejectionReason(cityConstructions: CityConstructions): String {
|
||||||
if (isWaterUnit() && !cityConstructions.cityInfo.isCoastal())
|
if (isWaterUnit() && !cityConstructions.cityInfo.isCoastal())
|
||||||
return "Can only build water units in coastal cities"
|
return "Can only build water units in coastal cities"
|
||||||
val civInfo = cityConstructions.cityInfo.civInfo
|
val civInfo = cityConstructions.cityInfo.civInfo
|
||||||
|
@ -429,11 +429,12 @@ class CityConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cityScreen.canChangeState
|
if (!cityScreen.canChangeState
|
||||||
|| city.isPuppet
|
|| !construction.isPurchasable(city.cityConstructions)
|
||||||
|| city.isInResistance()
|
|| city.isPuppet
|
||||||
|| !city.canPurchase(construction)
|
|| city.isInResistance()
|
||||||
|| (constructionBuyCost > city.getStatReserve(stat) && !city.civInfo.gameInfo.gameParameters.godMode))
|
|| !city.canPurchase(construction)
|
||||||
button.disable()
|
|| (constructionBuyCost > city.getStatReserve(stat) && !city.civInfo.gameInfo.gameParameters.godMode)
|
||||||
|
) button.disable()
|
||||||
}
|
}
|
||||||
|
|
||||||
button.labelCell.pad(5f)
|
button.labelCell.pad(5f)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user