From 42e6ab1c655facb0d91b372a2ccdc93c390c0d49 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 13 Nov 2018 21:10:23 +0200 Subject: [PATCH] Fixed great person point generation Added great person points to civ overview --- android/build.gradle | 4 +-- .../com/unciv/logic/city/PopulationManager.kt | 4 +-- .../logic/civilization/CivilizationInfo.kt | 11 +++++-- .../logic/civilization/GreatPersonManager.kt | 33 +++++++++++-------- core/src/com/unciv/ui/EmpireOverviewScreen.kt | 29 +++++++++++++++- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 6ae6f9c42f..72d6992a71 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 158 - versionName "2.9.10" + versionCode 159 + versionName "2.10.0" } buildTypes { release { diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index 1a37b24ffd..fdd91a0b7f 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -100,8 +100,8 @@ class PopulationManager { val maxSpecialists = getMaxSpecialists().toHashMap() val specialistsHashmap = specialists.toHashMap() for(entry in maxSpecialists) - if(specialistsHashmap[entry.key]!!>entry.value) - specialists.add(entry.key,specialistsHashmap[entry.key]!!-maxSpecialists[entry.key]!!) + if(specialistsHashmap[entry.key]!! > entry.value) + specialists.add(entry.key,specialistsHashmap[entry.key]!! - maxSpecialists[entry.key]!!) } fun getMaxSpecialists(): Stats { diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 71d6108422..1f501c409a 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -296,11 +296,12 @@ class CivilizationInfo { gold += nextTurnStats.gold.toInt() - if (cities.size > 0) tech.nextTurn(nextTurnStats.science.toInt()) + if (cities.isNotEmpty()) tech.nextTurn(nextTurnStats.science.toInt()) + + greatPeople.addGreatPersonPoints(getGreatPersonPointsForNextTurn()) for (city in cities.toList()) { // a city can be removed while iterating (if it's being razed) so we need to iterate over a copy city.endTurn() - greatPeople.addGreatPersonPoints(city.getGreatPersonPoints()) } val greatPerson = greatPeople.getNewGreatPerson() @@ -313,6 +314,12 @@ class CivilizationInfo { diplomacy.values.forEach{it.nextTurn()} } + fun getGreatPersonPointsForNextTurn(): Stats { + val stats = Stats() + for (city in cities) stats.add(city.getGreatPersonPoints()) + return stats + } + fun startTurn(){ getViewableTiles() // adds explored tiles so that the units will be able to perform automated actions better setCitiesConnectedToCapitalTransients() diff --git a/core/src/com/unciv/logic/civilization/GreatPersonManager.kt b/core/src/com/unciv/logic/civilization/GreatPersonManager.kt index 78ff6d3d03..4546387037 100644 --- a/core/src/com/unciv/logic/civilization/GreatPersonManager.kt +++ b/core/src/com/unciv/logic/civilization/GreatPersonManager.kt @@ -1,12 +1,20 @@ package com.unciv.logic.civilization +import com.unciv.models.stats.Stat import com.unciv.models.stats.Stats class GreatPersonManager { - private var pointsForNextGreatPerson = 100 - private var greatPersonPoints = Stats() + var pointsForNextGreatPerson = 100 + var greatPersonPoints = Stats() var freeGreatPeople=0 + val statToGreatPersonMapping = HashMap().apply { + put(Stat.Science,"Great Scientist") + put(Stat.Production,"Great Engineer") + put(Stat.Gold, "Great Merchant") + put(Stat.Culture, "Great Artist") + } + fun clone(): GreatPersonManager { val toReturn = GreatPersonManager() toReturn.freeGreatPeople=freeGreatPeople @@ -17,22 +25,19 @@ class GreatPersonManager { fun getNewGreatPerson(): String? { var greatPerson: String? = null - when { - greatPersonPoints.science > pointsForNextGreatPerson -> greatPerson = "Great Scientist" - greatPersonPoints.production > pointsForNextGreatPerson -> greatPerson = "Great Engineer" - greatPersonPoints.culture > pointsForNextGreatPerson -> greatPerson = "Great Artist" - greatPersonPoints.gold > pointsForNextGreatPerson -> greatPerson = "Great Merchant" - } - - if (greatPerson != null) { - greatPersonPoints.science -= pointsForNextGreatPerson.toFloat() - pointsForNextGreatPerson *= 2 + val greatPersonPointsHashmap = greatPersonPoints.toHashMap() + for(entry in statToGreatPersonMapping){ + if(greatPersonPointsHashmap[entry.key]!!>pointsForNextGreatPerson){ + greatPersonPoints.add(entry.key,-pointsForNextGreatPerson.toFloat()) + pointsForNextGreatPerson*=2 + return entry.value + } } return greatPerson } - fun addGreatPersonPoints(greatPersonPoints: Stats) { - greatPersonPoints.add(greatPersonPoints) + fun addGreatPersonPoints(greatPersonPointsForTurn: Stats) { + greatPersonPoints.add(greatPersonPointsForTurn) } diff --git a/core/src/com/unciv/ui/EmpireOverviewScreen.kt b/core/src/com/unciv/ui/EmpireOverviewScreen.kt index 3803f454f8..72b7e4e46a 100644 --- a/core/src/com/unciv/ui/EmpireOverviewScreen.kt +++ b/core/src/com/unciv/ui/EmpireOverviewScreen.kt @@ -40,7 +40,8 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){ setStatsInfoButton.onClick { centerTable.clear() centerTable.add(getHappinessTable()) - centerTable.add(getGoldTable()) + centerTable.add(getGoldTable()).row() + centerTable.add(getGreatPeopleTable()) centerTable.pack() centerTable.center(stage) } @@ -135,6 +136,32 @@ class EmpireOverviewScreen : CameraStageBaseScreen(){ return goldTable } + + private fun getGreatPeopleTable(): Table { + val greatPeopleTable = Table(skin) + + val greatPersonPoints = civInfo.greatPeople.greatPersonPoints.toHashMap() + val greatPersonPointsPerTurn = civInfo.getGreatPersonPointsForNextTurn().toHashMap() + val pointsToGreatPerson = civInfo.greatPeople.pointsForNextGreatPerson + + greatPeopleTable.defaults().pad(5f) + greatPeopleTable.add(Label("Great person points".tr(), skin).setFontSize(24)).colspan(3).row() + greatPeopleTable.add() + greatPeopleTable.add("Current points") + greatPeopleTable.add("Points per turn").row() + + val mapping = civInfo.greatPeople.statToGreatPersonMapping + for(entry in mapping){ + greatPeopleTable.add(entry.value) + greatPeopleTable.add(greatPersonPoints[entry.key]!!.toInt().toString()+"/"+pointsToGreatPerson) + greatPeopleTable.add(greatPersonPointsPerTurn[entry.key]!!.toInt().toString()).row() + } + greatPeopleTable.pack() + return greatPeopleTable + } + + + private fun getCityInfoTable(): Table { val iconSize = 20f//if you set this too low, there is a chance that the tables will be misaligned val padding = 5f