Years per turn improvement (#2607)

* Year issue fix

* Clean up and try

* real good update

* udf
This commit is contained in:
AcridBrimistic 2020-05-16 22:01:10 +03:00 committed by GitHub
parent 8877c18f31
commit 67f7e67f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 24 deletions

View File

@ -1,4 +1,5 @@
[ [
{ {
"name": "Farm", "name": "Farm",
"terrainsCanBeBuiltOn": ["Plains","Grassland","Desert","Flood plains"], "terrainsCanBeBuiltOn": ["Plains","Grassland","Desert","Flood plains"],

View File

@ -25,7 +25,6 @@ class TileImprovement : NamedStats() {
val turnsToBuild: Int = 0 // This is the base cost. val turnsToBuild: Int = 0 // This is the base cost.
fun getTurnsToBuild(civInfo: CivilizationInfo): Int { fun getTurnsToBuild(civInfo: CivilizationInfo): Int {
var realTurnsToBuild = turnsToBuild.toFloat() * civInfo.gameInfo.gameParameters.gameSpeed.modifier var realTurnsToBuild = turnsToBuild.toFloat() * civInfo.gameInfo.gameParameters.gameSpeed.modifier
if (civInfo.containsBuildingUnique("Worker construction increased 25%")) if (civInfo.containsBuildingUnique("Worker construction increased 25%"))

View File

@ -1,5 +1,6 @@
package com.unciv.ui.worldscreen package com.unciv.ui.worldscreen
import com.badlogic.gdx.Game
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Group
@ -7,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Label 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.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.metadata.GameSpeed
import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
@ -16,20 +18,23 @@ import com.unciv.ui.pickerscreens.TechPickerScreen
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
import com.unciv.ui.victoryscreen.VictoryScreen import com.unciv.ui.victoryscreen.VictoryScreen
import com.unciv.ui.worldscreen.mainmenu.WorldScreenMenuPopup import com.unciv.ui.worldscreen.mainmenu.WorldScreenMenuPopup
import java.time.Year
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.roundToInt import kotlin.math.roundToInt
import kotlin.system.exitProcess
class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() { class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
private val turnsLabel = "Turns: 0/400".toLabel() private val turnsLabel = "Turns: 0/400".toLabel()
private val goldLabel = "Gold:".toLabel(colorFromRGB(225, 217, 71) ) private val goldLabel = "Gold:".toLabel(colorFromRGB(225, 217, 71))
private val scienceLabel = "Science:".toLabel(colorFromRGB(78, 140, 151) ) private val scienceLabel = "Science:".toLabel(colorFromRGB(78, 140, 151))
private val happinessLabel = "Happiness:".toLabel() private val happinessLabel = "Happiness:".toLabel()
private val cultureLabel = "Culture:".toLabel(colorFromRGB(210, 94, 210) ) private val cultureLabel = "Culture:".toLabel(colorFromRGB(210, 94, 210))
private val resourceLabels = HashMap<String, Label>() private val resourceLabels = HashMap<String, Label>()
private val resourceImages = HashMap<String, Actor>() private val resourceImages = HashMap<String, Actor>()
private val happinessImage = Group() private val happinessImage = Group()
// These are all to improve performance IE reduce update time (was 150 ms on my phone, which is a lot!) // These are all to improve performance IE reduce update time (was 150 ms on my phone, which is a lot!)
private val malcontentColor = Color.valueOf("ef5350") private val malcontentColor = Color.valueOf("ef5350")
private val happinessColor = colorFromRGB(92, 194, 77) private val happinessColor = colorFromRGB(92, 194, 77)
@ -51,7 +56,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
overviewButton.pack() overviewButton.pack()
overviewButton.onClick { worldScreen.game.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv)) } overviewButton.onClick { worldScreen.game.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv)) }
overviewButton.center(this) overviewButton.center(this)
overviewButton.x = worldScreen.stage.width-overviewButton.width-10 overviewButton.x = worldScreen.stage.width - overviewButton.width - 10
addActor(overviewButton) addActor(overviewButton)
} }
@ -62,7 +67,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
val revealedStrategicResources = worldScreen.gameInfo.ruleSet.tileResources.values val revealedStrategicResources = worldScreen.gameInfo.ruleSet.tileResources.values
.filter { it.resourceType == ResourceType.Strategic } // && currentPlayerCivInfo.tech.isResearched(it.revealedBy!!) } .filter { it.resourceType == ResourceType.Strategic } // && currentPlayerCivInfo.tech.isResearched(it.revealedBy!!) }
for (resource in revealedStrategicResources) { for (resource in revealedStrategicResources) {
val resourceImage = ImageGetter.getResourceImage(resource.name,20f) val resourceImage = ImageGetter.getResourceImage(resource.name, 20f)
resourceImages[resource.name] = resourceImage resourceImages[resource.name] = resourceImage
resourceTable.add(resourceImage) resourceTable.add(resourceImage)
val resourceLabel = "0".toLabel() val resourceLabel = "0".toLabel()
@ -91,7 +96,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
statsTable.add(scienceLabel) //.apply { setAlignment(Align.center) }).align(Align.top) statsTable.add(scienceLabel) //.apply { setAlignment(Align.center) }).align(Align.top)
val scienceImage = ImageGetter.getStatIcon("Science") val scienceImage = ImageGetter.getStatIcon("Science")
statsTable.add(scienceImage).padRight(20f).size(20f) statsTable.add(scienceImage).padRight(20f).size(20f)
val invokeTechScreen = { worldScreen.game.setScreen(TechPickerScreen(worldScreen.viewingCiv)) } val invokeTechScreen = { worldScreen.game.setScreen(TechPickerScreen(worldScreen.viewingCiv)) }
scienceLabel.onClick(invokeTechScreen) scienceLabel.onClick(invokeTechScreen)
scienceImage.onClick(invokeTechScreen) scienceImage.onClick(invokeTechScreen)
@ -118,7 +123,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
.apply { setSize(50f, 50f) } .apply { setSize(50f, 50f) }
menuButton.color = Color.WHITE menuButton.color = Color.WHITE
menuButton.onClick { menuButton.onClick {
if(worldScreen.popups.none { it is WorldScreenMenuPopup }) if (worldScreen.popups.none { it is WorldScreenMenuPopup })
WorldScreenMenuPopup(worldScreen).open(force = true) WorldScreenMenuPopup(worldScreen).open(force = true)
} }
menuButton.centerY(this) menuButton.centerY(this)
@ -135,24 +140,27 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
val isRevealed = resource.revealedBy == null || civInfo.tech.isResearched(resource.revealedBy!!) val isRevealed = resource.revealedBy == null || civInfo.tech.isResearched(resource.revealedBy!!)
resourceLabels[resource.name]!!.isVisible = isRevealed resourceLabels[resource.name]!!.isVisible = isRevealed
resourceImages[resource.name]!!.isVisible = isRevealed resourceImages[resource.name]!!.isVisible = isRevealed
if (!civResources.any { it.resource==resource}) resourceLabels[resource.name]!!.setText("0") if (!civResources.any { it.resource == resource }) resourceLabels[resource.name]!!.setText("0")
else resourceLabels[resource.name]!!.setText(civResources.first { it.resource==resource }.amount.toString()) else resourceLabels[resource.name]!!.setText(civResources.first { it.resource == resource }.amount.toString())
} }
val marathon = listOf<YearsToTurn>(YearsToTurn(100, 15.0), YearsToTurn(400, 10.0), YearsToTurn(570, 5.0), YearsToTurn(771, 2.0), YearsToTurn(900, 1.0), YearsToTurn(1000, 0.5), YearsToTurn(1500, 0.25))
val epic = listOf<YearsToTurn>(YearsToTurn(140, 25.0), YearsToTurn(230, 15.0), YearsToTurn(270, 10.0), YearsToTurn(360, 5.0), YearsToTurn(430, 2.0), YearsToTurn(530, 1.0), YearsToTurn(1500, 0.5))
val standard = listOf<YearsToTurn>(YearsToTurn(75, 40.0), YearsToTurn(135, 25.0), YearsToTurn(160, 15.0), YearsToTurn(211, 10.0), YearsToTurn(270, 5.0), YearsToTurn(315, 2.0), YearsToTurn(440, 1.0))
val quick = listOf<YearsToTurn>(YearsToTurn(50, 60.0), YearsToTurn(80, 40.0), YearsToTurn(100, 25.0), YearsToTurn(130, 15.0), YearsToTurn(155, 10.0), YearsToTurn(195, 5.0), YearsToTurn(260, 2.0))
val turns = civInfo.gameInfo.turns val turns = civInfo.gameInfo.turns
val year = when{ val gameSpeed: List<YearsToTurn> = when (civInfo.gameInfo.gameParameters.gameSpeed) {
turns<=75 -> -4000+turns*40 GameSpeed.Marathon -> marathon
turns<=135 -> -1000+(turns-75)*25 GameSpeed.Epic -> epic
turns<=160 -> 500+(turns-135)*20 GameSpeed.Standard -> standard
turns<=210 -> 1000+(turns-160)*10 GameSpeed.Quick -> quick
turns<=270 -> 1500+(turns-210)*5
turns<=320 -> 1800+(turns-270)*2
turns<=440 -> 1900+(turns-320)
else -> 2020+(turns-440)/2
} }
val yearText = "["+ abs(year)+"] "+ if (year<0) "BC" else "AD" val year = getYear(gameSpeed, turns).toInt()
turnsLabel.setText("Turn".tr()+" " + civInfo.gameInfo.turns + " | "+ yearText.tr())
val yearText = "[" + abs(year) + "] " + if (year < 0) "BC" else "AD"
turnsLabel.setText("Turn".tr() + " " + civInfo.gameInfo.turns + " | " + yearText.tr())
turnsLabel.onClick { worldScreen.game.setScreen(VictoryScreen(worldScreen)) } turnsLabel.onClick { worldScreen.game.setScreen(VictoryScreen(worldScreen)) }
val nextTurnStats = civInfo.statsForNextTurn val nextTurnStats = civInfo.statsForNextTurn
@ -178,7 +186,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
private fun getCultureText(civInfo: CivilizationInfo, nextTurnStats: Stats): String { private fun getCultureText(civInfo: CivilizationInfo, nextTurnStats: Stats): String {
var cultureString = "+" + Math.round(nextTurnStats.culture) var cultureString = "+" + Math.round(nextTurnStats.culture)
if(nextTurnStats.culture==0f) return cultureString // when you start the game, you're not producing any culture if (nextTurnStats.culture == 0f) return cultureString // when you start the game, you're not producing any culture
val turnsToNextPolicy = (civInfo.policies.getCultureNeededForNextPolicy() - civInfo.policies.storedCulture) / nextTurnStats.culture val turnsToNextPolicy = (civInfo.policies.getCultureNeededForNextPolicy() - civInfo.policies.storedCulture) / nextTurnStats.culture
if (turnsToNextPolicy > 0) cultureString += " (" + ceil(turnsToNextPolicy).toInt() + ")" if (turnsToNextPolicy > 0) cultureString += " (" + ceil(turnsToNextPolicy).toInt() + ")"
@ -189,11 +197,28 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
private fun getHappinessText(civInfo: CivilizationInfo): String { private fun getHappinessText(civInfo: CivilizationInfo): String {
var happinessText = civInfo.getHappiness().toString() var happinessText = civInfo.getHappiness().toString()
if (civInfo.goldenAges.isGoldenAge()) if (civInfo.goldenAges.isGoldenAge())
happinessText += " "+"GOLDEN AGE".tr()+"(${civInfo.goldenAges.turnsLeftForCurrentGoldenAge})" happinessText += " " + "GOLDEN AGE".tr() + "(${civInfo.goldenAges.turnsLeftForCurrentGoldenAge})"
else else
happinessText += (" (" + civInfo.goldenAges.storedHappiness + "/" happinessText += (" (" + civInfo.goldenAges.storedHappiness + "/"
+ civInfo.goldenAges.happinessRequiredForNextGoldenAge() + ")") + civInfo.goldenAges.happinessRequiredForNextGoldenAge() + ")")
return happinessText return happinessText
} }
private class YearsToTurn(val toTurn: Int, val yearInterval: Double) // enum class with lists for each value group potentially more efficient?
private fun getYear(speed: List<YearsToTurn>, turn: Int): Float {
var year: Float = -4000f
var i: Int = 0;
var yearsPerTurn: Float
// if macros are ever added to kotlin, this is one hell of a place for em'
while (i < turn) {
yearsPerTurn = speed.firstOrNull { turn < it.toTurn }?.yearInterval?.toFloat() ?: 0.5f
year += yearsPerTurn;
++i;
}
return year
}
} }