Arial -> Aerial name refactoring

This commit is contained in:
Yair Morgenstern 2020-02-23 22:33:32 +02:00
parent 31d9bb0c5d
commit 3b4bce780a
10 changed files with 32 additions and 32 deletions

View file

@ -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<CityDistance>()
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) {

View file

@ -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<TileInfo, ArrayList<TileInfo>>, airUnit: MapUnit) {
private fun tryMoveToCitiesToAerialAttackFrom(pathsToCities: HashMap<TileInfo, ArrayList<TileInfo>>, 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)
}
}

View file

@ -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())

View file

@ -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%"))

View file

@ -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)

View file

@ -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)
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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()

View file

@ -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<TileInfo, ArrayList<TileInfo>> {
fun getAerialPathsToCities(): HashMap<TileInfo, ArrayList<TileInfo>> {
var tilesToCheck = ArrayList<TileInfo>()
/** each tile reached points to its parent tile, where we got to it from */
val tilesReached = HashMap<TileInfo, TileInfo>()