From 59cb9f972c4f703b3917d8c33515f1acee100d02 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 4 Sep 2019 20:12:13 +0300 Subject: [PATCH] You now see your own Diplomacy screen when in multiplayer, and not that of the current player --- .../jsons/Tutorials/Tutorials_English.json | 2 +- core/src/com/unciv/logic/map/TileMap.kt | 2 +- .../src/com/unciv/logic/map/UnitPromotions.kt | 3 +- .../src/com/unciv/ui/trade/DiplomacyScreen.kt | 41 +++++++++---------- .../com/unciv/ui/worldscreen/TradePopup.kt | 20 ++++----- .../com/unciv/ui/worldscreen/WorldScreen.kt | 2 +- .../unciv/ui/worldscreen/unit/UnitActions.kt | 2 +- 7 files changed, 34 insertions(+), 38 deletions(-) diff --git a/android/assets/jsons/Tutorials/Tutorials_English.json b/android/assets/jsons/Tutorials/Tutorials_English.json index bd8cf05d21..d6aad30582 100644 --- a/android/assets/jsons/Tutorials/Tutorials_English.json +++ b/android/assets/jsons/Tutorials/Tutorials_English.json @@ -251,7 +251,7 @@ EnemyCity: [ [ - "You have encoutered an enemy city!", + "You have encountered an enemy city!", "Cities can be conquered by reducing their health to 1,", " and entering the city with a melee unit.", "Since cities heal each turn, it is best to attack with ranged units" diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index b760b06e03..64613d2d78 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -87,7 +87,7 @@ class TileMap { // Only once we add the unit to the civ we can activate addPromotion, because it will try to update civ viewable tiles for(promotion in unit.baseUnit.promotions) - unit.promotions.addPromotion(promotion,true) + unit.promotions.addPromotion(promotion, true) // And update civ stats, since the new unit changes both unit upkeep and resource consumption civInfo.updateStatsForNextTurn() diff --git a/core/src/com/unciv/logic/map/UnitPromotions.kt b/core/src/com/unciv/logic/map/UnitPromotions.kt index 9535210547..87e7c2adaf 100644 --- a/core/src/com/unciv/logic/map/UnitPromotions.kt +++ b/core/src/com/unciv/logic/map/UnitPromotions.kt @@ -15,7 +15,7 @@ class UnitPromotions{ fun xpForNextPromotion() = (numberOfPromotions+1)*10 fun canBePromoted() = XP >= xpForNextPromotion() - fun addPromotion(promotionName:String, isFree:Boolean = false, updateViewableTiles:Boolean=true){ + fun addPromotion(promotionName: String, isFree: Boolean = false){ if (!isFree) { XP -= xpForNextPromotion() numberOfPromotions++ @@ -29,7 +29,6 @@ class UnitPromotions{ // Since some units get promotions upon construction, they will get the addPromotion from the unit.postBuildEvent // upon creation, BEFORE they are assigned to a tile, so the updateViewableTiles() would crash. // So, if the addPromotion was triggered from there, simply don't update -// if(updateViewableTiles) unit.updateViewableTiles() // some promotions/uniques give the unit bonus sight } diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index 1e84b0fdca..1b012bafc6 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -23,7 +23,7 @@ import com.unciv.ui.utils.* import com.unciv.ui.worldscreen.optionstable.YesNoPopupTable import kotlin.math.roundToInt -class DiplomacyScreen:CameraStageBaseScreen() { +class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { val leftSideTable = Table().apply { defaults().pad(10f) } val rightSideTable = Table() @@ -53,15 +53,14 @@ class DiplomacyScreen:CameraStageBaseScreen() { private fun updateLeftSideTable() { leftSideTable.clear() - val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() for (civ in UnCivGame.Current.gameInfo.civilizations - .filterNot { it.isDefeated() || it == currentPlayerCiv || it.isBarbarian() }) { - if (!currentPlayerCiv.knows(civ)) continue + .filterNot { it.isDefeated() || it == viewingCiv || it.isBarbarian() }) { + if (!viewingCiv.knows(civ)) continue val civIndicator = ImageGetter.getNationIndicator(civ.nation,100f) val relationship = ImageGetter.getCircle() - if(currentPlayerCiv.isAtWarWith(civ)) relationship.color = Color.RED + if(viewingCiv.isAtWarWith(civ)) relationship.color = Color.RED else relationship.color = Color.GREEN relationship.setSize(30f,30f) civIndicator.addActor(relationship) @@ -90,8 +89,7 @@ class DiplomacyScreen:CameraStageBaseScreen() { private fun getCityStateDiplomacyTable(otherCiv: CivilizationInfo): Table { - val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() - val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(currentPlayerCiv) + val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(viewingCiv) val diplomacyTable = Table() diplomacyTable.defaults().pad(10f) @@ -102,7 +100,7 @@ class DiplomacyScreen:CameraStageBaseScreen() { diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row() val friendBonusText = when (otherCiv.getCityStateType()) { - CityStateType.Cultured -> "Provides [" + (3 * (currentPlayerCiv.getEra().ordinal + 1)).toString() + "] culture at [30] Influence" + CityStateType.Cultured -> "Provides [" + (3 * (viewingCiv.getEra().ordinal + 1)).toString() + "] culture at [30] Influence" CityStateType.Maritime -> "Provides 3 food in capital and 1 food in other cities at [30] Influence" CityStateType.Mercantile -> "Provides 3 happiness at [30] Influence" CityStateType.Militaristic -> "Provides land units every 20 turns at [30] Influence" @@ -124,19 +122,19 @@ class DiplomacyScreen:CameraStageBaseScreen() { val influenceAmount = giftAmount / 10 val giftButton = TextButton("Gift [$giftAmount] gold (+[$influenceAmount] influence)".tr(), skin) giftButton.onClick { - currentPlayerCiv.giveGoldGift(otherCiv, giftAmount) + viewingCiv.giveGoldGift(otherCiv, giftAmount) updateRightSide(otherCiv) } diplomacyTable.add(giftButton).row() - if (currentPlayerCiv.gold < giftAmount || isNotPlayersTurn()) giftButton.disable() + if (viewingCiv.gold < giftAmount || isNotPlayersTurn()) giftButton.disable() - val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv) + val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv) - if (currentPlayerCiv.isAtWarWith(otherCiv)) { + if (viewingCiv.isAtWarWith(otherCiv)) { val peaceButton = TextButton("Negotiate Peace".tr(), skin) peaceButton.onClick { YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), { - val tradeLogic = TradeLogic(currentPlayerCiv, otherCiv) + val tradeLogic = TradeLogic(viewingCiv, otherCiv) tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.acceptTrade() @@ -155,8 +153,7 @@ class DiplomacyScreen:CameraStageBaseScreen() { } private fun getMajorCivDiplomacyTable(otherCiv: CivilizationInfo): Table { - val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() - val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(currentPlayerCiv) + val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(viewingCiv) val diplomacyTable = Table() diplomacyTable.defaults().pad(10f) @@ -169,7 +166,7 @@ class DiplomacyScreen:CameraStageBaseScreen() { diplomacyTable.add(translatedNation.neutralHello.toLabel()).row() diplomacyTable.addSeparator() - if(!currentPlayerCiv.isAtWarWith(otherCiv)) { + if(!viewingCiv.isAtWarWith(otherCiv)) { val tradeButton = TextButton("Trade".tr(), skin) tradeButton.onClick { setTrade(otherCiv) } diplomacyTable.add(tradeButton).row() @@ -190,11 +187,11 @@ class DiplomacyScreen:CameraStageBaseScreen() { diplomacyTable.add(negotiatePeaceButton).row() } - val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv) + val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv) - if (!currentPlayerCiv.isAtWarWith(otherCiv)) { + if (!viewingCiv.isAtWarWith(otherCiv)) { if(otherCivDiplomacyManager.relationshipLevel() > RelationshipLevel.Neutral && !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship) && !diplomacyManager.hasFlag(DiplomacyFlags.Denunceation)){ @@ -226,7 +223,7 @@ class DiplomacyScreen:CameraStageBaseScreen() { val demandsButton = TextButton("Demands".tr(),skin) demandsButton.onClick { rightSideTable.clear() - rightSideTable.add(getDemandsTable(currentPlayerCiv,otherCiv)) + rightSideTable.add(getDemandsTable(viewingCiv,otherCiv)) } diplomacyTable.add(demandsButton).row() if(isNotPlayersTurn()) demandsButton.disable() @@ -270,15 +267,15 @@ class DiplomacyScreen:CameraStageBaseScreen() { return diplomacyModifiersTable } - private fun getDemandsTable(currentPlayerCiv: CivilizationInfo, otherCiv: CivilizationInfo): Table { + private fun getDemandsTable(viewingCiv: CivilizationInfo, otherCiv: CivilizationInfo): Table { val demandsTable = Table() demandsTable.defaults().pad(10f) val dontSettleCitiesButton = TextButton("Please don't settle new cities near us.".tr(),skin) - if(otherCiv.popupAlerts.any { it.type==AlertType.DemandToStopSettlingCitiesNear && it.value==currentPlayerCiv.civName }) + if(otherCiv.popupAlerts.any { it.type==AlertType.DemandToStopSettlingCitiesNear && it.value==viewingCiv.civName }) dontSettleCitiesButton.disable() dontSettleCitiesButton.onClick { - otherCiv.popupAlerts.add(PopupAlert(AlertType.DemandToStopSettlingCitiesNear, currentPlayerCiv.civName)) + otherCiv.popupAlerts.add(PopupAlert(AlertType.DemandToStopSettlingCitiesNear, viewingCiv.civName)) dontSettleCitiesButton.disable() } demandsTable.add(dontSettleCitiesButton).row() diff --git a/core/src/com/unciv/ui/worldscreen/TradePopup.kt b/core/src/com/unciv/ui/worldscreen/TradePopup.kt index fea7959378..9380323f9e 100644 --- a/core/src/com/unciv/ui/worldscreen/TradePopup.kt +++ b/core/src/com/unciv/ui/worldscreen/TradePopup.kt @@ -15,8 +15,8 @@ import kotlin.math.max class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ init{ - val currentPlayerCiv = worldScreen.viewingCiv - val tradeRequest = currentPlayerCiv.tradeRequests.first() + val viewingCiv = worldScreen.viewingCiv + val tradeRequest = viewingCiv.tradeRequests.first() val requestingCiv = worldScreen.gameInfo.getCivilization(tradeRequest.requestingCiv) val translatedNation = requestingCiv.getTranslatedNation() @@ -39,10 +39,10 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ addGoodSizedLabel(translatedNation.tradeRequest).colspan(columns).row() addButton("Sounds good!"){ - val tradeLogic = TradeLogic(currentPlayerCiv, requestingCiv) + val tradeLogic = TradeLogic(viewingCiv, requestingCiv) tradeLogic.currentTrade.set(trade) tradeLogic.acceptTrade() - currentPlayerCiv.tradeRequests.remove(tradeRequest) + viewingCiv.tradeRequests.remove(tradeRequest) close() PopupTable(worldScreen).apply { add(otherCivLeaderName.toLabel()).colspan(2) @@ -56,12 +56,12 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ } open() } - requestingCiv.addNotification("[${currentPlayerCiv.civName}] has accepted your trade request", Color.GOLD) + requestingCiv.addNotification("[${viewingCiv.civName}] has accepted your trade request", Color.GOLD) } addButton("Not this time.".tr()){ - currentPlayerCiv.tradeRequests.remove(tradeRequest) + viewingCiv.tradeRequests.remove(tradeRequest) - val diplomacyManager = requestingCiv.getDiplomacyManager(currentPlayerCiv) + val diplomacyManager = requestingCiv.getDiplomacyManager(viewingCiv) if(trade.ourOffers.all { it.type==TradeType.Luxury_Resource } && trade.theirOffers.all { it.type==TradeType.Luxury_Resource }) diplomacyManager.setFlag(DiplomacyFlags.DeclinedLuxExchange,20) // offer again in 20 turns @@ -69,15 +69,15 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ diplomacyManager.setFlag(DiplomacyFlags.DeclinedPeace,5) close() - requestingCiv.addNotification("[${currentPlayerCiv.civName}] has denied your trade request", Color.GOLD) + requestingCiv.addNotification("[${viewingCiv.civName}] has denied your trade request", Color.GOLD) worldScreen.shouldUpdate=true } addButton("How about something else...".tr()){ - currentPlayerCiv.tradeRequests.remove(tradeRequest) + viewingCiv.tradeRequests.remove(tradeRequest) close() - val diplomacyScreen= DiplomacyScreen() + val diplomacyScreen= DiplomacyScreen(viewingCiv) val tradeTable = diplomacyScreen.setTrade(requestingCiv) tradeTable.tradeLogic.currentTrade.set(trade) tradeTable.offerColumnsTable.update() diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 98ac717a2f..e0978de4e3 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -231,7 +231,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() { .any()) { displayTutorials("OtherCivEncountered") val btn = TextButton("Diplomacy".tr(), skin) - btn.onClick { UnCivGame.Current.screen = DiplomacyScreen() } + btn.onClick { UnCivGame.Current.screen = DiplomacyScreen(viewingCiv) } btn.label.setFontSize(30) btn.labelCell.pad(10f) diplomacyButtonWrapper.add(btn) diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 3bcb1faa18..72c0a33999 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -96,7 +96,7 @@ class UnitActions { for(promotion in unit.baseUnit.promotions) if(promotion !in newunit.promotions.promotions) - newunit.promotions.addPromotion(promotion,true) + newunit.promotions.addPromotion(promotion, true) newunit.updateUniques() newunit.updateViewableTiles()