diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index 2a3b07a7..7bb0cc22 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -19,32 +19,30 @@ class NextTurnAutomation{ /** Top-level AI turn tasklist */ fun automateCivMoves(civInfo: CivilizationInfo) { - if (civInfo.isBarbarian()) { - BarbarianAutomation(civInfo).automate() + if (civInfo.isBarbarian()) return BarbarianAutomation(civInfo).automate() + + respondToDemands(civInfo) + respondToTradeRequests(civInfo) + + if(civInfo.isMajorCiv()) { + offerPeaceTreaty(civInfo) + exchangeTechs(civInfo) + exchangeLuxuries(civInfo) + issueRequests(civInfo) + adoptPolicy(civInfo) } else { - respondToDemands(civInfo) - respondToTradeRequests(civInfo) - - if(civInfo.isMajorCiv()) { - offerPeaceTreaty(civInfo) - exchangeTechs(civInfo) - exchangeLuxuries(civInfo) - issueRequests(civInfo) - adoptPolicy(civInfo) - } else { - getFreeTechForCityStates(civInfo) - } - - chooseTechToResearch(civInfo) - updateDiplomaticRelationship(civInfo) - declareWar(civInfo) - automateCityBombardment(civInfo) - useGold(civInfo) - automateUnits(civInfo) - reassignWorkedTiles(civInfo) - trainSettler(civInfo) + getFreeTechForCityStates(civInfo) } + chooseTechToResearch(civInfo) + updateDiplomaticRelationship(civInfo) + declareWar(civInfo) + automateCityBombardment(civInfo) + useGold(civInfo) + automateUnits(civInfo) + reassignWorkedTiles(civInfo) + trainSettler(civInfo) + civInfo.popupAlerts.clear() // AIs don't care about popups. } diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 6c845c8c..92d2d81f 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -7,8 +7,8 @@ import com.unciv.logic.city.CityInfo import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.tile.* -import com.unciv.models.translations.tr import com.unciv.models.stats.Stats +import com.unciv.models.translations.tr import kotlin.math.abs open class TileInfo { @@ -262,7 +262,7 @@ open class TileInfo { return resource != null && (getTileResource().revealedBy == null || civInfo.tech.isResearched(getTileResource().revealedBy!!)) } - fun getViewableTiles(distance:Int, ignoreCurrentTileHeight:Boolean = false): MutableList { + fun getViewableTiles(distance:Int, ignoreCurrentTileHeight:Boolean = false): List { return tileMap.getViewableTiles(this.position,distance,ignoreCurrentTileHeight) } diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 2a9bbb44..e3d9902b 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -150,50 +150,48 @@ class TileMap { } - fun getViewableTiles(position: Vector2, sightDistance: Int, ignoreCurrentTileHeight: Boolean = false): MutableList { - if (ignoreCurrentTileHeight) { - return getTilesInDistance(position, sightDistance).toMutableList() - } else { - val viewableTiles = getTilesInDistance(position, 1).toMutableList() - val currentTileHeight = get(position).getHeight() + fun getViewableTiles(position: Vector2, sightDistance: Int, ignoreCurrentTileHeight: Boolean = false): List { + if (ignoreCurrentTileHeight) return getTilesInDistance(position, sightDistance) - for (i in 1..sightDistance) { // in each layer, - // This is so we don't use tiles in the same distance to "see over", - // that is to say, the "viewableTiles.contains(it) check will return false for neighbors from the same distance - val tilesToAddInDistanceI = ArrayList() + val viewableTiles = getTilesInDistance(position, 1).toMutableList() + val currentTileHeight = get(position).getHeight() - for (tile in getTilesAtDistance(position, i)) { // for each tile in that layer, - val targetTileHeight = tile.getHeight() + for (i in 1..sightDistance) { // in each layer, + // This is so we don't use tiles in the same distance to "see over", + // that is to say, the "viewableTiles.contains(it) check will return false for neighbors from the same distance + val tilesToAddInDistanceI = ArrayList() - /* - Okay so, if we're looking at a tile from a to c with b in the middle, - we have several scenarios: - 1. a>b - - I can see everything, b does not hide c - 2. a==b - 2.1 a==b==0, all flat ground, no hiding - 2.2 a>0, b>=c - b hides c from view (say I am in a forest/jungle and b is a forest/jungle, or hill) - 2.3 a>0, c>b - c is tall enough I can see it over b! - 3. a=c - b hides c - 3.2 bb || c>b || b==0 " - */ + /* + Okay so, if we're looking at a tile from a to c with b in the middle, + we have several scenarios: + 1. a>b - - I can see everything, b does not hide c + 2. a==b + 2.1 a==b==0, all flat ground, no hiding + 2.2 a>0, b>=c - b hides c from view (say I am in a forest/jungle and b is a forest/jungle, or hill) + 2.3 a>0, c>b - c is tall enough I can see it over b! + 3. a=c - b hides c + 3.2 b neighborHeight // a>b - || targetTileHeight > neighborHeight // c>b - || neighborHeight == 0) // b==0 - } - if (containsViewableNeighborThatCanSeeOver) tilesToAddInDistanceI.add(tile) + This can all be summed up as "I can see c if a>b || c>b || b==0 " + */ + + val containsViewableNeighborThatCanSeeOver = tile.neighbors.any { + val neighborHeight = it.getHeight() + viewableTiles.contains(it) && ( + currentTileHeight > neighborHeight // a>b + || targetTileHeight > neighborHeight // c>b + || neighborHeight == 0) // b==0 } - viewableTiles.addAll(tilesToAddInDistanceI) + if (containsViewableNeighborThatCanSeeOver) tilesToAddInDistanceI.add(tile) } - - return viewableTiles + viewableTiles.addAll(tilesToAddInDistanceI) } + + return viewableTiles } fun setTransients(ruleset: Ruleset) {