AI destroys empty barbarian encampment. (#2793)

This commit is contained in:
Duan Tao 2020-07-03 20:48:28 +08:00 committed by GitHub
parent fdbc5279e5
commit a12b9b5e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,7 @@ object UnitAutomation {
} }
internal fun tryExplore(unit: MapUnit): Boolean { internal fun tryExplore(unit: MapUnit): Boolean {
if (tryGoToRuin(unit) && unit.currentMovement == 0f) return true if (tryGoToRuinAndEncampment(unit) && unit.currentMovement == 0f) return true
val explorableTilesThisTurn = val explorableTilesThisTurn =
unit.movement.getDistanceToTiles().keys.filter { isGoodTileToExplore(unit, it) } unit.movement.getDistanceToTiles().keys.filter { isGoodTileToExplore(unit, it) }
@ -46,16 +46,17 @@ object UnitAutomation {
return false return false
} }
private fun tryGoToRuin(unit: MapUnit): Boolean { private fun tryGoToRuinAndEncampment(unit: MapUnit): Boolean {
if (!unit.civInfo.isMajorCiv()) return false // barbs don't have anything to do in ruins if (!unit.civInfo.isMajorCiv()) return false // barbs don't have anything to do in ruins
val unitDistanceToTiles = unit.movement.getDistanceToTiles() val unitDistanceToTiles = unit.movement.getDistanceToTiles()
val tileWithRuin = unitDistanceToTiles.keys val tileWithRuinOrEncampment = unitDistanceToTiles.keys
.firstOrNull { .firstOrNull {
it.improvement == Constants.ancientRuins && unit.movement.canMoveTo(it) (it.improvement == Constants.ancientRuins || it.improvement == Constants.barbarianEncampment)
&& unit.movement.canMoveTo(it)
} }
if (tileWithRuin == null) if (tileWithRuinOrEncampment == null)
return false return false
unit.movement.moveToTile(tileWithRuin) unit.movement.moveToTile(tileWithRuinOrEncampment)
return true return true
} }
@ -115,7 +116,7 @@ object UnitAutomation {
&& unit.name in GreatPersonManager().statToGreatPersonMapping.values)// So "Great War Infantry" isn't caught here && unit.name in GreatPersonManager().statToGreatPersonMapping.values)// So "Great War Infantry" isn't caught here
return SpecificUnitAutomation.automateGreatPerson(unit) return SpecificUnitAutomation.automateGreatPerson(unit)
if (tryGoToRuin(unit)) { if (tryGoToRuinAndEncampment(unit)) {
if (unit.currentMovement == 0f) return if (unit.currentMovement == 0f) return
} }
@ -399,7 +400,7 @@ object UnitAutomation {
/** This is what a unit with the 'explore' action does. /** This is what a unit with the 'explore' action does.
It also explores, but also has other functions, like healing if necessary. */ It also explores, but also has other functions, like healing if necessary. */
fun automatedExplore(unit: MapUnit) { fun automatedExplore(unit: MapUnit) {
if (tryGoToRuin(unit) && unit.currentMovement == 0f) return if (tryGoToRuinAndEncampment(unit) && unit.currentMovement == 0f) return
if (unit.health < 80 && tryHealUnit(unit)) return if (unit.health < 80 && tryHealUnit(unit)) return
if (tryExplore(unit)) return if (tryExplore(unit)) return
unit.civInfo.addNotification("[${unit.name}] finished exploring.", unit.currentTile.position, Color.GRAY) unit.civInfo.addNotification("[${unit.name}] finished exploring.", unit.currentTile.position, Color.GRAY)