Split up unit types to its own JSON file (#4717)

* Split off unitTypes to its own json, only containing the domain it can travel in for now

* Updated translationFileWriter to handle this file correctly

* Updated promotions file

* Implemented requested changes

* Units without a sprite use the sprite of a first unit with the same type

* Implemented proposed changes
This commit is contained in:
Xander Lenstra
2021-08-03 18:06:59 +02:00
committed by GitHub
parent c33e7ae6d2
commit 3b4b9a27bf
29 changed files with 589 additions and 375 deletions

View File

@ -10,7 +10,6 @@ import com.unciv.models.ruleset.Nation
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.ruleset.unit.UnitType
import com.unciv.testing.GdxTestRunner
import org.junit.Assert
import org.junit.Before
@ -55,7 +54,7 @@ class UnitMovementAlgorithmsTests {
tile.terrainFeatures.clear()
tile.setTransients()
unit.baseUnit = BaseUnit().apply { unitType = UnitType.Melee }
unit.baseUnit = BaseUnit().apply { unitType = "Sword"; ruleset = ruleSet }
Assert.assertTrue(terrain.name, terrain.impassable != unit.movement.canPassThrough(tile))
}
@ -82,13 +81,13 @@ class UnitMovementAlgorithmsTests {
city.civInfo = civInfo
cityTile.owningCity = city
for (type in UnitType.values())
for (type in ruleSet.unitTypes)
{
unit.owner = civInfo.civName
unit.baseUnit = BaseUnit().apply { unitType = type }
unit.baseUnit = BaseUnit().apply { unitType = type.key; ruleset = ruleSet }
if(!unit.movement.canPassThrough(cityTile))
unit.movement.canPassThrough(cityTile)
Assert.assertTrue(type.name, unit.movement.canPassThrough(cityTile))
Assert.assertTrue(type.key, unit.movement.canPassThrough(cityTile))
}
}
@ -98,12 +97,11 @@ class UnitMovementAlgorithmsTests {
if (terrain.impassable) continue
tile.baseTerrain = terrain.name
tile.setTransients()
for (type in UnitType.values()) {
if (type == UnitType.City) continue
unit.baseUnit = BaseUnit().apply { unitType = type }
Assert.assertTrue("%s cannot be at %s".format(type, terrain.name),
(type.isWaterUnit() && tile.isLand) != unit.movement.canPassThrough(tile))
for (type in ruleSet.unitTypes) {
unit.baseUnit = BaseUnit().apply { unitType = type.key; ruleset = ruleSet }
Assert.assertTrue("%s cannot be at %s".format(type.key, terrain.name),
(unit.baseUnit.isWaterUnit() && tile.isLand) != unit.movement.canPassThrough(tile))
}
}
}
@ -115,16 +113,18 @@ class UnitMovementAlgorithmsTests {
tile.terrainFeatures.add(Constants.ice)
tile.setTransients()
for (type in UnitType.values()) {
unit.baseUnit = BaseUnit().apply { unitType = type }
for (type in ruleSet.unitTypes) {
unit.baseUnit = BaseUnit().apply { unitType = type.key; ruleset = ruleSet }
if (type == UnitType.WaterSubmarine) {
unit.baseUnit.uniques.add("Can enter ice tiles")
}
unit.updateUniques()
println(type.key + " " + unit.movement.canPassThrough(tile))
println()
Assert.assertTrue("$type cannot be in Ice",
(type == UnitType.WaterSubmarine) == unit.movement.canPassThrough(tile))
Assert.assertTrue("$type cannot be in Ice", (
type.value.uniques.contains("Can enter ice tiles"))
|| type.value.uniques.contains("Can pass through impassable tiles"
) == unit.movement.canPassThrough(tile))
}
}
@ -134,8 +134,8 @@ class UnitMovementAlgorithmsTests {
tile.naturalWonder = "Mount Fuji"
tile.setTransients()
for (type in UnitType.values()) {
unit.baseUnit = BaseUnit().apply { unitType = type }
for (type in ruleSet.unitTypes) {
unit.baseUnit = BaseUnit().apply { unitType = type.key; ruleset = ruleSet }
Assert.assertFalse("$type must not enter Wonder tile", unit.movement.canPassThrough(tile))
}
@ -149,11 +149,11 @@ class UnitMovementAlgorithmsTests {
tile.baseTerrain = Constants.coast
tile.setTransients()
for (type in UnitType.values()) {
unit.baseUnit = BaseUnit().apply { unitType = type }
for (type in ruleSet.unitTypes) {
unit.baseUnit = BaseUnit().apply { unitType = type.key; ruleset = ruleSet }
Assert.assertTrue("$type cannot be in Coast",
unit.type.isLandUnit() != unit.movement.canPassThrough(tile))
unit.baseUnit.isLandUnit() != unit.movement.canPassThrough(tile))
}
}
@ -165,11 +165,11 @@ class UnitMovementAlgorithmsTests {
tile.baseTerrain = Constants.ocean
tile.setTransients()
for (type in UnitType.values()) {
unit.baseUnit = BaseUnit().apply { unitType = type }
for (type in ruleSet.unitTypes) {
unit.baseUnit = BaseUnit().apply { unitType = type.key; ruleset = ruleSet }
Assert.assertTrue("$type cannot be in Ocean",
unit.type.isLandUnit() != unit.movement.canPassThrough(tile))
unit.baseUnit.isLandUnit() != unit.movement.canPassThrough(tile))
}
}
@ -179,24 +179,25 @@ class UnitMovementAlgorithmsTests {
tile.baseTerrain = Constants.ocean
tile.setTransients()
for (type in UnitType.values()) {
for (type in ruleSet.unitTypes) {
unit.baseUnit = BaseUnit().apply {
unitType = type
if (type == UnitType.Melee)
unitType = type.key
ruleset = ruleSet
if (this.isMelee())
uniques.add("Cannot enter ocean tiles")
if (type == UnitType.Ranged)
if (this.isRanged())
uniques.add("Cannot enter ocean tiles until Astronomy")
}
unit.updateUniques()
Assert.assertTrue("$type cannot be in Ocean",
(type == UnitType.Melee) != unit.movement.canPassThrough(tile))
(unit.baseUnit.isMelee()) != unit.movement.canPassThrough(tile))
civInfo.tech.techsResearched.remove("Astronomy")
Assert.assertTrue("$type cannot be in Ocean until Astronomy",
(type == UnitType.Melee ||
type == UnitType.Ranged) != unit.movement.canPassThrough(tile))
(unit.baseUnit.isMelee() || unit.baseUnit.isRanged())
!= unit.movement.canPassThrough(tile))
civInfo.tech.techsResearched.add("Astronomy")
}
@ -214,8 +215,8 @@ class UnitMovementAlgorithmsTests {
otherUnit.civInfo = otherCiv
tile.militaryUnit = otherUnit
for (type in UnitType.values()) {
unit.baseUnit = BaseUnit().apply { unitType = type }
for (type in ruleSet.unitTypes) {
unit.baseUnit = BaseUnit().apply { unitType = type.key; ruleset = ruleSet }
Assert.assertFalse("$type must not enter occupied tile", unit.movement.canPassThrough(tile))
}
@ -235,7 +236,7 @@ class UnitMovementAlgorithmsTests {
city.civInfo = otherCiv
tile.owningCity = city
unit.baseUnit = BaseUnit().apply { unitType = UnitType.Melee }
unit.baseUnit = BaseUnit().apply { unitType = ruleSet.unitTypes.keys.first(); ruleset = ruleSet }
unit.owner = civInfo.civName
Assert.assertFalse("Unit must not enter other civ tile", unit.movement.canPassThrough(tile))