mirror of
https://github.com/yairm210/Unciv.git
synced 2025-08-03 00:29:18 +07:00
Removed redundant "else"s for less indentation and 'happy pathing'
This commit is contained in:
@ -19,32 +19,30 @@ class NextTurnAutomation{
|
|||||||
|
|
||||||
/** Top-level AI turn tasklist */
|
/** Top-level AI turn tasklist */
|
||||||
fun automateCivMoves(civInfo: CivilizationInfo) {
|
fun automateCivMoves(civInfo: CivilizationInfo) {
|
||||||
if (civInfo.isBarbarian()) {
|
if (civInfo.isBarbarian()) return BarbarianAutomation(civInfo).automate()
|
||||||
BarbarianAutomation(civInfo).automate()
|
|
||||||
|
respondToDemands(civInfo)
|
||||||
|
respondToTradeRequests(civInfo)
|
||||||
|
|
||||||
|
if(civInfo.isMajorCiv()) {
|
||||||
|
offerPeaceTreaty(civInfo)
|
||||||
|
exchangeTechs(civInfo)
|
||||||
|
exchangeLuxuries(civInfo)
|
||||||
|
issueRequests(civInfo)
|
||||||
|
adoptPolicy(civInfo)
|
||||||
} else {
|
} else {
|
||||||
respondToDemands(civInfo)
|
getFreeTechForCityStates(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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
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.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.models.ruleset.Ruleset
|
import com.unciv.models.ruleset.Ruleset
|
||||||
import com.unciv.models.ruleset.tile.*
|
import com.unciv.models.ruleset.tile.*
|
||||||
import com.unciv.models.translations.tr
|
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
|
import com.unciv.models.translations.tr
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
open class TileInfo {
|
open class TileInfo {
|
||||||
@ -262,7 +262,7 @@ open class TileInfo {
|
|||||||
return resource != null && (getTileResource().revealedBy == null || civInfo.tech.isResearched(getTileResource().revealedBy!!))
|
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)
|
return tileMap.getViewableTiles(this.position,distance,ignoreCurrentTileHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,50 +150,48 @@ class TileMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getViewableTiles(position: Vector2, sightDistance: Int, ignoreCurrentTileHeight: Boolean = false): MutableList<TileInfo> {
|
fun getViewableTiles(position: Vector2, sightDistance: Int, ignoreCurrentTileHeight: Boolean = false): List<TileInfo> {
|
||||||
if (ignoreCurrentTileHeight) {
|
if (ignoreCurrentTileHeight) return getTilesInDistance(position, sightDistance)
|
||||||
return getTilesInDistance(position, sightDistance).toMutableList()
|
|
||||||
} else {
|
|
||||||
val viewableTiles = getTilesInDistance(position, 1).toMutableList()
|
|
||||||
val currentTileHeight = get(position).getHeight()
|
|
||||||
|
|
||||||
for (i in 1..sightDistance) { // in each layer,
|
val viewableTiles = getTilesInDistance(position, 1).toMutableList()
|
||||||
// This is so we don't use tiles in the same distance to "see over",
|
val currentTileHeight = get(position).getHeight()
|
||||||
// that is to say, the "viewableTiles.contains(it) check will return false for neighbors from the same distance
|
|
||||||
val tilesToAddInDistanceI = ArrayList<TileInfo>()
|
|
||||||
|
|
||||||
for (tile in getTilesAtDistance(position, i)) { // for each tile in that layer,
|
for (i in 1..sightDistance) { // in each layer,
|
||||||
val targetTileHeight = tile.getHeight()
|
// 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>()
|
||||||
|
|
||||||
/*
|
for (tile in getTilesAtDistance(position, i)) { // for each tile in that layer,
|
||||||
Okay so, if we're looking at a tile from a to c with b in the middle,
|
val targetTileHeight = tile.getHeight()
|
||||||
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!
|
|
||||||
|
|
||||||
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 {
|
This can all be summed up as "I can see c if a>b || c>b || b==0 "
|
||||||
val neighborHeight = it.getHeight()
|
*/
|
||||||
viewableTiles.contains(it) && (
|
|
||||||
currentTileHeight > neighborHeight // a>b
|
val containsViewableNeighborThatCanSeeOver = tile.neighbors.any {
|
||||||
|| targetTileHeight > neighborHeight // c>b
|
val neighborHeight = it.getHeight()
|
||||||
|| neighborHeight == 0) // b==0
|
viewableTiles.contains(it) && (
|
||||||
}
|
currentTileHeight > neighborHeight // a>b
|
||||||
if (containsViewableNeighborThatCanSeeOver) tilesToAddInDistanceI.add(tile)
|
|| targetTileHeight > neighborHeight // c>b
|
||||||
|
|| neighborHeight == 0) // b==0
|
||||||
}
|
}
|
||||||
viewableTiles.addAll(tilesToAddInDistanceI)
|
if (containsViewableNeighborThatCanSeeOver) tilesToAddInDistanceI.add(tile)
|
||||||
}
|
}
|
||||||
|
viewableTiles.addAll(tilesToAddInDistanceI)
|
||||||
return viewableTiles
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return viewableTiles
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTransients(ruleset: Ruleset) {
|
fun setTransients(ruleset: Ruleset) {
|
||||||
|
Reference in New Issue
Block a user