mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
chore(purity): Autosuggested, removed more localstate
This commit is contained in:
parent
33cd9821d0
commit
e3599e4591
@ -58,7 +58,8 @@ allprojects {
|
||||
"com.badlogic.gdx.math.Vector2.cpy",
|
||||
"com.badlogic.gdx.math.Vector2.hashCode",
|
||||
|
||||
"java.util.BitSet.get"
|
||||
"java.util.BitSet.get", // moved
|
||||
"kotlin.collections.getValue", // moved
|
||||
)
|
||||
wellKnownPureClasses = setOf<String>(
|
||||
)
|
||||
@ -71,6 +72,7 @@ allprojects {
|
||||
"kotlin.collections.Set",
|
||||
"kotlin.collections.Map",
|
||||
"kotlin.collections.ArrayDequeue",
|
||||
"java.util.BitSet",
|
||||
|
||||
"com.unciv.models.stats.Stats",
|
||||
"com.unciv.models.Counter",
|
||||
|
@ -7,7 +7,7 @@ import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.ui.components.input.KeyboardBinding
|
||||
import com.unciv.ui.screens.cityscreen.CitizenManagementTable
|
||||
import com.unciv.ui.images.ImageGetter
|
||||
import yairm210.purity.annotations.Pure
|
||||
|
||||
/**
|
||||
* Controls automatic worker-to-tile assignment
|
||||
@ -60,16 +60,17 @@ enum class CityFocus(
|
||||
|
||||
val binding: KeyboardBinding =
|
||||
binding ?:
|
||||
KeyboardBinding.values().firstOrNull { it.name == name } ?:
|
||||
KeyboardBinding.entries.firstOrNull { it.name == name } ?:
|
||||
KeyboardBinding.None
|
||||
|
||||
@Pure
|
||||
open fun getStatMultiplier(stat: Stat) = when (this.stat) {
|
||||
stat -> 3.05f // on ties, prefer the Focus
|
||||
else -> 1f
|
||||
}
|
||||
|
||||
private val statValuesForFocus: List<Stat> by lazy {
|
||||
Stat.values().filter { getStatMultiplier(it) != 1f }
|
||||
Stat.entries.filter { getStatMultiplier(it) != 1f }
|
||||
}
|
||||
|
||||
fun applyWeightTo(stats: Stats) {
|
||||
@ -82,9 +83,7 @@ enum class CityFocus(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun safeValueOf(stat: Stat): CityFocus {
|
||||
return values().firstOrNull { it.stat == stat } ?: NoFocus
|
||||
}
|
||||
@Pure fun safeValueOf(stat: Stat): CityFocus = entries.firstOrNull { it.stat == stat } ?: NoFocus
|
||||
|
||||
// set used in Automation. All non-Food Focuses, so targets 0 Surplus Food
|
||||
val zeroFoodFocuses = setOf(
|
||||
|
@ -201,7 +201,7 @@ class Civilization : IsPartOfGameInfoSerialization {
|
||||
// Limit camera within explored region
|
||||
var exploredRegion = ExploredRegion()
|
||||
|
||||
fun hasExplored(tile: Tile) = tile.isExplored(this)
|
||||
@Readonly fun hasExplored(tile: Tile) = tile.isExplored(this)
|
||||
|
||||
val lastSeenImprovement = LastSeenImprovement()
|
||||
|
||||
|
@ -24,7 +24,7 @@ class UnitMovement(val unit: MapUnit) {
|
||||
|
||||
class ParentTileAndTotalMovement(val tile: Tile, val parentTile: Tile, val totalMovement: Float)
|
||||
|
||||
fun isUnknownTileWeShouldAssumeToBePassable(tile: Tile) = !unit.civ.hasExplored(tile)
|
||||
@Readonly fun isUnknownTileWeShouldAssumeToBePassable(tile: Tile) = !unit.civ.hasExplored(tile)
|
||||
|
||||
|
||||
/**
|
||||
@ -109,6 +109,7 @@ class UnitMovement(val unit: MapUnit) {
|
||||
* Does not consider if the [destination] tile can actually be entered, use [canMoveTo] for that.
|
||||
* Returns an empty list if there's no way to get to the destination.
|
||||
*/
|
||||
@Readonly
|
||||
fun getShortestPath(destination: Tile, avoidDamagingTerrain: Boolean = false): List<Tile> {
|
||||
if (unit.cache.cannotMove) return listOf()
|
||||
|
||||
@ -142,7 +143,8 @@ class UnitMovement(val unit: MapUnit) {
|
||||
var distance = 1
|
||||
val unitMaxMovement = unit.getMaxMovement().toFloat()
|
||||
val newTilesToCheck = ArrayList<Tile>()
|
||||
val visitedTilesBitset = BitSet().apply { set(currentTile.zeroBasedIndex) }
|
||||
val visitedTilesBitset = BitSet()
|
||||
visitedTilesBitset.set(currentTile.zeroBasedIndex)
|
||||
val civilization = unit.civ
|
||||
|
||||
val passThroughCacheNew = ArrayList<Boolean?>()
|
||||
@ -226,6 +228,7 @@ class UnitMovement(val unit: MapUnit) {
|
||||
|
||||
class UnreachableDestinationException(msg: String) : Exception(msg)
|
||||
|
||||
@Readonly
|
||||
fun getTileToMoveToThisTurn(finalDestination: Tile): Tile {
|
||||
|
||||
val currentTile = unit.getTile()
|
||||
@ -283,10 +286,12 @@ class UnitMovement(val unit: MapUnit) {
|
||||
}
|
||||
|
||||
/** Cached and thus not as performance-heavy as [canReach] */
|
||||
@Readonly
|
||||
fun canReachInCurrentTurn(destination: Tile) = canReachCommon(destination) {
|
||||
getDistanceToTiles().containsKey(it)
|
||||
}
|
||||
|
||||
@Readonly
|
||||
private inline fun canReachCommon(destination: Tile, specificFunction: (Tile) -> Boolean) = when {
|
||||
unit.cache.cannotMove ->
|
||||
destination == unit.getTile()
|
||||
@ -302,6 +307,7 @@ class UnitMovement(val unit: MapUnit) {
|
||||
* @param includeOtherEscortUnit determines whether or not this method will also check its the other escort unit if it has one
|
||||
* Leave it as default unless you know what [getReachableTilesInCurrentTurn] does.
|
||||
*/
|
||||
@Readonly
|
||||
fun getReachableTilesInCurrentTurn(includeOtherEscortUnit: Boolean = true): Sequence<Tile> {
|
||||
return when {
|
||||
unit.cache.cannotMove -> sequenceOf(unit.getTile())
|
||||
@ -320,11 +326,13 @@ class UnitMovement(val unit: MapUnit) {
|
||||
}
|
||||
|
||||
/** Returns whether we can perform a swap move to the specified tile */
|
||||
@Readonly
|
||||
fun canUnitSwapTo(destination: Tile): Boolean {
|
||||
return canReachInCurrentTurn(destination) && canUnitSwapToReachableTile(destination)
|
||||
}
|
||||
|
||||
/** Returns the tiles to which we can perform a swap move */
|
||||
@Readonly
|
||||
fun getUnitSwappableTiles(): Sequence<Tile> {
|
||||
return getReachableTilesInCurrentTurn().filter { canUnitSwapToReachableTile(it) }
|
||||
}
|
||||
@ -333,6 +341,7 @@ class UnitMovement(val unit: MapUnit) {
|
||||
* Returns whether we can perform a unit swap move to the specified tile, given that it is
|
||||
* reachable in the current turn
|
||||
*/
|
||||
@Readonly
|
||||
private fun canUnitSwapToReachableTile(reachableTile: Tile): Boolean {
|
||||
// Air units cannot swap
|
||||
if (unit.baseUnit.movesLikeAirUnits) return false
|
||||
@ -592,6 +601,7 @@ class UnitMovement(val unit: MapUnit) {
|
||||
unit.mostRecentMoveType = UnitMovementMemoryType.UnitMoved
|
||||
}
|
||||
|
||||
@Readonly
|
||||
private fun isCityCenterCannotEnter(tile: Tile) = tile.isCityCenter()
|
||||
&& tile.getOwner() != unit.civ
|
||||
&& !tile.getCity()!!.hasJustBeenConquered
|
||||
@ -602,6 +612,7 @@ class UnitMovement(val unit: MapUnit) {
|
||||
* @param includeOtherEscortUnit determines whether or not this method will also check if the other escort unit [canMoveTo] if it has one.
|
||||
* Leave it as default unless you know what [canMoveTo] does.
|
||||
*/
|
||||
@Readonly
|
||||
fun canMoveTo(tile: Tile, assumeCanPassThrough: Boolean = false, allowSwap: Boolean = false, includeOtherEscortUnit: Boolean = true): Boolean {
|
||||
if (unit.baseUnit.movesLikeAirUnits)
|
||||
return canAirUnitMoveTo(tile, unit)
|
||||
|
@ -17,6 +17,7 @@ import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.ruleset.unique.expressions.Expressions
|
||||
import yairm210.purity.annotations.Cache
|
||||
import yairm210.purity.annotations.LocalState
|
||||
import yairm210.purity.annotations.Pure
|
||||
import yairm210.purity.annotations.Readonly
|
||||
|
||||
class UniqueValidator(val ruleset: Ruleset) {
|
||||
@ -76,7 +77,7 @@ class UniqueValidator(val ruleset: Ruleset) {
|
||||
val prefix by lazy { getUniqueContainerPrefix(uniqueContainer) + "\"${unique.text}\"" }
|
||||
if (unique.type == null) return checkUntypedUnique(unique, tryFixUnknownUniques, uniqueContainer, prefix, reportRulesetSpecificErrors)
|
||||
|
||||
@LocalState val rulesetErrors = RulesetErrorList(ruleset)
|
||||
val rulesetErrors = RulesetErrorList(ruleset)
|
||||
|
||||
if (uniqueContainer != null &&
|
||||
!(unique.type.canAcceptUniqueTarget(uniqueContainer.getUniqueTarget()) ||
|
||||
@ -156,7 +157,7 @@ class UniqueValidator(val ruleset: Ruleset) {
|
||||
uniqueContainer: IHasUniques?,
|
||||
unique: Unique
|
||||
): RulesetErrorList {
|
||||
@LocalState val rulesetErrors = RulesetErrorList()
|
||||
val rulesetErrors = RulesetErrorList()
|
||||
if (!complianceError.acceptableParameterTypes.contains(UniqueParameterType.Countable)) return rulesetErrors
|
||||
|
||||
val parseError = Expressions.getParsingError(complianceError.parameterName)
|
||||
@ -199,7 +200,7 @@ class UniqueValidator(val ruleset: Ruleset) {
|
||||
uniqueContainer: IHasUniques?,
|
||||
reportRulesetSpecificErrors: Boolean
|
||||
): RulesetErrorList {
|
||||
@LocalState val rulesetErrors = RulesetErrorList()
|
||||
val rulesetErrors = RulesetErrorList()
|
||||
if (unique.hasFlag(UniqueFlag.NoConditionals)) {
|
||||
rulesetErrors.add(
|
||||
"$prefix contains the conditional \"${conditional.text}\"," +
|
||||
@ -287,11 +288,11 @@ class UniqueValidator(val ruleset: Ruleset) {
|
||||
return rulesetErrors
|
||||
}
|
||||
|
||||
@Readonly
|
||||
@Pure
|
||||
private fun getUniqueTypeSpecificErrors(
|
||||
prefix: String, unique: Unique, uniqueContainer: IHasUniques?, reportRulesetSpecificErrors: Boolean
|
||||
): RulesetErrorList {
|
||||
@LocalState val rulesetErrors = RulesetErrorList()
|
||||
val rulesetErrors = RulesetErrorList()
|
||||
when(unique.type) {
|
||||
UniqueType.RuinsUpgrade -> {
|
||||
if (reportRulesetSpecificErrors && !anyAncientRuins)
|
||||
@ -308,7 +309,7 @@ class UniqueValidator(val ruleset: Ruleset) {
|
||||
prefix: String,
|
||||
uniqueContainer: IHasUniques?
|
||||
): RulesetErrorList {
|
||||
@LocalState val rulesetErrors = RulesetErrorList()
|
||||
val rulesetErrors = RulesetErrorList()
|
||||
val deprecationAnnotation = unique.getDeprecationAnnotation()
|
||||
if (deprecationAnnotation != null) {
|
||||
val replacementUniqueText = unique.getReplacementText(ruleset)
|
||||
|
Loading…
x
Reference in New Issue
Block a user