mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-10 15:59:33 +07:00
Added more unit tests (#7448)
This commit is contained in:
@ -542,7 +542,7 @@
|
||||
"favoredReligion": "Christianity",
|
||||
"uniqueName": "Seven Cities of Gold",
|
||||
"uniques": ["100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it)",
|
||||
"Double Happiness from Natural Wonders", "Tile yields from Natural Wonders doubled"],
|
||||
"Double Happiness from Natural Wonders", "[+100]% Yield from every [Natural Wonder]"],
|
||||
"cities": ["Madrid","Barcelona","Seville","Cordoba","Toledo","Santiago","Salamanca","Murcia","Valencia","Zaragoza","Pamplona",
|
||||
"Vitoria","Santander","Oviedo","Jaen","Logroño","Valladolid","Palma","Teruel","Almeria","Leon","Zamora","Mida",
|
||||
"Lugo","Alicante","Càdiz","Eiche","Alcorcon","Burgos","Vigo","Badajoz","La Coruña","Guadalquivir","Bilbao",
|
||||
|
@ -520,7 +520,7 @@
|
||||
"innerColor": [255,102,102],
|
||||
"uniqueName": "Seven Cities of Gold",
|
||||
"uniques": ["100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it)",
|
||||
"Double Happiness from Natural Wonders", "Tile yields from Natural Wonders doubled"],
|
||||
"Double Happiness from Natural Wonders", "[+100]% Yield from every [Natural Wonder]"],
|
||||
"cities": ["Madrid","Barcelona","Seville","Cordoba","Toledo","Santiago","Salamanca","Murcia","Valencia","Zaragoza","Pamplona",
|
||||
"Vitoria","Santander","Oviedo","Jaen","Logroño","Valladolid","Palma","Teruel","Almeria","Leon","Zamora","Mida",
|
||||
"Lugo","Alicante","Càdiz","Eiche","Alcorcon","Burgos","Vigo","Badajoz","La Coruña","Guadalquivir","Bilbao",
|
||||
|
@ -599,9 +599,12 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
|
||||
val growthNullifyingUnique = cityInfo.getMatchingUniques(UniqueType.NullifiesGrowth).firstOrNull()
|
||||
if (growthNullifyingUnique != null) {
|
||||
// Note that negative food will also be nullified. Pretty sure that's conform civ V, but haven't checked.
|
||||
val amountToRemove = -newFinalStatList.values.sumOf { it[Stat.Food].toDouble() }
|
||||
newFinalStatList[getSourceNameForUnique(growthNullifyingUnique)] =
|
||||
newFinalStatList.add(
|
||||
getSourceNameForUnique(growthNullifyingUnique),
|
||||
Stats().apply { this[Stat.Food] = amountToRemove.toFloat() }
|
||||
)
|
||||
}
|
||||
|
||||
if (cityInfo.isInResistance())
|
||||
|
@ -102,11 +102,12 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
||||
NullifiesStat("Nullifies [stat] [cityFilter]", UniqueTarget.Global),
|
||||
NullifiesGrowth("Nullifies Growth [cityFilter]", UniqueTarget.Global),
|
||||
|
||||
PercentProductionWonders("[relativeAmount]% Production when constructing [buildingFilter] wonders [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
|
||||
PercentProductionBuildings("[relativeAmount]% Production when constructing [buildingFilter] buildings [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
|
||||
PercentProductionUnits("[relativeAmount]% Production when constructing [baseUnitFilter] units [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
|
||||
PercentProductionWonders("[relativeAmount]% Production when constructing [buildingFilter] wonders [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
|
||||
PercentProductionBuildingsInCapital("[relativeAmount]% Production towards any buildings that already exist in the Capital", UniqueTarget.Global, UniqueTarget.FollowerBelief),
|
||||
// todo: maybe should be converted to "[+100]% Yield from every [Natural Wonder]"?
|
||||
@Deprecated("As of 4.1.19", ReplaceWith("[+100]% Yield from every [Natural Wonder]"))
|
||||
DoubleStatsFromNaturalWonders("Tile yields from Natural Wonders doubled", UniqueTarget.Global),
|
||||
|
||||
//endregion Stat providing uniques
|
||||
|
@ -24,7 +24,7 @@ class GlobalUniquesTests {
|
||||
game = TestGame()
|
||||
}
|
||||
|
||||
// region stat uniques
|
||||
// region base stat bonus providing uniques
|
||||
|
||||
@Test
|
||||
fun stats() {
|
||||
@ -56,7 +56,7 @@ class GlobalUniquesTests {
|
||||
val tile = game.setTileFeatures(Vector2(0f,0f), Constants.desert)
|
||||
val cityInfo = game.addCity(civInfo, tile, true, initialPopulation = 2)
|
||||
val building = game.createBuilding("[+3 Gold] from every specialist [in this city]")
|
||||
val specialistName = game.addEmptySpecialist()
|
||||
val specialistName = game.createSpecialist()
|
||||
building.specialistSlots.add(specialistName, 2)
|
||||
cityInfo.population.specialistAllocations[specialistName] = 2
|
||||
|
||||
@ -145,7 +145,7 @@ class GlobalUniquesTests {
|
||||
val civInfo = game.addCiv()
|
||||
val tile = game.setTileFeatures(Vector2(0f,0f), Constants.desert)
|
||||
val cityInfo = game.addCity(civInfo, tile, true, initialPopulation = 2)
|
||||
val specialist = game.addEmptySpecialist()
|
||||
val specialist = game.createSpecialist()
|
||||
val building = game.createBuilding("[+3 Faith] from every [${specialist}]")
|
||||
|
||||
cityInfo.cityConstructions.addBuilding(building.name)
|
||||
@ -350,7 +350,6 @@ class GlobalUniquesTests {
|
||||
val civInfo = game.addCiv()
|
||||
val cityState = game.addCiv(cityState = CityStateType.Maritime)
|
||||
|
||||
|
||||
val tile = game.getTile(Vector2(0f,0f))
|
||||
val city = game.addCity(civInfo, tile, true)
|
||||
val cityStateTile = game.getTile(Vector2(0f, 1f))
|
||||
@ -393,6 +392,109 @@ class GlobalUniquesTests {
|
||||
|
||||
// endregion
|
||||
|
||||
// region stat nullifying uniques
|
||||
|
||||
@Test
|
||||
fun nullifiesStat() {
|
||||
game.makeHexagonalMap(1)
|
||||
val civInfo = game.addCiv()
|
||||
val tile = game.getTile(Vector2(0f,0f))
|
||||
val city = game.addCity(civInfo, tile, true, 1)
|
||||
|
||||
val building = game.createBuilding("Nullifies [Faith] [in this city]", "[+10 Gold, +10 Faith] [in this city]")
|
||||
city.cityConstructions.addBuilding(building.name)
|
||||
city.cityStats.update()
|
||||
Assert.assertTrue(city.cityStats.finalStatList.map { it.value.gold }.sum() >= 10f)
|
||||
Assert.assertTrue(city.cityStats.finalStatList.map { it.value.faith }.sum() == 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nullifiesGrowth() {
|
||||
game.makeHexagonalMap(1)
|
||||
val civInfo = game.addCiv()
|
||||
val tile = game.getTile(Vector2(0f,0f))
|
||||
val city = game.addCity(civInfo, tile, true, 1)
|
||||
|
||||
val building = game.createBuilding("Nullifies Growth [in this city]", "[+10 Food, +10 Gold] [in this city]")
|
||||
city.cityConstructions.addBuilding(building.name)
|
||||
city.cityStats.update()
|
||||
Assert.assertTrue(city.cityStats.finalStatList.map { it.value.gold }.sum() >= 10f)
|
||||
Assert.assertTrue(city.cityStats.finalStatList.map { it.value.food }.sum() == 0f)
|
||||
|
||||
city.population.addPopulation(1)
|
||||
city.cityStats.update()
|
||||
Assert.assertTrue(city.cityStats.finalStatList.map { it.value.food }.sum() == 0f)
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
//region production percentage bonus providing uniques based on production
|
||||
|
||||
@Test
|
||||
fun percentProductionBuildings() {
|
||||
val civInfo = game.addCiv()
|
||||
val tile = game.getTile(Vector2(0f,0f))
|
||||
val city = game.addCity(civInfo, tile, true, 0)
|
||||
|
||||
val buildingToConstruct = game.createBuilding()
|
||||
val building = game.createBuilding("[+300]% Production when constructing [${buildingToConstruct.name}] buildings [in all cities]", "[+1 Production]")
|
||||
city.cityConstructions.addBuilding(building.name)
|
||||
city.cityConstructions.addToQueue(buildingToConstruct.name)
|
||||
city.cityStats.update()
|
||||
Assert.assertTrue(city.cityStats.statPercentBonusTree.totalStats.production == 300f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun percentProductionUnits() {
|
||||
val civInfo = game.addCiv()
|
||||
val tile = game.getTile(Vector2(0f,0f))
|
||||
val city = game.addCity(civInfo, tile, true, 0)
|
||||
|
||||
val unitToConstruct = game.createBaseUnit()
|
||||
val building = game.createBuilding("[+300]% Production when constructing [${unitToConstruct.name}] units [in all cities]", "[+1 Production]")
|
||||
city.cityConstructions.addBuilding(building.name)
|
||||
city.cityConstructions.addToQueue(unitToConstruct.name)
|
||||
city.cityStats.update()
|
||||
Assert.assertTrue(city.cityStats.statPercentBonusTree.totalStats.production == 300f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun percentProductionWonders() {
|
||||
val civInfo = game.addCiv()
|
||||
val tile = game.getTile(Vector2(0f,0f))
|
||||
val city = game.addCity(civInfo, tile, true, 0)
|
||||
|
||||
val buildingToConstruct = game.createBuilding()
|
||||
val building = game.createBuilding("[+300]% Production when constructing [${buildingToConstruct.name}] wonders [in all cities]", "[+1 Production]")
|
||||
city.cityConstructions.addBuilding(building.name)
|
||||
city.cityConstructions.addToQueue(buildingToConstruct.name)
|
||||
city.cityStats.update()
|
||||
Assert.assertTrue(city.cityStats.statPercentBonusTree.totalStats.production == 0f)
|
||||
|
||||
buildingToConstruct.isWonder = true
|
||||
city.cityStats.update()
|
||||
Assert.assertTrue(city.cityStats.statPercentBonusTree.totalStats.production == 300f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun percentProductionBuildingsInCapital() {
|
||||
game.makeHexagonalMap(3)
|
||||
val civInfo = game.addCiv("[+300]% Production towards any buildings that already exist in the Capital")
|
||||
val tile = game.getTile(Vector2(0f,2f))
|
||||
val city = game.addCity(civInfo, tile, true, 0)
|
||||
val city2 = game.addCity(civInfo, game.getTile(Vector2(0f, -2f)), initialPopulation = 0)
|
||||
|
||||
val buildingToConstruct = game.createBuilding()
|
||||
city2.cityConstructions.addToQueue(buildingToConstruct.name)
|
||||
city2.cityStats.update()
|
||||
Assert.assertTrue(city2.cityStats.statPercentBonusTree.totalStats.production == 0f)
|
||||
|
||||
city.cityConstructions.addBuilding(buildingToConstruct.name)
|
||||
city2.cityStats.update()
|
||||
Assert.assertTrue(city2.cityStats.statPercentBonusTree.totalStats.production == 300f)
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
@Test
|
||||
fun statsSpendingGreatPeople() {
|
||||
|
@ -18,6 +18,8 @@ import com.unciv.models.metadata.GameSettings
|
||||
import com.unciv.models.ruleset.*
|
||||
import com.unciv.models.ruleset.tile.TileImprovement
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.ruleset.unit.UnitType
|
||||
|
||||
class TestGame {
|
||||
|
||||
@ -145,7 +147,7 @@ class TestGame {
|
||||
return mapUnit
|
||||
}
|
||||
|
||||
fun addEmptySpecialist(): String {
|
||||
fun createSpecialist(): String {
|
||||
val name = "specialist-${objectsCreated++}"
|
||||
ruleset.specialists[name] = Specialist()
|
||||
return name
|
||||
@ -172,6 +174,13 @@ class TestGame {
|
||||
return obj
|
||||
}
|
||||
|
||||
fun createBaseUnit(unitType: String = createUnitType().name, vararg uniques: String) =
|
||||
createRulesetObject(ruleset.units, *uniques) {
|
||||
val baseUnit = BaseUnit()
|
||||
baseUnit.ruleset = gameInfo.ruleSet
|
||||
baseUnit.unitType = unitType
|
||||
baseUnit
|
||||
}
|
||||
fun createBelief(type: BeliefType = BeliefType.Any, vararg uniques: String) =
|
||||
createRulesetObject(ruleset.beliefs, *uniques) { Belief(type) }
|
||||
fun createBuilding(vararg uniques: String) =
|
||||
@ -180,4 +189,6 @@ class TestGame {
|
||||
createRulesetObject(ruleset.policies, *uniques) { Policy() }
|
||||
fun createTileImprovement(vararg uniques: String) =
|
||||
createRulesetObject(ruleset.tileImprovements, *uniques) { TileImprovement() }
|
||||
fun createUnitType(vararg uniques: String) =
|
||||
createRulesetObject(ruleset.unitTypes, *uniques) { UnitType() }
|
||||
}
|
||||
|
Reference in New Issue
Block a user