Organized 'explore' actions
This commit is contained in:
parent
6fc3b2fd0e
commit
20a7ff7c76
3 changed files with 12 additions and 32 deletions
|
@ -83,10 +83,7 @@ class BarbarianAutomation(val civInfo: CivilizationInfo) {
|
|||
if (UnitAutomation().tryPillageImprovement(unit, unitDistanceToTiles)) return
|
||||
|
||||
// 5 - heal the unit if needed
|
||||
if (unit.health < 100) {
|
||||
UnitAutomation().tryHealUnit(unit, unitDistanceToTiles)
|
||||
return
|
||||
}
|
||||
if (unit.health < 100 && UnitAutomation().tryHealUnit(unit, unitDistanceToTiles)) return
|
||||
|
||||
// 6 - wander
|
||||
UnitAutomation().wander(unit, unitDistanceToTiles)
|
||||
|
@ -114,10 +111,7 @@ class BarbarianAutomation(val civInfo: CivilizationInfo) {
|
|||
if (UnitAutomation().tryPillageImprovement(unit, unitDistanceToTiles)) return
|
||||
|
||||
// 4 - heal the unit if needed
|
||||
if (unit.health < 100) {
|
||||
UnitAutomation().tryHealUnit(unit, unitDistanceToTiles)
|
||||
return
|
||||
}
|
||||
if (unit.health < 100 && UnitAutomation().tryHealUnit(unit, unitDistanceToTiles)) return
|
||||
|
||||
// 5 - wander
|
||||
UnitAutomation().wander(unit, unitDistanceToTiles)
|
||||
|
|
|
@ -362,40 +362,25 @@ class UnitAutomation {
|
|||
}
|
||||
|
||||
internal fun tryExplore(unit: MapUnit, unitDistanceToTiles: PathsToTilesWithinTurn): Boolean {
|
||||
if (tryGoToRuin(unit, unitDistanceToTiles)) {
|
||||
if (unit.currentMovement == 0f) return true
|
||||
}
|
||||
if (tryGoToRuin(unit, unitDistanceToTiles) && unit.currentMovement == 0f) return true
|
||||
|
||||
for (tile in unit.currentTile.getTilesInDistance(5))
|
||||
for (tile in unit.currentTile.getTilesInDistance(10))
|
||||
if (unit.movement.canMoveTo(tile) && tile.position !in unit.civInfo.exploredTiles
|
||||
&& unit.movement.canReach(tile)) {
|
||||
&& unit.movement.canReach(tile)
|
||||
&& (tile.getOwner()==null || !tile.getOwner()!!.isCityState())) {
|
||||
unit.movement.headTowards(tile)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/** This is what a unit with the 'explore' action does.
|
||||
It also explores, but also has other functions, like healing if necessary. */
|
||||
fun automatedExplore(unit: MapUnit) {
|
||||
val unitDistanceToTiles = unit.movement.getDistanceToTiles()
|
||||
if (tryGoToRuin(unit, unitDistanceToTiles) && unit.currentMovement == 0f) return
|
||||
|
||||
if (unit.health < 80) {
|
||||
tryHealUnit(unit, unitDistanceToTiles)
|
||||
return
|
||||
}
|
||||
|
||||
for (i in 1..10) {
|
||||
val unexploredTilesAtDistance = unit.getTile().getTilesAtDistance(i)
|
||||
.filter {
|
||||
unit.movement.canMoveTo(it) && it.position !in unit.civInfo.exploredTiles
|
||||
&& unit.movement.canReach(it)
|
||||
&& (it.getOwner()==null || !it.getOwner()!!.isCityState())
|
||||
}
|
||||
if (unexploredTilesAtDistance.isNotEmpty()) {
|
||||
unit.movement.headTowards(unexploredTilesAtDistance.random())
|
||||
return
|
||||
}
|
||||
}
|
||||
if (unit.health < 80 && tryHealUnit(unit, unitDistanceToTiles)) return
|
||||
if (tryExplore(unit, unit.movement.getDistanceToTiles())) return
|
||||
unit.civInfo.addNotification("[${unit.name}] finished exploring.", unit.currentTile.position, Color.GRAY)
|
||||
}
|
||||
|
||||
|
|
|
@ -379,8 +379,9 @@ class CityInfo {
|
|||
|
||||
val oldCiv = civInfo
|
||||
// must be before moving the city to the conquering civ,
|
||||
// so the sum of population isn't 0 when conquering the last city of a civ
|
||||
// so the repercussions are properly checked
|
||||
diplomaticRepercussionsForConqueringCity(oldCiv, conqueringCiv)
|
||||
|
||||
moveToCiv(conqueringCiv)
|
||||
Battle.destroyIfDefeated(oldCiv, conqueringCiv)
|
||||
|
||||
|
|
Loading…
Reference in a new issue