The new age of scenarios is upon us!

Can save a game and have it get turned instantly into a scenario!
This commit is contained in:
Yair Morgenstern 2020-08-13 17:06:37 +03:00
parent 42c8a64943
commit a27aecda09
5 changed files with 57 additions and 8 deletions

View file

@ -74,7 +74,7 @@ class GameInfo {
fun nextTurn() {
val previousHumanPlayer = getCurrentPlayerCivilization()
var thisPlayer = previousHumanPlayer // not calling is currentPlayer because that's alreay taken and I can't think of a better name
var thisPlayer = previousHumanPlayer // not calling it currentPlayer because that's already taken and I can't think of a better name
var currentPlayerIndex = civilizations.indexOf(thisPlayer)

View file

@ -3,7 +3,6 @@ package com.unciv.logic.civilization
import com.badlogic.gdx.graphics.Color
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.map.MapSize
import com.unciv.logic.map.RoadStatus
import com.unciv.models.ruleset.tech.Technology
@ -62,7 +61,7 @@ class TechManager {
techCost *= civInfo.getDifficulty().researchCostModifier
techCost *= civInfo.gameInfo.gameParameters.gameSpeed.modifier
val techsResearchedKnownCivs = civInfo.getKnownCivs().count { it.isMajorCiv() && it.tech.isResearched(techName) }
val undefeatedCivs = UncivGame.Current.gameInfo.civilizations.count { it.isMajorCiv() && !it.isDefeated() }
val undefeatedCivs = civInfo.gameInfo.civilizations.count { it.isMajorCiv() && !it.isDefeated() }
// https://forums.civfanatics.com/threads/the-mechanics-of-overflow-inflation.517970/
techCost /= 1 + techsResearchedKnownCivs / undefeatedCivs.toFloat() * 0.3f
// http://www.civclub.net/bbs/forum.php?mod=viewthread&tid=123976
@ -186,7 +185,7 @@ class TechManager {
if (overflowScience != 0) { // https://forums.civfanatics.com/threads/the-mechanics-of-overflow-inflation.517970/
val techsResearchedKnownCivs = civInfo.getKnownCivs()
.count { it.isMajorCiv() && it.tech.isResearched(currentTechnologyName()!!) }
val undefeatedCivs = UncivGame.Current.gameInfo.civilizations.count { it.isMajorCiv() && !it.isDefeated() }
val undefeatedCivs = civInfo.gameInfo.civilizations.count { it.isMajorCiv() && !it.isDefeated() }
techsInProgress[currentTechnology] = techsInProgress[currentTechnology]!! + ((1 + techsResearchedKnownCivs / undefeatedCivs.toFloat() * 0.3f) * overflowScience).toInt()
overflowScience = 0
}

View file

@ -28,6 +28,8 @@ object MapType {
// Loaded scenario
const val scenario = "Scenario"
const val scenarioFromSavedGame = "ScenarioFromSavedGame"
// All ocean tiles
const val empty = "Empty"
}

View file

@ -4,6 +4,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Array
import com.unciv.UncivGame
import com.unciv.logic.GameInfo
import com.unciv.logic.GameSaver
import com.unciv.logic.MapSaver
import com.unciv.logic.map.MapType
import com.unciv.ui.utils.CameraStageBaseScreen
@ -17,6 +19,9 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
private val generatedMapOptionsTable = MapParametersTable(mapParameters)
private val savedMapOptionsTable = Table()
private val savedScenarioOptionsTable = Table()
private val scenarioFromSavedGameOptionsTable = Table()
var selectedScenarioSaveGame: GameInfo? = null
lateinit var mapTypeSelectBox: TranslatedSelectBox
init {
defaults().pad(5f)
@ -24,6 +29,15 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
addMapTypeSelection()
}
fun selectSavedGameAsScenario(gameName: String){
val savedGame = GameSaver.loadGameByName(gameName)
mapParameters.type = MapType.scenarioFromSavedGame
mapParameters.name = gameName
newGameScreen.updateTables()
newGameScreen.gameSetupInfo.gameParameters = savedGame.gameParameters
newGameScreen.gameSetupInfo.mapParameters = savedGame.tileMap.mapParameters
selectedScenarioSaveGame = savedGame
}
private fun addMapTypeSelection() {
add("{Map Type}:".toLabel())
@ -31,7 +45,9 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
if (MapSaver.getMaps().isNotEmpty()) mapTypes.add(MapType.custom)
if (MapSaver.getScenarios().isNotEmpty() && UncivGame.Current.settings.extendedMapEditor)
mapTypes.add(MapType.scenario)
val mapTypeSelectBox = TranslatedSelectBox(mapTypes, "Generated", CameraStageBaseScreen.skin)
if (UncivGame.Current.settings.extendedMapEditor && GameSaver.getSaves().any { it.endsWith("Scenario") })
mapTypes.add(MapType.scenarioFromSavedGame)
mapTypeSelectBox = TranslatedSelectBox(mapTypes, "Generated", CameraStageBaseScreen.skin)
val mapFileSelectBox = getMapFileSelectBox()
savedMapOptionsTable.defaults().pad(5f)
@ -40,6 +56,7 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
savedMapOptionsTable.add(mapFileSelectBox).maxWidth(newGameScreen.stage.width / 2)
.right().row()
val scenarioFileSelectBox = getScenarioFileSelectBox()
savedScenarioOptionsTable.defaults().pad(5f)
savedScenarioOptionsTable.add("{Scenario file}:".toLabel()).left()
@ -47,6 +64,17 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
savedScenarioOptionsTable.add(scenarioFileSelectBox).maxWidth(newGameScreen.stage.width / 2)
.right().row()
val scenarioFromSavedGameSelectBox = SelectBox<String>(CameraStageBaseScreen.skin)
for (savedGame in GameSaver.getSaves()) {
if (savedGame.endsWith("Scenario"))
scenarioFromSavedGameSelectBox.items.add(savedGame)
}
scenarioFromSavedGameSelectBox.onChange { selectSavedGameAsScenario(scenarioFromSavedGameSelectBox.selected) }
scenarioFromSavedGameSelectBox.selected = scenarioFileSelectBox.items.first()
scenarioFromSavedGameOptionsTable.add("{Scenario file}:".toLabel()).left()
scenarioFromSavedGameOptionsTable.add(scenarioFromSavedGameSelectBox)
fun updateOnMapTypeChange() {
mapTypeSpecificTable.clear()
if (mapTypeSelectBox.selected.value == MapType.custom) {
@ -66,7 +94,13 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
// update PlayerTable and GameOptionsTable
newGameScreen.lockTables()
newGameScreen.updateTables()
} else {
} else if(mapTypeSelectBox.selected.value == MapType.scenarioFromSavedGame){
selectSavedGameAsScenario(scenarioFromSavedGameSelectBox.selected)
mapTypeSpecificTable.add(scenarioFromSavedGameOptionsTable)
newGameScreen.updateRuleset()
newGameScreen.lockTables()
newGameScreen.updateTables()
} else { // generated map
mapParameters.name = ""
mapParameters.type = generatedMapOptionsTable.mapTypeSelectBox.selected.value
mapTypeSpecificTable.add(generatedMapOptionsTable)

View file

@ -9,6 +9,7 @@ import com.unciv.UncivGame
import com.unciv.logic.*
import com.unciv.logic.civilization.PlayerType
import com.unciv.logic.map.MapParameters
import com.unciv.logic.map.MapType
import com.unciv.models.metadata.GameParameters
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache
@ -98,7 +99,19 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
private fun newGameThread() {
try {
newGame = GameStarter.startNewGame(gameSetupInfo)
if (mapOptionsTable.mapTypeSelectBox.selected.value == MapType.scenarioFromSavedGame) {
newGame = mapOptionsTable.selectedScenarioSaveGame
// to take the definition of which players are human and which are AI
for (player in gameSetupInfo.gameParameters.players) {
newGame!!.getCivilization(player.chosenCiv).playerType = player.playerType
}
if (newGame!!.getCurrentPlayerCivilization().playerType == PlayerType.AI) {
newGame!!.setTransients()
newGame!!.nextTurn() // can't start the game on an AI turn
}
newGame!!.gameParameters.godMode = false
}
else newGame = GameStarter.startNewGame(gameSetupInfo)
} catch (exception: Exception) {
Gdx.app.postRunnable {
val cantMakeThatMapPopup = Popup(this)
@ -163,7 +176,8 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
var newGame: GameInfo? = null
override fun render(delta: Float) {
if (newGame != null) game.loadGame(newGame!!)
if (newGame != null)
game.loadGame(newGame!!)
super.render(delta)
}
}