From 8441ab9e565027dc9a3fcad1caa9afdba21fe4b9 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 8 Jun 2021 21:59:23 +0300 Subject: [PATCH] Cities in resistance cannot bombard, as per Civ V - #663 --- .../com/unciv/logic/automation/UnitAutomation.kt | 14 +++++--------- core/src/com/unciv/logic/city/CityInfo.kt | 10 ++++------ .../com/unciv/logic/civilization/Notification.kt | 1 - core/src/com/unciv/logic/map/TileInfo.kt | 2 +- core/src/com/unciv/ui/cityscreen/CityInfoTable.kt | 2 +- .../src/com/unciv/ui/worldscreen/WorldMapHolder.kt | 4 ++-- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index b108fa149f..0635fc5ad4 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -377,15 +377,11 @@ object UnitAutomation { } fun tryBombardEnemy(city: CityInfo): Boolean { - return when { - city.attackedThisTurn -> false - else -> { - val enemy = chooseBombardTarget(city) - if (enemy == null) return false - Battle.attack(CityCombatant(city), enemy) - true - } - } + if (!city.canBombard()) return false + val enemy = chooseBombardTarget(city) + if (enemy == null) return false + Battle.attack(CityCombatant(city), enemy) + return true } private fun chooseBombardTarget(city: CityInfo): ICombatant? { diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 3599881291..d094fd939c 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -157,7 +157,7 @@ class CityInfo { return toReturn } - + fun canBombard() = !attackedThisTurn && !isInResistance() fun getCenterTile(): TileInfo = centerTileInfo fun getTiles(): Sequence = tiles.asSequence().map { tileMap[it] } fun getWorkableTiles() = tilesInRange.asSequence().filter { it.getOwner() == civInfo } @@ -242,7 +242,6 @@ class CityInfo { } fun isGrowing() = foodForNextTurn() > 0 - fun isStarving() = foodForNextTurn() < 0 private fun foodForNextTurn() = cityStats.currentCityStats.food.roundToInt() @@ -265,7 +264,7 @@ class CityInfo { fun containsBuildingUnique(unique: String) = cityConstructions.getBuiltBuildings().any { it.uniques.contains(unique) } - fun getGreatPersonMap(): StatMap { + fun getGreatPersonPointsForNextTurn(): StatMap { val stats = StatMap() for ((specialist, amount) in population.getNewSpecialists()) if (getRuleset().specialists.containsKey(specialist)) // To solve problems in total remake mods @@ -300,7 +299,7 @@ class CityInfo { fun getGreatPersonPoints(): Stats { val stats = Stats() - for (entry in getGreatPersonMap().values) + for (entry in getGreatPersonPointsForNextTurn().values) stats.add(entry) return stats } @@ -437,8 +436,7 @@ class CityInfo { } /* - When someone settles a city within 6 tiles of another civ, - this makes the AI unhappy and it starts a rolling event. + When someone settles a city within 6 tiles of another civ, this makes the AI unhappy and it starts a rolling event. The SettledCitiesNearUs flag gets added to the AI so it knows this happened, and on its turn it asks the player to stop (with a DemandToStopSettlingCitiesNear alert type) If the player says "whatever, I'm not promising to stop", they get a -10 modifier which gradually disappears in 40 turns diff --git a/core/src/com/unciv/logic/civilization/Notification.kt b/core/src/com/unciv/logic/civilization/Notification.kt index e1345b696e..6fa5b918e2 100644 --- a/core/src/com/unciv/logic/civilization/Notification.kt +++ b/core/src/com/unciv/logic/civilization/Notification.kt @@ -1,6 +1,5 @@ package com.unciv.logic.civilization -import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.math.Vector2 import com.unciv.ui.cityscreen.CityScreen import com.unciv.ui.pickerscreens.TechPickerScreen diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index d96c818c64..50249e1c50 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -394,7 +394,7 @@ open class TileInfo { || baseTerrainObject.uniques.contains(filter) || improvement == filter || resource == filter - || (resource != null && getTileResource().resourceType.name + " resource" == filter) + || resource != null && getTileResource().resourceType.name + " resource" == filter || filter == "Water" && isWater || filter == "Land" && isLand || filter == "Coastal" && isCoastalTile() diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index b6ffe2710c..d41d15ecc9 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -239,7 +239,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS } private fun Table.addGreatPersonPointInfo(cityInfo: CityInfo) { - val greatPersonPoints = cityInfo.getGreatPersonMap() + val greatPersonPoints = cityInfo.getGreatPersonPointsForNextTurn() val statToGreatPerson = GreatPersonManager().statToGreatPersonMapping for (stat in Stat.values()) { if (!statToGreatPerson.containsKey(stat)) continue diff --git a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt index 021b68020c..82904dfd23 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt @@ -166,7 +166,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap if (newSelectedUnit == null || newSelectedUnit.type == UnitType.Civilian) { val unitsInTile = selectedTile!!.getUnits() - if (previousSelectedCity != null && !previousSelectedCity.attackedThisTurn + if (previousSelectedCity != null && previousSelectedCity.canBombard() && selectedTile!!.getTilesInDistance(2).contains(previousSelectedCity.getCenterTile()) && unitsInTile.any() && unitsInTile.first().civInfo.isAtWarWith(worldScreen.viewingCiv)) { @@ -548,7 +548,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap } private fun updateTilegroupsForSelectedCity(city: CityInfo, playerViewableTilePositions: HashSet) { - if (city.attackedThisTurn) return + if (!city.canBombard()) return val attackableTiles = UnitAutomation.getBombardTargets(city) .filter { (UncivGame.Current.viewEntireMapForDebug || playerViewableTilePositions.contains(it.position)) }