chore: removed city state functions from civinfo

This commit is contained in:
Yair Morgenstern 2023-01-18 15:05:15 +02:00
parent bdc239fd34
commit 2bd07652b1
9 changed files with 44 additions and 62 deletions

View File

@ -272,11 +272,11 @@ object NextTurnAutomation {
private fun tryGainInfluence(civInfo: CivilizationInfo, cityState: CivilizationInfo) {
if (civInfo.gold < 250) return // save up
if (cityState.getDiplomacyManager(civInfo).getInfluence() < 20) {
cityState.receiveGoldGift(civInfo, 250)
cityState.cityStateFunctions.receiveGoldGift(civInfo, 250)
return
}
if (civInfo.gold < 500) return // it's not worth it to invest now, wait until you have enough for 2
cityState.receiveGoldGift(civInfo, 500)
cityState.cityStateFunctions.receiveGoldGift(civInfo, 500)
return
}
@ -292,7 +292,7 @@ object NextTurnAutomation {
if (civInfo.wantsToFocusOn(Victory.Focus.Culture)) {
for (cityState in civInfo.getKnownCivs()
.filter { it.isCityState() && it.cityStateFunctions.canGiveStat(Stat.Culture) }) {
.filter { it.isCityState() && it.cityStateFunctions.canProvideStat(Stat.Culture) }) {
val diploManager = cityState.getDiplomacyManager(civInfo)
if (diploManager.getInfluence() < 40) { // we want to gain influence with them
tryGainInfluence(civInfo, cityState)
@ -326,10 +326,10 @@ object NextTurnAutomation {
private fun valueCityStateAlliance(civInfo: CivilizationInfo, cityState: CivilizationInfo): Int {
var value = 0
if (civInfo.wantsToFocusOn(Victory.Focus.Culture) && cityState.canGiveStat(Stat.Culture)) {
if (civInfo.wantsToFocusOn(Victory.Focus.Culture) && cityState.cityStateFunctions.canProvideStat(Stat.Culture)) {
value += 10
}
else if (civInfo.wantsToFocusOn(Victory.Focus.Science) && cityState.canGiveStat(Stat.Science)) {
else if (civInfo.wantsToFocusOn(Victory.Focus.Science) && cityState.cityStateFunctions.canProvideStat(Stat.Science)) {
// In case someone mods this in
value += 10
}
@ -346,10 +346,10 @@ object NextTurnAutomation {
else if (civInfo.wantsToFocusOn(Victory.Focus.CityStates)) {
value += 5 // Generally be friendly
}
if (civInfo.getHappiness() < 5 && cityState.canGiveStat(Stat.Happiness)) {
if (civInfo.getHappiness() < 5 && cityState.cityStateFunctions.canProvideStat(Stat.Happiness)) {
value += 10 - civInfo.getHappiness()
}
if (civInfo.getHappiness() > 5 && cityState.canGiveStat(Stat.Food)) {
if (civInfo.getHappiness() > 5 && cityState.cityStateFunctions.canProvideStat(Stat.Food)) {
value += 5
}
@ -380,12 +380,12 @@ object NextTurnAutomation {
for (state in civInfo.getKnownCivs().filter{!it.isDefeated() && it.isCityState()}) {
val diplomacyManager = state.getDiplomacyManager(civInfo.civName)
if(diplomacyManager.relationshipLevel() >= RelationshipLevel.Friend
&& state.otherCivCanPledgeProtection(civInfo))
&& state.cityStateFunctions.otherCivCanPledgeProtection(civInfo))
{
state.addProtectorCiv(civInfo)
state.cityStateFunctions.addProtectorCiv(civInfo)
} else if (diplomacyManager.relationshipLevel() < RelationshipLevel.Friend
&& state.otherCivCanWithdrawProtection(civInfo)) {
state.removeProtectorCiv(civInfo)
&& state.cityStateFunctions.otherCivCanWithdrawProtection(civInfo)) {
state.cityStateFunctions.removeProtectorCiv(civInfo)
}
}
}
@ -396,8 +396,8 @@ object NextTurnAutomation {
if(diplomacyManager.relationshipLevel() < RelationshipLevel.Friend
&& diplomacyManager.diplomaticStatus == DiplomaticStatus.Peace
&& valueCityStateAlliance(civInfo, state) <= 0
&& state.getTributeWillingness(civInfo) >= 0) {
if (state.getTributeWillingness(civInfo, demandingWorker = true) > 0)
&& state.cityStateFunctions.getTributeWillingness(civInfo) >= 0) {
if (state.cityStateFunctions.getTributeWillingness(civInfo, demandingWorker = true) > 0)
state.cityStateFunctions.tributeWorker(civInfo)
else
state.cityStateFunctions.tributeGold(civInfo)
@ -741,8 +741,8 @@ object NextTurnAutomation {
var theirCombatStrength = otherCiv.getStatForRanking(RankingType.Force).toFloat() + baseForce + CityCombatant(otherCiv.getCapital()!!).getCityStrength()
//for city-states, also consider their protectors
if (otherCiv.isCityState() and otherCiv.getProtectorCivs().isNotEmpty()) {
theirCombatStrength += otherCiv.getProtectorCivs().filterNot { it == civInfo }
if (otherCiv.isCityState() and otherCiv.cityStateFunctions.getProtectorCivs().isNotEmpty()) {
theirCombatStrength += otherCiv.cityStateFunctions.getProtectorCivs().filterNot { it == civInfo }
.sumOf { it.getStatForRanking(RankingType.Force) }
}

View File

@ -60,6 +60,8 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
return true
}
fun turnsForGreatPersonFromCityState(): Int = ((37 + Random().nextInt(7)) * civInfo.gameInfo.speed.modifier).toInt()
/** Gain a random great person from the city state */
fun giveGreatPersonToPatron(receivingCiv: CivilizationInfo) {
@ -417,7 +419,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
civInfo.addFlag(CivFlags.RecentlyBullied.name, 20)
}
fun canGiveStat(statType: Stat): Boolean {
fun canProvideStat(statType: Stat): Boolean {
if (!civInfo.isCityState())
return false
for (bonus in getCityStateBonuses(civInfo.cityStateType, RelationshipLevel.Ally)) {
@ -486,7 +488,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
private fun cityStateBullied(bully: CivilizationInfo) {
if (!civInfo.isCityState()) return // What are we doing here?
for (protector in civInfo.getProtectorCivs()) {
for (protector in civInfo.cityStateFunctions.getProtectorCivs()) {
if (!protector.knows(bully)) // Who?
continue
val protectorDiplomacy = protector.getDiplomacyManager(bully)
@ -568,7 +570,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
}
}
for (protector in civInfo.getProtectorCivs()) {
for (protector in civInfo.cityStateFunctions.getProtectorCivs()) {
if (!protector.knows(attacker)) // Who?
continue
val protectorDiplomacy = protector.getDiplomacyManager(attacker)
@ -596,7 +598,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
fun cityStateDestroyed(attacker: CivilizationInfo) {
if (!civInfo.isCityState()) return // What are we doing here?
for (protector in civInfo.getProtectorCivs()) {
for (protector in civInfo.cityStateFunctions.getProtectorCivs()) {
if (!protector.knows(attacker)) // Who?
continue
val protectorDiplomacy = protector.getDiplomacyManager(attacker)

View File

@ -17,7 +17,7 @@ import kotlin.math.min
import kotlin.math.pow
/** CivInfo class was getting too crowded */
class CivInfoStats(val civInfo: CivilizationInfo) {
class CivInfoStatsForNextTurn(val civInfo: CivilizationInfo) {
@Transient
/** Happiness for next turn */

View File

@ -391,7 +391,7 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
}
@Transient
val stats = CivInfoStats(this)
val stats = CivInfoStatsForNextTurn(this)
@Transient
val cache = CivInfoTransientCache(this)
@ -630,7 +630,7 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
else
otherCiv.addNotification(meetString, NotificationCategory.Diplomacy, NotificationIcon.Gold)
if (otherCiv.isCityState() && otherCiv.canGiveStat(Stat.Faith)){
if (otherCiv.isCityState() && otherCiv.cityStateFunctions.canProvideStat(Stat.Faith)){
otherCiv.addNotification(religionMeetString, NotificationCategory.Diplomacy, NotificationIcon.Faith)
for ((key, value) in faithAmount)
@ -1073,7 +1073,7 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
&& givingCityState != null
) {
givingCityState.cityStateFunctions.giveGreatPersonToPatron(this)
flagsCountdown[flag] = turnsForGreatPersonFromCityState()
flagsCountdown[flag] = cityStateFunctions.turnsForGreatPersonFromCityState()
}
continue
@ -1389,29 +1389,9 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
moveCapitalTo(newCapital)
}
//////////////////////// City State wrapper functions ////////////////////////
fun receiveGoldGift(donorCiv: CivilizationInfo, giftAmount: Int) =
cityStateFunctions.receiveGoldGift(donorCiv, giftAmount)
fun turnsForGreatPersonFromCityState(): Int = ((37 + Random().nextInt(7)) * gameInfo.speed.modifier).toInt()
fun getProtectorCivs() = cityStateFunctions.getProtectorCivs()
fun addProtectorCiv(otherCiv: CivilizationInfo) = cityStateFunctions.addProtectorCiv(otherCiv)
fun removeProtectorCiv(otherCiv: CivilizationInfo, forced: Boolean = false) =
cityStateFunctions.removeProtectorCiv(otherCiv, forced)
fun otherCivCanPledgeProtection(otherCiv: CivilizationInfo) = cityStateFunctions.otherCivCanPledgeProtection(otherCiv)
fun otherCivCanWithdrawProtection(otherCiv: CivilizationInfo) = cityStateFunctions.otherCivCanWithdrawProtection(otherCiv)
fun updateAllyCivForCityState() = cityStateFunctions.updateAllyCivForCityState()
fun getTributeWillingness(demandingCiv: CivilizationInfo, demandingWorker: Boolean = false)
= cityStateFunctions.getTributeWillingness(demandingCiv, demandingWorker)
fun canGiveStat(statType: Stat) = cityStateFunctions.canGiveStat(statType)
fun getAllyCiv() = allyCivName
fun setAllyCiv(newAllyName: String?) { allyCivName = newAllyName }
//endregion
fun asPreview() = CivilizationInfoPreview(this)
}

View File

@ -371,7 +371,7 @@ class QuestManager : IsPartOfGameInfoSerialization {
QuestName.GreatPerson.value -> getGreatPersonForQuest(challenger) != null
QuestName.FindPlayer.value -> getCivilizationToFindForQuest(challenger) != null
QuestName.FindNaturalWonder.value -> getNaturalWonderToFindForQuest(challenger) != null
QuestName.PledgeToProtect.value -> mostRecentBully != null && challenger !in civInfo.getProtectorCivs()
QuestName.PledgeToProtect.value -> mostRecentBully != null && challenger !in civInfo.cityStateFunctions.getProtectorCivs()
QuestName.GiveGold.value -> mostRecentBully != null
QuestName.DenounceCiv.value -> mostRecentBully != null && challenger.knows(mostRecentBully)
&& !challenger.getDiplomacyManager(mostRecentBully).hasFlag(DiplomacyFlags.Denunciation)
@ -395,7 +395,7 @@ class QuestManager : IsPartOfGameInfoSerialization {
QuestName.GreatPerson.value -> assignee.getCivGreatPeople().any { it.baseUnit.getReplacedUnit(civInfo.gameInfo.ruleSet).name == assignedQuest.data1 }
QuestName.FindPlayer.value -> assignee.hasMetCivTerritory(civInfo.gameInfo.getCivilization(assignedQuest.data1))
QuestName.FindNaturalWonder.value -> assignee.naturalWonders.contains(assignedQuest.data1)
QuestName.PledgeToProtect.value -> assignee in civInfo.getProtectorCivs()
QuestName.PledgeToProtect.value -> assignee in civInfo.cityStateFunctions.getProtectorCivs()
QuestName.DenounceCiv.value -> assignee.getDiplomacyManager(assignedQuest.data1).hasFlag(DiplomacyFlags.Denunciation)
QuestName.SpreadReligion.value -> civInfo.getCapital()!!.religion.getMajorityReligion() == civInfo.gameInfo.religions[assignedQuest.data2]
else -> false

View File

@ -176,7 +176,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
if (civInfo.isCityState()) return when {
getInfluence() <= -30 || civInfo.isAtWarWith(otherCiv()) -> RelationshipLevel.Unforgivable
getInfluence() < 0 -> RelationshipLevel.Enemy
getInfluence() < 30 && civInfo.getTributeWillingness(otherCiv()) > 0 -> RelationshipLevel.Afraid
getInfluence() < 30 && civInfo.cityStateFunctions.getTributeWillingness(otherCiv()) > 0 -> RelationshipLevel.Afraid
getInfluence() >= 60 && civInfo.getAllyCiv() == otherCivName -> RelationshipLevel.Ally
getInfluence() >= 30 -> RelationshipLevel.Friend
else -> RelationshipLevel.Neutral
@ -234,7 +234,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
fun setInfluence(amount: Float) {
influence = max(amount, MINIMUM_INFLUENCE)
civInfo.updateAllyCivForCityState()
civInfo.cityStateFunctions.updateAllyCivForCityState()
}
fun getInfluence() = if (civInfo.isAtWarWith(otherCiv())) MINIMUM_INFLUENCE else influence
@ -470,7 +470,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
// Potentially notify about afraid status
if (getInfluence() < 30 // We usually don't want to bully our friends
&& !hasFlag(DiplomacyFlags.NotifiedAfraid)
&& civInfo.getTributeWillingness(otherCiv()) > 0
&& civInfo.cityStateFunctions.getTributeWillingness(otherCiv()) > 0
&& otherCiv().isMajorCiv()
) {
setFlag(DiplomacyFlags.NotifiedAfraid, 20) // Wait 20 turns until next reminder
@ -645,8 +645,8 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
val civAtWarWith = otherCiv()
if (civInfo.isCityState() && civInfo.getProtectorCivs().contains(civAtWarWith)) {
civInfo.removeProtectorCiv(civAtWarWith, forced = true)
if (civInfo.isCityState() && civInfo.cityStateFunctions.getProtectorCivs().contains(civAtWarWith)) {
civInfo.cityStateFunctions.removeProtectorCiv(civAtWarWith, forced = true)
}
diplomaticStatus = DiplomaticStatus.War
@ -692,7 +692,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
// You attacked your own ally, you're a right bastard
if (otherCiv.getAllyCiv() == civInfo.civName) {
otherCiv.updateAllyCivForCityState()
otherCiv.cityStateFunctions.updateAllyCivForCityState()
otherCivDiplomacy.setInfluence(-120f)
for (knownCiv in civInfo.getKnownCivs()) {
knownCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.BetrayedDeclarationOfFriendship, -10f)

View File

@ -339,7 +339,7 @@ object UniqueTriggerActivation {
CityStateCanGiftGreatPeople -> {
civInfo.addFlag(
CivFlags.CityStateGreatPersonGift.name,
civInfo.turnsForGreatPersonFromCityState() / 2
civInfo.cityStateFunctions.turnsForGreatPersonFromCityState() / 2
)
if (notification != null) {
civInfo.addNotification(notification, NotificationCategory.Diplomacy, NotificationIcon.CityState)

View File

@ -215,7 +215,7 @@ class DiplomacyScreen(
}
diplomacyTable.row().padTop(15f)
otherCiv.updateAllyCivForCityState()
otherCiv.cityStateFunctions.updateAllyCivForCityState()
var ally = otherCiv.getAllyCiv()
if (ally != null) {
val allyInfluence = otherCiv.getDiplomacyManager(ally).getInfluence().toInt()
@ -226,7 +226,7 @@ class DiplomacyScreen(
.row()
}
val protectors = otherCiv.getProtectorCivs()
val protectors = otherCiv.cityStateFunctions.getProtectorCivs()
if (protectors.isNotEmpty()) {
val newProtectors = arrayListOf<String>()
for (protector in protectors) {
@ -355,12 +355,12 @@ class DiplomacyScreen(
val revokeProtectionButton = "Revoke Protection".toTextButton()
revokeProtectionButton.onClick {
ConfirmPopup(this, "Revoke protection for [${otherCiv.civName}]?", "Revoke Protection") {
otherCiv.removeProtectorCiv(viewingCiv)
otherCiv.cityStateFunctions.removeProtectorCiv(viewingCiv)
updateLeftSideTable(otherCiv)
updateRightSide(otherCiv)
}.open()
}
if (isNotPlayersTurn() || !otherCiv.otherCivCanWithdrawProtection(viewingCiv)) revokeProtectionButton.disable()
if (isNotPlayersTurn() || !otherCiv.cityStateFunctions.otherCivCanWithdrawProtection(viewingCiv)) revokeProtectionButton.disable()
return revokeProtectionButton
}
@ -373,12 +373,12 @@ class DiplomacyScreen(
"Pledge to protect",
true
) {
otherCiv.addProtectorCiv(viewingCiv)
otherCiv.cityStateFunctions.addProtectorCiv(viewingCiv)
updateLeftSideTable(otherCiv)
updateRightSide(otherCiv)
}.open()
}
if (isNotPlayersTurn() || !otherCiv.otherCivCanPledgeProtection(viewingCiv)) protectionButton.disable()
if (isNotPlayersTurn() || !otherCiv.cityStateFunctions.otherCivCanPledgeProtection(viewingCiv)) protectionButton.disable()
return protectionButton
}
@ -484,7 +484,7 @@ class DiplomacyScreen(
val giftButton =
"Gift [$giftAmount] gold (+[$influenceAmount] influence)".toTextButton()
giftButton.onClick {
otherCiv.receiveGoldGift(viewingCiv, giftAmount)
otherCiv.cityStateFunctions.receiveGoldGift(viewingCiv, giftAmount)
updateLeftSideTable(otherCiv)
updateRightSide(otherCiv)
}
@ -571,7 +571,7 @@ class DiplomacyScreen(
rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv)))
}
diplomacyTable.add(demandGoldButton).row()
if (otherCiv.getTributeWillingness(viewingCiv, demandingWorker = false) < 0) demandGoldButton.disable()
if (otherCiv.cityStateFunctions.getTributeWillingness(viewingCiv, demandingWorker = false) < 0) demandGoldButton.disable()
val demandWorkerButton = "Take worker (-50 Influence)".toTextButton()
demandWorkerButton.onClick {
@ -580,7 +580,7 @@ class DiplomacyScreen(
rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv)))
}
diplomacyTable.add(demandWorkerButton).row()
if (otherCiv.getTributeWillingness(viewingCiv, demandingWorker = true) < 0) demandWorkerButton.disable()
if (otherCiv.cityStateFunctions.getTributeWillingness(viewingCiv, demandingWorker = true) < 0) demandWorkerButton.disable()
val backButton = "Back".toTextButton()
backButton.onClick {

View File

@ -312,7 +312,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
add(getCloseButton("Very well.", 'n') {
val capitalLocation = LocationAction(cityState.cities.asSequence().map { it.location }) // in practice 0 or 1 entries, that's OK
player.addNotification("You have broken your Pledge to Protect [${cityState.civName}]!", capitalLocation, NotificationCategory.Diplomacy, cityState.civName)
cityState.removeProtectorCiv(player, forced = true)
cityState.cityStateFunctions.removeProtectorCiv(player, forced = true)
}).row()
}
AlertType.RecapturedCivilian -> addRecapturedCivilianTable()