2022-05-05 08:09:15 +02:00
|
|
|
package com.unciv.uniques
|
|
|
|
|
|
|
|
import com.badlogic.gdx.math.Vector2
|
2023-06-07 12:35:53 +02:00
|
|
|
import com.sun.source.tree.AssertTree
|
|
|
|
import com.unciv.logic.map.mapunit.UnitTurnManager
|
2023-03-21 13:06:35 +01:00
|
|
|
import com.unciv.models.ruleset.unique.UniqueType
|
|
|
|
import com.unciv.models.translations.fillPlaceholders
|
2022-05-05 08:09:15 +02:00
|
|
|
import com.unciv.testing.GdxTestRunner
|
2023-02-19 07:47:29 +02:00
|
|
|
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActions
|
2023-03-21 13:06:35 +01:00
|
|
|
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActions.getImprovementConstructionActions
|
|
|
|
import org.junit.Assert
|
2022-05-05 08:09:15 +02:00
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
2023-06-07 12:35:53 +02:00
|
|
|
import kotlin.math.roundToInt
|
2022-05-05 08:09:15 +02:00
|
|
|
|
|
|
|
@RunWith(GdxTestRunner::class)
|
|
|
|
class UnitUniquesTests {
|
|
|
|
private lateinit var game: TestGame
|
|
|
|
|
|
|
|
@Before
|
|
|
|
fun initTheWorld() {
|
|
|
|
game = TestGame()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Sweden can gift Great Persons to City States`() {
|
|
|
|
// when
|
2022-05-17 15:42:27 +02:00
|
|
|
game.makeHexagonalMap(1)
|
2022-11-21 20:30:52 +02:00
|
|
|
val cityState = game.addCiv(cityStateType = "Cultured")
|
2022-05-17 15:42:27 +02:00
|
|
|
val cityStateCapitalTile = game.getTile(Vector2(0f, 0f))
|
2022-05-05 08:09:15 +02:00
|
|
|
val cityStateCapital = game.addCity(cityState, cityStateCapitalTile)
|
|
|
|
|
2022-05-22 18:51:05 +02:00
|
|
|
val mainCiv = game.addCiv("Gain [90] Influence with a [Great Person] gift to a City-State",
|
2022-05-05 08:09:15 +02:00
|
|
|
isPlayer = true
|
|
|
|
)
|
|
|
|
|
2022-05-17 15:42:27 +02:00
|
|
|
val unitTile = game.getTile(Vector2(1f, 0f))
|
2022-05-05 08:09:15 +02:00
|
|
|
cityStateCapital.expansion.takeOwnership(unitTile)
|
|
|
|
|
|
|
|
val greatPerson = game.addUnit("Great Scientist", mainCiv, unitTile)
|
|
|
|
|
|
|
|
// then
|
|
|
|
val giftAction = UnitActions.getGiftAction(greatPerson, unitTile)
|
|
|
|
|
2023-03-21 13:06:35 +01:00
|
|
|
Assert.assertNotNull("Great Person should have a gift action", giftAction)
|
|
|
|
}
|
2023-06-07 12:35:53 +02:00
|
|
|
|
2023-03-21 13:06:35 +01:00
|
|
|
@Test
|
|
|
|
fun CanConstructResourceRequiringImprovement() {
|
|
|
|
// Do this early so the uniqueObjects lazy is still un-triggered
|
|
|
|
val improvement = game.ruleset.tileImprovements["Manufactory"]!!
|
|
|
|
val requireUnique = UniqueType.ConsumesResources.text.fillPlaceholders("3", "Iron")
|
|
|
|
improvement.uniques.add(requireUnique)
|
|
|
|
Assert.assertFalse("Test preparation failed to add ConsumesResources to Manufactory",
|
|
|
|
improvement.uniqueObjects.none { it.type == UniqueType.ConsumesResources })
|
|
|
|
|
|
|
|
val civ = game.addCiv(isPlayer = true)
|
|
|
|
val centerTile = game.getTile(Vector2.Zero)
|
|
|
|
val capital = game.addCity(civ, centerTile)
|
|
|
|
|
|
|
|
// Place an Engineer and see if he could create a Manufactory
|
|
|
|
val unitTile = game.getTile(Vector2(1f,0f))
|
|
|
|
val unit = game.addUnit("Great Engineer", civ, unitTile)
|
|
|
|
unit.currentMovement = unit.baseUnit.movement.toFloat() // Required!
|
|
|
|
val actionsWithoutIron = try {
|
|
|
|
getImprovementConstructionActions(unit, unitTile)
|
|
|
|
} catch (ex: Throwable) {
|
|
|
|
// Give that IndexOutOfBoundsException a nicer name
|
|
|
|
Assert.fail("getImprovementConstructionActions throws Exception ${ex.javaClass.simpleName}")
|
|
|
|
return
|
|
|
|
}.filter { it.action != null }
|
|
|
|
Assert.assertTrue("Great Engineer should NOT be able to create a Manufactory modded to require Iron with 0 Iron",
|
|
|
|
actionsWithoutIron.isEmpty())
|
|
|
|
|
|
|
|
// Supply Iron
|
|
|
|
val ironTile = game.getTile(Vector2(0f,1f))
|
|
|
|
ironTile.resource = "Iron"
|
|
|
|
ironTile.resourceAmount = 3
|
|
|
|
ironTile.improvement = "Mine"
|
|
|
|
civ.tech.addTechnology("Mining")
|
|
|
|
civ.tech.addTechnology("Iron Working")
|
|
|
|
// capital already owns tile, but this relinquishes first - shouldn't require manual setTerrainTransients, updateCivResources called automatically
|
|
|
|
capital.expansion.takeOwnership(ironTile)
|
|
|
|
val ironAvailable = civ.getCivResourcesByName()["Iron"] ?: 0
|
|
|
|
Assert.assertTrue("Test preparation failed to add Iron to Civ resources", ironAvailable >= 3)
|
|
|
|
|
|
|
|
// See if that same Engineer could create a Manufactory NOW
|
|
|
|
val actionsWithIron = getImprovementConstructionActions(unit, unitTile)
|
|
|
|
.filter { it.action != null }
|
|
|
|
Assert.assertFalse("Great Engineer SHOULD be able to create a Manufactory modded to require Iron once Iron is available",
|
|
|
|
actionsWithIron.isEmpty())
|
2022-05-05 08:09:15 +02:00
|
|
|
}
|
2023-06-07 12:35:53 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Check Hakkapeliitta TransferMovement ability`() {
|
|
|
|
val civ = game.addCiv(isPlayer = true)
|
|
|
|
val centerTile = game.getTile(Vector2.Zero)
|
|
|
|
|
|
|
|
// Hardcoded names mean test *must* run under G&K ruleset, not Vanilla, which the TestGame class ensures
|
|
|
|
val general = game.addUnit("Great General", civ, centerTile)
|
|
|
|
val boostingUnit = game.addUnit("Hakkapeliitta", civ, centerTile)
|
|
|
|
boostingUnit.baseUnit.promotions.forEach { boostingUnit.promotions.addPromotion(it, true) }
|
|
|
|
boostingUnit.updateUniques()
|
|
|
|
|
|
|
|
val baseMovement = general.baseUnit.movement
|
|
|
|
UnitTurnManager(general).startTurn()
|
|
|
|
val actualMovement = general.currentMovement.roundToInt()
|
|
|
|
val boosterMovement = boostingUnit.baseUnit.movement
|
|
|
|
|
|
|
|
Assert.assertEquals("Great General stacked with a Hakkapeliitta should have increased movement points.", boosterMovement, actualMovement)
|
|
|
|
// This effectively tests whether the G&K rules have not been tampered with, but won't hurt
|
|
|
|
Assert.assertNotEquals("Great General stacked with a Hakkapeliitta should NOT have its normal movement points.", baseMovement, actualMovement)
|
|
|
|
}
|
2022-05-22 18:51:05 +02:00
|
|
|
}
|