mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-12 16:59:11 +07:00
Consume stockpiled resources when purchasing constructions that require them
This commit is contained in:
@ -690,6 +690,17 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
) {
|
||||
city.civ.civConstructions.boughtItemsWithIncreasingPrice.add(construction.name, 1)
|
||||
}
|
||||
|
||||
// Consume stockpiled resources - usually consumed when construction starts, but not when bought
|
||||
if (getWorkDone(construction.name) == 0){ // we didn't pay the resources when we started building
|
||||
val costUniques = construction.getMatchingUniques(UniqueType.CostsResources, conditionalState)
|
||||
|
||||
for (unique in costUniques) {
|
||||
val amount = unique.params[0].toInt()
|
||||
val resourceName = unique.params[1]
|
||||
city.civ.resourceStockpiles.add(resourceName, -amount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (queuePosition in 0 until constructionQueue.size)
|
||||
|
@ -304,4 +304,18 @@ class ResourceTests {
|
||||
game.gameInfo.nextTurn()
|
||||
assert(civInfo.getCivResourcesByName()[resource.name] == 1) // 1 was consumed because production started
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stockpiledResourcesConsumedWhenConstructionPurchased() {
|
||||
// given
|
||||
val resource = game.createResource(UniqueType.Stockpiled.text)
|
||||
val building = game.createBuilding("Instantly provides [2] [${resource.name}]")
|
||||
city.cityConstructions.addBuilding(building)
|
||||
assert(civInfo.getCivResourcesByName()[resource.name] == 2)
|
||||
|
||||
val consumingBuilding = game.createBuilding("Costs [1] [${resource.name}]")
|
||||
assert(civInfo.getCivResourcesByName()[resource.name] == 2) // no change yet
|
||||
city.cityConstructions.purchaseConstruction(consumingBuilding.name, -1, false)
|
||||
assert(civInfo.getCivResourcesByName()[resource.name] == 1) // 1 was consumed because production started
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user