From 2a3395882fec3018f05d6c9243c5d3c0e781e17d Mon Sep 17 00:00:00 2001 From: Interdice <67503847+Interdice@users.noreply.github.com> Date: Fri, 6 Aug 2021 23:07:38 +1000 Subject: [PATCH] City state resources (#4755) * Ai now cares about distance from it's cities * Ai now cares about distance from it's cities * Ai now cares about distance from it's cities * Ai will pay extra pay extra for bordering cities or surrounding cities * Ai will pay extra pay extra for bordering cities or surrounding cities * Ai will pay extra for cities that are closer to their territory * The code is cleaner * The code is cleaner * The code is cleaner * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * Ai now cares about distance from it's cities * Ai now cares about distance from it's cities * Ai will pay extra pay extra for bordering cities or surrounding cities * Ai will pay extra pay extra for bordering cities or surrounding cities * Ai will pay extra for cities that are closer to their territory * The code is cleaner * The code is cleaner * The code is cleaner * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * Ai now cares about distance from it's cities * Ai now cares about distance from it's cities * Ai now cares about distance from it's cities * Ai will pay extra pay extra for bordering cities or surrounding cities * Ai will pay extra pay extra for bordering cities or surrounding cities * Ai will pay extra for cities that are closer to their territory * The code is cleaner * The code is cleaner * The code is cleaner * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * Ai now values distance * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * You can now gift improvements to the ai * Update template.properties --- .../jsons/translations/template.properties | 5 +- core/src/com/unciv/logic/city/CityInfo.kt | 2 + .../src/com/unciv/ui/trade/DiplomacyScreen.kt | 58 ++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 744e302582..d7a17b0478 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -158,7 +158,10 @@ Protected by = Revoke Protection = Pledge to protect = Declare Protection of [cityStateName]? = - +Build [improvementName] on [resourceName] (200 Gold) = +Gift Improvement = + + Cultured = Maritime = Mercantile = diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 5a00b21383..a61040ccc3 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -667,6 +667,8 @@ class CityInfo { .map { it.getOwner()?.civName }.filterNotNull().toSet() .distinct().toList() } + fun getImprovableTiles(): Sequence = getTiles() + .filter {it.hasViewableResource(civInfo) && it.improvement == null} //endregion diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index cf92dee887..d53289b871 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -174,7 +174,30 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { } diplomacyTable.add(giveGiftButton).row() if (isNotPlayersTurn()) giveGiftButton.disable() - + + val improvableTiles = otherCiv.getCapital().getImprovableTiles().filterNot {it.getTileResource().resourceType == ResourceType.Bonus}.toList() + val improvements = otherCiv.gameInfo.ruleSet.tileImprovements.filter { it.value.turnsToBuild != 0 } + var needsImprovements = false + + for (improvableTile in improvableTiles) + for (tileImprovement in improvements.values) + if (improvableTile.canBuildImprovement(tileImprovement, otherCiv) && improvableTile.getTileResource().improvement == tileImprovement.name) + needsImprovements = true + + + val improveTileButton = "Gift Improvement".toTextButton() + improveTileButton.onClick { + rightSideTable.clear() + rightSideTable.add(ScrollPane(getImprovementGiftTable(otherCiv))) + } + + + if (isNotPlayersTurn() || otherCivDiplomacyManager.influence < 60 || !needsImprovements) + improveTileButton.disable() + + + + diplomacyTable.add(improveTileButton).row() if (otherCivDiplomacyManager.diplomaticStatus == DiplomaticStatus.Protector){ val revokeProtectionButton = "Revoke Protection".toTextButton() revokeProtectionButton.onClick { @@ -258,6 +281,39 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { diplomacyTable.add(backButton) return diplomacyTable } + private fun getImprovementGiftTable(otherCiv: CivilizationInfo): Table{ + val improvementGiftTable = getCityStateDiplomacyTableHeader(otherCiv) + improvementGiftTable.addSeparator() + + val improvableTiles = otherCiv.getCapital().getImprovableTiles().filterNot {it.getTileResource().resourceType == ResourceType.Bonus}.toList() + val tileImprovements = otherCiv.gameInfo.ruleSet.tileImprovements.filter { it.value.turnsToBuild != 0 } + + for (improvableTile in improvableTiles){ + for (tileImprovement in tileImprovements.values){ + if (improvableTile.canBuildImprovement(tileImprovement, otherCiv) && improvableTile.getTileResource().improvement == tileImprovement.name){ + val improveTileButton = "Build [${tileImprovement}] on [${improvableTile.getTileResource()}] (200 Gold)".toTextButton() + improveTileButton.onClick { + viewingCiv.giveGoldGift(otherCiv, 200) + improvableTile.improvement = tileImprovement.name + rightSideTable.clear() + rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv))) + } + if (viewingCiv.gold < 200) + improveTileButton.disable() + improvementGiftTable.add(improveTileButton).row() + } + } + } + + val backButton = "Back".toTextButton() + backButton.onClick { + rightSideTable.clear() + rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv))) + } + improvementGiftTable.add(backButton) + return improvementGiftTable + + } private fun getQuestTable(assignedQuest: AssignedQuest): Table { val questTable = Table()