mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 22:37:02 -04:00
Much more turn-efficient exploration!
This commit is contained in:
parent
b6f75f0583
commit
fea202dbd6
@ -17,13 +17,29 @@ object UnitAutomation {
|
|||||||
const val CLOSE_ENEMY_TILES_AWAY_LIMIT = 5
|
const val CLOSE_ENEMY_TILES_AWAY_LIMIT = 5
|
||||||
const val CLOSE_ENEMY_TURNS_AWAY_LIMIT = 3f
|
const val CLOSE_ENEMY_TURNS_AWAY_LIMIT = 3f
|
||||||
|
|
||||||
|
private fun isGoodTileToExplore(unit:MapUnit, tile:TileInfo): Boolean {
|
||||||
|
return unit.movement.canMoveTo(tile)
|
||||||
|
&& (tile.getOwner() == null || !tile.getOwner()!!.isCityState())
|
||||||
|
&& tile.neighbors.any { it.position !in unit.civInfo.exploredTiles }
|
||||||
|
&& unit.movement.canReach(tile)
|
||||||
|
}
|
||||||
|
|
||||||
internal fun tryExplore(unit: MapUnit): Boolean {
|
internal fun tryExplore(unit: MapUnit): Boolean {
|
||||||
if (tryGoToRuin(unit) && unit.currentMovement == 0f) return true
|
if (tryGoToRuin(unit) && unit.currentMovement == 0f) return true
|
||||||
|
|
||||||
for (tile in unit.currentTile.getTilesInDistance(5)) // number increases exponentially with distance - at 10 this took a looong time
|
val explorableTilesThisTurn =
|
||||||
if (unit.movement.canMoveTo(tile) && tile.neighbors.any { it.position !in unit.civInfo.exploredTiles }
|
unit.movement.getDistanceToTiles().keys.filter { isGoodTileToExplore(unit, it) }
|
||||||
&& unit.movement.canReach(tile)
|
if (explorableTilesThisTurn.any()) {
|
||||||
&& (tile.getOwner() == null || !tile.getOwner()!!.isCityState())) {
|
val bestTile = explorableTilesThisTurn
|
||||||
|
.sortedByDescending { it.getHeight() } // secondary sort is by 'how far can you see'
|
||||||
|
.maxBy { it.aerialDistanceTo(unit.currentTile) }!! // primary sort is by 'how far can you go'
|
||||||
|
unit.movement.headTowards(bestTile)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing immediate, let's look further. Number increases exponentially with distance - at 10 this took a looong time
|
||||||
|
for (tile in unit.currentTile.getTilesInDistance(5))
|
||||||
|
if (isGoodTileToExplore(unit, tile)) {
|
||||||
unit.movement.headTowards(tile)
|
unit.movement.headTowards(tile)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -94,10 +94,6 @@ open class TileInfo {
|
|||||||
if (resource == null) throw Exception("No resource exists for this tile!")
|
if (resource == null) throw Exception("No resource exists for this tile!")
|
||||||
else ruleset.tileResources[resource!!]!!
|
else ruleset.tileResources[resource!!]!!
|
||||||
|
|
||||||
fun getTileResourceOrNull(): TileResource? =
|
|
||||||
if (resource == null) null
|
|
||||||
else ruleset.tileResources.getOrElse(resource!!) {null }
|
|
||||||
|
|
||||||
fun getNaturalWonder() : Terrain =
|
fun getNaturalWonder() : Terrain =
|
||||||
if (naturalWonder == null) throw Exception("No natural wonder exists for this tile!")
|
if (naturalWonder == null) throw Exception("No natural wonder exists for this tile!")
|
||||||
else ruleset.terrains[naturalWonder!!]!!
|
else ruleset.terrains[naturalWonder!!]!!
|
||||||
@ -323,9 +319,13 @@ open class TileInfo {
|
|||||||
|
|
||||||
fun isRoughTerrain() = getBaseTerrain().rough || getTerrainFeature()?.rough == true
|
fun isRoughTerrain() = getBaseTerrain().rough || getTerrainFeature()?.rough == true
|
||||||
|
|
||||||
fun toString(viewingCiv: CivilizationInfo): String {
|
override fun toString():String { // for debugging, it helps to see what you're doing
|
||||||
|
return toString(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toString(viewingCiv: CivilizationInfo?): String {
|
||||||
val lineList = ArrayList<String>() // more readable than StringBuilder, with same performance for our use-case
|
val lineList = ArrayList<String>() // more readable than StringBuilder, with same performance for our use-case
|
||||||
val isViewableToPlayer = UncivGame.Current.viewEntireMapForDebug
|
val isViewableToPlayer = viewingCiv==null || UncivGame.Current.viewEntireMapForDebug
|
||||||
|| viewingCiv.viewableTiles.contains(this)
|
|| viewingCiv.viewableTiles.contains(this)
|
||||||
|
|
||||||
if (isCityCenter()) {
|
if (isCityCenter()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user