mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
Current worker automation assumes A LOT about the current ruleset. This is only step 1, which allows skipping irrelevant improvements to reach actually useful improvements. Comments welcome.
This commit is contained in:
parent
e477e4917a
commit
8846c158fb
@ -339,14 +339,19 @@ class WorkerAutomation(
|
||||
}
|
||||
|
||||
// turnsToBuild is what defines them as buildable
|
||||
val tileImprovements = ruleSet.tileImprovements.filter { it.value.turnsToBuild != 0 }
|
||||
val tileImprovements = ruleSet.tileImprovements.filter {
|
||||
it.value.turnsToBuild != 0 && tile.canImprovementBeBuiltHere(it.value, tile.hasViewableResource(civInfo)) }
|
||||
val uniqueImprovement = tileImprovements.values
|
||||
.firstOrNull { it.uniqueTo == civInfo.civName }
|
||||
|
||||
val currentlyBuildableImprovements = tileImprovements.values.filter { tile.canBuildImprovement(it, civInfo) }
|
||||
val bestBuildableImprovement = currentlyBuildableImprovements.map { Pair(it, Automation.rankStatsValue(it, civInfo)) }
|
||||
.filter { it.second > 0f }
|
||||
.maxByOrNull { it.second }?.first
|
||||
|
||||
val improvementString = when {
|
||||
tile.improvementInProgress != null -> tile.improvementInProgress!!
|
||||
improvementStringForResource != null && tileImprovements.containsKey(improvementStringForResource)
|
||||
&& tileImprovements[improvementStringForResource]!!.turnsToBuild != 0 -> improvementStringForResource
|
||||
improvementStringForResource != null && tileImprovements.containsKey(improvementStringForResource) -> improvementStringForResource
|
||||
tile.containsGreatImprovement() -> return null
|
||||
tile.containsUnfinishedGreatImprovement() -> return null
|
||||
|
||||
@ -362,11 +367,16 @@ class WorkerAutomation(
|
||||
tile.terrainFeatures.contains(Constants.marsh) -> "Remove Marsh"
|
||||
tile.terrainFeatures.contains(Constants.jungle) -> Constants.tradingPost
|
||||
tile.terrainFeatures.contains("Oasis") -> return null
|
||||
tile.terrainFeatures.contains(Constants.forest) -> "Lumber mill"
|
||||
tile.isHill() -> "Mine"
|
||||
tile.baseTerrain in listOf(Constants.grassland, Constants.desert, Constants.plains) -> "Farm"
|
||||
tile.isAdjacentToFreshwater -> "Farm"
|
||||
tile.baseTerrain in listOf(Constants.tundra, Constants.snow) -> Constants.tradingPost
|
||||
tile.terrainFeatures.contains(Constants.forest) && tileImprovements.containsKey("Lumber mill") -> "Lumber mill"
|
||||
tile.isHill() && tileImprovements.containsKey("Mine") -> "Mine"
|
||||
tile.baseTerrain in listOf(Constants.grassland, Constants.desert, Constants.plains)
|
||||
&& tileImprovements.containsKey("Farm") -> "Farm"
|
||||
tile.isAdjacentToFreshwater && tileImprovements.containsKey("Farm") -> "Farm"
|
||||
tile.baseTerrain in listOf(Constants.tundra, Constants.snow) && tileImprovements.containsKey(Constants.tradingPost)
|
||||
-> Constants.tradingPost
|
||||
|
||||
// This is the ONLY thing that will catch modded non-unique improvements
|
||||
bestBuildableImprovement != null -> bestBuildableImprovement.name
|
||||
else -> return null
|
||||
}
|
||||
return ruleSet.tileImprovements[improvementString] // For mods, the tile improvement may not exist, so don't assume.
|
||||
|
@ -472,7 +472,7 @@ open class TileInfo {
|
||||
/** Without regards to what CivInfo it is, a lot of the checks are just for the improvement on the tile.
|
||||
* Doubles as a check for the map editor.
|
||||
*/
|
||||
private fun canImprovementBeBuiltHere(improvement: TileImprovement, resourceIsVisible: Boolean = resource != null): Boolean {
|
||||
fun canImprovementBeBuiltHere(improvement: TileImprovement, resourceIsVisible: Boolean = resource != null): Boolean {
|
||||
val topTerrain = getLastTerrain()
|
||||
|
||||
return when {
|
||||
|
Loading…
Reference in New Issue
Block a user