mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-11 00:08:58 +07:00
Added more unit tests (#7448)
This commit is contained in:
@ -542,7 +542,7 @@
|
|||||||
"favoredReligion": "Christianity",
|
"favoredReligion": "Christianity",
|
||||||
"uniqueName": "Seven Cities of Gold",
|
"uniqueName": "Seven Cities of Gold",
|
||||||
"uniques": ["100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it)",
|
"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",
|
"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",
|
"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",
|
"Lugo","Alicante","Càdiz","Eiche","Alcorcon","Burgos","Vigo","Badajoz","La Coruña","Guadalquivir","Bilbao",
|
||||||
@ -852,9 +852,9 @@
|
|||||||
"uniqueName": "Patriarchate of Constantinople",
|
"uniqueName": "Patriarchate of Constantinople",
|
||||||
"uniques": ["May choose [1] additional belief(s) of any type when [founding] a religion"],
|
"uniques": ["May choose [1] additional belief(s) of any type when [founding] a religion"],
|
||||||
|
|
||||||
"cities": ["Constantinople", "Adrianople", "Nicaea", "Antioch", "Varna", "Ohrid", "Nicomedia", "Trebizond", "Cherson", "Sardica",
|
"cities": ["Constantinople", "Adrianople", "Nicaea", "Antioch", "Varna", "Ohrid", "Nicomedia", "Trebizond", "Cherson", "Sardica",
|
||||||
"Ani", "Dyrrachium", "Edessa", "Chalcedon", "Naissus", "Bari", "Iconium", "Prilep", "Samosata", "Kars", "Nicopolis", "Theodosiopolis",
|
"Ani", "Dyrrachium", "Edessa", "Chalcedon", "Naissus", "Bari", "Iconium", "Prilep", "Samosata", "Kars", "Nicopolis", "Theodosiopolis",
|
||||||
"Tyana", "Gaza", "Kerkyra", "Phoenice", "Selymbria", "Sillyon", "Chrysopolis", "Vodena", "Caesarea", "Traianoupoli", "Constantia", "Athens",
|
"Tyana", "Gaza", "Kerkyra", "Phoenice", "Selymbria", "Sillyon", "Chrysopolis", "Vodena", "Caesarea", "Traianoupoli", "Constantia", "Athens",
|
||||||
"Patra", "Korinthos"]
|
"Patra", "Korinthos"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -520,7 +520,7 @@
|
|||||||
"innerColor": [255,102,102],
|
"innerColor": [255,102,102],
|
||||||
"uniqueName": "Seven Cities of Gold",
|
"uniqueName": "Seven Cities of Gold",
|
||||||
"uniques": ["100 Gold for discovering a Natural Wonder (bonus enhanced to 500 Gold if first to discover it)",
|
"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",
|
"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",
|
"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",
|
"Lugo","Alicante","Càdiz","Eiche","Alcorcon","Burgos","Vigo","Badajoz","La Coruña","Guadalquivir","Bilbao",
|
||||||
@ -1045,7 +1045,7 @@
|
|||||||
"innerColor": [0,102,102],
|
"innerColor": [0,102,102],
|
||||||
"cities": ["Valletta"]
|
"cities": ["Valletta"]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
//Barbarian
|
//Barbarian
|
||||||
{
|
{
|
||||||
|
@ -599,9 +599,12 @@ class CityStats(val cityInfo: CityInfo) {
|
|||||||
|
|
||||||
val growthNullifyingUnique = cityInfo.getMatchingUniques(UniqueType.NullifiesGrowth).firstOrNull()
|
val growthNullifyingUnique = cityInfo.getMatchingUniques(UniqueType.NullifiesGrowth).firstOrNull()
|
||||||
if (growthNullifyingUnique != null) {
|
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() }
|
val amountToRemove = -newFinalStatList.values.sumOf { it[Stat.Food].toDouble() }
|
||||||
newFinalStatList[getSourceNameForUnique(growthNullifyingUnique)] =
|
newFinalStatList.add(
|
||||||
|
getSourceNameForUnique(growthNullifyingUnique),
|
||||||
Stats().apply { this[Stat.Food] = amountToRemove.toFloat() }
|
Stats().apply { this[Stat.Food] = amountToRemove.toFloat() }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cityInfo.isInResistance())
|
if (cityInfo.isInResistance())
|
||||||
|
@ -102,11 +102,12 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
|||||||
NullifiesStat("Nullifies [stat] [cityFilter]", UniqueTarget.Global),
|
NullifiesStat("Nullifies [stat] [cityFilter]", UniqueTarget.Global),
|
||||||
NullifiesGrowth("Nullifies Growth [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),
|
PercentProductionBuildings("[relativeAmount]% Production when constructing [buildingFilter] buildings [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
|
||||||
PercentProductionUnits("[relativeAmount]% Production when constructing [baseUnitFilter] units [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),
|
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]"?
|
// 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),
|
DoubleStatsFromNaturalWonders("Tile yields from Natural Wonders doubled", UniqueTarget.Global),
|
||||||
|
|
||||||
//endregion Stat providing uniques
|
//endregion Stat providing uniques
|
||||||
|
@ -24,7 +24,7 @@ class GlobalUniquesTests {
|
|||||||
game = TestGame()
|
game = TestGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
// region stat uniques
|
// region base stat bonus providing uniques
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun stats() {
|
fun stats() {
|
||||||
@ -56,7 +56,7 @@ class GlobalUniquesTests {
|
|||||||
val tile = game.setTileFeatures(Vector2(0f,0f), Constants.desert)
|
val tile = game.setTileFeatures(Vector2(0f,0f), Constants.desert)
|
||||||
val cityInfo = game.addCity(civInfo, tile, true, initialPopulation = 2)
|
val cityInfo = game.addCity(civInfo, tile, true, initialPopulation = 2)
|
||||||
val building = game.createBuilding("[+3 Gold] from every specialist [in this city]")
|
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)
|
building.specialistSlots.add(specialistName, 2)
|
||||||
cityInfo.population.specialistAllocations[specialistName] = 2
|
cityInfo.population.specialistAllocations[specialistName] = 2
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ class GlobalUniquesTests {
|
|||||||
val civInfo = game.addCiv()
|
val civInfo = game.addCiv()
|
||||||
val tile = game.setTileFeatures(Vector2(0f,0f), Constants.desert)
|
val tile = game.setTileFeatures(Vector2(0f,0f), Constants.desert)
|
||||||
val cityInfo = game.addCity(civInfo, tile, true, initialPopulation = 2)
|
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}]")
|
val building = game.createBuilding("[+3 Faith] from every [${specialist}]")
|
||||||
|
|
||||||
cityInfo.cityConstructions.addBuilding(building.name)
|
cityInfo.cityConstructions.addBuilding(building.name)
|
||||||
@ -350,7 +350,6 @@ class GlobalUniquesTests {
|
|||||||
val civInfo = game.addCiv()
|
val civInfo = game.addCiv()
|
||||||
val cityState = game.addCiv(cityState = CityStateType.Maritime)
|
val cityState = game.addCiv(cityState = CityStateType.Maritime)
|
||||||
|
|
||||||
|
|
||||||
val tile = game.getTile(Vector2(0f,0f))
|
val tile = game.getTile(Vector2(0f,0f))
|
||||||
val city = game.addCity(civInfo, tile, true)
|
val city = game.addCity(civInfo, tile, true)
|
||||||
val cityStateTile = game.getTile(Vector2(0f, 1f))
|
val cityStateTile = game.getTile(Vector2(0f, 1f))
|
||||||
@ -393,6 +392,109 @@ class GlobalUniquesTests {
|
|||||||
|
|
||||||
// endregion
|
// 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
|
@Test
|
||||||
fun statsSpendingGreatPeople() {
|
fun statsSpendingGreatPeople() {
|
||||||
|
@ -18,6 +18,8 @@ import com.unciv.models.metadata.GameSettings
|
|||||||
import com.unciv.models.ruleset.*
|
import com.unciv.models.ruleset.*
|
||||||
import com.unciv.models.ruleset.tile.TileImprovement
|
import com.unciv.models.ruleset.tile.TileImprovement
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
|
import com.unciv.models.ruleset.unit.BaseUnit
|
||||||
|
import com.unciv.models.ruleset.unit.UnitType
|
||||||
|
|
||||||
class TestGame {
|
class TestGame {
|
||||||
|
|
||||||
@ -145,7 +147,7 @@ class TestGame {
|
|||||||
return mapUnit
|
return mapUnit
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addEmptySpecialist(): String {
|
fun createSpecialist(): String {
|
||||||
val name = "specialist-${objectsCreated++}"
|
val name = "specialist-${objectsCreated++}"
|
||||||
ruleset.specialists[name] = Specialist()
|
ruleset.specialists[name] = Specialist()
|
||||||
return name
|
return name
|
||||||
@ -172,12 +174,21 @@ class TestGame {
|
|||||||
return obj
|
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) =
|
fun createBelief(type: BeliefType = BeliefType.Any, vararg uniques: String) =
|
||||||
createRulesetObject(ruleset.beliefs, *uniques) { Belief(type) }
|
createRulesetObject(ruleset.beliefs, *uniques) { Belief(type) }
|
||||||
fun createBuilding(vararg uniques: String) =
|
fun createBuilding(vararg uniques: String) =
|
||||||
createRulesetObject(ruleset.buildings, *uniques) { Building() }
|
createRulesetObject(ruleset.buildings, *uniques) { Building() }
|
||||||
fun createPolicy(vararg uniques: String) =
|
fun createPolicy(vararg uniques: String) =
|
||||||
createRulesetObject(ruleset.policies, *uniques) { Policy() }
|
createRulesetObject(ruleset.policies, *uniques) { Policy() }
|
||||||
fun createTileImprovement(vararg uniques: String) =
|
fun createTileImprovement(vararg uniques: String) =
|
||||||
createRulesetObject(ruleset.tileImprovements, *uniques) { TileImprovement() }
|
createRulesetObject(ruleset.tileImprovements, *uniques) { TileImprovement() }
|
||||||
|
fun createUnitType(vararg uniques: String) =
|
||||||
|
createRulesetObject(ruleset.unitTypes, *uniques) { UnitType() }
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user