Resolved #12488 - don't reject constructions for missing stockpiled resource costs, AFTER you've already paid them

This commit is contained in:
yairm210 2024-11-18 10:35:40 +02:00
parent f5b0727732
commit 0655cc63a4
3 changed files with 20 additions and 15 deletions

View File

@ -398,13 +398,15 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
}
}
for (unique in getMatchingUniques(UniqueType.CostsResources, stateForConditionals)) {
val amount = unique.params[0].toInt()
val resourceName = unique.params[1]
val availableResources = cityConstructions.city.getAvailableResourceAmount(resourceName)
if (availableResources < amount)
yield(RejectionReasonType.ConsumesResources.toInstance(resourceName.getNeedMoreAmountString(amount - availableResources)))
}
// If we've already paid the unit costs, we don't need to pay it again
if (cityConstructions.getWorkDone(name) == 0)
for (unique in getMatchingUniques(UniqueType.CostsResources, stateForConditionals)) {
val amount = unique.params[0].toInt()
val resourceName = unique.params[1]
val availableResources = cityConstructions.city.getAvailableResourceAmount(resourceName)
if (availableResources < amount)
yield(RejectionReasonType.ConsumesResources.toInstance(resourceName.getNeedMoreAmountString(amount - availableResources)))
}
if (requiredNearbyImprovedResources != null) {
val containsResourceWithImprovement = cityConstructions.city.getWorkableTiles()

View File

@ -191,7 +191,8 @@ enum class UniqueType(
//todo should these two be merged to avoid the confusion?
/** @see UnitActionStockpileCost */
CostsResources("Costs [amount] [stockpiledResource]", UniqueTarget.Improvement, UniqueTarget.Building, UniqueTarget.Unit,
docDescription = "Do not confuse with \"costs [amount] [stockpiledResource]\" (lowercase 'c'), the Unit Action Modifier."),
docDescription = "These resources are removed *when work begins* on the construction. " +
"Do not confuse with \"costs [amount] [stockpiledResource]\" (lowercase 'c'), the Unit Action Modifier."),
// Todo: Get rid of forced sign (+[relativeAmount]) and unify these two, e.g.: "[relativeAmount]% [resource/resourceType] production"
// Note that the parameter type 'resourceType' (strategic, luxury, bonus) currently doesn't exist and should then be added as well
StrategicResourcesIncrease("Quantity of strategic resources produced by the empire +[relativeAmount]%", UniqueTarget.Global), // used by Policies

View File

@ -258,13 +258,15 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
}
}
for (unique in getMatchingUniques(UniqueType.CostsResources, stateForConditionals)) {
val amount = unique.params[0].toInt()
val resourceName = unique.params[1]
val availableResources = city?.getAvailableResourceAmount(resourceName) ?: civ.getResourceAmount(resourceName)
if (availableResources < amount)
yield(RejectionReasonType.ConsumesResources.toInstance(resourceName.getNeedMoreAmountString(amount - availableResources)))
}
// If we've already paid the unit costs, we don't need to pay it again
if (city == null || city.cityConstructions.getWorkDone(name) == 0)
for (unique in getMatchingUniques(UniqueType.CostsResources, stateForConditionals)) {
val amount = unique.params[0].toInt()
val resourceName = unique.params[1]
val availableResources = city?.getAvailableResourceAmount(resourceName) ?: civ.getResourceAmount(resourceName)
if (availableResources < amount)
yield(RejectionReasonType.ConsumesResources.toInstance(resourceName.getNeedMoreAmountString(amount - availableResources)))
}
}
for (unique in civ.getMatchingUniques(UniqueType.CannotBuildUnits, stateForConditionals))