2018-03-02 13:34:24 +00:00
|
|
|
package com.unciv.ui
|
|
|
|
|
|
|
|
import com.badlogic.gdx.Game
|
|
|
|
import com.badlogic.gdx.Gdx
|
|
|
|
import com.badlogic.gdx.math.Vector2
|
|
|
|
import com.badlogic.gdx.utils.Json
|
|
|
|
import com.unciv.logic.GameInfo
|
|
|
|
import com.unciv.logic.civilization.CivilizationInfo
|
|
|
|
import com.unciv.logic.map.TileMap
|
|
|
|
import com.unciv.models.gamebasics.*
|
|
|
|
import com.unciv.models.gamebasics.Unit
|
|
|
|
import com.unciv.models.stats.INamed
|
|
|
|
import com.unciv.ui.utils.GameSaver
|
|
|
|
import com.unciv.ui.worldscreen.WorldScreen
|
|
|
|
|
|
|
|
class UnCivGame : Game() {
|
|
|
|
var gameInfo: GameInfo = GameInfo()
|
|
|
|
var settings = GameSettings()
|
|
|
|
|
|
|
|
var worldScreen: WorldScreen? = null
|
|
|
|
override fun create() {
|
|
|
|
setupGameBasics()
|
|
|
|
|
|
|
|
Current = this
|
|
|
|
if (GameSaver.GetSave("Autosave").exists()) {
|
|
|
|
try {
|
|
|
|
GameSaver.LoadGame(this, "Autosave")
|
2018-03-22 21:45:28 +00:00
|
|
|
gameInfo.getPlayerCivilization().civName="Babylon"
|
|
|
|
gameInfo.tileMap.values.forEach {
|
|
|
|
if (it.owner == "Player") it.owner = "Babylon"
|
|
|
|
if (it.unit != null && it.unit!!.owner == "Player") it.unit!!.owner = "Babylon"
|
|
|
|
}
|
2018-03-02 13:34:24 +00:00
|
|
|
} catch (ex: Exception) { // silent fail if we can't read the autosave
|
|
|
|
startNewGame()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else startNewGame()
|
|
|
|
|
|
|
|
worldScreen = WorldScreen()
|
|
|
|
setWorldScreen()
|
|
|
|
}
|
|
|
|
|
2018-04-02 12:16:28 +00:00
|
|
|
fun startNewGame(saveTutorialState:Boolean = false) {
|
|
|
|
if(saveTutorialState) {
|
|
|
|
val tutorials = gameInfo.tutorial
|
|
|
|
gameInfo = GameInfo()
|
|
|
|
gameInfo.tutorial = tutorials
|
|
|
|
}
|
|
|
|
else gameInfo = GameInfo()
|
|
|
|
|
2018-03-02 13:34:24 +00:00
|
|
|
gameInfo.tileMap = TileMap(20)
|
2018-03-22 21:45:28 +00:00
|
|
|
gameInfo.civilizations.add(CivilizationInfo("Babylon", Vector2.Zero, gameInfo))
|
2018-04-04 14:13:01 +00:00
|
|
|
val barbarianCivilization = CivilizationInfo()
|
|
|
|
barbarianCivilization.civName = "Barbarians"
|
|
|
|
gameInfo.civilizations.add(barbarianCivilization)
|
|
|
|
|
|
|
|
for(i in 1..5) {
|
|
|
|
gameInfo.placeBarbarianUnit()
|
|
|
|
}
|
|
|
|
|
2018-03-02 13:34:24 +00:00
|
|
|
gameInfo.setTransients()
|
|
|
|
|
|
|
|
worldScreen = WorldScreen()
|
|
|
|
setWorldScreen()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun setWorldScreen() {
|
|
|
|
setScreen(worldScreen)
|
|
|
|
worldScreen!!.update()
|
|
|
|
Gdx.input.inputProcessor = worldScreen!!.stage
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun <T> getFromJson(tClass: Class<T>, name: String): T {
|
|
|
|
val jsonText = Gdx.files.internal("jsons/$name.json").readString()
|
|
|
|
return Json().fromJson(tClass, jsonText)
|
|
|
|
}
|
|
|
|
|
2018-03-12 16:35:57 +00:00
|
|
|
private fun <T : INamed> createHashmap(items: Array<T>): LinkedHashMap<String, T> {
|
|
|
|
val hashMap = LinkedHashMap<String, T>()
|
2018-03-02 13:34:24 +00:00
|
|
|
for (item in items)
|
|
|
|
hashMap[item.name] = item
|
|
|
|
return hashMap
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setupGameBasics() {
|
2018-03-12 16:35:57 +00:00
|
|
|
GameBasics.Buildings += createHashmap(getFromJson(Array<Building>::class.java, "Buildings"))
|
|
|
|
GameBasics.Terrains += createHashmap(getFromJson(Array<Terrain>::class.java, "Terrains"))
|
|
|
|
GameBasics.TileResources += createHashmap(getFromJson(Array<TileResource>::class.java, "TileResources"))
|
|
|
|
GameBasics.TileImprovements += createHashmap(getFromJson(Array<TileImprovement>::class.java, "TileImprovements"))
|
|
|
|
GameBasics.Helps += createHashmap(getFromJson(Array<BasicHelp>::class.java, "BasicHelp"))
|
|
|
|
GameBasics.Units += createHashmap(getFromJson(Array<Unit>::class.java, "Units"))
|
|
|
|
GameBasics.PolicyBranches += createHashmap(getFromJson(Array<PolicyBranch>::class.java, "Policies"))
|
2018-03-22 21:45:28 +00:00
|
|
|
GameBasics.Civilizations += createHashmap(getFromJson(Array<Civilization>::class.java, "Civilizations"))
|
2018-03-02 13:34:24 +00:00
|
|
|
|
2018-03-12 21:33:03 +00:00
|
|
|
// ...Yes. Total Voodoo. I wish I didn't have to do this.
|
|
|
|
val x = LinkedHashMap<String,com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<String>>>()
|
|
|
|
val tutorials = getFromJson(x.javaClass, "Tutorials")
|
|
|
|
for (tut in tutorials)
|
2018-03-22 21:45:28 +00:00
|
|
|
GameBasics.Tutorials[tut.key] = tut.value.map{it.joinToString("\r\n")}
|
2018-03-12 21:33:03 +00:00
|
|
|
|
2018-03-02 13:34:24 +00:00
|
|
|
val techColumns = getFromJson(Array<TechColumn>::class.java, "Techs")
|
|
|
|
for (techColumn in techColumns) {
|
|
|
|
for (tech in techColumn.techs) {
|
|
|
|
tech.cost = techColumn.techCost
|
|
|
|
tech.column = techColumn
|
|
|
|
GameBasics.Technologies[tech.name] = tech
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (building in GameBasics.Buildings.values) {
|
|
|
|
if (building.requiredTech == null) continue
|
|
|
|
val column = building.getRequiredTech().column
|
|
|
|
if (building.cost == 0)
|
|
|
|
building.cost = if (building.isWonder) column!!.wonderCost else column!!.buildingCost
|
|
|
|
}
|
|
|
|
|
|
|
|
for (branch in GameBasics.PolicyBranches.values) {
|
2018-03-07 19:51:33 +00:00
|
|
|
branch.requires = ArrayList()
|
2018-03-02 13:34:24 +00:00
|
|
|
branch.branch = branch.name
|
|
|
|
for (policy in branch.policies) {
|
|
|
|
policy.branch = branch.name
|
|
|
|
if (policy.requires == null) {
|
2018-03-07 19:51:33 +00:00
|
|
|
policy.requires = ArrayList()
|
2018-03-02 13:34:24 +00:00
|
|
|
policy.requires!!.add(branch.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
branch.policies[branch.policies.size - 1].name = branch.name + " Complete"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
lateinit var Current: UnCivGame
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|