Years per turn improvement (#2607)
* Year issue fix * Clean up and try * real good update * udf
This commit is contained in:
parent
8877c18f31
commit
67f7e67f55
3 changed files with 49 additions and 24 deletions
|
@ -1,4 +1,5 @@
|
|||
[
|
||||
|
||||
{
|
||||
"name": "Farm",
|
||||
"terrainsCanBeBuiltOn": ["Plains","Grassland","Desert","Flood plains"],
|
||||
|
|
|
@ -25,7 +25,6 @@ class TileImprovement : NamedStats() {
|
|||
|
||||
val turnsToBuild: Int = 0 // This is the base cost.
|
||||
|
||||
|
||||
fun getTurnsToBuild(civInfo: CivilizationInfo): Int {
|
||||
var realTurnsToBuild = turnsToBuild.toFloat() * civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
||||
if (civInfo.containsBuildingUnique("Worker construction increased 25%"))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.unciv.ui.worldscreen
|
||||
|
||||
import com.badlogic.gdx.Game
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
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.Table
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.metadata.GameSpeed
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.stats.Stats
|
||||
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.victoryscreen.VictoryScreen
|
||||
import com.unciv.ui.worldscreen.mainmenu.WorldScreenMenuPopup
|
||||
import java.time.Year
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
||||
|
||||
private val turnsLabel = "Turns: 0/400".toLabel()
|
||||
private val goldLabel = "Gold:".toLabel(colorFromRGB(225, 217, 71) )
|
||||
private val scienceLabel = "Science:".toLabel(colorFromRGB(78, 140, 151) )
|
||||
private val goldLabel = "Gold:".toLabel(colorFromRGB(225, 217, 71))
|
||||
private val scienceLabel = "Science:".toLabel(colorFromRGB(78, 140, 151))
|
||||
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 resourceImages = HashMap<String, Actor>()
|
||||
private val happinessImage = Group()
|
||||
|
||||
// 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 happinessColor = colorFromRGB(92, 194, 77)
|
||||
|
@ -51,7 +56,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
|||
overviewButton.pack()
|
||||
overviewButton.onClick { worldScreen.game.setScreen(EmpireOverviewScreen(worldScreen.viewingCiv)) }
|
||||
overviewButton.center(this)
|
||||
overviewButton.x = worldScreen.stage.width-overviewButton.width-10
|
||||
overviewButton.x = worldScreen.stage.width - overviewButton.width - 10
|
||||
addActor(overviewButton)
|
||||
}
|
||||
|
||||
|
@ -62,7 +67,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
|||
val revealedStrategicResources = worldScreen.gameInfo.ruleSet.tileResources.values
|
||||
.filter { it.resourceType == ResourceType.Strategic } // && currentPlayerCivInfo.tech.isResearched(it.revealedBy!!) }
|
||||
for (resource in revealedStrategicResources) {
|
||||
val resourceImage = ImageGetter.getResourceImage(resource.name,20f)
|
||||
val resourceImage = ImageGetter.getResourceImage(resource.name, 20f)
|
||||
resourceImages[resource.name] = resourceImage
|
||||
resourceTable.add(resourceImage)
|
||||
val resourceLabel = "0".toLabel()
|
||||
|
@ -118,7 +123,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
|||
.apply { setSize(50f, 50f) }
|
||||
menuButton.color = Color.WHITE
|
||||
menuButton.onClick {
|
||||
if(worldScreen.popups.none { it is WorldScreenMenuPopup })
|
||||
if (worldScreen.popups.none { it is WorldScreenMenuPopup })
|
||||
WorldScreenMenuPopup(worldScreen).open(force = true)
|
||||
}
|
||||
menuButton.centerY(this)
|
||||
|
@ -135,24 +140,27 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
|||
val isRevealed = resource.revealedBy == null || civInfo.tech.isResearched(resource.revealedBy!!)
|
||||
resourceLabels[resource.name]!!.isVisible = isRevealed
|
||||
resourceImages[resource.name]!!.isVisible = isRevealed
|
||||
if (!civResources.any { it.resource==resource}) resourceLabels[resource.name]!!.setText("0")
|
||||
else resourceLabels[resource.name]!!.setText(civResources.first { it.resource==resource }.amount.toString())
|
||||
if (!civResources.any { it.resource == resource }) resourceLabels[resource.name]!!.setText("0")
|
||||
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 year = when{
|
||||
turns<=75 -> -4000+turns*40
|
||||
turns<=135 -> -1000+(turns-75)*25
|
||||
turns<=160 -> 500+(turns-135)*20
|
||||
turns<=210 -> 1000+(turns-160)*10
|
||||
turns<=270 -> 1500+(turns-210)*5
|
||||
turns<=320 -> 1800+(turns-270)*2
|
||||
turns<=440 -> 1900+(turns-320)
|
||||
else -> 2020+(turns-440)/2
|
||||
val gameSpeed: List<YearsToTurn> = when (civInfo.gameInfo.gameParameters.gameSpeed) {
|
||||
GameSpeed.Marathon -> marathon
|
||||
GameSpeed.Epic -> epic
|
||||
GameSpeed.Standard -> standard
|
||||
GameSpeed.Quick -> quick
|
||||
}
|
||||
|
||||
val yearText = "["+ abs(year)+"] "+ if (year<0) "BC" else "AD"
|
||||
turnsLabel.setText("Turn".tr()+" " + civInfo.gameInfo.turns + " | "+ yearText.tr())
|
||||
val year = getYear(gameSpeed, turns).toInt()
|
||||
|
||||
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)) }
|
||||
|
||||
val nextTurnStats = civInfo.statsForNextTurn
|
||||
|
@ -178,7 +186,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
|||
|
||||
private fun getCultureText(civInfo: CivilizationInfo, nextTurnStats: Stats): String {
|
||||
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
|
||||
if (turnsToNextPolicy > 0) cultureString += " (" + ceil(turnsToNextPolicy).toInt() + ")"
|
||||
|
@ -189,11 +197,28 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
|||
private fun getHappinessText(civInfo: CivilizationInfo): String {
|
||||
var happinessText = civInfo.getHappiness().toString()
|
||||
if (civInfo.goldenAges.isGoldenAge())
|
||||
happinessText += " "+"GOLDEN AGE".tr()+"(${civInfo.goldenAges.turnsLeftForCurrentGoldenAge})"
|
||||
happinessText += " " + "GOLDEN AGE".tr() + "(${civInfo.goldenAges.turnsLeftForCurrentGoldenAge})"
|
||||
else
|
||||
happinessText += (" (" + civInfo.goldenAges.storedHappiness + "/"
|
||||
+ civInfo.goldenAges.happinessRequiredForNextGoldenAge() + ")")
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue