chore(purity): Update version, remove most well-knowns, fix function invokes

This commit is contained in:
yairm210 2025-08-08 09:57:14 +03:00
parent 8911dfbed5
commit 67c3c7292b
6 changed files with 20 additions and 17 deletions

View File

@ -38,7 +38,7 @@ plugins {
// This is *with* gradle 8.2 downloaded according the project specs, no idea what that's about
kotlin("multiplatform") version "1.9.24"
kotlin("plugin.serialization") version "1.9.24"
id("io.github.yairm210.purity-plugin") version "0.0.46" apply(false)
id("io.github.yairm210.purity-plugin") version "0.0.49" apply(false)
}
allprojects {
@ -74,21 +74,12 @@ allprojects {
// "java.lang.Integer" // moved
)
wellKnownInternalStateClasses = setOf<String>(
// Moved all
// "kotlin.collections.MutableList",
// "kotlin.collections.MutableSet",
// "kotlin.collections.MutableMap",
// "kotlin.collections.List",
// "kotlin.collections.Set",
// "kotlin.collections.Map",
// "kotlin.collections.ArrayDequeue",
// "java.util.BitSet",
"com.badlogic.gdx.math.Vector2",
"com.unciv.models.stats.Stats",
"com.unciv.models.Counter",
"com.unciv.models.ruleset.tile.ResourceSupplyList",
"com.badlogic.gdx.math.Vector2",
"com.unciv.models.ruleset.validation.RulesetErrorList"
"com.unciv.models.ruleset.validation.RulesetErrorList",
"com.unciv.logic.map.BFS",
)
warnOnPossibleAnnotations = true
}

View File

@ -138,6 +138,7 @@ object MotivationToAttackAutomation {
return motivationSoFar
}
@Readonly
private fun calculateCombatStrengthWithProtectors(otherCiv: Civilization, baseForce: Float, civInfo: Civilization): Float {
var theirCombatStrength = calculateSelfCombatStrength(otherCiv, baseForce)
@ -149,6 +150,7 @@ object MotivationToAttackAutomation {
return theirCombatStrength
}
@Readonly
private fun calculateSelfCombatStrength(civInfo: Civilization, baseForce: Float): Float {
var ourCombatStrength = civInfo.getStatForRanking(RankingType.Force).toFloat() + baseForce
if (civInfo.getCapital() != null) ourCombatStrength += CityCombatant(civInfo.getCapital()!!).getCityStrength()
@ -173,6 +175,7 @@ object MotivationToAttackAutomation {
}
/** If they are at war with our allies, then we should join in */
@Readonly
private fun getAlliedWarMotivation(civInfo: Civilization, otherCiv: Civilization): Float {
var alliedWarMotivation = 0f
for (thirdCiv in civInfo.getDiplomacyManager(otherCiv)!!.getCommonKnownCivs()) {
@ -191,6 +194,7 @@ object MotivationToAttackAutomation {
return alliedWarMotivation * civInfo.getPersonality().modifierFocus(PersonalityValue.Loyal, .5f)
}
@Readonly
private fun getRelationshipModifier(diplomacyManager: DiplomacyManager): Float {
val relationshipModifier = when (diplomacyManager.relationshipIgnoreAfraid()) {
RelationshipLevel.Unforgivable -> 10f
@ -205,6 +209,7 @@ object MotivationToAttackAutomation {
return relationshipModifier * diplomacyManager.civInfo.getPersonality().modifierFocus(PersonalityValue.Loyal, .3f)
}
@Readonly
private fun getProductionRatioModifier(civInfo: Civilization, otherCiv: Civilization): Float {
// If either of our Civs are suffering from a supply deficit, our army must be too large
// There is no easy way to check the raw production if a civ has a supply deficit
@ -224,6 +229,7 @@ object MotivationToAttackAutomation {
return productionRatioModifier
}
@Readonly
private fun getScoreRatioModifier(otherCiv: Civilization, civInfo: Civilization): Float {
// Civs with more score are more threatening to our victory
// Bias towards attacking civs with a high score and low military
@ -243,6 +249,7 @@ object MotivationToAttackAutomation {
return scoreRatioModifier * civInfo.getPersonality().modifierFocus(PersonalityValue.Culture, .3f)
}
@Readonly
private fun getDefensivePactAlliesScore(otherCiv: Civilization, civInfo: Civilization, baseForce: Float, ourCombatStrength: Float): Float {
var theirAlliesValue = 0f
for (thirdCiv in otherCiv.diplomacy.values.filter { it.hasFlag(DiplomacyFlags.DefensivePact) && it.otherCiv() != civInfo }) {
@ -259,6 +266,7 @@ object MotivationToAttackAutomation {
return theirAlliesValue
}
@Readonly
private fun getCombatStrengthModifier(civInfo: Civilization, targetCiv: Civilization, ourCombatStrength: Float, theirCombatStrength: Float): Float {
var combatStrengthRatio = ourCombatStrength / theirCombatStrength
@ -287,6 +295,7 @@ object MotivationToAttackAutomation {
return combatStrengthModifier
}
@Readonly
private fun hasNoUnitsThatCanAttackCityWithoutDying(civInfo: Civilization, theirCity: City) = civInfo.units.getCivUnits().filter { it.isMilitary() }.none {
val damageReceivedWhenAttacking =
BattleDamage.calculateDamageToAttacker(
@ -304,6 +313,7 @@ object MotivationToAttackAutomation {
*
* @return The motivation ranging from -30 to around +10
*/
@Readonly
private fun getAttackPathsModifier(civInfo: Civilization, otherCiv: Civilization, targetCitiesWithOurCity: List<Pair<City, City>>): Float {
fun isTileCanMoveThrough(civInfo: Civilization, tile: Tile): Boolean {

View File

@ -181,7 +181,7 @@ class City : IsPartOfGameInfoSerialization, INamed {
@Readonly fun getExpandRange(): Int = civ.gameInfo.ruleset.modOptions.constants.cityExpandRange
@Readonly @Suppress("purity") // the readonly connection type not respected for some reason for default value
fun isConnectedToCapital(connectionTypePredicate: (Set<String>) -> Boolean = { true }): Boolean {
fun isConnectedToCapital(@Readonly connectionTypePredicate: (Set<String>) -> Boolean = { true }): Boolean {
val mediumTypes = civ.cache.citiesConnectedToCapitalToMediums[this] ?: return false
return connectionTypePredicate(mediumTypes)
}

View File

@ -447,8 +447,8 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
}
return goldPerTurnForUs
}
@Readonly
fun resourcesFromTrade(): ResourceSupplyList {
val newResourceSupplyList = ResourceSupplyList()
val resourcesMap = civInfo.gameInfo.ruleset.tileResources

View File

@ -4,6 +4,7 @@ import com.unciv.logic.civilization.Civilization
import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.tile.Tile
import com.unciv.utils.Log
import yairm210.purity.annotations.Readonly
//TODO: Eventually, all path generation in the game should be moved into here.
object MapPathing {
@ -103,6 +104,7 @@ object MapPathing {
* Gets the connection to the end tile. This does not take into account tile movement costs.
* Takes in a civilization instead of a specific unit.
*/
@Readonly @Suppress("purity") // todo continue
fun getConnection(civ: Civilization,
startTile: Tile,
endTile: Tile,

View File

@ -400,7 +400,7 @@ class Spy private constructor() : IsPartOfGameInfoSerialization {
@Readonly fun isDoingWork() = action.isDoingWork(this)
/** Returns the City this Spy is in, or `null` if it is in the hideout. */
@Readonly @Suppress("purity") // this also appears to be NOT readonly. Something is fishy.
@Readonly @Suppress("purity") // it seems this also *updates*, hooray.
fun getCityOrNull(): City? {
if (location == null) return null
if (city == null) city = civInfo.gameInfo.tileMap[location!!].getCity()