Code cleaning - no more direct access to the cached center tile in CityInfo

This commit is contained in:
Yair Morgenstern 2019-12-26 18:08:11 +02:00
parent cc00497816
commit 6c10d1d4f8
4 changed files with 7 additions and 7 deletions

View File

@ -53,9 +53,9 @@ class WorkerAutomation(val unit: MapUnit) {
val mostUndevelopedCity = unit.civInfo.cities
.filter { citiesToNumberOfUnimprovedTiles[it.name]!! > 0 }
.sortedByDescending { citiesToNumberOfUnimprovedTiles[it.name] }
.firstOrNull { unit.movement.canReach(it.ccenterTile) } //goto most undeveloped city
.firstOrNull { unit.movement.canReach(it.getCenterTile()) } //goto most undeveloped city
if (mostUndevelopedCity != null && mostUndevelopedCity != unit.currentTile.owningCity) {
val reachedTile = unit.movement.headTowards(mostUndevelopedCity.ccenterTile)
val reachedTile = unit.movement.headTowards(mostUndevelopedCity.getCenterTile())
if (reachedTile != currentTile) unit.doPreTurnAction() // since we've moved, maybe we can do something here - automate
return
}

View File

@ -24,7 +24,7 @@ import kotlin.math.roundToInt
class CityInfo {
@Transient lateinit var civInfo: CivilizationInfo
@Transient lateinit var ccenterTile:TileInfo // cached for better performance
@Transient lateinit private var centerTileInfo:TileInfo // cached for better performance
@Transient val range = 2
@Transient lateinit var tileMap: TileMap
@Transient lateinit var tilesInRange:HashSet<TileInfo>
@ -115,7 +115,7 @@ class CityInfo {
fun getCenterTile(): TileInfo = ccenterTile
fun getCenterTile(): TileInfo = centerTileInfo
fun getTiles(): List<TileInfo> = tiles.map { tileMap[it] }
fun getWorkableTiles() = getTiles().filter { it in tilesInRange }
@ -239,7 +239,7 @@ class CityInfo {
//region state-changing functions
fun setTransients() {
tileMap = civInfo.gameInfo.tileMap
ccenterTile = tileMap[location]
centerTileInfo = tileMap[location]
tilesInRange = getCenterTile().getTilesInDistance( 3).toHashSet()
population.cityInfo = this
expansion.cityInfo = this

View File

@ -82,7 +82,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
// when deselected, move city button to its original position
if (isButtonMoved
&& unitTable.selectedCity != city
&& unitTable.selectedUnit?.currentTile != city.ccenterTile) {
&& unitTable.selectedUnit?.currentTile != city.getCenterTile()) {
moveButtonUp()
}

View File

@ -126,7 +126,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
if(newSelectedUnit==null || newSelectedUnit.type==UnitType.Civilian){
val unitsInTile = selectedTile!!.getUnits()
if(previousSelectedCity != null && !previousSelectedCity.attackedThisTurn
&& selectedTile!!.getTilesInDistance(2).contains(previousSelectedCity.ccenterTile)
&& selectedTile!!.getTilesInDistance(2).contains(previousSelectedCity.getCenterTile())
&& unitsInTile.isNotEmpty()
&& unitsInTile.first().civInfo.isAtWarWith(worldScreen.viewingCiv)){
// try to select the closest city to bombard this guy