@Interdice even after all that there was still a bug - we didn't check if the tiles we were sending the missionary/inquisitor to was actually reachable :)

This commit is contained in:
yairm210 2021-12-16 22:54:46 +02:00
parent a7b880c033
commit 9d38ce75c4

View File

@ -300,7 +300,8 @@ object SpecificUnitAutomation {
val destination = cities.getTiles().asSequence() val destination = cities.getTiles().asSequence()
.filterNot { unit.getTile().owningCity == it.owningCity } // to prevent the ai from moving around randomly .filterNot { unit.getTile().owningCity == it.owningCity } // to prevent the ai from moving around randomly
.filter { unit.movement.canMoveTo(it) } .filter { unit.movement.canMoveTo(it) }
.minByOrNull { it.aerialDistanceTo(unit.currentTile) } .sortedBy { it.aerialDistanceTo(unit.currentTile) }
.firstOrNull { unit.movement.canReach(it) }
if (destination != null) { if (destination != null) {
@ -311,7 +312,7 @@ object SpecificUnitAutomation {
doReligiousAction(unit, unit.getTile()) doReligiousAction(unit, unit.getTile())
} }
fun automateInquisitor(unit: MapUnit){ fun automateInquisitor(unit: MapUnit) {
val cityToConvert = unit.civInfo.cities.asSequence() val cityToConvert = unit.civInfo.cities.asSequence()
.filterNot { it.religion.getMajorityReligion()?.name == null } .filterNot { it.religion.getMajorityReligion()?.name == null }
.filterNot { it.religion.getMajorityReligion()?.name == unit.religion } .filterNot { it.religion.getMajorityReligion()?.name == unit.religion }
@ -319,34 +320,35 @@ object SpecificUnitAutomation {
val cityToProtect = unit.civInfo.cities.asSequence() val cityToProtect = unit.civInfo.cities.asSequence()
.filter { it.religion.getMajorityReligion()?.name == unit.religion } .filter { it.religion.getMajorityReligion()?.name == unit.religion }
.filter { isInquisitorInTheCity(it, unit)} .filter { isInquisitorInTheCity(it, unit) }
.maxByOrNull { it.population.population } // cities with most populations will be prioritized by the AI .maxByOrNull { it.population.population } // cities with most populations will be prioritized by the AI
var destination: TileInfo? = null var destination: TileInfo? = null
if (cityToProtect != null){ if (cityToProtect != null) {
destination = cityToProtect.getCenterTile().neighbors.asSequence() destination = cityToProtect.getCenterTile().neighbors.asSequence()
.filterNot { unit.getTile().owningCity == it.owningCity } // to prevent the ai from moving around randomly .filterNot { unit.getTile().owningCity == it.owningCity } // to prevent the ai from moving around randomly
.filter { unit.movement.canMoveTo(it) } .filter { unit.movement.canMoveTo(it) }
.minByOrNull { it.aerialDistanceTo(unit.currentTile) } .sortedBy { it.aerialDistanceTo(unit.currentTile) }
.firstOrNull { unit.movement.canReach(it) }
} }
if (destination == null){ if (destination == null) {
if (cityToConvert == null) return if (cityToConvert == null) return
destination = cityToConvert.getCenterTile().neighbors.asSequence() destination = cityToConvert.getCenterTile().neighbors.asSequence()
.filterNot { unit.getTile().owningCity == it.owningCity } // to prevent the ai from moving around randomly .filterNot { unit.getTile().owningCity == it.owningCity } // to prevent the ai from moving around randomly
.filter { unit.movement.canMoveTo(it) } .filter { unit.movement.canMoveTo(it) }
.minByOrNull { it.aerialDistanceTo(unit.currentTile) } .sortedBy { it.aerialDistanceTo(unit.currentTile) }
.firstOrNull { unit.movement.canReach(it) }
} }
if (destination != null) if (destination != null)
unit.movement.headTowards(destination) unit.movement.headTowards(destination)
if (cityToConvert != null && unit.currentTile.getCity() == destination!!.getCity()){ if (cityToConvert != null && unit.currentTile.getCity() == destination!!.getCity()) {
doReligiousAction(unit, destination) doReligiousAction(unit, destination)
} }
} }
private fun isInquisitorInTheCity(city: CityInfo, unit: MapUnit): Boolean { private fun isInquisitorInTheCity(city: CityInfo, unit: MapUnit): Boolean {