1package com.unciv.logic.city
2
3import com.badlogic.gdx.math.Vector2
4import com.unciv.logic.city.managers.CityConquestFunctions
5import com.unciv.logic.civilization.Civilization
6import com.unciv.logic.map.HexCoord
7import com.unciv.models.ruleset.unique.UniqueType
8import com.unciv.models.translations.fillPlaceholders
9import com.unciv.testing.GdxTestRunner
10import com.unciv.testing.TestGame
11import org.junit.Assert.assertEquals
12import org.junit.Assert.assertFalse
…lines 13–30 unchanged (18 lines)
31 @Before
32 fun setUp() {
33 testGame.makeHexagonalMap(3)
34 attackerCiv = testGame.addCiv()
35 defenderCiv = testGame.addCiv()
36
37 defenderCity = testGame.addCity(defenderCiv, testGame.getTile(HexCoord.Zero), initialPopulation = 10)
38 cityConquestFunctions = CityConquestFunctions(defenderCity)
39
40 // otherwise test crashes when puppetying city
41 testGame.gameInfo.currentPlayerCiv = testGame.addCiv()
42 testGame.gameInfo.currentPlayer = testGame.gameInfo.currentPlayerCiv.civName
43 }
…lines 44–81 unchanged (38 lines)
82
83 @Test
84 fun `should plunder more gold the more people live in the captured city`() {
85 // No repeat like `should plunder gold upon capture` - mor work and one range check might be enough
86
87 // given
88 val largeCity = testGame.addCity(defenderCiv, testGame.getTile(1,0), initialPopulation = 20)
89 val smallCity = testGame.addCity(defenderCiv, testGame.getTile(0,1), initialPopulation = 5)
90 val secondAttackerCiv = testGame.addCiv()
91 testGame.gameInfo.turns = 50
92
93 // when
94 CityConquestFunctions(largeCity).puppetCity(attackerCiv)
95 CityConquestFunctions(smallCity).puppetCity(secondAttackerCiv)
…lines 96–101 unchanged (6 lines)
102 }
103
104 @Test
105 fun `should plunder more gold with building uniques upon capture`() {
106 // given
107 val building = testGame.createBuilding(UniqueType.GoldFromCapturingCity.text.fillPlaceholders("+100"))
108 val city = testGame.addCity(defenderCiv, testGame.getTile(1,0), initialPopulation = 10)
109 city.cityConstructions.addBuilding(building.name)
110
111 val secondAttackerCiv = testGame.addCiv()
112 testGame.gameInfo.turns = 50
113
114 // when
…lines 115–157 unchanged (43 lines)
158 wonders.forEach { assertFalse(defenderCity.cityConstructions.builtBuildings.contains(it)) }
159 }
160
161 @Test
162 fun `should kill population upon capture`() {
163 // given
164 val largeCity = testGame.addCity(defenderCiv, testGame.getTile(1,0), initialPopulation = 20)
165 val smallCity = testGame.addCity(defenderCiv, testGame.getTile(0,1), initialPopulation = 5)
166
167 // when
168 cityConquestFunctions.puppetCity(attackerCiv)
169 CityConquestFunctions(largeCity).puppetCity(attackerCiv)
170 CityConquestFunctions(smallCity).puppetCity(attackerCiv)
171
172 // then
173 assertEquals(7, defenderCity.population.population)
174 assertEquals(14, largeCity.population.population)
175 assertEquals(3, smallCity.population.population)
176 }
177
178 @Test
179 fun `should never reduce population below 1 upon capture`() {
180 // given
181 val onePopCity = testGame.addCity(defenderCiv, testGame.getTile(1,0), initialPopulation = 1)
182
183 // when
184 CityConquestFunctions(onePopCity).puppetCity(attackerCiv)
185
186 // then
187 assertEquals(1, onePopCity.population.population)
…lines 188–195 unchanged (8 lines)
196 assertTrue(defenderCity.isInResistance())
197 }
198
199 @Test
200 fun `should relocate capital to largest upon city moving`() {
201 // given
202 val smallerCity = testGame.addCity(defenderCiv, testGame.getTile(1,0), initialPopulation = 5)
203 val largerCity = testGame.addCity(defenderCiv, testGame.getTile(0,1), initialPopulation = 8)
204
205 // when
206 cityConquestFunctions.moveToCiv(attackerCiv)
207
208 // then
209 assertTrue(largerCity.isCapital())
210 assertFalse(smallerCity.isCapital())
211 }
212
213 @Test
214 fun `should remove free buildings upon city moving`() {
215 // given
216 val freeBuildingCiv = testGame.addCiv(gainFreeBuildingTestingUniqueText)
217 val city = testGame.addCity(freeBuildingCiv, testGame.getTile(0,1), initialPopulation = 10)
218
219 // when
220 CityConquestFunctions(city).moveToCiv(attackerCiv)
221
222 // then
223 assertFalse(city.cityConstructions.containsBuildingOrEquivalent("Monument"))
…lines 224–250 unchanged (27 lines)