mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-28 05:39:10 +07:00
Minor improvements
This commit is contained in:
@ -24,7 +24,7 @@ class UnCivGame : Game() {
|
||||
override fun create() {
|
||||
Current = this
|
||||
Gdx.input.isCatchBackKey=true
|
||||
GameBasics.run { } // just to initialize
|
||||
GameBasics.run { } // just to initialize the GameBasics
|
||||
settings = GameSaver().getGeneralSettings()
|
||||
if (GameSaver().getSave("Autosave").exists()) {
|
||||
try {
|
||||
|
@ -203,15 +203,20 @@ class UnitAutomation{
|
||||
private fun tryHeadTowardsEnemyCity(unit: MapUnit): Boolean {
|
||||
if(unit.civInfo.cities.isEmpty()) return false
|
||||
|
||||
var enemyCities = unit.civInfo.gameInfo.civilizations.filter { unit.civInfo.isAtWarWith(it) }
|
||||
.flatMap { it.cities }.filter { it.location in unit.civInfo.exploredTiles }.map { it.getCenterTile() }
|
||||
if(unit.baseUnit().unitType.isRanged())
|
||||
var enemyCities = unit.civInfo.gameInfo.civilizations
|
||||
.filter { unit.civInfo.isAtWarWith(it) }
|
||||
.flatMap { it.cities }.asSequence()
|
||||
.filter { it.location in unit.civInfo.exploredTiles }
|
||||
.map { it.getCenterTile() }.toList()
|
||||
|
||||
if(unit.baseUnit().unitType.isRanged()) // ranged units don't harm capturable cities, waste of a turn
|
||||
enemyCities = enemyCities.filterNot { it.getCity()!!.health==1 }
|
||||
|
||||
val closestReachableEnemyCity = enemyCities
|
||||
.asSequence()
|
||||
.filter { unit.movementAlgs().canReach(it) }
|
||||
.minBy { city ->
|
||||
unit.civInfo.cities.map { HexMath().getDistance(city.position, it.getCenterTile().position) }.min()!!
|
||||
unit.civInfo.cities.asSequence().map { HexMath().getDistance(city.position, it.getCenterTile().position) }.min()!!
|
||||
}
|
||||
if (closestReachableEnemyCity != null) {
|
||||
unit.movementAlgs().headTowards(closestReachableEnemyCity)
|
||||
|
@ -89,7 +89,7 @@ class CityConstructions {
|
||||
throw NotBuildingOrUnitException("$constructionName is not a building or a unit!")
|
||||
}
|
||||
|
||||
internal fun getBuiltBuildings(): List<Building> = builtBuildings.map { GameBasics.Buildings[it]!! }
|
||||
internal fun getBuiltBuildings(): List<Building> = builtBuildings.toList().map { GameBasics.Buildings[it]!! } // toList os to avoid concurrency problems
|
||||
|
||||
fun containsBuildingOrEquivalent(building: String): Boolean =
|
||||
isBuilt(building) || getBuiltBuildings().any{it.replaces==building}
|
||||
|
Reference in New Issue
Block a user