mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 09:48:12 +07:00
Notifications are now per-civ instead of game-wide, in preparation for multiplayer
Added player type to civinfo, in preparation for multiplayer
This commit is contained in:
@ -3,6 +3,7 @@ package com.unciv
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
@ -21,6 +22,7 @@ class GameStarter{
|
||||
|
||||
val playerCiv = CivilizationInfo(newGameParameters.nation)
|
||||
playerCiv.difficulty=newGameParameters.difficulty
|
||||
playerCiv.playerType=PlayerType.Human
|
||||
gameInfo.civilizations.add(playerCiv) // first one is player civ
|
||||
|
||||
val barbarianCivilization = CivilizationInfo()
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.unciv.logic.automation.NextTurnAutomation
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.Notification
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
@ -22,7 +23,6 @@ class GameInfo {
|
||||
val toReturn = GameInfo()
|
||||
toReturn.tileMap = tileMap.clone()
|
||||
toReturn.civilizations.addAll(civilizations.map { it.clone() })
|
||||
toReturn.notifications.addAll(notifications)
|
||||
toReturn.turns = turns
|
||||
return toReturn
|
||||
}
|
||||
@ -32,7 +32,6 @@ class GameInfo {
|
||||
//endregion
|
||||
|
||||
fun nextTurn() {
|
||||
notifications.clear()
|
||||
val player = getPlayerCivilization()
|
||||
|
||||
for (civInfo in civilizations) {
|
||||
@ -95,6 +94,11 @@ class GameInfo {
|
||||
// this is separated into 2 loops because when we activate updateViewableTiles in civ.setTransients,
|
||||
// we try to find new civs, and we check if civ is barbarian, which we can't know unless the gameInfo is already set.
|
||||
for (civInfo in civilizations) civInfo.gameInfo = this
|
||||
|
||||
// PlayerType was only added in 2.11.1, so we need to adjust for older saved games
|
||||
if(civilizations.all { it.playerType==PlayerType.AI })
|
||||
getPlayerCivilization().playerType=PlayerType.Human
|
||||
|
||||
for (civInfo in civilizations) civInfo.setTransients()
|
||||
|
||||
for (civInfo in civilizations) {
|
||||
|
@ -150,8 +150,8 @@ class Battle(val gameInfo:GameInfo) {
|
||||
if(city.cityConstructions.isBuilt("Palace")){
|
||||
city.cityConstructions.removeBuilding("Palace")
|
||||
if(enemyCiv.isDefeated()) {
|
||||
gameInfo.getPlayerCivilization()
|
||||
.addNotification("The civilization of [${enemyCiv.civName}] has been destroyed!", null, Color.RED)
|
||||
for(civ in gameInfo.civilizations)
|
||||
civ.addNotification("The civilization of [${enemyCiv.civName}] has been destroyed!", null, Color.RED)
|
||||
enemyCiv.getCivUnits().forEach { it.destroy() }
|
||||
}
|
||||
else if(enemyCiv.cities.isNotEmpty()){
|
||||
|
@ -153,9 +153,10 @@ class CityConstructions {
|
||||
inProgressConstructions.remove(currentConstruction)
|
||||
|
||||
if (construction is Building && construction.isWonder && construction.requiredBuildingInAllCities == null) {
|
||||
val playerCiv = cityInfo.civInfo.gameInfo.getPlayerCivilization()
|
||||
val builtLocation = if (playerCiv.exploredTiles.contains(cityInfo.location)) cityInfo.name else "a faraway land"
|
||||
playerCiv.addNotification("[$currentConstruction] has been built in [$builtLocation]", cityInfo.location, Color.BROWN)
|
||||
for (civ in cityInfo.civInfo.gameInfo.civilizations) {
|
||||
val builtLocation = if (civ.exploredTiles.contains(cityInfo.location)) cityInfo.name else "a faraway land"
|
||||
civ.addNotification("[$currentConstruction] has been built in [$builtLocation]", cityInfo.location, Color.BROWN)
|
||||
}
|
||||
} else
|
||||
cityInfo.civInfo.addNotification("[$currentConstruction] has been built in [" + cityInfo.name + "]", cityInfo.location, Color.BROWN)
|
||||
|
||||
|
@ -23,6 +23,10 @@ import kotlin.math.max
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
enum class PlayerType{
|
||||
AI,
|
||||
Human
|
||||
}
|
||||
|
||||
class CivilizationInfo {
|
||||
@Transient lateinit var gameInfo: GameInfo
|
||||
@ -38,6 +42,7 @@ class CivilizationInfo {
|
||||
var gold = 0
|
||||
var happiness = 15
|
||||
var difficulty = "Chieftain"
|
||||
var playerType = PlayerType.AI
|
||||
var civName = ""
|
||||
var tech = TechManager()
|
||||
var policies = PolicyManager()
|
||||
@ -45,6 +50,7 @@ class CivilizationInfo {
|
||||
var greatPeople = GreatPersonManager()
|
||||
var scienceVictory = ScienceVictoryManager()
|
||||
var diplomacy = HashMap<String,DiplomacyManager>()
|
||||
var notifications = ArrayList<Notification>()
|
||||
|
||||
// if we only use lists, and change the list each time the cities are changed,
|
||||
// we won't get concurrent modification exceptions.
|
||||
@ -73,6 +79,7 @@ class CivilizationInfo {
|
||||
toReturn.diplomacy.putAll(diplomacy.values.map { it.clone() }.associateBy { it.otherCivName })
|
||||
toReturn.cities = cities.map { it.clone() }
|
||||
toReturn.exploredTiles.addAll(exploredTiles)
|
||||
toReturn.notifications.addAll(notifications)
|
||||
return toReturn
|
||||
}
|
||||
|
||||
@ -304,6 +311,8 @@ class CivilizationInfo {
|
||||
}
|
||||
|
||||
fun endTurn() {
|
||||
notifications.clear()
|
||||
|
||||
val nextTurnStats = getStatsForNextTurn()
|
||||
|
||||
policies.endTurn(nextTurnStats.culture.toInt())
|
||||
@ -363,8 +372,8 @@ class CivilizationInfo {
|
||||
}
|
||||
|
||||
fun addNotification(text: String, location: Vector2?,color: Color) {
|
||||
if(isPlayerCivilization())
|
||||
gameInfo.notifications.add(Notification(text, location,color))
|
||||
if(playerType==PlayerType.AI) return // no point in lengthening the saved game info if no one will read it
|
||||
notifications.add(Notification(text, location,color))
|
||||
}
|
||||
|
||||
fun addGreatPerson(greatPerson: String) {
|
||||
|
@ -148,7 +148,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
||||
tileMapHolder.updateTiles(civInfo)
|
||||
|
||||
topBar.update(cloneCivilization)
|
||||
notificationsScroll.update(gameClone.notifications)
|
||||
notificationsScroll.update(civInfo.notifications)
|
||||
notificationsScroll.width = stage.width/3
|
||||
notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f,
|
||||
nextTurnButton.y - notificationsScroll.height - 5f)
|
||||
|
Reference in New Issue
Block a user