You now choose civilizations from a list which also tells you what's unique to that civ
This commit is contained in:
parent
8978d13cdc
commit
d48d7aa9fe
3 changed files with 132 additions and 40 deletions
|
@ -5,28 +5,29 @@ import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.map.TileMap
|
import com.unciv.logic.map.TileMap
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
|
import com.unciv.ui.NewGameScreen
|
||||||
import com.unciv.ui.utils.getRandom
|
import com.unciv.ui.utils.getRandom
|
||||||
|
|
||||||
class GameStarter(){
|
class GameStarter(){
|
||||||
fun startNewGame(mapRadius: Int, numberOfCivs: Int, civilization: String, difficulty:String): GameInfo {
|
fun startNewGame(newGameParameters: NewGameScreen.NewGameParameters): GameInfo {
|
||||||
val gameInfo = GameInfo()
|
val gameInfo = GameInfo()
|
||||||
|
|
||||||
gameInfo.tileMap = TileMap(mapRadius)
|
gameInfo.tileMap = TileMap(newGameParameters.mapRadius)
|
||||||
gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map
|
gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map
|
||||||
|
|
||||||
|
|
||||||
fun vectorIsWithinNTilesOfEdge(vector: Vector2,n:Int): Boolean {
|
fun vectorIsWithinNTilesOfEdge(vector: Vector2,n:Int): Boolean {
|
||||||
return vector.x < mapRadius-n
|
return vector.x < newGameParameters.mapRadius-n
|
||||||
&& vector.x > n-mapRadius
|
&& vector.x > n-newGameParameters.mapRadius
|
||||||
&& vector.y < mapRadius-n
|
&& vector.y < newGameParameters.mapRadius-n
|
||||||
&& vector.y > n-mapRadius
|
&& vector.y > n-newGameParameters.mapRadius
|
||||||
}
|
}
|
||||||
|
|
||||||
val distanceAroundStartingPointNoOneElseWillStartIn = 5
|
val distanceAroundStartingPointNoOneElseWillStartIn = 5
|
||||||
val freeTiles = gameInfo.tileMap.values.toMutableList().filter { vectorIsWithinNTilesOfEdge(it.position,3)}.toMutableList()
|
val freeTiles = gameInfo.tileMap.values.toMutableList().filter { vectorIsWithinNTilesOfEdge(it.position,3)}.toMutableList()
|
||||||
val playerPosition = freeTiles.getRandom().position
|
val playerPosition = freeTiles.getRandom().position
|
||||||
val playerCiv = CivilizationInfo(civilization, gameInfo)
|
val playerCiv = CivilizationInfo(newGameParameters.nation, gameInfo)
|
||||||
playerCiv.difficulty=difficulty
|
playerCiv.difficulty=newGameParameters.difficulty
|
||||||
gameInfo.civilizations.add(playerCiv) // first one is player civ
|
gameInfo.civilizations.add(playerCiv) // first one is player civ
|
||||||
|
|
||||||
freeTiles.removeAll(gameInfo.tileMap.getTilesInDistance(playerPosition, distanceAroundStartingPointNoOneElseWillStartIn ))
|
freeTiles.removeAll(gameInfo.tileMap.getTilesInDistance(playerPosition, distanceAroundStartingPointNoOneElseWillStartIn ))
|
||||||
|
@ -34,8 +35,9 @@ class GameStarter(){
|
||||||
val barbarianCivilization = CivilizationInfo()
|
val barbarianCivilization = CivilizationInfo()
|
||||||
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
||||||
|
|
||||||
for (civname in GameBasics.Nations.keys.filterNot { it=="Barbarians" || it==civilization }.take(numberOfCivs)) {
|
for (nationName in GameBasics.Nations.keys.filterNot { it=="Barbarians" || it==newGameParameters.nation }.shuffled()
|
||||||
val civ = CivilizationInfo(civname, gameInfo)
|
.take(newGameParameters.numberOfEnemies)) {
|
||||||
|
val civ = CivilizationInfo(nationName, gameInfo)
|
||||||
civ.tech.techsResearched.addAll(playerCiv.getDifficulty().aiFreeTechs)
|
civ.tech.techsResearched.addAll(playerCiv.getDifficulty().aiFreeTechs)
|
||||||
gameInfo.civilizations.add(civ)
|
gameInfo.civilizations.add(civ)
|
||||||
}
|
}
|
||||||
|
@ -48,7 +50,10 @@ class GameStarter(){
|
||||||
// and only now do we add units for everyone, because otherwise both the gameInfo.setTransients() and the placeUnit will both add the unit to the civ's unit list!
|
// and only now do we add units for everyone, because otherwise both the gameInfo.setTransients() and the placeUnit will both add the unit to the civ's unit list!
|
||||||
|
|
||||||
for (civ in gameInfo.civilizations.toList().filter { !it.isBarbarianCivilization() }) {
|
for (civ in gameInfo.civilizations.toList().filter { !it.isBarbarianCivilization() }) {
|
||||||
if(freeTiles.isEmpty()) gameInfo.civilizations.remove(civ) // we can't add any more civs.
|
if(freeTiles.isEmpty()){
|
||||||
|
gameInfo.civilizations.remove(civ)
|
||||||
|
continue
|
||||||
|
} // we can't add any more civs.
|
||||||
val startingLocation = freeTiles.toList().getRandom().position
|
val startingLocation = freeTiles.toList().getRandom().position
|
||||||
|
|
||||||
civ.placeUnitNearTile(startingLocation, "Settler")
|
civ.placeUnitNearTile(startingLocation, "Settler")
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.Gdx
|
||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.GameSaver
|
import com.unciv.logic.GameSaver
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
|
import com.unciv.ui.NewGameScreen
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ class UnCivGame : Game() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startNewGame() {
|
fun startNewGame() {
|
||||||
val newGame = GameStarter().startNewGame(20, 3, "Babylon","Chieftain")
|
val newGame = GameStarter().startNewGame(NewGameScreen.NewGameParameters().apply { difficulty="Chieftain" })
|
||||||
gameInfo = newGame
|
gameInfo = newGame
|
||||||
|
|
||||||
worldScreen = WorldScreen()
|
worldScreen = WorldScreen()
|
||||||
|
|
|
@ -1,51 +1,139 @@
|
||||||
package com.unciv.ui
|
package com.unciv.ui
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.*
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
|
||||||
import com.badlogic.gdx.utils.Array
|
import com.badlogic.gdx.utils.Array
|
||||||
import com.unciv.GameStarter
|
import com.unciv.GameStarter
|
||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
|
import com.unciv.models.gamebasics.Nation
|
||||||
import com.unciv.ui.pickerscreens.PickerScreen
|
import com.unciv.ui.pickerscreens.PickerScreen
|
||||||
import com.unciv.ui.utils.addClickListener
|
import com.unciv.ui.utils.*
|
||||||
import com.unciv.ui.utils.disable
|
|
||||||
import com.unciv.ui.utils.enable
|
|
||||||
import com.unciv.ui.utils.tr
|
|
||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class NewGameScreen: PickerScreen(){
|
class NewGameScreen: PickerScreen(){
|
||||||
|
|
||||||
|
class NewGameParameters{
|
||||||
|
var difficulty="Prince"
|
||||||
|
var nation="Babylon"
|
||||||
|
var mapRadius=20
|
||||||
|
var numberOfEnemies=3
|
||||||
|
}
|
||||||
|
|
||||||
|
val newGameParameters=NewGameParameters()
|
||||||
|
|
||||||
|
class NationTable(val nation:Nation,val newGameParameters: NewGameParameters, skin:Skin, onClick:()->Unit):Table(skin){
|
||||||
|
init {
|
||||||
|
pad(10f)
|
||||||
|
background=ImageGetter.getBackground(nation.getColor().apply { a=0.5f })
|
||||||
|
add(Label(nation.name, skin).apply { setFontColor(Color.WHITE)}).row()
|
||||||
|
add(Label(getUniqueLabel(nation), skin).apply { setFontColor(Color.WHITE)})
|
||||||
|
addClickListener { newGameParameters.nation=nation.name; onClick() }
|
||||||
|
touchable=Touchable.enabled
|
||||||
|
update()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getUniqueLabel(nation: Nation): CharSequence? {
|
||||||
|
for (building in GameBasics.Buildings.values)
|
||||||
|
if (building.uniqueTo == nation.name) {
|
||||||
|
var text = building.name + " - {replaces} " + building.replaces + "\n"
|
||||||
|
val originalBuilding = GameBasics.Buildings[building.replaces]!!
|
||||||
|
val originalBuildingStatMap = originalBuilding.toHashMap()
|
||||||
|
for (stat in building.toHashMap())
|
||||||
|
if (stat.value != originalBuildingStatMap[stat.key])
|
||||||
|
text += stat.value.toInt().toString() + " " + stat.key + " vs " + originalBuildingStatMap[stat.key]!!.toInt() + "\n"
|
||||||
|
if (building.maintenance != originalBuilding.maintenance)
|
||||||
|
text += "{Maintainance} " + building.maintenance + " vs " + originalBuilding.maintenance + "\n"
|
||||||
|
return text.tr()
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unit in GameBasics.Units.values)
|
||||||
|
if (unit.uniqueTo == nation.name) {
|
||||||
|
var text = unit.name + " - {replaces} " + unit.replaces + "\n"
|
||||||
|
val originalUnit = GameBasics.Units[unit.replaces]!!
|
||||||
|
if (unit.strength != originalUnit.strength)
|
||||||
|
text += "{Combat strength} " + unit.strength + " vs " + originalUnit.strength + "\n"
|
||||||
|
if (unit.rangedStrength!= originalUnit.rangedStrength)
|
||||||
|
text += "{Ranged strength} " + unit.rangedStrength+ " vs " + originalUnit.rangedStrength + "\n"
|
||||||
|
if (unit.range!= originalUnit.range)
|
||||||
|
text += "{Range} " + unit.range+ " vs " + originalUnit.range + "\n"
|
||||||
|
if (unit.movement!= originalUnit.movement)
|
||||||
|
text += "{Movement} " + unit.movement+ " vs " + originalUnit.movement + "\n"
|
||||||
|
return text.tr()
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun update(){
|
||||||
|
val color = nation.getColor()
|
||||||
|
if(newGameParameters.nation!=nation.name) color.a=0.5f
|
||||||
|
background=ImageGetter.getBackground(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val nationTables = ArrayList<NationTable>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
val mainTable = Table()
|
||||||
|
mainTable.add(getOptionsTable())
|
||||||
|
val civPickerTable = Table().apply { defaults().pad(5f) }
|
||||||
|
for(nation in GameBasics.Nations.values.filterNot { it.name == "Barbarians" }){
|
||||||
|
val nationTable = NationTable(nation,newGameParameters,skin){updateNationTables()}
|
||||||
|
nationTables.add(nationTable)
|
||||||
|
civPickerTable.add(nationTable).width(stage.width/3).row()
|
||||||
|
}
|
||||||
|
mainTable.setFillParent(true)
|
||||||
|
mainTable.add(ScrollPane(civPickerTable))
|
||||||
|
topTable.addActor(mainTable)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateNationTables(){
|
||||||
|
nationTables.forEach { it.update() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getOptionsTable(): Table {
|
||||||
val table = Table()
|
val table = Table()
|
||||||
table.skin= skin
|
table.skin = skin
|
||||||
|
|
||||||
|
|
||||||
table.add("{Civilization}:".tr())
|
|
||||||
val civSelectBox = TranslatedSelectBox(GameBasics.Nations.keys.filterNot { it=="Barbarians" },
|
|
||||||
"Babylon",skin)
|
|
||||||
table.add(civSelectBox).pad(10f).row()
|
|
||||||
|
|
||||||
table.add("{World size}:".tr())
|
table.add("{World size}:".tr())
|
||||||
val worldSizeToRadius=LinkedHashMap<String,Int>()
|
val worldSizeToRadius = LinkedHashMap<String, Int>()
|
||||||
worldSizeToRadius["Small"] = 10
|
worldSizeToRadius["Small"] = 10
|
||||||
worldSizeToRadius["Medium"] = 20
|
worldSizeToRadius["Medium"] = 20
|
||||||
worldSizeToRadius["Large"] = 30
|
worldSizeToRadius["Large"] = 30
|
||||||
val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys,"Medium",skin)
|
val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, "Medium", skin)
|
||||||
|
|
||||||
|
worldSizeSelectBox.addListener(object : ChangeListener() {
|
||||||
|
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||||
|
newGameParameters.mapRadius = worldSizeToRadius[worldSizeSelectBox.selected.value]!!
|
||||||
|
}
|
||||||
|
})
|
||||||
table.add(worldSizeSelectBox).pad(10f).row()
|
table.add(worldSizeSelectBox).pad(10f).row()
|
||||||
|
|
||||||
|
|
||||||
table.add("{Number of enemies}:".tr())
|
table.add("{Number of enemies}:".tr())
|
||||||
val enemiesSelectBox = SelectBox<Int>(skin)
|
val enemiesSelectBox = SelectBox<Int>(skin)
|
||||||
val enemiesArray=Array<Int>()
|
val enemiesArray = Array<Int>()
|
||||||
(1..5).forEach { enemiesArray.add(it) }
|
(1..5).forEach { enemiesArray.add(it) }
|
||||||
enemiesSelectBox.items=enemiesArray
|
enemiesSelectBox.items = enemiesArray
|
||||||
enemiesSelectBox.selected=3
|
enemiesSelectBox.selected = newGameParameters.numberOfEnemies
|
||||||
|
|
||||||
|
enemiesSelectBox.addListener(object : ChangeListener() {
|
||||||
|
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||||
|
newGameParameters.numberOfEnemies = enemiesSelectBox.selected
|
||||||
|
}
|
||||||
|
})
|
||||||
table.add(enemiesSelectBox).pad(10f).row()
|
table.add(enemiesSelectBox).pad(10f).row()
|
||||||
|
|
||||||
|
|
||||||
table.add("{Difficulty}:".tr())
|
table.add("{Difficulty}:".tr())
|
||||||
val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, "Prince", skin)
|
val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, newGameParameters.difficulty, skin)
|
||||||
table.add(difficultySelectBox).pad(10f).row()
|
table.add(difficultySelectBox).pad(10f).row()
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,17 +144,15 @@ class NewGameScreen: PickerScreen(){
|
||||||
rightSideButton.disable()
|
rightSideButton.disable()
|
||||||
rightSideButton.setText("Working...".tr())
|
rightSideButton.setText("Working...".tr())
|
||||||
|
|
||||||
kotlin.concurrent.thread { // Creating a new game can tke a while and we don't want ANRs
|
thread {
|
||||||
newGame = GameStarter().startNewGame(
|
// Creating a new game can tke a while and we don't want ANRs
|
||||||
worldSizeToRadius[worldSizeSelectBox.selected.value]!!, enemiesSelectBox.selected,
|
newGame = GameStarter().startNewGame(newGameParameters)
|
||||||
civSelectBox.selected.value, difficultySelectBox.selected.value )
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table.setFillParent(true)
|
|
||||||
table.pack()
|
table.pack()
|
||||||
stage.addActor(table)
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
var newGame:GameInfo?=null
|
var newGame:GameInfo?=null
|
||||||
|
|
||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
|
|
Loading…
Reference in a new issue