mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 13:49:54 +07:00
Can now play with multiple human players!
Need to find a way for all human players to choose their civs in a simple manner
This commit is contained in:
@ -31,20 +31,23 @@ class GameStarter{
|
|||||||
val startingLocations = getStartingLocations(
|
val startingLocations = getStartingLocations(
|
||||||
newGameParameters.numberOfEnemies+newGameParameters.humanPlayers, gameInfo.tileMap)
|
newGameParameters.numberOfEnemies+newGameParameters.humanPlayers, gameInfo.tileMap)
|
||||||
|
|
||||||
|
val availableCivNames = Stack<String>()
|
||||||
|
availableCivNames.addAll(GameBasics.Nations.keys.shuffled())
|
||||||
|
availableCivNames.remove(newGameParameters.nation)
|
||||||
|
|
||||||
for(i in 1..newGameParameters.humanPlayers) {
|
for(i in 1..newGameParameters.humanPlayers) {
|
||||||
val playerCiv = CivilizationInfo(newGameParameters.nation)
|
val playerCiv =
|
||||||
|
if(i==1) CivilizationInfo(newGameParameters.nation)
|
||||||
|
else CivilizationInfo(availableCivNames.pop())
|
||||||
gameInfo.difficulty = newGameParameters.difficulty
|
gameInfo.difficulty = newGameParameters.difficulty
|
||||||
playerCiv.playerType = PlayerType.Human
|
playerCiv.playerType = PlayerType.Human
|
||||||
gameInfo.civilizations.add(playerCiv)
|
gameInfo.civilizations.add(playerCiv)
|
||||||
}
|
}
|
||||||
|
|
||||||
val barbarianCivilization = CivilizationInfo()
|
val barbarianCivilization = CivilizationInfo("Barbarians")
|
||||||
barbarianCivilization.civName = "Barbarians"
|
|
||||||
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
||||||
|
|
||||||
for (nationName in GameBasics.Nations.keys.filterNot { it=="Barbarians" || it==newGameParameters.nation }.shuffled()
|
for (nationName in availableCivNames.take(newGameParameters.numberOfEnemies)) {
|
||||||
.take(newGameParameters.numberOfEnemies)) {
|
|
||||||
val civ = CivilizationInfo(nationName)
|
val civ = CivilizationInfo(nationName)
|
||||||
gameInfo.civilizations.add(civ)
|
gameInfo.civilizations.add(civ)
|
||||||
}
|
}
|
||||||
|
@ -37,46 +37,52 @@ class GameInfo {
|
|||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
fun nextTurn() {
|
fun nextTurn() {
|
||||||
val currentPlayer = 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
|
||||||
for (civInfo in civilizations) {
|
var currentPlayerIndex = civilizations.indexOf(thisPlayer)
|
||||||
if (civInfo.tech.techsToResearch.isEmpty()) { // should belong in automation? yes/no?
|
|
||||||
val researchableTechs = GameBasics.Technologies.values
|
|
||||||
.filter { !civInfo.tech.isResearched(it.name) && civInfo.tech.canBeResearched(it.name) }
|
|
||||||
civInfo.tech.techsToResearch.add(researchableTechs.minBy { it.cost }!!.name)
|
|
||||||
}
|
|
||||||
civInfo.endTurn()
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to update the stats after ALL the cities are done updating because
|
|
||||||
// maybe one of them has a wonder that affects the stats of all the rest of the cities
|
|
||||||
|
|
||||||
for (civInfo in civilizations.filterNot { it == currentPlayer || (it.isDefeated() && !it.isBarbarianCivilization()) }) {
|
|
||||||
civInfo.startTurn()
|
|
||||||
NextTurnAutomation().automateCivMoves(civInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fun switchTurn(){
|
||||||
|
thisPlayer.endTurn()
|
||||||
|
currentPlayerIndex = (currentPlayerIndex+1) % civilizations.size
|
||||||
|
if(currentPlayerIndex==0){
|
||||||
|
turns++
|
||||||
if (turns % 10 == 0) { // every 10 turns add a barbarian in a random place
|
if (turns % 10 == 0) { // every 10 turns add a barbarian in a random place
|
||||||
placeBarbarianUnit(null)
|
placeBarbarianUnit(null)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
thisPlayer = civilizations[currentPlayerIndex]
|
||||||
|
thisPlayer.startTurn()
|
||||||
|
}
|
||||||
|
|
||||||
|
switchTurn()
|
||||||
|
|
||||||
|
while(thisPlayer.playerType==PlayerType.AI){
|
||||||
|
NextTurnAutomation().automateCivMoves(thisPlayer)
|
||||||
|
if (thisPlayer.tech.techsToResearch.isEmpty()) { // should belong in automation? yes/no?
|
||||||
|
val researchableTechs = GameBasics.Technologies.values
|
||||||
|
.filter { !thisPlayer.tech.isResearched(it.name) && thisPlayer.tech.canBeResearched(it.name) }
|
||||||
|
thisPlayer.tech.techsToResearch.add(researchableTechs.minBy { it.cost }!!.name)
|
||||||
|
}
|
||||||
|
switchTurn()
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPlayer=thisPlayer.civName
|
||||||
|
|
||||||
// Start our turn immediately before the player can made decisions - affects whether our units can commit automated actions and then be attacked immediately etc.
|
// Start our turn immediately before the player can made decisions - affects whether our units can commit automated actions and then be attacked immediately etc.
|
||||||
|
|
||||||
currentPlayer.startTurn()
|
val enemyUnitsCloseToTerritory = thisPlayer.viewableTiles
|
||||||
|
|
||||||
val enemyUnitsCloseToTerritory = currentPlayer.viewableTiles
|
|
||||||
.filter {
|
.filter {
|
||||||
it.militaryUnit != null && it.militaryUnit!!.civInfo != currentPlayer
|
it.militaryUnit != null && it.militaryUnit!!.civInfo != thisPlayer
|
||||||
&& currentPlayer.isAtWarWith(it.militaryUnit!!.civInfo)
|
&& thisPlayer.isAtWarWith(it.militaryUnit!!.civInfo)
|
||||||
&& (it.getOwner() == currentPlayer || it.neighbors.any { neighbor -> neighbor.getOwner() == currentPlayer })
|
&& (it.getOwner() == thisPlayer || it.neighbors.any { neighbor -> neighbor.getOwner() == thisPlayer })
|
||||||
}
|
}
|
||||||
for (enemyUnitTile in enemyUnitsCloseToTerritory) {
|
|
||||||
val inOrNear = if (enemyUnitTile.getOwner() == currentPlayer) "in" else "near"
|
for (enemyUnitTile in enemyUnitsCloseToTerritory) {
|
||||||
val unitName = enemyUnitTile.militaryUnit!!.name
|
val inOrNear = if (enemyUnitTile.getOwner() == thisPlayer) "in" else "near"
|
||||||
currentPlayer.addNotification("An enemy [$unitName] was spotted $inOrNear our territory", enemyUnitTile.position, Color.RED)
|
val unitName = enemyUnitTile.militaryUnit!!.name
|
||||||
|
thisPlayer.addNotification("An enemy [$unitName] was spotted $inOrNear our territory", enemyUnitTile.position, Color.RED)
|
||||||
}
|
}
|
||||||
|
|
||||||
turns++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun placeBarbarianUnit(tileToPlace: TileInfo?) {
|
fun placeBarbarianUnit(tileToPlace: TileInfo?) {
|
||||||
|
@ -264,6 +264,13 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||||||
var shouldUpdate=false
|
var shouldUpdate=false
|
||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
if(shouldUpdate){ // This is so that updates happen in the MAIN THREAD, where there is a GL Context,
|
if(shouldUpdate){ // This is so that updates happen in the MAIN THREAD, where there is a GL Context,
|
||||||
|
if(currentPlayerCiv!=gameInfo.getCurrentPlayerCivilization()){
|
||||||
|
UnCivGame.Current.worldScreen= WorldScreen().apply {
|
||||||
|
shouldUpdate=true
|
||||||
|
}
|
||||||
|
UnCivGame.Current.setWorldScreen()
|
||||||
|
}
|
||||||
|
|
||||||
// otherwise images will not load properly!
|
// otherwise images will not load properly!
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user