From 3b4bce780a9b7b4d7159a0455ffd92fc4e7d978b Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 23 Feb 2020 22:33:32 +0200 Subject: [PATCH] Arial -> Aerial name refactoring --- .../logic/automation/NextTurnAutomation.kt | 8 ++++---- .../logic/automation/SpecificUnitAutomation.kt | 18 +++++++++--------- .../unciv/logic/automation/UnitAutomation.kt | 18 +++++++++--------- .../unciv/logic/city/CityExpansionManager.kt | 2 +- core/src/com/unciv/logic/city/CityInfo.kt | 4 ++-- .../com/unciv/logic/city/PopulationManager.kt | 4 ++-- core/src/com/unciv/logic/map/MapGenerator.kt | 2 +- core/src/com/unciv/logic/map/MapUnit.kt | 2 +- core/src/com/unciv/logic/map/TileInfo.kt | 2 +- .../unciv/logic/map/UnitMovementAlgorithms.kt | 4 ++-- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index bcab9d94..e1a1bfef 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -284,18 +284,18 @@ class NextTurnAutomation{ } fun getMinDistanceBetweenCities(civ1: CivilizationInfo, civ2: CivilizationInfo): Int { - return getClosestCities(civ1,civ2).arialDistance + return getClosestCities(civ1,civ2).aerialDistance } - data class CityDistance(val city1:CityInfo, val city2:CityInfo, val arialDistance: Int) + data class CityDistance(val city1:CityInfo, val city2:CityInfo, val aerialDistance: Int) fun getClosestCities(civ1: CivilizationInfo, civ2: CivilizationInfo): CityDistance { val cityDistances = arrayListOf() for(civ1city in civ1.cities) for(civ2city in civ2.cities) cityDistances.add(CityDistance(civ1city,civ2city, - civ1city.getCenterTile().arialDistanceTo(civ2city.getCenterTile()))) + civ1city.getCenterTile().aerialDistanceTo(civ2city.getCenterTile()))) - return cityDistances.minBy { it.arialDistance }!! + return cityDistances.minBy { it.aerialDistance }!! } private fun offerDeclarationOfFriendship(civInfo: CivilizationInfo) { diff --git a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt index 061e898c..8f900910 100644 --- a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt @@ -25,7 +25,7 @@ class SpecificUnitAutomation{ val seaResourcesInCities = unit.civInfo.cities.asSequence() .flatMap { city -> city.getWorkableTiles() } .filter { hasWorkableSeaResource(it, unit.civInfo) && (unit.movement.canMoveTo(it) || unit.currentTile == it) } - val closestReachableResource = seaResourcesInCities.sortedBy { it.arialDistanceTo(unit.currentTile) } + val closestReachableResource = seaResourcesInCities.sortedBy { it.aerialDistanceTo(unit.currentTile) } .firstOrNull { unit.movement.canReach(it) } if (closestReachableResource != null) { @@ -60,7 +60,7 @@ class SpecificUnitAutomation{ //if no unit to follow, take refuge in city. val cityToGarrison = unit.civInfo.cities.map {it.getCenterTile()} - .sortedBy { it.arialDistanceTo(unit.currentTile) } + .sortedBy { it.aerialDistanceTo(unit.currentTile) } .firstOrNull { it.civilianUnit == null && unit.movement.canMoveTo(it) && unit.movement.canReach(it)} if (cityToGarrison != null) { @@ -204,7 +204,7 @@ class SpecificUnitAutomation{ } } - val pathsToCities = unit.movement.getArialPathsToCities() + val pathsToCities = unit.movement.getAerialPathsToCities() if (pathsToCities.isEmpty()) return // can't actually move anywhere else val citiesByNearbyAirUnits = pathsToCities.keys @@ -226,7 +226,7 @@ class SpecificUnitAutomation{ } // no city needs fighters to defend, so let's attack stuff from the closest possible location - tryMoveToCitiesToArialAttackFrom(pathsToCities, unit) + tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit) } @@ -248,12 +248,12 @@ class SpecificUnitAutomation{ } } - val pathsToCities = unit.movement.getArialPathsToCities() + val pathsToCities = unit.movement.getAerialPathsToCities() if (pathsToCities.isEmpty()) return // can't actually move anywhere else - tryMoveToCitiesToArialAttackFrom(pathsToCities, unit) + tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit) } - private fun tryMoveToCitiesToArialAttackFrom(pathsToCities: HashMap>, airUnit: MapUnit) { + private fun tryMoveToCitiesToAerialAttackFrom(pathsToCities: HashMap>, airUnit: MapUnit) { val citiesThatCanAttackFrom = pathsToCities.keys .filter { it != airUnit.currentTile @@ -288,9 +288,9 @@ class SpecificUnitAutomation{ } } - val pathsToCities = unit.movement.getArialPathsToCities() + val pathsToCities = unit.movement.getAerialPathsToCities() if (pathsToCities.isEmpty()) return // can't actually move anywhere else - tryMoveToCitiesToArialAttackFrom(pathsToCities, unit) + tryMoveToCitiesToAerialAttackFrom(pathsToCities, unit) } } \ No newline at end of file diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index a67d48e6..d51ab7fa 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -137,8 +137,8 @@ class UnitAutomation { val knownEncampments = unit.civInfo.gameInfo.tileMap.values.asSequence() .filter { it.improvement == Constants.barbarianEncampment && unit.civInfo.exploredTiles.contains(it.position) } val cities = unit.civInfo.cities - val encampmentsCloseToCities = knownEncampments.filter { cities.any { city -> city.getCenterTile().arialDistanceTo(it) < 6 } } - .sortedBy { it.arialDistanceTo(unit.currentTile) } + val encampmentsCloseToCities = knownEncampments.filter { cities.any { city -> city.getCenterTile().aerialDistanceTo(it) < 6 } } + .sortedBy { it.aerialDistanceTo(unit.currentTile) } val encampmentToHeadTowards = encampmentsCloseToCities.firstOrNull { unit.movement.canReach(it) } if (encampmentToHeadTowards == null) { return false @@ -158,7 +158,7 @@ class UnitAutomation { if (tilesByHealingRate.keys.none { it != 0 }) { // We can't heal here at all! We're probably embarked val reachableCityTile = unit.civInfo.cities.map { it.getCenterTile() } - .sortedBy { it.arialDistanceTo(unit.currentTile) } + .sortedBy { it.aerialDistanceTo(unit.currentTile) } .firstOrNull { unit.movement.canReach(it) } if (reachableCityTile != null) unit.movement.headTowards(reachableCityTile) else wander(unit, unitDistanceToTiles) @@ -221,7 +221,7 @@ class UnitAutomation { if (unit.type.isRanged()) closeEnemies = closeEnemies.filterNot { it.tileToAttack.isCityCenter() && it.tileToAttack.getCity()!!.health == 1 } - val closestEnemy = closeEnemies.minBy { it.tileToAttack.arialDistanceTo(unit.getTile()) } + val closestEnemy = closeEnemies.minBy { it.tileToAttack.aerialDistanceTo(unit.getTile()) } if (closestEnemy != null) { unit.movement.headTowards(closestEnemy.tileToAttackFrom) @@ -271,7 +271,7 @@ class UnitAutomation { .asSequence().map { it.getCenterTile() } .sortedBy { cityCenterTile -> // sort enemy cities by closeness to our cities, and only then choose the first reachable - checking canReach is comparatively very time-intensive! - unit.civInfo.cities.asSequence().map { cityCenterTile.arialDistanceTo(it.getCenterTile()) }.min()!! + unit.civInfo.cities.asSequence().map { cityCenterTile.aerialDistanceTo(it.getCenterTile()) }.min()!! } .firstOrNull { unit.movement.canReach(it) } @@ -284,7 +284,7 @@ class UnitAutomation { // this is against tha AI's brilliant plan of having everyone embarked and attacking via sea when unnecessary. val tileToHeadTo = closestReachableEnemyCity.getTilesInDistanceRange(3..4) .filter { it.isLand } - .sortedBy { it.arialDistanceTo(unit.currentTile) } + .sortedBy { it.aerialDistanceTo(unit.currentTile) } .firstOrNull { unit.movement.canReach(it) } ?: closestReachableEnemyCity if (tileToHeadTo !in tilesInBombardRange) // no need to worry, keep going as the movement alg. says @@ -294,7 +294,7 @@ class UnitAutomation { val tileToMoveTo = unitDistanceToTiles.asSequence() .filter { it.key !in tilesInBombardRange - && it.key.arialDistanceTo(closestReachableEnemyCity) <= + && it.key.aerialDistanceTo(closestReachableEnemyCity) <= unit.getRange() } .minBy { it.value.totalDistance }?.key @@ -360,7 +360,7 @@ class UnitAutomation { for (enemyCivCity in unit.civInfo.diplomacy.values .filter { it.diplomaticStatus == DiplomaticStatus.War } .map { it.otherCiv() }.flatMap { it.cities }) - if (city.getCenterTile().arialDistanceTo(enemyCivCity.getCenterTile()) <= 5) return true // this is an edge city that needs defending + if (city.getCenterTile().aerialDistanceTo(enemyCivCity.getCenterTile()) <= 5) return true // this is an edge city that needs defending return false } @@ -378,7 +378,7 @@ class UnitAutomation { } val closestReachableCityNeedsDefending = citiesToTry - .sortedBy { it.getCenterTile().arialDistanceTo(unit.currentTile) } + .sortedBy { it.getCenterTile().aerialDistanceTo(unit.currentTile) } .firstOrNull { unit.movement.canReach(it.getCenterTile()) } if (closestReachableCityNeedsDefending == null) return false unit.movement.headTowards(closestReachableCityNeedsDefending.getCenterTile()) diff --git a/core/src/com/unciv/logic/city/CityExpansionManager.kt b/core/src/com/unciv/logic/city/CityExpansionManager.kt index 53659f8d..54c26ac0 100644 --- a/core/src/com/unciv/logic/city/CityExpansionManager.kt +++ b/core/src/com/unciv/logic/city/CityExpansionManager.kt @@ -45,7 +45,7 @@ class CityExpansionManager { fun getGoldCostOfTile(tileInfo: TileInfo): Int { val baseCost = 50 val numTilesClaimed= cityInfo.tiles.size - 7 - val distanceFromCenter = tileInfo.arialDistanceTo(cityInfo.getCenterTile()) + val distanceFromCenter = tileInfo.aerialDistanceTo(cityInfo.getCenterTile()) var cost = baseCost * (distanceFromCenter-1) + numTilesClaimed*5.0 if (cityInfo.civInfo.containsBuildingUnique("Cost of acquiring new tiles reduced by 25%")) diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index c3027b1f..e707d324 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -527,7 +527,7 @@ class CityInfo { val owningCity = newTileInfo.getCity() if (owningCity!=null && owningCity!=this && newTileInfo.getOwner()!!.isCurrentPlayer() - && newTileInfo.arialDistanceTo(getCenterTile()) <= 3 + && newTileInfo.aerialDistanceTo(getCenterTile()) <= 3 && newTileInfo.neighbors.any{it.getCity()==this}) { return true } @@ -579,7 +579,7 @@ class CityInfo { private fun triggerCitiesSettledNearOtherCiv(){ val citiesWithin6Tiles = civInfo.gameInfo.civilizations.filter { it.isMajorCiv() && it!=civInfo } .flatMap { it.cities } - .filter { it.getCenterTile().arialDistanceTo(getCenterTile()) <= 6 } + .filter { it.getCenterTile().aerialDistanceTo(getCenterTile()) <= 6 } val civsWithCloseCities = citiesWithin6Tiles.map { it.civInfo }.distinct() .filter { it.knows(civInfo) && it.exploredTiles.contains(location) } for(otherCiv in civsWithCloseCities) diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index 747fe3d6..91bf13a4 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -78,7 +78,7 @@ class PopulationManager { //evaluate tiles val bestTile: TileInfo? = cityInfo.getTiles() - .filter { it.arialDistanceTo(cityInfo.getCenterTile()) <= 3 } + .filter { it.aerialDistanceTo(cityInfo.getCenterTile()) <= 3 } .filterNot { cityInfo.workedTiles.contains(it.position) || cityInfo.location==it.position} .maxBy { Automation().rankTileForCityWork(it,cityInfo, foodWeight) } val valueBestTile = if(bestTile==null) 0f @@ -112,7 +112,7 @@ class PopulationManager { for(tile in cityInfo.workedTiles.map { cityInfo.tileMap[it] }) { if (tile.getCity() != cityInfo) cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(tile.position) - if(tile.arialDistanceTo(cityInfo.getCenterTile()) > 3) // AutoAssignPopulation used to assign pop outside of allowed range, fixed as of 2.10.4 + if(tile.aerialDistanceTo(cityInfo.getCenterTile()) > 3) // AutoAssignPopulation used to assign pop outside of allowed range, fixed as of 2.10.4 cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(tile.position) } diff --git a/core/src/com/unciv/logic/map/MapGenerator.kt b/core/src/com/unciv/logic/map/MapGenerator.kt index 4e8b3fe9..7c4b03fd 100644 --- a/core/src/com/unciv/logic/map/MapGenerator.kt +++ b/core/src/com/unciv/logic/map/MapGenerator.kt @@ -546,7 +546,7 @@ class MapGenerator(val ruleset: Ruleset) { val firstKeyWithTilesLeft = orderedKeys .first { availableTiles.any { tile -> tile.baseTerrain== it} } val chosenTile = availableTiles.filter { it.baseTerrain==firstKeyWithTilesLeft }.random() - availableTiles = availableTiles.filter { it.arialDistanceTo(chosenTile) > distanceBetweenResources } + availableTiles = availableTiles.filter { it.aerialDistanceTo(chosenTile) > distanceBetweenResources } chosenTiles.add(chosenTile) baseTerrainsToChosenTiles[firstKeyWithTilesLeft] = baseTerrainsToChosenTiles[firstKeyWithTilesLeft]!!+1 } diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 3630e616..2c5de0e1 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -620,7 +620,7 @@ class MapUnit { if(attacksThisTurn>1) return false if(interceptChance()==0) return false if(attacksThisTurn>0 && !hasUnique("1 extra Interception may be made per turn")) return false - if(currentTile.arialDistanceTo(attackedTile) > baseUnit.interceptRange) return false + if(currentTile.aerialDistanceTo(attackedTile) > baseUnit.interceptRange) return false return true } diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 09fdbc7b..2c368a3b 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -276,7 +276,7 @@ open class TileInfo { return bonus } - fun arialDistanceTo(otherTile:TileInfo): Int { + fun aerialDistanceTo(otherTile:TileInfo): Int { val xDelta = position.x-otherTile.position.x val yDelta = position.y-otherTile.position.y return listOf(abs(xDelta),abs(yDelta), abs(xDelta-yDelta)).max()!!.toInt() diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index d9113ac4..4fc19e09 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -180,7 +180,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { fun canReach(destination: TileInfo): Boolean { if(unit.type.isAirUnit()) - return unit.currentTile.arialDistanceTo(destination) <= unit.getRange() + return unit.currentTile.aerialDistanceTo(destination) <= unit.getRange() return getShortestPath(destination).isNotEmpty() } @@ -347,7 +347,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { fun getDistanceToTiles(): PathsToTilesWithinTurn = getDistanceToTilesWithinTurn(unit.currentTile.position,unit.currentMovement) - fun getArialPathsToCities(): HashMap> { + fun getAerialPathsToCities(): HashMap> { var tilesToCheck = ArrayList() /** each tile reached points to its parent tile, where we got to it from */ val tilesReached = HashMap()