mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-19 20:28:56 +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(
|
||||
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) {
|
||||
val playerCiv = CivilizationInfo(newGameParameters.nation)
|
||||
val playerCiv =
|
||||
if(i==1) CivilizationInfo(newGameParameters.nation)
|
||||
else CivilizationInfo(availableCivNames.pop())
|
||||
gameInfo.difficulty = newGameParameters.difficulty
|
||||
playerCiv.playerType = PlayerType.Human
|
||||
gameInfo.civilizations.add(playerCiv)
|
||||
}
|
||||
|
||||
val barbarianCivilization = CivilizationInfo()
|
||||
barbarianCivilization.civName = "Barbarians"
|
||||
val barbarianCivilization = CivilizationInfo("Barbarians")
|
||||
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
||||
|
||||
for (nationName in GameBasics.Nations.keys.filterNot { it=="Barbarians" || it==newGameParameters.nation }.shuffled()
|
||||
.take(newGameParameters.numberOfEnemies)) {
|
||||
for (nationName in availableCivNames.take(newGameParameters.numberOfEnemies)) {
|
||||
val civ = CivilizationInfo(nationName)
|
||||
gameInfo.civilizations.add(civ)
|
||||
}
|
||||
|
@ -37,46 +37,52 @@ class GameInfo {
|
||||
//endregion
|
||||
|
||||
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
|
||||
var currentPlayerIndex = civilizations.indexOf(thisPlayer)
|
||||
|
||||
for (civInfo in civilizations) {
|
||||
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)
|
||||
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
|
||||
placeBarbarianUnit(null)
|
||||
}
|
||||
}
|
||||
civInfo.endTurn()
|
||||
thisPlayer = civilizations[currentPlayerIndex]
|
||||
thisPlayer.startTurn()
|
||||
}
|
||||
|
||||
// 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
|
||||
switchTurn()
|
||||
|
||||
for (civInfo in civilizations.filterNot { it == currentPlayer || (it.isDefeated() && !it.isBarbarianCivilization()) }) {
|
||||
civInfo.startTurn()
|
||||
NextTurnAutomation().automateCivMoves(civInfo)
|
||||
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()
|
||||
}
|
||||
|
||||
if (turns % 10 == 0) { // every 10 turns add a barbarian in a random place
|
||||
placeBarbarianUnit(null)
|
||||
}
|
||||
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.
|
||||
|
||||
currentPlayer.startTurn()
|
||||
|
||||
val enemyUnitsCloseToTerritory = currentPlayer.viewableTiles
|
||||
val enemyUnitsCloseToTerritory = thisPlayer.viewableTiles
|
||||
.filter {
|
||||
it.militaryUnit != null && it.militaryUnit!!.civInfo != currentPlayer
|
||||
&& currentPlayer.isAtWarWith(it.militaryUnit!!.civInfo)
|
||||
&& (it.getOwner() == currentPlayer || it.neighbors.any { neighbor -> neighbor.getOwner() == currentPlayer })
|
||||
it.militaryUnit != null && it.militaryUnit!!.civInfo != thisPlayer
|
||||
&& thisPlayer.isAtWarWith(it.militaryUnit!!.civInfo)
|
||||
&& (it.getOwner() == thisPlayer || it.neighbors.any { neighbor -> neighbor.getOwner() == thisPlayer })
|
||||
}
|
||||
|
||||
for (enemyUnitTile in enemyUnitsCloseToTerritory) {
|
||||
val inOrNear = if (enemyUnitTile.getOwner() == currentPlayer) "in" else "near"
|
||||
val inOrNear = if (enemyUnitTile.getOwner() == thisPlayer) "in" else "near"
|
||||
val unitName = enemyUnitTile.militaryUnit!!.name
|
||||
currentPlayer.addNotification("An enemy [$unitName] was spotted $inOrNear our territory", enemyUnitTile.position, Color.RED)
|
||||
thisPlayer.addNotification("An enemy [$unitName] was spotted $inOrNear our territory", enemyUnitTile.position, Color.RED)
|
||||
}
|
||||
|
||||
turns++
|
||||
}
|
||||
|
||||
fun placeBarbarianUnit(tileToPlace: TileInfo?) {
|
||||
|
@ -264,6 +264,13 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
var shouldUpdate=false
|
||||
override fun render(delta: Float) {
|
||||
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!
|
||||
update()
|
||||
|
||||
|
Reference in New Issue
Block a user