diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 36be6cedc9..b7542ab0b0 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -70,6 +70,10 @@ class CityConstructions { return GameBasics.Buildings[constructionName]!! else if (GameBasics.Units.containsKey(constructionName)) return GameBasics.Units[constructionName]!! + else{ + val special = getSpecialConstructions().firstOrNull{it.name==constructionName} + if(special!=null) return special + } throw Exception("$constructionName is not a building or a unit!") } @@ -83,6 +87,7 @@ class CityConstructions { fun nextTurn(cityStats: Stats) { var construction = getConstruction(currentConstruction) + if(construction is SpecialConstruction) return // Let's try to remove the building from the city, and see if we can still build it (we need to remove because of wonders etc.) val saveCurrentConstruction = currentConstruction @@ -151,4 +156,18 @@ class CityConstructions { fun chooseNextConstruction() { Automation().chooseNextConstruction(this) } + + fun getSpecialConstructions(): List { + val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){ + override fun isBuildable(construction: CityConstructions): Boolean { + return construction.cityInfo.civInfo.tech.isResearched("Education") + } + } + val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){ + override fun isBuildable(construction: CityConstructions): Boolean { + return construction.cityInfo.civInfo.tech.isResearched("Currency") + } + } + return listOf(science,gold) + } } // for json parsing, we need to have a default constructor \ No newline at end of file diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index c363693600..555e80e5cb 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -37,15 +37,17 @@ class CityStats { } - private fun getStatsFromProduction(): Stats { + private fun getStatsFromProduction(production:Float): Stats { val stats = Stats() - if ("Gold" == cityInfo.cityConstructions.currentConstruction) stats.gold += stats.production / 4 - if ("Science" == cityInfo.cityConstructions.currentConstruction) { - var scienceProduced = stats.production / 4 - if (cityInfo.civInfo.buildingUniques.contains("ScienceConversionIncrease")) scienceProduced *= 1.33f - if (cityInfo.civInfo.policies.isAdopted("Rationalism")) scienceProduced *= 1.33f - stats.science += scienceProduced + when(cityInfo.cityConstructions.currentConstruction) { + "Gold" -> stats.gold += production / 4 + "Science" -> { + var scienceProduced = production / 4 + if (cityInfo.civInfo.buildingUniques.contains("ScienceConversionIncrease")) scienceProduced *= 1.33f + if (cityInfo.civInfo.policies.isAdopted("Rationalism")) scienceProduced *= 1.33f + stats.science += scienceProduced + } } return stats } @@ -208,7 +210,9 @@ class CityStats { for (stat in baseStatList.values) stats.add(stat) stats.production *= 1 + statPercentBonuses.production / 100 // So they get bonuses for production and gold/science - stats.add(getStatsFromProduction()) + val statsFromProduction = getStatsFromProduction(stats.production) + stats.add(statsFromProduction) + baseStatList["Construction"] = statsFromProduction stats.gold *= 1 + statPercentBonuses.gold / 100 diff --git a/core/src/com/unciv/logic/city/IConstruction.kt b/core/src/com/unciv/logic/city/IConstruction.kt index 2f3f689628..6f118c0ae6 100644 --- a/core/src/com/unciv/logic/city/IConstruction.kt +++ b/core/src/com/unciv/logic/city/IConstruction.kt @@ -1,10 +1,47 @@ package com.unciv.logic.city +import com.unciv.models.gamebasics.ICivilopedia import com.unciv.models.stats.INamed -interface IConstruction : INamed { +interface IConstruction : INamed, ICivilopedia { fun getProductionCost(adoptedPolicies: HashSet): Int fun getGoldCost(adoptedPolicies: HashSet): Int fun isBuildable(construction: CityConstructions): Boolean fun postBuildEvent(construction: CityConstructions) // Yes I'm hilarious. } + + + +open class SpecialConstruction(override var name: String, override val description: String) : IConstruction{ + + fun getSpecialConstructions(): List { + val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){ + override fun isBuildable(construction: CityConstructions): Boolean { + return construction.cityInfo.civInfo.tech.isResearched("Education") + } + } + val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){ + override fun isBuildable(construction: CityConstructions): Boolean { + return construction.cityInfo.civInfo.tech.isResearched("Currency") + } + } + return listOf(science,gold) + } + + override fun getProductionCost(adoptedPolicies: HashSet): Int { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun getGoldCost(adoptedPolicies: HashSet): Int { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun isBuildable(construction: CityConstructions): Boolean { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun postBuildEvent(construction: CityConstructions) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + +} \ No newline at end of file diff --git a/core/src/com/unciv/models/gamebasics/Building.kt b/core/src/com/unciv/models/gamebasics/Building.kt index 4c4f162355..e509a9a791 100644 --- a/core/src/com/unciv/models/gamebasics/Building.kt +++ b/core/src/com/unciv/models/gamebasics/Building.kt @@ -8,7 +8,7 @@ import com.unciv.models.stats.Stats import com.unciv.ui.VictoryScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen -class Building : NamedStats(), IConstruction, ICivilopedia { +class Building : NamedStats(), IConstruction{ private lateinit var baseDescription: String override val description: String get() = getDescription(false, hashSetOf()) diff --git a/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt b/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt index ef62dceb86..03205411b6 100644 --- a/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt @@ -4,8 +4,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.utils.Align -import com.unciv.models.gamebasics.Building import com.unciv.UnCivGame +import com.unciv.logic.city.SpecialConstruction +import com.unciv.models.gamebasics.Building import com.unciv.ui.pickerscreens.ConstructionPickerScreen import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.ImageGetter @@ -57,7 +58,8 @@ class CityStatsTable(val cityScreen: CityScreen) : Table(){ // https://forums.civfanatics.com/threads/rush-buying-formula.393892/ val construction = city.cityConstructions.getCurrentConstruction() - if (!(construction is Building && construction.isWonder)) { + if (construction !is SpecialConstruction && + !(construction is Building && construction.isWonder)) { row() val buildingGoldCost = construction.getGoldCost(city.civInfo.policies.getAdoptedPolicies()) val buildingBuyButton = TextButton("Buy for \r\n$buildingGoldCost gold", CameraStageBaseScreen.skin) diff --git a/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt index 4d61d21981..7eaa129d7f 100644 --- a/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ConstructionPickerScreen.kt @@ -6,14 +6,13 @@ import com.unciv.logic.city.CityInfo import com.unciv.models.gamebasics.GameBasics import com.unciv.ui.cityscreen.CityScreen import com.unciv.ui.cityscreen.addClickListener -import com.unciv.ui.utils.CameraStageBaseScreen class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() { private var selectedProduction: String? = null private fun getProductionButton(production: String, buttonText: String, description: String?, rightSideButtonText: String): TextButton { - val productionTextButton = TextButton(buttonText, CameraStageBaseScreen.skin) + val productionTextButton = TextButton(buttonText, skin) productionTextButton.addClickListener { selectedProduction = production pick(rightSideButtonText) @@ -63,13 +62,10 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() { unit.getDescription(true), "Train " + unit.name)) } - if (civInfo.tech.isResearched("Education")) - specials.addActor(getProductionButton("Science", "Produce Science", - "Convert production to science at a rate of 4 to 1", "Produce Science")) - - if (civInfo.tech.isResearched("Currency")) - specials.addActor(getProductionButton("Gold", "Produce Gold", - "Convert production to gold at a rate of 4 to 1", "Produce Gold")) + for(specialConstruction in cityConstructions.getSpecialConstructions().filter { it.isBuildable(cityConstructions) }){ + specials.addActor(getProductionButton(specialConstruction.name, "Produce ${specialConstruction.name}", + specialConstruction.description, "Produce ${specialConstruction.name}")) + } topTable.add(units) topTable.add(regularBuildings) diff --git a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt index ebddb708c6..1c890deab9 100644 --- a/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/TileMapHolder.kt @@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener -import com.badlogic.gdx.utils.Align import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileMap @@ -64,7 +63,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: widget = allTiles setFillParent(true) - setOrigin(Align.center) + setOrigin(worldScreen.stage.width/2,worldScreen.stage.height/2) setSize(worldScreen.stage.width, worldScreen.stage.height) addListener(object : ActorGestureListener() { var lastScale = 1f