mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 02:09:21 +07:00
Can now select as many enemy civs as there are civilizations to assign to them
Can now start the game with "Huge" maps, because "Large" wasn't big enough for everyone apparently -_-
This commit is contained in:
@ -3,10 +3,12 @@ package com.unciv
|
|||||||
import com.badlogic.gdx.math.Vector2
|
import com.badlogic.gdx.math.Vector2
|
||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
|
import com.unciv.logic.map.TileInfo
|
||||||
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.NewGameScreen
|
||||||
import com.unciv.ui.utils.getRandom
|
import com.unciv.ui.utils.getRandom
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class GameStarter(){
|
class GameStarter(){
|
||||||
fun startNewGame(newGameParameters: NewGameScreen.NewGameParameters): GameInfo {
|
fun startNewGame(newGameParameters: NewGameScreen.NewGameParameters): GameInfo {
|
||||||
@ -14,26 +16,13 @@ class GameStarter(){
|
|||||||
|
|
||||||
gameInfo.tileMap = TileMap(newGameParameters.mapRadius, newGameParameters.mapType)
|
gameInfo.tileMap = TileMap(newGameParameters.mapRadius, newGameParameters.mapType)
|
||||||
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
|
||||||
|
val startingLocations = getStartingLocations(newGameParameters.numberOfEnemies+1,gameInfo.tileMap)
|
||||||
|
|
||||||
|
|
||||||
fun vectorIsWithinNTilesOfEdge(vector: Vector2,n:Int): Boolean {
|
|
||||||
return vector.x < newGameParameters.mapRadius-n
|
|
||||||
&& vector.x > n-newGameParameters.mapRadius
|
|
||||||
&& vector.y < newGameParameters.mapRadius-n
|
|
||||||
&& vector.y > n-newGameParameters.mapRadius
|
|
||||||
}
|
|
||||||
|
|
||||||
val distanceAroundStartingPointNoOneElseWillStartIn = 5
|
|
||||||
val freeTiles = gameInfo.tileMap.values
|
|
||||||
.filter { it.isLand() && vectorIsWithinNTilesOfEdge(it.position,3)}
|
|
||||||
.toMutableList()
|
|
||||||
val playerPosition = freeTiles.getRandom().position
|
|
||||||
val playerCiv = CivilizationInfo(newGameParameters.nation)
|
val playerCiv = CivilizationInfo(newGameParameters.nation)
|
||||||
playerCiv.difficulty=newGameParameters.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 ))
|
|
||||||
|
|
||||||
val barbarianCivilization = CivilizationInfo()
|
val barbarianCivilization = CivilizationInfo()
|
||||||
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
||||||
|
|
||||||
@ -51,20 +40,46 @@ 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.filter { !it.isBarbarianCivilization() }) {
|
||||||
if(freeTiles.isEmpty()){
|
val startingLocation = startingLocations.pop()!!
|
||||||
gameInfo.civilizations.remove(civ)
|
|
||||||
continue
|
|
||||||
} // we can't add any more civs.
|
|
||||||
val startingLocation = freeTiles.toList().getRandom().position
|
|
||||||
|
|
||||||
civ.placeUnitNearTile(startingLocation, "Settler")
|
civ.placeUnitNearTile(startingLocation.position, "Settler")
|
||||||
civ.placeUnitNearTile(startingLocation, "Warrior")
|
civ.placeUnitNearTile(startingLocation.position, "Warrior")
|
||||||
civ.placeUnitNearTile(startingLocation, "Scout")
|
civ.placeUnitNearTile(startingLocation.position, "Scout")
|
||||||
|
|
||||||
freeTiles.removeAll(gameInfo.tileMap.getTilesInDistance(startingLocation, distanceAroundStartingPointNoOneElseWillStartIn ))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return gameInfo
|
return gameInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getStartingLocations(numberOfPlayers:Int,tileMap: TileMap): Stack<TileInfo> {
|
||||||
|
for(minimumDistanceBetweenStartingLocations in 7 downTo 1){
|
||||||
|
val freeTiles = tileMap.values
|
||||||
|
.filter { it.isLand() && vectorIsWithinNTilesOfEdge(it.position,3,tileMap)}
|
||||||
|
.toMutableList()
|
||||||
|
|
||||||
|
val startingLocations = ArrayList<TileInfo>()
|
||||||
|
for(player in 0..numberOfPlayers){
|
||||||
|
if(freeTiles.isEmpty()) break // we failed to get all the starting locations with this minimum distance
|
||||||
|
val randomLocation = freeTiles.getRandom()
|
||||||
|
startingLocations.add(randomLocation)
|
||||||
|
freeTiles.removeAll(tileMap.getTilesInDistance(randomLocation.position,minimumDistanceBetweenStartingLocations))
|
||||||
|
}
|
||||||
|
if(startingLocations.size < numberOfPlayers) continue // let's try again with less minimum distance!
|
||||||
|
val stack = Stack<TileInfo>()
|
||||||
|
stack.addAll(startingLocations)
|
||||||
|
return stack
|
||||||
|
}
|
||||||
|
throw Exception("Didn't manage to get starting locations even with distance of 1?")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun vectorIsWithinNTilesOfEdge(vector: Vector2,n:Int, tileMap: TileMap): Boolean {
|
||||||
|
val arrayXIndex = vector.x.toInt()-tileMap.leftX
|
||||||
|
val arrayYIndex = vector.y.toInt()-tileMap.bottomY
|
||||||
|
|
||||||
|
return arrayXIndex < tileMap.tileMatrix.size-n
|
||||||
|
&& arrayXIndex > n
|
||||||
|
&& arrayYIndex < tileMap.tileMatrix[arrayXIndex].size-n
|
||||||
|
&& arrayYIndex > n
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -115,6 +115,7 @@ class NewGameScreen: PickerScreen(){
|
|||||||
worldSizeToRadius["Small"] = 10
|
worldSizeToRadius["Small"] = 10
|
||||||
worldSizeToRadius["Medium"] = 20
|
worldSizeToRadius["Medium"] = 20
|
||||||
worldSizeToRadius["Large"] = 30
|
worldSizeToRadius["Large"] = 30
|
||||||
|
worldSizeToRadius["Huge"] = 40
|
||||||
val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, "Medium", skin)
|
val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, "Medium", skin)
|
||||||
|
|
||||||
worldSizeSelectBox.addListener(object : ChangeListener() {
|
worldSizeSelectBox.addListener(object : ChangeListener() {
|
||||||
@ -128,7 +129,7 @@ class NewGameScreen: PickerScreen(){
|
|||||||
newGameOptionsTable.add("{Number of enemies}:".tr())
|
newGameOptionsTable.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..GameBasics.Nations.size-1).forEach { enemiesArray.add(it) }
|
||||||
enemiesSelectBox.items = enemiesArray
|
enemiesSelectBox.items = enemiesArray
|
||||||
enemiesSelectBox.selected = newGameParameters.numberOfEnemies
|
enemiesSelectBox.selected = newGameParameters.numberOfEnemies
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user