Removed redundant "else"s for less indentation and 'happy pathing'
This commit is contained in:
parent
725edc2a31
commit
ca59dc4e1f
3 changed files with 57 additions and 61 deletions
|
@ -19,32 +19,30 @@ class NextTurnAutomation{
|
|||
|
||||
/** Top-level AI turn tasklist */
|
||||
fun automateCivMoves(civInfo: CivilizationInfo) {
|
||||
if (civInfo.isBarbarian()) {
|
||||
BarbarianAutomation(civInfo).automate()
|
||||
if (civInfo.isBarbarian()) return BarbarianAutomation(civInfo).automate()
|
||||
|
||||
respondToDemands(civInfo)
|
||||
respondToTradeRequests(civInfo)
|
||||
|
||||
if(civInfo.isMajorCiv()) {
|
||||
offerPeaceTreaty(civInfo)
|
||||
exchangeTechs(civInfo)
|
||||
exchangeLuxuries(civInfo)
|
||||
issueRequests(civInfo)
|
||||
adoptPolicy(civInfo)
|
||||
} else {
|
||||
respondToDemands(civInfo)
|
||||
respondToTradeRequests(civInfo)
|
||||
|
||||
if(civInfo.isMajorCiv()) {
|
||||
offerPeaceTreaty(civInfo)
|
||||
exchangeTechs(civInfo)
|
||||
exchangeLuxuries(civInfo)
|
||||
issueRequests(civInfo)
|
||||
adoptPolicy(civInfo)
|
||||
} else {
|
||||
getFreeTechForCityStates(civInfo)
|
||||
}
|
||||
|
||||
chooseTechToResearch(civInfo)
|
||||
updateDiplomaticRelationship(civInfo)
|
||||
declareWar(civInfo)
|
||||
automateCityBombardment(civInfo)
|
||||
useGold(civInfo)
|
||||
automateUnits(civInfo)
|
||||
reassignWorkedTiles(civInfo)
|
||||
trainSettler(civInfo)
|
||||
getFreeTechForCityStates(civInfo)
|
||||
}
|
||||
|
||||
chooseTechToResearch(civInfo)
|
||||
updateDiplomaticRelationship(civInfo)
|
||||
declareWar(civInfo)
|
||||
automateCityBombardment(civInfo)
|
||||
useGold(civInfo)
|
||||
automateUnits(civInfo)
|
||||
reassignWorkedTiles(civInfo)
|
||||
trainSettler(civInfo)
|
||||
|
||||
civInfo.popupAlerts.clear() // AIs don't care about popups.
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import com.unciv.logic.city.CityInfo
|
|||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.tile.*
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.models.translations.tr
|
||||
import kotlin.math.abs
|
||||
|
||||
open class TileInfo {
|
||||
|
@ -262,7 +262,7 @@ open class TileInfo {
|
|||
return resource != null && (getTileResource().revealedBy == null || civInfo.tech.isResearched(getTileResource().revealedBy!!))
|
||||
}
|
||||
|
||||
fun getViewableTiles(distance:Int, ignoreCurrentTileHeight:Boolean = false): MutableList<TileInfo> {
|
||||
fun getViewableTiles(distance:Int, ignoreCurrentTileHeight:Boolean = false): List<TileInfo> {
|
||||
return tileMap.getViewableTiles(this.position,distance,ignoreCurrentTileHeight)
|
||||
}
|
||||
|
||||
|
|
|
@ -150,50 +150,48 @@ class TileMap {
|
|||
}
|
||||
|
||||
|
||||
fun getViewableTiles(position: Vector2, sightDistance: Int, ignoreCurrentTileHeight: Boolean = false): MutableList<TileInfo> {
|
||||
if (ignoreCurrentTileHeight) {
|
||||
return getTilesInDistance(position, sightDistance).toMutableList()
|
||||
} else {
|
||||
val viewableTiles = getTilesInDistance(position, 1).toMutableList()
|
||||
val currentTileHeight = get(position).getHeight()
|
||||
fun getViewableTiles(position: Vector2, sightDistance: Int, ignoreCurrentTileHeight: Boolean = false): List<TileInfo> {
|
||||
if (ignoreCurrentTileHeight) return getTilesInDistance(position, sightDistance)
|
||||
|
||||
for (i in 1..sightDistance) { // in each layer,
|
||||
// This is so we don't use tiles in the same distance to "see over",
|
||||
// that is to say, the "viewableTiles.contains(it) check will return false for neighbors from the same distance
|
||||
val tilesToAddInDistanceI = ArrayList<TileInfo>()
|
||||
val viewableTiles = getTilesInDistance(position, 1).toMutableList()
|
||||
val currentTileHeight = get(position).getHeight()
|
||||
|
||||
for (tile in getTilesAtDistance(position, i)) { // for each tile in that layer,
|
||||
val targetTileHeight = tile.getHeight()
|
||||
for (i in 1..sightDistance) { // in each layer,
|
||||
// This is so we don't use tiles in the same distance to "see over",
|
||||
// that is to say, the "viewableTiles.contains(it) check will return false for neighbors from the same distance
|
||||
val tilesToAddInDistanceI = ArrayList<TileInfo>()
|
||||
|
||||
/*
|
||||
Okay so, if we're looking at a tile from a to c with b in the middle,
|
||||
we have several scenarios:
|
||||
1. a>b - - I can see everything, b does not hide c
|
||||
2. a==b
|
||||
2.1 a==b==0, all flat ground, no hiding
|
||||
2.2 a>0, b>=c - b hides c from view (say I am in a forest/jungle and b is a forest/jungle, or hill)
|
||||
2.3 a>0, c>b - c is tall enough I can see it over b!
|
||||
3. a<b
|
||||
3.1 b>=c - b hides c
|
||||
3.2 b<c - c is tall enough I can see it over b!
|
||||
for (tile in getTilesAtDistance(position, i)) { // for each tile in that layer,
|
||||
val targetTileHeight = tile.getHeight()
|
||||
|
||||
This can all be summed up as "I can see c if a>b || c>b || b==0 "
|
||||
*/
|
||||
/*
|
||||
Okay so, if we're looking at a tile from a to c with b in the middle,
|
||||
we have several scenarios:
|
||||
1. a>b - - I can see everything, b does not hide c
|
||||
2. a==b
|
||||
2.1 a==b==0, all flat ground, no hiding
|
||||
2.2 a>0, b>=c - b hides c from view (say I am in a forest/jungle and b is a forest/jungle, or hill)
|
||||
2.3 a>0, c>b - c is tall enough I can see it over b!
|
||||
3. a<b
|
||||
3.1 b>=c - b hides c
|
||||
3.2 b<c - c is tall enough I can see it over b!
|
||||
|
||||
val containsViewableNeighborThatCanSeeOver = tile.neighbors.any {
|
||||
val neighborHeight = it.getHeight()
|
||||
viewableTiles.contains(it) && (
|
||||
currentTileHeight > neighborHeight // a>b
|
||||
|| targetTileHeight > neighborHeight // c>b
|
||||
|| neighborHeight == 0) // b==0
|
||||
}
|
||||
if (containsViewableNeighborThatCanSeeOver) tilesToAddInDistanceI.add(tile)
|
||||
This can all be summed up as "I can see c if a>b || c>b || b==0 "
|
||||
*/
|
||||
|
||||
val containsViewableNeighborThatCanSeeOver = tile.neighbors.any {
|
||||
val neighborHeight = it.getHeight()
|
||||
viewableTiles.contains(it) && (
|
||||
currentTileHeight > neighborHeight // a>b
|
||||
|| targetTileHeight > neighborHeight // c>b
|
||||
|| neighborHeight == 0) // b==0
|
||||
}
|
||||
viewableTiles.addAll(tilesToAddInDistanceI)
|
||||
if (containsViewableNeighborThatCanSeeOver) tilesToAddInDistanceI.add(tile)
|
||||
}
|
||||
|
||||
return viewableTiles
|
||||
viewableTiles.addAll(tilesToAddInDistanceI)
|
||||
}
|
||||
|
||||
return viewableTiles
|
||||
}
|
||||
|
||||
fun setTransients(ruleset: Ruleset) {
|
||||
|
|
Loading…
Reference in a new issue