test: Added test to ensure stockpiled resources are consumed when starting work on "Costs [amount] [stockpiledResource]" construction

This commit is contained in:
yairm210
2024-08-23 10:41:33 +03:00
parent 6265e160e6
commit 9d13303db6

View File

@ -1,6 +1,7 @@
package com.unciv.uniques
import com.badlogic.gdx.math.Vector2
import com.unciv.logic.civilization.PlayerType
import com.unciv.models.ruleset.BeliefType
import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
@ -256,7 +257,7 @@ class ResourceTests {
@Test
fun CityResourcesWorkWithConditional() {
fun cityResourcesWorkWithConditional() {
// given
val resource = game.createResource(UniqueType.CityResource.text)
val resourceAndConditionalBuilding = game.createBuilding("Provides [2] [${resource.name}]",
@ -271,7 +272,7 @@ class ResourceTests {
}
@Test
fun CityResourcesFromImprovementWithConditional() {
fun cityResourcesFromImprovementWithConditional() {
// given
val resource = game.createResource(UniqueType.CityResource.text)
val resourceImprovement = game.createTileImprovement("Provides [2] [${resource.name}] <in [non-[Fresh water]] tiles>")
@ -284,4 +285,23 @@ class ResourceTests {
val resourceAmountInCapital = city.getAvailableResourceAmount(resource.name)
assert(resourceAmountInCapital == 0)
}
@Test
fun stockpiledResourcesConsumedWhenConstructionStarts() {
// 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.currentConstructionFromQueue = consumingBuilding.name
civInfo.playerType = PlayerType.Human // to not loop endlessly on "next turn"
game.gameInfo.currentPlayer = civInfo.civName
game.gameInfo.currentPlayerCiv = civInfo
game.gameInfo.nextTurn()
assert(civInfo.getCivResourcesByName()[resource.name] == 1) // 1 was consumed because production started
}
}