From 563bbaf021079ea993e6c4e183269010f718420e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 21 Feb 2019 20:12:17 +0200 Subject: [PATCH] Unit construction moved to the beginning of the turn, so they won't be generated out in the open and vulnerable to enemy attacks before you can control them - Kudos am-per-sand! --- .../com/unciv/logic/city/CityConstructions.kt | 13 +++++------- core/src/com/unciv/logic/city/CityInfo.kt | 5 ++++- .../logic/civilization/CivilizationInfo.kt | 21 ++++++++----------- .../unciv/ui/worldscreen/unit/UnitActions.kt | 5 ++++- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 1bd69833..c514d2db 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -66,11 +66,6 @@ class CityConstructions { return result } - fun getAmountConstructedText(): String = - if (SpecialConstruction.getSpecialConstructions().any { it.name== currentConstruction}) "" - else " (" + getWorkDone(currentConstruction) + "/" + - getCurrentConstruction().getProductionCost(cityInfo.civInfo.policies.adoptedPolicies) + ")" - fun getCurrentConstruction(): IConstruction = getConstruction(currentConstruction) fun isBuilt(buildingName: String): Boolean = builtBuildings.contains(buildingName) @@ -120,10 +115,12 @@ class CityConstructions { builtBuildingObjects = ArrayList(builtBuildings.map { GameBasics.Buildings[it]!! }) } - fun addProduction(productionToAdd: Int) { + fun addProductionPoints(productionToAdd: Int) { if (!inProgressConstructions.containsKey(currentConstruction)) inProgressConstructions[currentConstruction] = 0 inProgressConstructions[currentConstruction] = inProgressConstructions[currentConstruction]!! + productionToAdd + } + fun constructIfEnough(){ val construction = getConstruction(currentConstruction) val productionCost = construction.getProductionCost(cityInfo.civInfo.policies.adoptedPolicies) if (inProgressConstructions[currentConstruction]!! >= productionCost) { @@ -131,7 +128,7 @@ class CityConstructions { } } - fun nextTurn(cityStats: Stats) { + fun endTurn(cityStats: Stats) { val construction = getConstruction(currentConstruction) if(construction is SpecialConstruction) return @@ -145,7 +142,7 @@ class CityConstructions { } else currentConstruction = saveCurrentConstruction - addProduction(Math.round(cityStats.production)) + addProductionPoints(Math.round(cityStats.production)) } fun constructionComplete(construction: IConstruction) { diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index c2170573..ba30af14 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -189,6 +189,9 @@ class CityInfo { } fun startTurn(){ + // Construct units at the beginning of the turn, + // so they won't be generated out in the open and vulnerable to enemy attacks before you can control them + cityConstructions.constructIfEnough() cityStats.update() tryUpdateRoadStatus() attackedThisTurn = false @@ -202,7 +205,7 @@ class CityInfo { stats.food = 0f } - cityConstructions.nextTurn(stats) + cityConstructions.endTurn(stats) expansion.nextTurn(stats.culture) if(isBeingRazed){ population.population-- diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 86985d4b..2465f82d 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -336,11 +336,17 @@ class CivilizationInfo { } fun startTurn(){ + // Generate great people at the start of the turn, + // so they won't be generated out in the open and vulnerable to enemy attacks before you can control them + if (cities.isNotEmpty()) { //if no city available, addGreatPerson will throw exception + val greatPerson = greatPeople.getNewGreatPerson() + if (greatPerson != null) addGreatPerson(greatPerson) + } + updateViewableTiles() // adds explored tiles so that the units will be able to perform automated actions better setCitiesConnectedToCapitalTransients() - for (city in cities){ - city.startTurn() - } + for (city in cities) city.startTurn() + happiness = getHappinessForNextTurn().values.sum().roundToInt() getCivUnits().toList().forEach { it.startTurn() } } @@ -375,15 +381,6 @@ class CivilizationInfo { city.endTurn() } - //if no city available, addGreatPerson will throw exception - if (cities.isNotEmpty()) { - val greatPerson = greatPeople.getNewGreatPerson() - if (greatPerson != null) { - addGreatPerson(greatPerson) - } - } - - goldenAges.endTurn(happiness) getCivUnits().forEach { it.endTurn() } diplomacy.values.forEach{it.nextTurn()} diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 7e188c7e..1d132315 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -181,7 +181,10 @@ class UnitActions { tile.getCity()!!.cityConstructions.getCurrentConstruction() is Building && (tile.getCity()!!.cityConstructions.getCurrentConstruction() as Building).isWonder ) { - tile.getCity()!!.cityConstructions.addProduction(300 + 30 * tile.getCity()!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) + tile.getCity()!!.cityConstructions.apply { + addProductionPoints(300 + 30 * tile.getCity()!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) + constructIfEnough() + } unit.destroy() }.sound("chimes") }