1package com.unciv.uniques
2
3import com.badlogic.gdx.math.Vector2
4import com.unciv.json.json
5import com.unciv.logic.map.mapunit.UnitTurnManager
6import com.unciv.models.UnitActionType
7import com.unciv.models.ruleset.tile.TileImprovement
8import com.unciv.models.ruleset.unique.UniqueType
9import com.unciv.models.translations.fillPlaceholders
10import com.unciv.testing.GdxTestRunner
11import com.unciv.testing.TestGame
…lines 12–28 unchanged (17 lines)
29
30 @Test
31 fun `Sweden can gift Great Persons to City States`() {
32 // when
33 game.makeHexagonalMap(1)
34 val cityState = game.addCiv(cityStateType = "Cultured")
35 val cityStateCapitalTile = game.getTile(Vector2.Zero)
36 val cityStateCapital = game.addCity(cityState, cityStateCapitalTile)
37
38 val mainCiv = game.addCiv("Gain [90] Influence with a [Great Person] gift to a City-State",
39 isPlayer = true
40 )
41
42 val unitTile = game.getTile(Vector2(1f, 0f))
43 cityStateCapital.expansion.takeOwnership(unitTile)
44
45 val greatPerson = game.addUnit("Great Scientist", mainCiv, unitTile)
46
47 // then
48 val giftAction = UnitActions.getUnitActions(greatPerson, UnitActionType.GiftUnit)
…lines 49–61 unchanged (13 lines)
62 Assert.assertFalse("Test preparation failed to add ConsumesResources to Manufactory",
63 improvement.uniqueObjects.none { it.type == UniqueType.ConsumesResources })
64 game.ruleset.tileImprovements["Manufactory"] = improvement
65
66 game.makeHexagonalMap(1)
67 val civ = game.addCiv(isPlayer = true)
68 val centerTile = game.getTile(Vector2.Zero)
69 val capital = game.addCity(civ, centerTile)
70
71 // Place an Engineer and see if he could create a Manufactory
72 val unitTile = game.getTile(Vector2(1f,0f))
73 val unit = game.addUnit("Great Engineer", civ, unitTile)
74 unit.currentMovement = unit.baseUnit.movement.toFloat() // Required!
75 val actionsWithoutIron = try {
76 UnitActionsFromUniques.getImprovementConstructionActionsFromGeneralUnique(unit, unitTile)
77 } catch (ex: Throwable) {
78 // Give that IndexOutOfBoundsException a nicer name
79 Assert.fail("getImprovementConstructionActions throws Exception ${ex.javaClass.simpleName}")
80 game.ruleset.tileImprovements["Manufactory"] = oldImprovement
81 return
82 }.filter { it.action != null }
83 Assert.assertTrue("Great Engineer should NOT be able to create a Manufactory modded to require Iron with 0 Iron",
84 actionsWithoutIron.none())
85
86 // Supply Iron
87 val ironTile = game.getTile(Vector2(0f,1f))
88 ironTile.resource = "Iron"
89 ironTile.resourceAmount = 3
90 ironTile.improvement = "Mine"
91 civ.tech.addTechnology("Mining")
92 civ.tech.addTechnology("Iron Working")
93 // capital already owns tile, but this relinquishes first - shouldn't require manual setTerrainTransients, updateCivResources called automatically
…lines 94–102 unchanged (9 lines)
103 game.ruleset.tileImprovements["Manufactory"] = oldImprovement
104 }
105
106 @Test
107 fun `Check Hakkapeliitta TransferMovement ability`() {
108 val civ = game.addCiv(isPlayer = true)
109 val centerTile = game.getTile(Vector2.Zero)
110
111 // Hardcoded names mean test *must* run under G&K ruleset, not Vanilla, which the TestGame class ensures
112 val general = game.addUnit("Great General", civ, centerTile)
113 val boostingUnit = game.addUnit("Hakkapeliitta", civ, centerTile)
114 boostingUnit.baseUnit.promotions.forEach { boostingUnit.promotions.addPromotion(it, true) }
115 boostingUnit.updateUniques()
…lines 116–124 unchanged (9 lines)
125 }
126
127 @Test
128 fun testCanGetPromotionsWithXP() {
129 val civ = game.addCiv(isPlayer = true)
130
131 val centerTile = game.getTile(Vector2.Zero)
132 val unit = game.addUnit("Scout", civ, centerTile)
133 val tree = PromotionTree(unit)
134
135 Assert.assertFalse(tree.allNodes().any { !it.unreachable && tree.canBuyUpTo(it.promotion) })
136 unit.promotions.XP += 10
137 Assert.assertTrue(tree.allNodes().any { !it.unreachable && tree.canBuyUpTo(it.promotion) })
…lines 138–142 unchanged (5 lines)
143 * @see unciv.models.ruleset.unique.UniqueType.OneTimeUnitGetsName
144 */
145 @Test
146 fun testOneTimeUnitGetsName() {
147 val unit = game.addDefaultMeleeUnitWithUniques(
148 game.addCiv(),
149 game.getTile(Vector2.Zero),
150 "[This Unit] gets a name from the [Scientist] group <upon turn start>")
151 UnitTurnManager(unit).startTurn()
152
153 Assert.assertTrue(unit.instanceName != null)
154 Assert.assertTrue(game.ruleset.unitNameGroups["Scientist"]?.unitNames?.contains(unit.instanceName) ?: false)
155 }
…lines 156–210 unchanged (55 lines)