diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 047064d970..e2f5973098 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -4,8 +4,8 @@ package com.unciv.build object BuildConfig { const val kotlinVersion = "1.8.21" const val appName = "Unciv" - const val appCodeNumber = 887 - const val appVersion = "4.7.6-patch1" + const val appCodeNumber = 888 + const val appVersion = "4.7.6-patch2" const val gdxVersion = "1.11.0" const val ktorVersion = "2.2.3" diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 721d693ccf..9dea4a068f 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -536,7 +536,7 @@ open class UncivGame(val isConsoleMode: Boolean = false) : Game(), PlatformSpeci companion object { //region AUTOMATICALLY GENERATED VERSION DATA - DO NOT CHANGE THIS REGION, INCLUDING THIS COMMENT - val VERSION = Version("4.7.6-patch1", 887) + val VERSION = Version("4.7.6-patch2", 888) //endregion lateinit var Current: UncivGame diff --git a/core/src/com/unciv/logic/civilization/Civilization.kt b/core/src/com/unciv/logic/civilization/Civilization.kt index 5399f2f2e4..552f43f82d 100644 --- a/core/src/com/unciv/logic/civilization/Civilization.kt +++ b/core/src/com/unciv/logic/civilization/Civilization.kt @@ -810,7 +810,9 @@ class Civilization : IsPartOfGameInfoSerialization { city.cityConstructions.addBuilding(city.capitalCityIndicator()) city.isBeingRazed = false // stop razing the new capital if it was being razed } - oldCapital?.cityConstructions?.removeBuilding(oldCapital.capitalCityIndicator()) + // Don't use removeBuilding, since that rebuilds uniques and can generate errors when we have no capital + // We're going to recalc the uniques anyway once we move it to the new civ + oldCapital?.cityConstructions?.builtBuildings?.remove(oldCapital.capitalCityIndicator()) } fun moveCapitalToNextLargest() { diff --git a/desktop/src/com/unciv/app/desktop/UiElementDocsWriter.kt b/desktop/src/com/unciv/app/desktop/UiElementDocsWriter.kt index 8717b57aa8..fc3c0e7c82 100644 --- a/desktop/src/com/unciv/app/desktop/UiElementDocsWriter.kt +++ b/desktop/src/com/unciv/app/desktop/UiElementDocsWriter.kt @@ -4,7 +4,7 @@ import java.io.File class UiElementDocsWriter { companion object { - private const val docPath = "../../docs/Modders/5-Creating-a-UI-skin.md" + private const val docPath = "../../docs/Modders/Creating-a-UI-skin.md" private const val startMarker = "" private const val endMarker = "" private const val srcPath = "../../core/src/com/unciv/" diff --git a/tests/src/com/unciv/logic/civilization/CityMovingTests.kt b/tests/src/com/unciv/logic/civilization/CityMovingTests.kt new file mode 100644 index 0000000000..01919f92df --- /dev/null +++ b/tests/src/com/unciv/logic/civilization/CityMovingTests.kt @@ -0,0 +1,107 @@ +package com.unciv.logic.civilization + +import com.unciv.logic.map.tile.RoadStatus +import com.unciv.testing.GdxTestRunner +import com.unciv.uniques.TestGame +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(GdxTestRunner::class) +class UnitMovementTests { + + private lateinit var civInfo: Civilization + private lateinit var enemy: Civilization + private var testGame = TestGame() + + @Before + fun initTheWorld() { + testGame.makeHexagonalMap(5) // enough space for lots of cities + civInfo = testGame.addCiv() + enemy = testGame.addCiv() + + // Required for enemy to utilize roads + enemy.tech.techsResearched.addAll(testGame.ruleset.technologies.keys) + + civInfo.diplomacyFunctions.makeCivilizationsMeet(enemy) + civInfo.getDiplomacyManager(enemy).declareWar() + } + + @Test + fun moveOtherCityToUs() { + val ourCapital = testGame.addCity(civInfo, testGame.tileMap[2,2]) + val theirCapital = testGame.addCity(enemy, testGame.tileMap[-2,-2]) + val theirOtherCity = testGame.addCity(enemy, testGame.tileMap[-2, 2]) + + theirOtherCity.moveToCiv(civInfo) + Assert.assertTrue(!theirOtherCity.isCapital()) + Assert.assertTrue(theirOtherCity.civ == civInfo) + } + + @Test + fun moveCapitalToUs() { + val ourCapital = testGame.addCity(civInfo, testGame.tileMap[2,2]) + val theirCapital = testGame.addCity(enemy, testGame.tileMap[-2,-2]) + val theirOtherCity = testGame.addCity(enemy, testGame.tileMap[-2, 2]) + + for (i in listOf(-1,0,1)){ + val tile = testGame.tileMap[-2, i] + tile.roadStatus = RoadStatus.Road + } + enemy.cache.updateCitiesConnectedToCapital() + Assert.assertTrue(theirOtherCity.isConnectedToCapital()) + + theirCapital.moveToCiv(civInfo) + Assert.assertTrue(theirOtherCity.isCapital()) + Assert.assertTrue(theirCapital.isCapital()) + Assert.assertTrue(theirCapital.civ == civInfo) + } + + @Test + fun moveCapitalToUsWhenWeHaveNoCities() { + val theirCapital = testGame.addCity(enemy, testGame.tileMap[-2,-2]) + val theirOtherCity = testGame.addCity(enemy, testGame.tileMap[-2, 2]) + + for (i in listOf(-1,0,1)){ + val tile = testGame.tileMap[-2, i] + tile.roadStatus = RoadStatus.Road + } + enemy.cache.updateCitiesConnectedToCapital() + Assert.assertTrue(theirOtherCity.isConnectedToCapital()) + + theirCapital.moveToCiv(civInfo) + Assert.assertTrue(theirOtherCity.isCapital()) + Assert.assertTrue(theirOtherCity.civ == enemy) + Assert.assertTrue(theirCapital.isCapital()) + Assert.assertTrue(theirCapital.civ == civInfo) + } + + @Test + fun moveNonCapitalToUsWhenWeHaveNoCities() { + val theirCapital = testGame.addCity(enemy, testGame.tileMap[-2,-2]) + val theirOtherCity = testGame.addCity(enemy, testGame.tileMap[-2, 2]) + + for (i in listOf(-1,0,1)){ + val tile = testGame.tileMap[-2, i] + tile.roadStatus = RoadStatus.Road + } + enemy.cache.updateCitiesConnectedToCapital() + Assert.assertTrue(theirOtherCity.isConnectedToCapital()) + + theirOtherCity.moveToCiv(civInfo) + Assert.assertTrue(theirOtherCity.isCapital()) + Assert.assertTrue(theirCapital.isCapital()) + Assert.assertTrue(theirOtherCity.civ == civInfo) + } + + @Test + fun moveTheirOnlyCityToUsWhenWeHaveNoCities() { + val theirCapital = testGame.addCity(enemy, testGame.tileMap[-2,-2]) + enemy.cache.updateCitiesConnectedToCapital() + + theirCapital.moveToCiv(civInfo) + Assert.assertTrue(theirCapital.isCapital()) + Assert.assertTrue(theirCapital.civ == civInfo) + } +}