From c5f127e555e06f15de3a127cf0735725f2798ff8 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 25 Jun 2018 18:09:38 +0300 Subject: [PATCH] Policy branches are unlocked by era --- android/assets/jsons/Policies.json | 6 +++++ android/assets/jsons/Units.json | 2 ++ .../logic/civilization/CivilizationInfo.kt | 18 ++++++++++++- .../unciv/logic/civilization/PolicyManager.kt | 3 ++- .../src/com/unciv/models/gamebasics/Policy.kt | 4 +++ .../unciv/models/gamebasics/PolicyBranch.kt | 1 + .../com/unciv/models/gamebasics/TechColumn.kt | 26 ++++++++++++++----- .../com/unciv/models/gamebasics/Technology.kt | 4 ++- .../ui/pickerscreens/PolicyPickerScreen.kt | 11 +++++--- 9 files changed, 62 insertions(+), 13 deletions(-) diff --git a/android/assets/jsons/Policies.json b/android/assets/jsons/Policies.json index 7b2d5d9fff..56183010f6 100644 --- a/android/assets/jsons/Policies.json +++ b/android/assets/jsons/Policies.json @@ -1,6 +1,7 @@ [ { name:"Tradition", + era:"Ancient", description:"+3 culture in capital and increased rate of border expansion", policies:[ { @@ -42,6 +43,7 @@ ] },{ name:"Liberty", + era:"Ancient", description:"+1 culture in evey city", policies:[ { @@ -84,6 +86,7 @@ ] },{ name:"Piety", + era:"Classical", description:"Building time of culture buildings reduced by 15%", policies:[ { @@ -127,6 +130,7 @@ },{ name:"Commerce", description:"+25% gold in capital", + era:"Medieval", policies:[ { name:"Trade Unions", @@ -168,6 +172,7 @@ ] },{ name:"Rationalism", + era:"Renaissance", description:"Production to science conversion in cities increased by 33%", policies:[ { @@ -210,6 +215,7 @@ ] },{ name:"Freedom", + era:"Renaissance", description:"+25% great people rate", policies:[ { diff --git a/android/assets/jsons/Units.json b/android/assets/jsons/Units.json index eb2c13cf5b..7320ebf66a 100644 --- a/android/assets/jsons/Units.json +++ b/android/assets/jsons/Units.json @@ -247,6 +247,8 @@ hurryCostModifier:20 uniques:["Can move after attacking","No defensive terrain bonus","Penalty vs City 33%","Bonus vs Mounted 50%" ], }, + + // UNITS FROM HERE NEED IMAGES { name:"Rifleman", unitType:"Melee", diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index a8d6b6f08e..f767c96d78 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -9,6 +9,7 @@ import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.TileInfo import com.unciv.models.gamebasics.Civilization import com.unciv.models.gamebasics.GameBasics +import com.unciv.models.gamebasics.TechEra import com.unciv.models.gamebasics.tile.ResourceType import com.unciv.models.gamebasics.tile.TileResource import com.unciv.models.linq.Counter @@ -208,4 +209,19 @@ class CivilizationInfo { override fun toString(): String {return civName} // for debug fun isDefeated()= cities.isEmpty() && !getCivUnits().any{it.name=="Settler"} -} \ No newline at end of file + fun getEra(): TechEra { + return tech.techsResearched.map { GameBasics.Technologies[it]!! } + .map { it.era() } + .max()!! + } +} + +//enum class DiplomaticStatus{ +// Peace, +// War +//} +// +//class DiplomacyManager { +// lateinit var otherCivName:String +// var status:DiplomaticStatus = DiplomaticStatus.Peace +//} \ No newline at end of file diff --git a/core/src/com/unciv/logic/civilization/PolicyManager.kt b/core/src/com/unciv/logic/civilization/PolicyManager.kt index f7181af71f..8a4058ac29 100644 --- a/core/src/com/unciv/logic/civilization/PolicyManager.kt +++ b/core/src/com/unciv/logic/civilization/PolicyManager.kt @@ -35,6 +35,7 @@ class PolicyManager { fun isAdoptable(policy: Policy) = !policy.name.endsWith("Complete") && getAdoptedPolicies().containsAll(policy.requires!!) + && policy.getBranch().era <= civInfo.getEra() fun canAdoptPolicy(): Boolean = freePolicies > 0 || storedCulture >= getCultureNeededForNextPolicy() @@ -48,7 +49,7 @@ class PolicyManager { adoptedPolicies.add(policy.name) if (!branchCompletion) { - val branch = GameBasics.PolicyBranches[policy.branch]!! + val branch = policy.getBranch() if (branch.policies.count { isAdopted(it.name) } == branch.policies.size - 1) { // All done apart from branch completion adopt(branch.policies.last(), true) // add branch completion! } diff --git a/core/src/com/unciv/models/gamebasics/Policy.kt b/core/src/com/unciv/models/gamebasics/Policy.kt index 90f9e2dbc7..2130b3de06 100644 --- a/core/src/com/unciv/models/gamebasics/Policy.kt +++ b/core/src/com/unciv/models/gamebasics/Policy.kt @@ -9,5 +9,9 @@ open class Policy : INamed { var row: Int = 0 var column: Int = 0 var requires: ArrayList? = null + + fun getBranch():PolicyBranch{ + return GameBasics.PolicyBranches[branch]!! + } } diff --git a/core/src/com/unciv/models/gamebasics/PolicyBranch.kt b/core/src/com/unciv/models/gamebasics/PolicyBranch.kt index d66905cc38..027bccdbfa 100644 --- a/core/src/com/unciv/models/gamebasics/PolicyBranch.kt +++ b/core/src/com/unciv/models/gamebasics/PolicyBranch.kt @@ -2,4 +2,5 @@ package com.unciv.models.gamebasics class PolicyBranch : Policy() { var policies: ArrayList = arrayListOf() + lateinit var era:TechEra } diff --git a/core/src/com/unciv/models/gamebasics/TechColumn.kt b/core/src/com/unciv/models/gamebasics/TechColumn.kt index 8ad34ad0aa..764056d9ba 100644 --- a/core/src/com/unciv/models/gamebasics/TechColumn.kt +++ b/core/src/com/unciv/models/gamebasics/TechColumn.kt @@ -1,12 +1,24 @@ package com.unciv.models.gamebasics -import java.util.ArrayList +import java.util.* class TechColumn { - @JvmField var columnNumber: Int = 0 - @JvmField var era: String? = null - @JvmField var techs = ArrayList() - @JvmField var techCost: Int = 0 - @JvmField var buildingCost: Int = 0 - @JvmField var wonderCost: Int = 0 + var columnNumber: Int = 0 + lateinit var era: TechEra + var techs = ArrayList() + var techCost: Int = 0 + var buildingCost: Int = 0 + var wonderCost: Int = 0 } + + +enum class TechEra{ + Ancient, + Classical, + Medieval, + Renaissance, + Industrial, + Modern, + Information, + Future +} \ No newline at end of file diff --git a/core/src/com/unciv/models/gamebasics/Technology.kt b/core/src/com/unciv/models/gamebasics/Technology.kt index b8e4c91697..22626e1728 100644 --- a/core/src/com/unciv/models/gamebasics/Technology.kt +++ b/core/src/com/unciv/models/gamebasics/Technology.kt @@ -49,4 +49,6 @@ class Technology : ICivilopedia { override fun toString(): String { return name } -} \ No newline at end of file + + fun era() = column!!.era +} diff --git a/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt index f597ffdb7b..b8e47249dc 100644 --- a/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PolicyPickerScreen.kt @@ -89,8 +89,12 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen( } pickedPolicy = policy var policyText = policy.name + "\r\n" + policy.description + "\r\n" - if (!policy.name.endsWith("Complete") && policy.requires!!.isNotEmpty()) - policyText += "Requires " + policy.requires!!.joinToString() + if (!policy.name.endsWith("Complete")){ + if(policy.requires!!.isNotEmpty()) + policyText += "Requires " + policy.requires!!.joinToString() + else + policyText += "Unlocked at "+policy.getBranch().era+" era" + } descriptionLabel.setText(policyText) } @@ -99,8 +103,9 @@ class PolicyPickerScreen(internal val civInfo: CivilizationInfo) : PickerScreen( if (image) { val policyImage = ImageGetter.getImage("PolicyIcons/" + policy.name.replace(" ", "_") + "_(Civ5).png") policyButton.add(policyImage).size(30f) - } else + } else { policyButton = TextButton(policy.name, CameraStageBaseScreen.skin) + } if (civInfo.policies.isAdopted(policy.name)) { // existing policyButton.color = Color.GREEN