Fixed bugs that prevented picking Gold and Science as city constructions

This commit is contained in:
Yair Morgenstern 2018-05-16 23:31:17 +03:00
parent 9c576d6bdc
commit a1995a3e37
7 changed files with 80 additions and 23 deletions

View File

@ -70,6 +70,10 @@ class CityConstructions {
return GameBasics.Buildings[constructionName]!! return GameBasics.Buildings[constructionName]!!
else if (GameBasics.Units.containsKey(constructionName)) else if (GameBasics.Units.containsKey(constructionName))
return GameBasics.Units[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!") throw Exception("$constructionName is not a building or a unit!")
} }
@ -83,6 +87,7 @@ class CityConstructions {
fun nextTurn(cityStats: Stats) { fun nextTurn(cityStats: Stats) {
var construction = getConstruction(currentConstruction) 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.) // 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 val saveCurrentConstruction = currentConstruction
@ -151,4 +156,18 @@ class CityConstructions {
fun chooseNextConstruction() { fun chooseNextConstruction() {
Automation().chooseNextConstruction(this) Automation().chooseNextConstruction(this)
} }
fun getSpecialConstructions(): List<SpecialConstruction> {
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 } // for json parsing, we need to have a default constructor

View File

@ -37,16 +37,18 @@ class CityStats {
} }
private fun getStatsFromProduction(): Stats { private fun getStatsFromProduction(production:Float): Stats {
val stats = Stats() val stats = Stats()
if ("Gold" == cityInfo.cityConstructions.currentConstruction) stats.gold += stats.production / 4 when(cityInfo.cityConstructions.currentConstruction) {
if ("Science" == cityInfo.cityConstructions.currentConstruction) { "Gold" -> stats.gold += production / 4
var scienceProduced = stats.production / 4 "Science" -> {
var scienceProduced = production / 4
if (cityInfo.civInfo.buildingUniques.contains("ScienceConversionIncrease")) scienceProduced *= 1.33f if (cityInfo.civInfo.buildingUniques.contains("ScienceConversionIncrease")) scienceProduced *= 1.33f
if (cityInfo.civInfo.policies.isAdopted("Rationalism")) scienceProduced *= 1.33f if (cityInfo.civInfo.policies.isAdopted("Rationalism")) scienceProduced *= 1.33f
stats.science += scienceProduced stats.science += scienceProduced
} }
}
return stats return stats
} }
@ -208,7 +210,9 @@ class CityStats {
for (stat in baseStatList.values) stats.add(stat) for (stat in baseStatList.values) stats.add(stat)
stats.production *= 1 + statPercentBonuses.production / 100 // So they get bonuses for production and gold/science 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 stats.gold *= 1 + statPercentBonuses.gold / 100

View File

@ -1,10 +1,47 @@
package com.unciv.logic.city package com.unciv.logic.city
import com.unciv.models.gamebasics.ICivilopedia
import com.unciv.models.stats.INamed import com.unciv.models.stats.INamed
interface IConstruction : INamed { interface IConstruction : INamed, ICivilopedia {
fun getProductionCost(adoptedPolicies: HashSet<String>): Int fun getProductionCost(adoptedPolicies: HashSet<String>): Int
fun getGoldCost(adoptedPolicies: HashSet<String>): Int fun getGoldCost(adoptedPolicies: HashSet<String>): Int
fun isBuildable(construction: CityConstructions): Boolean fun isBuildable(construction: CityConstructions): Boolean
fun postBuildEvent(construction: CityConstructions) // Yes I'm hilarious. fun postBuildEvent(construction: CityConstructions) // Yes I'm hilarious.
} }
open class SpecialConstruction(override var name: String, override val description: String) : IConstruction{
fun getSpecialConstructions(): List<SpecialConstruction> {
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<String>): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getGoldCost(adoptedPolicies: HashSet<String>): 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.
}
}

View File

@ -8,7 +8,7 @@ import com.unciv.models.stats.Stats
import com.unciv.ui.VictoryScreen import com.unciv.ui.VictoryScreen
import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.pickerscreens.PolicyPickerScreen
class Building : NamedStats(), IConstruction, ICivilopedia { class Building : NamedStats(), IConstruction{
private lateinit var baseDescription: String private lateinit var baseDescription: String
override val description: String override val description: String
get() = getDescription(false, hashSetOf()) get() = getDescription(false, hashSetOf())

View File

@ -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.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.models.gamebasics.Building
import com.unciv.UnCivGame 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.pickerscreens.ConstructionPickerScreen
import com.unciv.ui.utils.CameraStageBaseScreen import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.ImageGetter 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/ // https://forums.civfanatics.com/threads/rush-buying-formula.393892/
val construction = city.cityConstructions.getCurrentConstruction() val construction = city.cityConstructions.getCurrentConstruction()
if (!(construction is Building && construction.isWonder)) { if (construction !is SpecialConstruction &&
!(construction is Building && construction.isWonder)) {
row() row()
val buildingGoldCost = construction.getGoldCost(city.civInfo.policies.getAdoptedPolicies()) val buildingGoldCost = construction.getGoldCost(city.civInfo.policies.getAdoptedPolicies())
val buildingBuyButton = TextButton("Buy for \r\n$buildingGoldCost gold", CameraStageBaseScreen.skin) val buildingBuyButton = TextButton("Buy for \r\n$buildingGoldCost gold", CameraStageBaseScreen.skin)

View File

@ -6,14 +6,13 @@ import com.unciv.logic.city.CityInfo
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.cityscreen.CityScreen import com.unciv.ui.cityscreen.CityScreen
import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.cityscreen.addClickListener
import com.unciv.ui.utils.CameraStageBaseScreen
class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() { class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
private var selectedProduction: String? = null private var selectedProduction: String? = null
private fun getProductionButton(production: String, buttonText: String, private fun getProductionButton(production: String, buttonText: String,
description: String?, rightSideButtonText: String): TextButton { description: String?, rightSideButtonText: String): TextButton {
val productionTextButton = TextButton(buttonText, CameraStageBaseScreen.skin) val productionTextButton = TextButton(buttonText, skin)
productionTextButton.addClickListener { productionTextButton.addClickListener {
selectedProduction = production selectedProduction = production
pick(rightSideButtonText) pick(rightSideButtonText)
@ -63,13 +62,10 @@ class ConstructionPickerScreen(val city: CityInfo) : PickerScreen() {
unit.getDescription(true), "Train " + unit.name)) unit.getDescription(true), "Train " + unit.name))
} }
if (civInfo.tech.isResearched("Education")) for(specialConstruction in cityConstructions.getSpecialConstructions().filter { it.isBuildable(cityConstructions) }){
specials.addActor(getProductionButton("Science", "Produce Science", specials.addActor(getProductionButton(specialConstruction.name, "Produce ${specialConstruction.name}",
"Convert production to science at a rate of 4 to 1", "Produce Science")) specialConstruction.description, "Produce ${specialConstruction.name}"))
}
if (civInfo.tech.isResearched("Currency"))
specials.addActor(getProductionButton("Gold", "Produce Gold",
"Convert production to gold at a rate of 4 to 1", "Produce Gold"))
topTable.add(units) topTable.add(units)
topTable.add(regularBuildings) topTable.add(regularBuildings)

View File

@ -6,7 +6,6 @@ import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener
import com.badlogic.gdx.utils.Align
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
@ -64,7 +63,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
widget = allTiles widget = allTiles
setFillParent(true) setFillParent(true)
setOrigin(Align.center) setOrigin(worldScreen.stage.width/2,worldScreen.stage.height/2)
setSize(worldScreen.stage.width, worldScreen.stage.height) setSize(worldScreen.stage.width, worldScreen.stage.height)
addListener(object : ActorGestureListener() { addListener(object : ActorGestureListener() {
var lastScale = 1f var lastScale = 1f