chore: purity diplomacyFunctions

This commit is contained in:
yairm210 2025-07-19 23:09:30 +03:00
parent 237e286d4d
commit c6c820afa3
3 changed files with 11 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import com.unciv.ui.screens.worldscreen.UndoHandler.Companion.clearUndoCheckpoin
import com.unciv.ui.screens.worldscreen.worldmap.WorldMapHolder
import com.unciv.ui.screens.worldscreen.WorldScreen
import com.unciv.ui.screens.worldscreen.unit.UnitTable
import yairm210.purity.annotations.Readonly
object GUI {
@ -24,6 +25,7 @@ object GUI {
UncivGame.Current.resetToWorldScreen()
}
@Readonly
fun getSettings(): GameSettings {
return UncivGame.Current.settings
}

View File

@ -87,13 +87,15 @@ class DiplomacyFunctions(val civInfo: Civilization) {
}
}
}
@Readonly
fun canSignDeclarationOfFriendshipWith(otherCiv: Civilization): Boolean {
return otherCiv.isMajorCiv() && !otherCiv.isAtWarWith(civInfo)
&& !civInfo.getDiplomacyManager(otherCiv)!!.hasFlag(DiplomacyFlags.Denunciation)
&& !civInfo.getDiplomacyManager(otherCiv)!!.hasFlag(DiplomacyFlags.DeclarationOfFriendship)
}
@Readonly
fun canSignResearchAgreement(): Boolean {
if (!civInfo.isMajorCiv()) return false
if (!civInfo.hasUnique(UniqueType.EnablesResearchAgreements)) return false
@ -101,6 +103,7 @@ class DiplomacyFunctions(val civInfo: Civilization) {
return true
}
@Readonly
fun canSignResearchAgreementNoCostWith (otherCiv: Civilization): Boolean {
val diplomacyManager = civInfo.getDiplomacyManager(otherCiv)!!
return canSignResearchAgreement() && otherCiv.diplomacyFunctions.canSignResearchAgreement()
@ -109,12 +112,14 @@ class DiplomacyFunctions(val civInfo: Civilization) {
&& !diplomacyManager.otherCivDiplomacy().hasFlag(DiplomacyFlags.ResearchAgreement)
}
@Readonly
fun canSignResearchAgreementsWith(otherCiv: Civilization): Boolean {
val cost = getResearchAgreementCost(otherCiv)
return canSignResearchAgreementNoCostWith(otherCiv)
&& civInfo.gold >= cost && otherCiv.gold >= cost
}
@Readonly
fun getResearchAgreementCost(otherCiv: Civilization): Int {
// https://forums.civfanatics.com/resources/research-agreements-bnw.25568/
return ( max(civInfo.getEra().researchAgreementCost, otherCiv.getEra().researchAgreementCost)
@ -122,12 +127,14 @@ class DiplomacyFunctions(val civInfo: Civilization) {
).toInt()
}
@Readonly
fun canSignDefensivePact(): Boolean {
if (!civInfo.isMajorCiv()) return false
if (!civInfo.hasUnique(UniqueType.EnablesDefensivePacts)) return false
return true
}
@Readonly
fun canSignDefensivePactWith(otherCiv: Civilization): Boolean {
val diplomacyManager = civInfo.getDiplomacyManager(otherCiv)!!
return canSignDefensivePact() && otherCiv.diplomacyFunctions.canSignDefensivePact()

View File

@ -189,6 +189,7 @@ class TechManager : IsPartOfGameInfoSerialization {
return tech.prerequisites.all { isResearched(it) }
}
@Readonly @Suppress("purity") // should be autorecognized
fun allTechsAreResearched() = allTechsAreResearched
//endregion