Workboats improve resources outside of city work range (#11384)

* AI now improves luxury resources outside of city work range

* Strategic resources will now be built on as well outside of city working range

* Renamed a helper method

* Added some spaces after type declaration
This commit is contained in:
Oskar Niesen
2024-04-04 15:40:25 -05:00
committed by GitHub
parent aab6e2643e
commit 455afcee75

View File

@ -399,7 +399,7 @@ class WorkerAutomation(
val removedObject = improvementName.replace(Constants.remove, "")
val removedFeature = tile.terrainFeatures.firstOrNull { it == removedObject }
val removedImprovement = if (removedObject == tile.improvement) removedObject else null
if (removedFeature != null || removedImprovement != null) {
val newTile = tile.clone()
newTile.setTerrainTransients()
@ -570,13 +570,16 @@ class WorkerAutomation(
&& evaluateFortSurroundings(tile, isCitadel) > 0
}
fun isImprovementProbablyAFort(improvementName:String): Boolean = isImprovementProbablyAFort(ruleSet.tileImprovements[improvementName]!!)
fun isImprovementProbablyAFort(improvementName: String): Boolean = isImprovementProbablyAFort(ruleSet.tileImprovements[improvementName]!!)
fun isImprovementProbablyAFort(improvement: TileImprovement): Boolean = improvement.hasUnique(UniqueType.DefensiveBonus)
private fun hasWorkableSeaResource(tile: Tile, civInfo: Civilization): Boolean =
tile.isWater && tile.improvement == null && tile.hasViewableResource(civInfo)
private fun isNotBonusResourceOrWorkable(tile: Tile, civInfo: Civilization): Boolean =
tile.tileResource.resourceType != ResourceType.Bonus || civInfo.cities.any { it.tilesInRange.contains(tile) }
/** Try improving a Water Resource
*
* No logic to avoid capture by enemies yet!
@ -585,13 +588,13 @@ class WorkerAutomation(
*/
fun automateWorkBoats(unit: MapUnit): Boolean {
val closestReachableResource = unit.civ.cities.asSequence()
.flatMap { city -> city.getWorkableTiles() }
.flatMap { city -> city.getTiles() }
.filter {
hasWorkableSeaResource(it, unit.civ)
&& (unit.currentTile == it || unit.movement.canMoveTo(it))
}
.sortedBy { it.aerialDistanceTo(unit.currentTile) }
.firstOrNull { unit.movement.canReach(it) }
.firstOrNull { unit.movement.canReach(it) && isNotBonusResourceOrWorkable(it, unit.civ) }
?: return false
// could be either fishing boats or oil well