mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 10:18:26 +07:00
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:
@ -74,7 +74,7 @@ class GameInfo {
|
|||||||
|
|
||||||
fun nextTurn() {
|
fun nextTurn() {
|
||||||
val previousHumanPlayer = getCurrentPlayerCivilization()
|
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)
|
var currentPlayerIndex = civilizations.indexOf(thisPlayer)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package com.unciv.logic.civilization
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
import com.unciv.UncivGame
|
|
||||||
import com.unciv.logic.map.MapSize
|
import com.unciv.logic.map.MapSize
|
||||||
import com.unciv.logic.map.RoadStatus
|
import com.unciv.logic.map.RoadStatus
|
||||||
import com.unciv.models.ruleset.tech.Technology
|
import com.unciv.models.ruleset.tech.Technology
|
||||||
@ -62,7 +61,7 @@ class TechManager {
|
|||||||
techCost *= civInfo.getDifficulty().researchCostModifier
|
techCost *= civInfo.getDifficulty().researchCostModifier
|
||||||
techCost *= civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
techCost *= civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
||||||
val techsResearchedKnownCivs = civInfo.getKnownCivs().count { it.isMajorCiv() && it.tech.isResearched(techName) }
|
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/
|
// https://forums.civfanatics.com/threads/the-mechanics-of-overflow-inflation.517970/
|
||||||
techCost /= 1 + techsResearchedKnownCivs / undefeatedCivs.toFloat() * 0.3f
|
techCost /= 1 + techsResearchedKnownCivs / undefeatedCivs.toFloat() * 0.3f
|
||||||
// http://www.civclub.net/bbs/forum.php?mod=viewthread&tid=123976
|
// 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/
|
if (overflowScience != 0) { // https://forums.civfanatics.com/threads/the-mechanics-of-overflow-inflation.517970/
|
||||||
val techsResearchedKnownCivs = civInfo.getKnownCivs()
|
val techsResearchedKnownCivs = civInfo.getKnownCivs()
|
||||||
.count { it.isMajorCiv() && it.tech.isResearched(currentTechnologyName()!!) }
|
.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()
|
techsInProgress[currentTechnology] = techsInProgress[currentTechnology]!! + ((1 + techsResearchedKnownCivs / undefeatedCivs.toFloat() * 0.3f) * overflowScience).toInt()
|
||||||
overflowScience = 0
|
overflowScience = 0
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ object MapType {
|
|||||||
// Loaded scenario
|
// Loaded scenario
|
||||||
const val scenario = "Scenario"
|
const val scenario = "Scenario"
|
||||||
|
|
||||||
|
const val scenarioFromSavedGame = "ScenarioFromSavedGame"
|
||||||
|
|
||||||
// All ocean tiles
|
// All ocean tiles
|
||||||
const val empty = "Empty"
|
const val empty = "Empty"
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||||
import com.badlogic.gdx.utils.Array
|
import com.badlogic.gdx.utils.Array
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.logic.GameInfo
|
||||||
|
import com.unciv.logic.GameSaver
|
||||||
import com.unciv.logic.MapSaver
|
import com.unciv.logic.MapSaver
|
||||||
import com.unciv.logic.map.MapType
|
import com.unciv.logic.map.MapType
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
@ -17,6 +19,9 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
|
|||||||
private val generatedMapOptionsTable = MapParametersTable(mapParameters)
|
private val generatedMapOptionsTable = MapParametersTable(mapParameters)
|
||||||
private val savedMapOptionsTable = Table()
|
private val savedMapOptionsTable = Table()
|
||||||
private val savedScenarioOptionsTable = Table()
|
private val savedScenarioOptionsTable = Table()
|
||||||
|
private val scenarioFromSavedGameOptionsTable = Table()
|
||||||
|
var selectedScenarioSaveGame: GameInfo? = null
|
||||||
|
lateinit var mapTypeSelectBox: TranslatedSelectBox
|
||||||
|
|
||||||
init {
|
init {
|
||||||
defaults().pad(5f)
|
defaults().pad(5f)
|
||||||
@ -24,6 +29,15 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
|
|||||||
addMapTypeSelection()
|
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() {
|
private fun addMapTypeSelection() {
|
||||||
add("{Map Type}:".toLabel())
|
add("{Map Type}:".toLabel())
|
||||||
@ -31,7 +45,9 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
|
|||||||
if (MapSaver.getMaps().isNotEmpty()) mapTypes.add(MapType.custom)
|
if (MapSaver.getMaps().isNotEmpty()) mapTypes.add(MapType.custom)
|
||||||
if (MapSaver.getScenarios().isNotEmpty() && UncivGame.Current.settings.extendedMapEditor)
|
if (MapSaver.getScenarios().isNotEmpty() && UncivGame.Current.settings.extendedMapEditor)
|
||||||
mapTypes.add(MapType.scenario)
|
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()
|
val mapFileSelectBox = getMapFileSelectBox()
|
||||||
savedMapOptionsTable.defaults().pad(5f)
|
savedMapOptionsTable.defaults().pad(5f)
|
||||||
@ -40,6 +56,7 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
|
|||||||
savedMapOptionsTable.add(mapFileSelectBox).maxWidth(newGameScreen.stage.width / 2)
|
savedMapOptionsTable.add(mapFileSelectBox).maxWidth(newGameScreen.stage.width / 2)
|
||||||
.right().row()
|
.right().row()
|
||||||
|
|
||||||
|
|
||||||
val scenarioFileSelectBox = getScenarioFileSelectBox()
|
val scenarioFileSelectBox = getScenarioFileSelectBox()
|
||||||
savedScenarioOptionsTable.defaults().pad(5f)
|
savedScenarioOptionsTable.defaults().pad(5f)
|
||||||
savedScenarioOptionsTable.add("{Scenario file}:".toLabel()).left()
|
savedScenarioOptionsTable.add("{Scenario file}:".toLabel()).left()
|
||||||
@ -47,6 +64,17 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
|
|||||||
savedScenarioOptionsTable.add(scenarioFileSelectBox).maxWidth(newGameScreen.stage.width / 2)
|
savedScenarioOptionsTable.add(scenarioFileSelectBox).maxWidth(newGameScreen.stage.width / 2)
|
||||||
.right().row()
|
.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() {
|
fun updateOnMapTypeChange() {
|
||||||
mapTypeSpecificTable.clear()
|
mapTypeSpecificTable.clear()
|
||||||
if (mapTypeSelectBox.selected.value == MapType.custom) {
|
if (mapTypeSelectBox.selected.value == MapType.custom) {
|
||||||
@ -66,7 +94,13 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
|
|||||||
// update PlayerTable and GameOptionsTable
|
// update PlayerTable and GameOptionsTable
|
||||||
newGameScreen.lockTables()
|
newGameScreen.lockTables()
|
||||||
newGameScreen.updateTables()
|
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.name = ""
|
||||||
mapParameters.type = generatedMapOptionsTable.mapTypeSelectBox.selected.value
|
mapParameters.type = generatedMapOptionsTable.mapTypeSelectBox.selected.value
|
||||||
mapTypeSpecificTable.add(generatedMapOptionsTable)
|
mapTypeSpecificTable.add(generatedMapOptionsTable)
|
||||||
|
@ -9,6 +9,7 @@ import com.unciv.UncivGame
|
|||||||
import com.unciv.logic.*
|
import com.unciv.logic.*
|
||||||
import com.unciv.logic.civilization.PlayerType
|
import com.unciv.logic.civilization.PlayerType
|
||||||
import com.unciv.logic.map.MapParameters
|
import com.unciv.logic.map.MapParameters
|
||||||
|
import com.unciv.logic.map.MapType
|
||||||
import com.unciv.models.metadata.GameParameters
|
import com.unciv.models.metadata.GameParameters
|
||||||
import com.unciv.models.ruleset.Ruleset
|
import com.unciv.models.ruleset.Ruleset
|
||||||
import com.unciv.models.ruleset.RulesetCache
|
import com.unciv.models.ruleset.RulesetCache
|
||||||
@ -98,7 +99,19 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
|
|||||||
|
|
||||||
private fun newGameThread() {
|
private fun newGameThread() {
|
||||||
try {
|
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) {
|
} catch (exception: Exception) {
|
||||||
Gdx.app.postRunnable {
|
Gdx.app.postRunnable {
|
||||||
val cantMakeThatMapPopup = Popup(this)
|
val cantMakeThatMapPopup = Popup(this)
|
||||||
@ -163,7 +176,8 @@ class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSe
|
|||||||
var newGame: GameInfo? = null
|
var newGame: GameInfo? = null
|
||||||
|
|
||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
if (newGame != null) game.loadGame(newGame!!)
|
if (newGame != null)
|
||||||
|
game.loadGame(newGame!!)
|
||||||
super.render(delta)
|
super.render(delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user