mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
When exchanging peace for cities, units no longer teleport out of cities you traded for
This commit is contained in:
parent
39e88d3a1a
commit
2a3e707f24
@ -83,19 +83,20 @@ class TradeLogic(val ourCivilization:Civilization, val otherCivilization: Civili
|
||||
}
|
||||
|
||||
// instant transfers
|
||||
fun transferTrade(to: Civilization, from: Civilization, trade: Trade) {
|
||||
for (offer in trade.theirOffers) {
|
||||
if (offer.type == TradeType.Gold) {
|
||||
fun transferTrade(from: Civilization, to: Civilization, offer: TradeOffer) {
|
||||
when (offer.type) {
|
||||
TradeType.Gold -> {
|
||||
to.addGold(offer.amount)
|
||||
from.addGold(-offer.amount)
|
||||
}
|
||||
if (offer.type == TradeType.Technology) {
|
||||
TradeType.Technology -> {
|
||||
to.tech.addTechnology(offer.name)
|
||||
}
|
||||
if (offer.type == TradeType.City) {
|
||||
TradeType.City -> {
|
||||
val city = from.cities.first { it.id == offer.name }
|
||||
city.moveToCiv(to)
|
||||
city.getCenterTile().getUnits().toList().forEach { it.movement.teleportToClosestMoveableTile() }
|
||||
city.getCenterTile().getUnits().toList()
|
||||
.forEach { it.movement.teleportToClosestMoveableTile() }
|
||||
for (tile in city.getTiles()) {
|
||||
for (unit in tile.getUnits().toList()) {
|
||||
if (!unit.civInfo.diplomacyFunctions.canPassThroughTiles(to) && !unit.canEnterForeignTerrain)
|
||||
@ -107,30 +108,44 @@ class TradeLogic(val ourCivilization:Civilization, val otherCivilization: Civili
|
||||
|
||||
// suggest an option to liberate the city
|
||||
if (to.isHuman()
|
||||
&& city.foundingCiv != ""
|
||||
&& from.civName != city.foundingCiv // can't liberate if the city actually belongs to those guys
|
||||
&& to.civName != city.foundingCiv) // can't liberate if it's our city
|
||||
to.popupAlerts.add(PopupAlert(AlertType.CityTraded, city.id))
|
||||
&& city.foundingCiv != ""
|
||||
&& from.civName != city.foundingCiv // can't liberate if the city actually belongs to those guys
|
||||
&& to.civName != city.foundingCiv
|
||||
) // can't liberate if it's our city
|
||||
to.popupAlerts.add(PopupAlert(AlertType.CityTraded, city.id))
|
||||
}
|
||||
if (offer.type == TradeType.Treaty) {
|
||||
TradeType.Treaty -> {
|
||||
if (offer.name == Constants.peaceTreaty) to.getDiplomacyManager(from).makePeace()
|
||||
if (offer.name == Constants.researchAgreement) {
|
||||
to.addGold(-offer.amount)
|
||||
to.getDiplomacyManager(from).setFlag(DiplomacyFlags.ResearchAgreement, offer.duration)
|
||||
to.getDiplomacyManager(from)
|
||||
.setFlag(DiplomacyFlags.ResearchAgreement, offer.duration)
|
||||
}
|
||||
}
|
||||
if (offer.type == TradeType.Introduction)
|
||||
to.diplomacyFunctions.makeCivilizationsMeet(to.gameInfo.getCivilization(offer.name))
|
||||
if (offer.type == TradeType.WarDeclaration) {
|
||||
TradeType.Introduction -> to.diplomacyFunctions.makeCivilizationsMeet(to.gameInfo.getCivilization(offer.name))
|
||||
TradeType.WarDeclaration -> {
|
||||
val nameOfCivToDeclareWarOn = offer.name
|
||||
from.getDiplomacyManager(nameOfCivToDeclareWarOn).declareWar()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
to.updateStatsForNextTurn()
|
||||
to.cache.updateCivResources()
|
||||
}
|
||||
|
||||
transferTrade(ourCivilization, otherCivilization, currentTrade)
|
||||
transferTrade(otherCivilization, ourCivilization, currentTrade.reverse())
|
||||
// Transfer of cities needs to happen before peace treaty, to avoid our units teleporting out of areas that soon will be ours
|
||||
for (offer in currentTrade.theirOffers.filterNot { it.type == TradeType.Treaty })
|
||||
transferTrade(otherCivilization, ourCivilization, offer)
|
||||
for (offer in currentTrade.ourOffers.filterNot { it.type == TradeType.Treaty })
|
||||
transferTrade(ourCivilization, otherCivilization, offer)
|
||||
|
||||
for (offer in currentTrade.theirOffers.filter { it.type == TradeType.Treaty })
|
||||
transferTrade(otherCivilization, ourCivilization, offer)
|
||||
for (offer in currentTrade.ourOffers.filter { it.type == TradeType.Treaty })
|
||||
transferTrade(ourCivilization, otherCivilization, offer)
|
||||
|
||||
ourCivilization.cache.updateCivResources()
|
||||
ourCivilization.updateStatsForNextTurn()
|
||||
|
||||
otherCivilization.cache.updateCivResources()
|
||||
otherCivilization.updateStatsForNextTurn()
|
||||
}
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
||||
DefensiveBonus("Gives a defensive bonus of [relativeAmount]%", UniqueTarget.Improvement),
|
||||
ImprovementMaintenance("Costs [amount] [stat] per turn when in your territory", UniqueTarget.Improvement), // Roads
|
||||
ImprovementAllMaintenance("Costs [amount] [stat] per turn", UniqueTarget.Improvement), // Roads
|
||||
//@Deprecated("as of 4.3.9", ReplaceWith("Costs [amount] [stats] per turn when in your territory"), DeprecationLevel.ERROR)
|
||||
@Deprecated("as of 4.3.9", ReplaceWith("Costs [amount] [stats] per turn when in your territory"))
|
||||
OldImprovementMaintenance("Costs [amount] gold per turn when in your territory", UniqueTarget.Improvement), // unused
|
||||
DamagesAdjacentEnemyUnits("Adjacent enemy units ending their turn take [amount] damage", UniqueTarget.Improvement),
|
||||
|
||||
@ -713,7 +713,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
||||
TriggerUponFoundingCity("upon founding a city", UniqueTarget.TriggerCondition),
|
||||
TriggerUponDiscoveringNaturalWonder("upon discovering a Natural Wonder", UniqueTarget.TriggerCondition),
|
||||
TriggerUponConstructingBuilding("upon constructing [buildingFilter]", UniqueTarget.TriggerCondition),
|
||||
// Not auto cityfiltered, since 'in all cities' can be read 'only if it's in all cities'
|
||||
// We have a separate trigger to include the cityFilter, since '[in all cities]' can be read '*only* if it's in all cities'
|
||||
TriggerUponConstructingBuildingCityFilter("upon constructing [buildingFilter] [cityFilter]", UniqueTarget.TriggerCondition),
|
||||
|
||||
TriggerUponFoundingPantheon("upon founding a Pantheon", UniqueTarget.TriggerCondition),
|
||||
|
Loading…
x
Reference in New Issue
Block a user