mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-13 00:04:38 +07:00
chore: Modernized WorkerAutomationTest
This commit is contained in:
parent
05f9d3cb36
commit
c787ab1a30
@ -1,21 +1,9 @@
|
|||||||
package com.unciv.logic.automation.unit
|
package com.unciv.logic.automation.unit
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2
|
|
||||||
import com.unciv.UncivGame
|
|
||||||
import com.unciv.logic.GameInfo
|
|
||||||
import com.unciv.logic.city.City
|
|
||||||
import com.unciv.logic.civilization.Civilization
|
import com.unciv.logic.civilization.Civilization
|
||||||
import com.unciv.logic.civilization.PlayerType
|
|
||||||
import com.unciv.logic.map.TileMap
|
|
||||||
import com.unciv.logic.map.mapunit.MapUnit
|
|
||||||
import com.unciv.logic.map.tile.RoadStatus
|
import com.unciv.logic.map.tile.RoadStatus
|
||||||
import com.unciv.logic.map.tile.Tile
|
|
||||||
import com.unciv.models.metadata.GameSettings
|
|
||||||
import com.unciv.models.ruleset.Ruleset
|
|
||||||
import com.unciv.models.ruleset.RulesetCache
|
|
||||||
import com.unciv.models.ruleset.nation.Nation
|
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
|
||||||
import com.unciv.testing.GdxTestRunner
|
import com.unciv.testing.GdxTestRunner
|
||||||
|
import com.unciv.uniques.TestGame
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@ -24,41 +12,15 @@ import org.junit.runner.RunWith
|
|||||||
|
|
||||||
@RunWith(GdxTestRunner::class)
|
@RunWith(GdxTestRunner::class)
|
||||||
internal class WorkerAutomationTest {
|
internal class WorkerAutomationTest {
|
||||||
private val testCivilizationNames = arrayListOf("America", "Germany", "Greece","Hanoi", "Genoa")
|
|
||||||
private lateinit var workerAutomation: WorkerAutomation
|
private lateinit var workerAutomation: WorkerAutomation
|
||||||
private lateinit var civInfo: Civilization
|
private lateinit var civInfo: Civilization
|
||||||
private lateinit var gameInfo: GameInfo
|
|
||||||
private lateinit var ruleset: Ruleset
|
val testGame = TestGame()
|
||||||
private lateinit var uncivGame: UncivGame
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
// RuleSet
|
testGame.makeHexagonalMap(7)
|
||||||
RulesetCache.loadRulesets(noMods = true)
|
civInfo = testGame.addCiv()
|
||||||
ruleset = RulesetCache.getVanillaRuleset()
|
|
||||||
|
|
||||||
// GameInfo
|
|
||||||
gameInfo = GameInfo()
|
|
||||||
gameInfo.ruleset = ruleset
|
|
||||||
|
|
||||||
// UncivGame
|
|
||||||
uncivGame = UncivGame(true)
|
|
||||||
uncivGame.settings = GameSettings()
|
|
||||||
UncivGame.Current = uncivGame
|
|
||||||
|
|
||||||
for (civName in testCivilizationNames)
|
|
||||||
gameInfo.civilizations.add(Civilization(civName).apply { playerType= PlayerType.Human })
|
|
||||||
gameInfo.tileMap = TileMap(7, ruleset)
|
|
||||||
|
|
||||||
// Initialize test civilizations
|
|
||||||
for (ci in gameInfo.civilizations) {
|
|
||||||
ci.gameInfo = gameInfo
|
|
||||||
ci.nation = Nation()
|
|
||||||
ci.nation.name = ci.civName
|
|
||||||
}
|
|
||||||
gameInfo.setTransients()
|
|
||||||
civInfo = gameInfo.civilizations.first()
|
|
||||||
|
|
||||||
workerAutomation = WorkerAutomation(civInfo, 3)
|
workerAutomation = WorkerAutomation(civInfo, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,16 +28,17 @@ internal class WorkerAutomationTest {
|
|||||||
fun `should replace already existing improvement to enable resource`() {
|
fun `should replace already existing improvement to enable resource`() {
|
||||||
// Add the needed tech to construct the improvements below
|
// Add the needed tech to construct the improvements below
|
||||||
for (improvement in listOf(RoadStatus.Road.name, "Farm", "Mine")) {
|
for (improvement in listOf(RoadStatus.Road.name, "Farm", "Mine")) {
|
||||||
civInfo.tech.techsResearched.add(ruleset.tileImprovements[improvement]!!.techRequired!!)
|
civInfo.tech.techsResearched.add(testGame.ruleset.tileImprovements[improvement]!!.techRequired!!)
|
||||||
}
|
}
|
||||||
civInfo.tech.techsResearched.add(ruleset.tileResources["Iron"]!!.revealedBy!!)
|
civInfo.tech.techsResearched.add(testGame.ruleset.tileResources["Iron"]!!.revealedBy!!)
|
||||||
|
|
||||||
civInfo.cities = listOf(createCity(civInfo, Vector2(0f, 0f), "Capital", true))
|
testGame.addCity(civInfo, testGame.tileMap[0,0])
|
||||||
val currentTile = gameInfo.tileMap[1,1]
|
|
||||||
currentTile.setOwningCity(civInfo.cities.first())
|
val currentTile = testGame.tileMap[1,1] // owned by city
|
||||||
currentTile.improvement = "Farm" // Set existing improvement
|
currentTile.improvement = "Farm" // Set existing improvement
|
||||||
currentTile.resource = "Iron" // This tile also has a resource needs to be enabled by a building a Mine
|
currentTile.resource = "Iron" // This tile also has a resource needs to be enabled by a building a Mine
|
||||||
val mapUnit = addUnit("Worker", civInfo, currentTile)
|
|
||||||
|
val mapUnit = testGame.addUnit("Worker", civInfo, currentTile)
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
workerAutomation.automateWorkerAction(mapUnit, setOf())
|
workerAutomation.automateWorkerAction(mapUnit, setOf())
|
||||||
@ -85,26 +48,4 @@ internal class WorkerAutomationTest {
|
|||||||
"Mine", currentTile.improvementInProgress)
|
"Mine", currentTile.improvementInProgress)
|
||||||
assertTrue(currentTile.turnsToImprovement > 0)
|
assertTrue(currentTile.turnsToImprovement > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createCity(civInfo: Civilization, position: Vector2, name: String,
|
|
||||||
capital: Boolean = false
|
|
||||||
): City {
|
|
||||||
return City().apply {
|
|
||||||
location = position
|
|
||||||
if (capital)
|
|
||||||
cityConstructions.builtBuildings.add(ruleset.buildings.values.first { it.hasUnique(
|
|
||||||
UniqueType.IndicatesCapital) }.name)
|
|
||||||
this.name = name
|
|
||||||
setTransients(civInfo)
|
|
||||||
gameInfo.tileMap[location].setOwningCity(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addUnit(name: String, civInfo: Civilization, tile: Tile): MapUnit {
|
|
||||||
val baseUnit = ruleset.units[name]!!
|
|
||||||
baseUnit.ruleset = ruleset
|
|
||||||
val mapUnit = baseUnit.getMapUnit(civInfo)
|
|
||||||
mapUnit.putInTile(tile)
|
|
||||||
return mapUnit
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user