mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 15:27:50 +07:00
Removed many "proxy functions" from civInfo to cityStateFunctions
This commit is contained in:
@ -235,7 +235,7 @@ object GameStarter {
|
||||
|
||||
val cityStateName = availableCityStatesNames.pop()
|
||||
val civ = CivilizationInfo(cityStateName)
|
||||
if (civ.initCityState(ruleset, newGameParameters.startingEra, availableCivNames)) {
|
||||
if (civ.cityStateFunctions.initCityState(ruleset, newGameParameters.startingEra, availableCivNames)) {
|
||||
gameInfo.civilizations.add(civ)
|
||||
addedCityStates++
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ object NextTurnAutomation {
|
||||
adoptPolicy(civInfo) // todo can take a second - why?
|
||||
freeUpSpaceResources(civInfo)
|
||||
} else {
|
||||
civInfo.getFreeTechForCityState()
|
||||
civInfo.updateDiplomaticRelationshipForCityState()
|
||||
civInfo.cityStateFunctions.getFreeTechForCityState()
|
||||
civInfo.cityStateFunctions.updateDiplomaticRelationshipForCityState()
|
||||
}
|
||||
|
||||
chooseTechToResearch(civInfo)
|
||||
@ -237,8 +237,8 @@ object NextTurnAutomation {
|
||||
private fun useGold(civInfo: CivilizationInfo) {
|
||||
if (civInfo.getHappiness() > 0 && civInfo.hasUnique(UniqueType.CityStateCanBeBoughtForGold)) {
|
||||
for (cityState in civInfo.getKnownCivs().filter { it.isCityState() } ) {
|
||||
if (cityState.canBeMarriedBy(civInfo))
|
||||
cityState.diplomaticMarriage(civInfo)
|
||||
if (cityState.cityStateFunctions.canBeMarriedBy(civInfo))
|
||||
cityState.cityStateFunctions.diplomaticMarriage(civInfo)
|
||||
if (civInfo.getHappiness() <= 0) break // Stop marrying if happiness is getting too low
|
||||
}
|
||||
}
|
||||
@ -344,9 +344,9 @@ object NextTurnAutomation {
|
||||
&& valueCityStateAlliance(civInfo, state) <= 0
|
||||
&& state.getTributeWillingness(civInfo) >= 0) {
|
||||
if (state.getTributeWillingness(civInfo, demandingWorker = true) > 0)
|
||||
state.tributeWorker(civInfo)
|
||||
state.cityStateFunctions.tributeWorker(civInfo)
|
||||
else
|
||||
state.tributeGold(civInfo)
|
||||
state.cityStateFunctions.tributeGold(civInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ object Battle {
|
||||
if (defeatedUnit.matchesCategory("Barbarian") && defeatedUnit.matchesCategory("Military") && civUnit.getCivInfo().isMajorCiv()) {
|
||||
for (cityState in UncivGame.Current.gameInfo.getAliveCityStates()) {
|
||||
if (civUnit.getCivInfo().knows(cityState) && defeatedUnit.unit.threatensCiv(cityState)) {
|
||||
cityState.threateningBarbarianKilledBy(civUnit.getCivInfo())
|
||||
cityState.cityStateFunctions.threateningBarbarianKilledBy(civUnit.getCivInfo())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -540,7 +540,7 @@ object Battle {
|
||||
fun destroyIfDefeated(attackedCiv: CivilizationInfo, attacker: CivilizationInfo) {
|
||||
if (attackedCiv.isDefeated()) {
|
||||
if (attackedCiv.isCityState())
|
||||
attackedCiv.cityStateDestroyed(attacker)
|
||||
attackedCiv.cityStateFunctions.cityStateDestroyed(attacker)
|
||||
attackedCiv.destroy()
|
||||
attacker.popupAlerts.add(PopupAlert(AlertType.Defeated, attackedCiv.civName))
|
||||
}
|
||||
|
@ -778,6 +778,8 @@ class CivilizationInfo {
|
||||
for (unit in getCivUnits()) unit.startTurn()
|
||||
hasMovedAutomatedUnits = false
|
||||
|
||||
updateDetailedCivResources() // If you offered a trade last turn, this turn it will have been accepted/declined
|
||||
|
||||
for (tradeRequest in tradeRequests.toList()) { // remove trade requests where one of the sides can no longer supply
|
||||
val offeringCiv = gameInfo.getCivilization(tradeRequest.requestingCiv)
|
||||
if (offeringCiv.isDefeated() || !TradeEvaluation().isTradeValid(tradeRequest.trade, this, offeringCiv)) {
|
||||
@ -786,7 +788,6 @@ class CivilizationInfo {
|
||||
offeringCiv.addNotification("Our proposed trade is no longer relevant!", NotificationIcon.Trade)
|
||||
}
|
||||
}
|
||||
updateDetailedCivResources() // If you offered a trade last turn, this turn it will have been accepted/declined
|
||||
}
|
||||
|
||||
fun endTurn() {
|
||||
@ -856,7 +857,7 @@ class CivilizationInfo {
|
||||
&& cityStateAllies.any { it.cities.isNotEmpty() }
|
||||
) {
|
||||
val givingCityState = getKnownCivs().filter { it.isCityState() && it.getAllyCiv() == civName && it.cities.isNotEmpty()}.random()
|
||||
givingCityState.giveGreatPersonToPatron(this)
|
||||
givingCityState.cityStateFunctions.giveGreatPersonToPatron(this)
|
||||
flagsCountdown[flag] = turnsForGreatPersonFromCityState()
|
||||
}
|
||||
|
||||
@ -1116,17 +1117,15 @@ class CivilizationInfo {
|
||||
}
|
||||
|
||||
// Check if different continents (unless already max distance, or water map)
|
||||
if (connections > 0 && proximity != Proximity.Distant
|
||||
&& !gameInfo.tileMap.isWaterMap()) {
|
||||
|
||||
if (getCapital().getCenterTile().getContinent() != otherCiv.getCapital().getCenterTile().getContinent()) {
|
||||
// Different continents - increase separation by one step
|
||||
proximity = when (proximity) {
|
||||
Proximity.Far -> Proximity.Distant
|
||||
Proximity.Close -> Proximity.Far
|
||||
Proximity.Neighbors -> Proximity.Close
|
||||
else -> proximity
|
||||
}
|
||||
if (connections > 0 && proximity != Proximity.Distant && !gameInfo.tileMap.isWaterMap()
|
||||
&& getCapital().getCenterTile().getContinent() != otherCiv.getCapital().getCenterTile().getContinent()
|
||||
) {
|
||||
// Different continents - increase separation by one step
|
||||
proximity = when (proximity) {
|
||||
Proximity.Far -> Proximity.Distant
|
||||
Proximity.Close -> Proximity.Far
|
||||
Proximity.Neighbors -> Proximity.Close
|
||||
else -> proximity
|
||||
}
|
||||
}
|
||||
|
||||
@ -1144,71 +1143,26 @@ class CivilizationInfo {
|
||||
|
||||
//////////////////////// City State wrapper functions ////////////////////////
|
||||
|
||||
fun initCityState(ruleset: Ruleset, startingEra: String, unusedMajorCivs: Collection<String>)
|
||||
= cityStateFunctions.initCityState(ruleset, startingEra, unusedMajorCivs)
|
||||
/** Gain a random great person from the city state */
|
||||
private fun giveGreatPersonToPatron(receivingCiv: CivilizationInfo) {
|
||||
cityStateFunctions.giveGreatPersonToPatron(receivingCiv)
|
||||
}
|
||||
fun giveMilitaryUnitToPatron(receivingCiv: CivilizationInfo) {
|
||||
cityStateFunctions.giveMilitaryUnitToPatron(receivingCiv)
|
||||
}
|
||||
fun influenceGainedByGift(donorCiv: CivilizationInfo, giftAmount: Int)
|
||||
= cityStateFunctions.influenceGainedByGift(donorCiv, giftAmount)
|
||||
fun receiveGoldGift(donorCiv: CivilizationInfo, giftAmount: Int) {
|
||||
fun receiveGoldGift(donorCiv: CivilizationInfo, giftAmount: Int) =
|
||||
cityStateFunctions.receiveGoldGift(donorCiv, giftAmount)
|
||||
}
|
||||
fun turnsForGreatPersonFromCityState(): Int = ((37 + Random().nextInt(7)) * gameInfo.gameParameters.gameSpeed.modifier).toInt()
|
||||
fun turnsForGreatPersonFromCityState(): Int = ((37 + Random().nextInt(7)) * gameInfo.gameParameters.gameSpeed.modifier).toInt()
|
||||
|
||||
fun getProtectorCivs() = cityStateFunctions.getProtectorCivs()
|
||||
fun addProtectorCiv(otherCiv: CivilizationInfo) {
|
||||
cityStateFunctions.addProtectorCiv(otherCiv)
|
||||
}
|
||||
fun removeProtectorCiv(otherCiv: CivilizationInfo, forced: Boolean = false) {
|
||||
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 getDiplomaticMarriageCost() = cityStateFunctions.getDiplomaticMarriageCost()
|
||||
fun canBeMarriedBy(otherCiv: CivilizationInfo) = cityStateFunctions.canBeMarriedBy(otherCiv)
|
||||
fun diplomaticMarriage(otherCiv: CivilizationInfo) {
|
||||
cityStateFunctions.diplomaticMarriage(otherCiv)
|
||||
}
|
||||
|
||||
fun updateAllyCivForCityState() = cityStateFunctions.updateAllyCivForCityState()
|
||||
fun getTributeWillingness(demandingCiv: CivilizationInfo, demandingWorker: Boolean = false)
|
||||
= cityStateFunctions.getTributeWillingness(demandingCiv, demandingWorker)
|
||||
fun getTributeModifiers(demandingCiv: CivilizationInfo, demandingWorker: Boolean = false, requireWholeList: Boolean = false)
|
||||
= cityStateFunctions.getTributeModifiers(demandingCiv, demandingWorker, requireWholeList)
|
||||
fun goldGainedByTribute() = cityStateFunctions.goldGainedByTribute()
|
||||
fun tributeGold(demandingCiv: CivilizationInfo) {
|
||||
cityStateFunctions.tributeGold(demandingCiv)
|
||||
}
|
||||
fun tributeWorker(demandingCiv: CivilizationInfo) {
|
||||
cityStateFunctions.tributeWorker(demandingCiv)
|
||||
}
|
||||
fun canGiveStat(statType: Stat) = cityStateFunctions.canGiveStat(statType)
|
||||
fun updateDiplomaticRelationshipForCityState() {
|
||||
cityStateFunctions.updateDiplomaticRelationshipForCityState()
|
||||
}
|
||||
fun getFreeTechForCityState() {
|
||||
cityStateFunctions.getFreeTechForCityState()
|
||||
}
|
||||
fun getNumThreateningBarbarians() = cityStateFunctions.getNumThreateningBarbarians()
|
||||
fun threateningBarbarianKilledBy(otherCiv: CivilizationInfo) {
|
||||
cityStateFunctions.threateningBarbarianKilledBy(otherCiv)
|
||||
}
|
||||
|
||||
fun getAllyCiv() = allyCivName
|
||||
fun setAllyCiv(newAllyName: String?) { allyCivName = newAllyName }
|
||||
|
||||
fun cityStateAttacked(attacker: CivilizationInfo) {
|
||||
cityStateFunctions.cityStateAttacked(attacker)
|
||||
}
|
||||
fun cityStateDestroyed(attacker: CivilizationInfo) {
|
||||
cityStateFunctions.cityStateDestroyed(attacker)
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
fun asPreview() = CivilizationInfoPreview(this)
|
||||
|
@ -218,7 +218,7 @@ class QuestManager {
|
||||
|
||||
private fun tryBarbarianInvasion() {
|
||||
if ((civInfo.getTurnsTillCallForBarbHelp() == null || civInfo.getTurnsTillCallForBarbHelp() == 0)
|
||||
&& civInfo.getNumThreateningBarbarians() >= 2) {
|
||||
&& civInfo.cityStateFunctions.getNumThreateningBarbarians() >= 2) {
|
||||
|
||||
for (otherCiv in civInfo.getKnownCivs().filter {
|
||||
it.isMajorCiv()
|
||||
|
@ -524,7 +524,7 @@ class DiplomacyManager() {
|
||||
if (civInfo.cities.isEmpty() || otherCiv().cities.isEmpty())
|
||||
continue@loop
|
||||
else
|
||||
otherCiv().giveMilitaryUnitToPatron(civInfo)
|
||||
otherCiv().cityStateFunctions.giveMilitaryUnitToPatron(civInfo)
|
||||
}
|
||||
DiplomacyFlags.AgreedToNotSettleNearUs.name -> {
|
||||
addModifier(DiplomaticModifiers.FulfilledPromiseToNotSettleCitiesNearUs, 10f)
|
||||
@ -674,7 +674,7 @@ class DiplomacyManager() {
|
||||
if (otherCiv.isCityState()) {
|
||||
otherCivDiplomacy.setInfluence(-60f)
|
||||
civInfo.changeMinorCivsAttacked(1)
|
||||
otherCiv.cityStateAttacked(civInfo)
|
||||
otherCiv.cityStateFunctions.cityStateAttacked(civInfo)
|
||||
}
|
||||
|
||||
for (thirdCiv in civInfo.getKnownCivs()) {
|
||||
|
@ -418,15 +418,15 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo): BaseScreen() {
|
||||
return null
|
||||
|
||||
val diplomaticMarriageButton =
|
||||
"Diplomatic Marriage ([${otherCiv.getDiplomaticMarriageCost()}] Gold)".toTextButton()
|
||||
"Diplomatic Marriage ([${otherCiv.cityStateFunctions.getDiplomaticMarriageCost()}] Gold)".toTextButton()
|
||||
diplomaticMarriageButton.onClick {
|
||||
val newCities = otherCiv.cities
|
||||
otherCiv.diplomaticMarriage(viewingCiv)
|
||||
otherCiv.cityStateFunctions.diplomaticMarriage(viewingCiv)
|
||||
UncivGame.Current.setWorldScreen() // The other civ will no longer exist
|
||||
for (city in newCities)
|
||||
viewingCiv.popupAlerts.add(PopupAlert(AlertType.DiplomaticMarriage, city.id)) // Player gets to choose between annex and puppet
|
||||
}
|
||||
if (isNotPlayersTurn() || !otherCiv.canBeMarriedBy(viewingCiv)) diplomaticMarriageButton.disable()
|
||||
if (isNotPlayersTurn() || !otherCiv.cityStateFunctions.canBeMarriedBy(viewingCiv)) diplomaticMarriageButton.disable()
|
||||
return diplomaticMarriageButton
|
||||
}
|
||||
|
||||
@ -435,7 +435,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo): BaseScreen() {
|
||||
diplomacyTable.addSeparator()
|
||||
|
||||
for (giftAmount in listOf(250, 500, 1000)) {
|
||||
val influenceAmount = otherCiv.influenceGainedByGift(viewingCiv, giftAmount)
|
||||
val influenceAmount = otherCiv.cityStateFunctions.influenceGainedByGift(viewingCiv, giftAmount)
|
||||
val giftButton =
|
||||
"Gift [$giftAmount] gold (+[$influenceAmount] influence)".toTextButton()
|
||||
giftButton.onClick {
|
||||
@ -505,7 +505,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo): BaseScreen() {
|
||||
diplomacyTable.addSeparator()
|
||||
diplomacyTable.add("Tribute Willingness".toLabel()).row()
|
||||
val modifierTable = Table()
|
||||
val tributeModifiers = otherCiv.getTributeModifiers(viewingCiv, requireWholeList = true)
|
||||
val tributeModifiers = otherCiv.cityStateFunctions.getTributeModifiers(viewingCiv, requireWholeList = true)
|
||||
for (item in tributeModifiers) {
|
||||
val color = if (item.value >= 0) Color.GREEN else Color.RED
|
||||
modifierTable.add(item.key.toLabel(color))
|
||||
@ -517,9 +517,9 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo): BaseScreen() {
|
||||
diplomacyTable.add("At least 0 to take gold, at least 30 and size 4 city for worker".toLabel()).row()
|
||||
diplomacyTable.addSeparator()
|
||||
|
||||
val demandGoldButton = "Take [${otherCiv.goldGainedByTribute()}] gold (-15 Influence)".toTextButton()
|
||||
val demandGoldButton = "Take [${otherCiv.cityStateFunctions.goldGainedByTribute()}] gold (-15 Influence)".toTextButton()
|
||||
demandGoldButton.onClick {
|
||||
otherCiv.tributeGold(viewingCiv)
|
||||
otherCiv.cityStateFunctions.tributeGold(viewingCiv)
|
||||
rightSideTable.clear()
|
||||
rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv)))
|
||||
}
|
||||
@ -528,7 +528,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo): BaseScreen() {
|
||||
|
||||
val demandWorkerButton = "Take worker (-50 Influence)".toTextButton()
|
||||
demandWorkerButton.onClick {
|
||||
otherCiv.tributeWorker(viewingCiv)
|
||||
otherCiv.cityStateFunctions.tributeWorker(viewingCiv)
|
||||
rightSideTable.clear()
|
||||
rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user