From 86c6624f8e4d5d54aff611ac42a95d55e5cbb078 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 9 Nov 2020 21:26:26 +0200 Subject: [PATCH] Resolved #3326 - Settling a city removes the improvement in progress --- .../unciv/app/MultiplayerTurnCheckWorker.kt | 53 +++++++++---------- core/src/com/unciv/logic/city/CityInfo.kt | 35 ++++++------ core/src/com/unciv/logic/map/MapUnit.kt | 3 +- .../unciv/ui/worldscreen/unit/UnitActions.kt | 1 - 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt b/android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt index 231254a923..58aa0cc83d 100644 --- a/android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt +++ b/android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt @@ -71,18 +71,17 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame * For more infos: https://developer.android.com/training/notify-user/channels.html#CreateChannel */ fun createNotificationChannelInfo(appContext: Context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val name = appContext.resources.getString(R.string.Notify_ChannelInfo_Short) - val descriptionText = appContext.resources.getString(R.string.Notify_ChannelInfo_Long) - val importance = NotificationManager.IMPORTANCE_HIGH - val mChannel = NotificationChannel(NOTIFICATION_CHANNEL_ID_INFO, name, importance) - mChannel.description = descriptionText - mChannel.setShowBadge(true) - mChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return + val name = appContext.resources.getString(R.string.Notify_ChannelInfo_Short) + val descriptionText = appContext.resources.getString(R.string.Notify_ChannelInfo_Long) + val importance = NotificationManager.IMPORTANCE_HIGH + val mChannel = NotificationChannel(NOTIFICATION_CHANNEL_ID_INFO, name, importance) + mChannel.description = descriptionText + mChannel.setShowBadge(true) + mChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC) - val notificationManager = appContext.getSystemService(AndroidApplication.NOTIFICATION_SERVICE) as NotificationManager - notificationManager.createNotificationChannel(mChannel) - } + val notificationManager = appContext.getSystemService(AndroidApplication.NOTIFICATION_SERVICE) as NotificationManager + notificationManager.createNotificationChannel(mChannel) } /** @@ -93,18 +92,17 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame * For more infos: https://developer.android.com/training/notify-user/channels.html#CreateChannel */ fun createNotificationChannelService(appContext: Context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val name = appContext.resources.getString(R.string.Notify_ChannelService_Short) - val descriptionText = appContext.resources.getString(R.string.Notify_ChannelService_Long) - val importance = NotificationManager.IMPORTANCE_MIN - val mChannel = NotificationChannel(NOTIFICATION_CHANNEL_ID_SERVICE, name, importance) - mChannel.setShowBadge(false) - mChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC) - mChannel.description = descriptionText + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return + val name = appContext.resources.getString(R.string.Notify_ChannelService_Short) + val descriptionText = appContext.resources.getString(R.string.Notify_ChannelService_Long) + val importance = NotificationManager.IMPORTANCE_MIN + val mChannel = NotificationChannel(NOTIFICATION_CHANNEL_ID_SERVICE, name, importance) + mChannel.setShowBadge(false) + mChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC) + mChannel.description = descriptionText - val notificationManager = appContext.getSystemService(AndroidApplication.NOTIFICATION_SERVICE) as NotificationManager - notificationManager.createNotificationChannel(mChannel) - } + val notificationManager = appContext.getSystemService(AndroidApplication.NOTIFICATION_SERVICE) as NotificationManager + notificationManager.createNotificationChannel(mChannel) } /** @@ -194,12 +192,11 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame * Therefore Unciv needs to create new ones and delete legacy ones. */ private fun destroyOldChannels(appContext: Context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val notificationManager = appContext.getSystemService(AndroidApplication.NOTIFICATION_SERVICE) as NotificationManager - HISTORIC_NOTIFICATION_CHANNELS.forEach { - if (null != notificationManager.getNotificationChannel(it)) { - notificationManager.deleteNotificationChannel(it) - } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return + val notificationManager = appContext.getSystemService(AndroidApplication.NOTIFICATION_SERVICE) as NotificationManager + HISTORIC_NOTIFICATION_CHANNELS.forEach { + if (null != notificationManager.getNotificationChannel(it)) { + notificationManager.deleteNotificationChannel(it) } } } diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 8fbed2bccc..757ab5932a 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -76,16 +76,7 @@ class CityInfo { this.location = cityLocation setTransients() - val nationCities = civInfo.nation.cities - val cityNameIndex = civInfo.citiesCreated % nationCities.size - val cityName = nationCities[cityNameIndex] - - val cityNameRounds = civInfo.citiesCreated / nationCities.size - val cityNamePrefix = if(cityNameRounds==0) "" - else if(cityNameRounds==1) "New " - else "Neo " - - name = cityNamePrefix + cityName + setNewCityName(civInfo) isOriginalCapital = civInfo.citiesCreated == 0 civInfo.citiesCreated++ @@ -93,21 +84,22 @@ class CityInfo { civInfo.cities = civInfo.cities.toMutableList().apply { add(this@CityInfo) } civInfo.addNotification("[$name] has been founded!", cityLocation, Color.PURPLE) - if (civInfo.cities.size == 1) { - cityConstructions.addBuilding(capitalCityIndicator()) - } + if (civInfo.cities.size == 1) cityConstructions.addBuilding(capitalCityIndicator()) civInfo.policies.tryAddLegalismBuildings() expansion.reset() - val tile = getCenterTile() tryUpdateRoadStatus() - if (getRuleset().tileImprovements.containsKey("Remove "+tile.terrainFeature)) + val tile = getCenterTile() + if (getRuleset().tileImprovements.containsKey("Remove " + tile.terrainFeature)) tile.terrainFeature = null + tile.improvement = null + tile.improvementInProgress = null + workedTiles = hashSetOf() //reassign 1st working tile population.autoAssignPopulation() cityStats.update() @@ -115,6 +107,19 @@ class CityInfo { triggerCitiesSettledNearOtherCiv() } + private fun setNewCityName(civInfo: CivilizationInfo) { + val nationCities = civInfo.nation.cities + val cityNameIndex = civInfo.citiesCreated % nationCities.size + val cityName = nationCities[cityNameIndex] + + val cityNameRounds = civInfo.citiesCreated / nationCities.size + val cityNamePrefix = if (cityNameRounds == 0) "" + else if (cityNameRounds == 1) "New " + else "Neo " + + name = cityNamePrefix + cityName + } + //region pure functions fun clone(): CityInfo { diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index c679fe9ac8..8c216b9fea 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -349,7 +349,8 @@ class MapUnit { if (tile.improvementInProgress == "Remove Road" || tile.improvementInProgress == "Remove Railroad") tile.roadStatus = RoadStatus.None else { - if (tile.tileMap.gameInfo.ruleSet.terrains[tile.terrainFeature]!!.uniques + // We put "tile.terrainFeature!=null" because of a strange edge case that SHOULD be solved from 3.11.11+, so we should remove it then and see + if (tile.terrainFeature!=null && tile.tileMap.gameInfo.ruleSet.terrains[tile.terrainFeature!!]!!.uniques .contains("Provides a one-time Production bonus to the closest city when cut down")) tryProvideProductionToClosestCity() tile.terrainFeature = null diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index dc039c88fe..1f5ab8e982 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -137,7 +137,6 @@ object UnitActions { action = { UncivGame.Current.settings.addCompletedTutorialTask("Found city") unit.civInfo.addCity(tile.position) - tile.improvement = null unit.destroy() }.takeIf { unit.currentMovement > 0 && !tile.getTilesInDistance(3).any { it.isCityCenter() } }) }