Remove unnecessary/harmful open on classes without subclasses (#11217)

* Remove open modifier from classes never actually subclassed

* Correct resulting compilation errors with readabilty improvement
This commit is contained in:
SomeTroglodyte 2024-02-28 22:52:46 +01:00 committed by GitHub
parent 6a61a71c36
commit 8946ee8bfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 9 deletions

View File

@ -144,11 +144,17 @@ object SpecificUnitAutomation {
if (bestCityLocation == null) {
// Find the best tile that is within
bestCityLocation = bestTilesInfo.tileRankMap.filter { bestTilesInfo.bestTile == null || it.value >= bestTilesInfo.tileRankMap[bestTilesInfo.bestTile]!! - 5 }.asSequence().sortedByDescending { it.value }.firstOrNull {
if (it.key in dangerousTiles && it != unit.getTile()) return@firstOrNull false
fun isTileRankOK(it: Map.Entry<Tile, Float>): Boolean {
if (it.key in dangerousTiles && it.key != unit.getTile()) return false
val pathSize = unit.movement.getShortestPath(it.key).size
return@firstOrNull pathSize in 1..3
}?.key
return pathSize in 1..3
}
bestCityLocation = bestTilesInfo.tileRankMap.entries.asSequence()
.filter { bestTilesInfo.bestTile == null || it.value >= bestTilesInfo.tileRankMap[bestTilesInfo.bestTile]!! - 5 }
.sortedByDescending { it.value }
.firstOrNull(::isTileRankOK)
?.key
}
// We still haven't found a best city tile within 3 turns so lets just head to the best tile

View File

@ -169,7 +169,7 @@ class WorkerAutomation(
*/
private fun findTileToWork(unit: MapUnit, tilesToAvoid: Set<Tile>): Tile {
val currentTile = unit.getTile()
if (currentTile != tilesToAvoid && getBasePriority(currentTile, unit) >= 5
if (currentTile !in tilesToAvoid && getBasePriority(currentTile, unit) >= 5
&& (tileHasWorkToDo(currentTile, unit) || currentTile.isPillaged() || currentTile.hasFalloutEquivalent())) {
return currentTile
}

View File

@ -6,7 +6,7 @@ import com.unciv.logic.IsPartOfGameInfoSerialization
import com.unciv.ui.screens.victoryscreen.RankingType
/** Records for each turn (key of outer map) what the score (value of inner map) was for each RankingType. */
open class CivRankingHistory : HashMap<Int, Map<RankingType, Int>>(),
class CivRankingHistory : HashMap<Int, Map<RankingType, Int>>(),
IsPartOfGameInfoSerialization {
/**

View File

@ -108,7 +108,7 @@ class UnitMovement(val unit: MapUnit) {
return cachedPath
val currentTile = unit.getTile()
if (currentTile.position == destination) {
if (currentTile.position == destination.position) {
// edge case that's needed, so that workers will know that they can reach their own tile. *sigh*
pathfindingCache.setShortestPathCache(destination, listOf(currentTile))
return listOf(currentTile)

View File

@ -33,7 +33,7 @@ import kotlin.math.abs
import kotlin.math.min
import kotlin.random.Random
open class Tile : IsPartOfGameInfoSerialization {
class Tile : IsPartOfGameInfoSerialization {
@Transient
lateinit var tileMap: TileMap

View File

@ -13,7 +13,7 @@ import java.util.TreeMap
*
* @see com.unciv.ui.screens.victoryscreen.ReplayMap
*/
open class TileHistory : IsPartOfGameInfoSerialization {
class TileHistory : IsPartOfGameInfoSerialization {
class TileHistoryState(
/** The name of the civilization owning this tile or `null` if there is no owner. */