River adjacency functions and gold bonus for tiles adjacent to rivers

This commit is contained in:
Yair Morgenstern
2020-05-17 21:29:12 +03:00
parent 8a43d5c5d6
commit 3032ba9c73

View File

@ -242,6 +242,8 @@ open class TileInfo {
if (stats.gold != 0f && observingCiv.goldenAges.isGoldenAge())
stats.gold++
if (isAdjacentToRiver()) stats.gold++
if (stats.production < 0) stats.production = 0f
return stats
@ -336,6 +338,21 @@ open class TileInfo {
return toString(null)
}
fun isConnectedByRiver(otherTile:TileInfo): Boolean {
if(otherTile !in neighbors) throw Exception("Should never call this function on a non-neighbor!")
val xDifference = this.position.x - otherTile.position.x
val yDifference = this.position.y - otherTile.position.y
return when {
xDifference == 1f && yDifference == 1f -> hasBottomRiver // we're directly above it
xDifference == 1f -> hasBottomRightRiver // we're to the top-left of it
yDifference == 1f -> hasBottomLeftRiver // we're to the top-right of it
else -> otherTile.isConnectedByRiver(this) // we're below it, check the other tile
}
}
fun isAdjacentToRiver() = neighbors.any { isConnectedByRiver(it) }
fun toString(viewingCiv: CivilizationInfo?): String {
val lineList = ArrayList<String>() // more readable than StringBuilder, with same performance for our use-case
val isViewableToPlayer = viewingCiv == null || UncivGame.Current.viewEntireMapForDebug
@ -412,6 +429,7 @@ open class TileInfo {
improvementInProgress = improvement.name
turnsToImprovement = improvement.getTurnsToBuild(civInfo)
}
fun stopWorkingOnImprovement() {
improvementInProgress = null
turnsToImprovement = 0