mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-20 20:59:18 +07:00
When picking an improvement for a sleeping worker, it un-sleeps
This commit is contained in:
@ -11,18 +11,19 @@ import com.unciv.ui.utils.getRandom
|
|||||||
|
|
||||||
class GameInfo {
|
class GameInfo {
|
||||||
var notifications = mutableListOf<Notification>()
|
var notifications = mutableListOf<Notification>()
|
||||||
@Deprecated("As of 2.6.9") var tutorial = mutableListOf<String>()
|
@Deprecated("As of 2.6.9")
|
||||||
|
var tutorial = mutableListOf<String>()
|
||||||
var civilizations = mutableListOf<CivilizationInfo>()
|
var civilizations = mutableListOf<CivilizationInfo>()
|
||||||
var tileMap: TileMap = TileMap()
|
var tileMap: TileMap = TileMap()
|
||||||
var turns = 0
|
var turns = 0
|
||||||
|
|
||||||
//region pure functions
|
//region pure functions
|
||||||
fun clone():GameInfo{
|
fun clone(): GameInfo {
|
||||||
val toReturn = GameInfo()
|
val toReturn = GameInfo()
|
||||||
toReturn.tileMap=tileMap.clone()
|
toReturn.tileMap = tileMap.clone()
|
||||||
toReturn.civilizations.addAll(civilizations.map { it.clone() })
|
toReturn.civilizations.addAll(civilizations.map { it.clone() })
|
||||||
toReturn.notifications.addAll(notifications)
|
toReturn.notifications.addAll(notifications)
|
||||||
toReturn.turns=turns
|
toReturn.turns = turns
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,8 +35,8 @@ class GameInfo {
|
|||||||
notifications.clear()
|
notifications.clear()
|
||||||
val player = getPlayerCivilization()
|
val player = getPlayerCivilization()
|
||||||
|
|
||||||
for (civInfo in civilizations){
|
for (civInfo in civilizations) {
|
||||||
if(civInfo.tech.techsToResearch.isEmpty()){ // should belong in automation? yes/no?
|
if (civInfo.tech.techsToResearch.isEmpty()) { // should belong in automation? yes/no?
|
||||||
val researchableTechs = GameBasics.Technologies.values
|
val researchableTechs = GameBasics.Technologies.values
|
||||||
.filter { !civInfo.tech.isResearched(it.name) && civInfo.tech.canBeResearched(it.name) }
|
.filter { !civInfo.tech.isResearched(it.name) && civInfo.tech.canBeResearched(it.name) }
|
||||||
civInfo.tech.techsToResearch.add(researchableTechs.minBy { it.cost }!!.name)
|
civInfo.tech.techsToResearch.add(researchableTechs.minBy { it.cost }!!.name)
|
||||||
@ -46,12 +47,12 @@ class GameInfo {
|
|||||||
// We need to update the stats after ALL the cities are done updating because
|
// 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
|
// maybe one of them has a wonder that affects the stats of all the rest of the cities
|
||||||
|
|
||||||
for (civInfo in civilizations.filterNot { it==player || (it.isDefeated() && !it.isBarbarianCivilization()) }){
|
for (civInfo in civilizations.filterNot { it == player || (it.isDefeated() && !it.isBarbarianCivilization()) }) {
|
||||||
civInfo.startTurn()
|
civInfo.startTurn()
|
||||||
NextTurnAutomation().automateCivMoves(civInfo)
|
NextTurnAutomation().automateCivMoves(civInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +61,13 @@ class GameInfo {
|
|||||||
player.startTurn()
|
player.startTurn()
|
||||||
|
|
||||||
val enemyUnitsCloseToTerritory = player.getViewableTiles()
|
val enemyUnitsCloseToTerritory = player.getViewableTiles()
|
||||||
.filter { it.militaryUnit!=null && it.militaryUnit!!.civInfo!=player
|
.filter {
|
||||||
&& player.isAtWarWith(it.militaryUnit!!.civInfo)
|
it.militaryUnit != null && it.militaryUnit!!.civInfo != player
|
||||||
&& (it.getOwner()==player || it.neighbors.any { neighbor -> neighbor.getOwner()==player }) }
|
&& player.isAtWarWith(it.militaryUnit!!.civInfo)
|
||||||
for(enemyUnitTile in enemyUnitsCloseToTerritory) {
|
&& (it.getOwner() == player || it.neighbors.any { neighbor -> neighbor.getOwner() == player })
|
||||||
val inOrNear = if(enemyUnitTile.getOwner()==player) "in" else "near"
|
}
|
||||||
|
for (enemyUnitTile in enemyUnitsCloseToTerritory) {
|
||||||
|
val inOrNear = if (enemyUnitTile.getOwner() == player) "in" else "near"
|
||||||
val unitName = enemyUnitTile.militaryUnit!!.name
|
val unitName = enemyUnitTile.militaryUnit!!.name
|
||||||
player.addNotification("An enemy [$unitName] was spotted $inOrNear our territory", enemyUnitTile.position, Color.RED)
|
player.addNotification("An enemy [$unitName] was spotted $inOrNear our territory", enemyUnitTile.position, Color.RED)
|
||||||
}
|
}
|
||||||
@ -74,15 +77,15 @@ class GameInfo {
|
|||||||
|
|
||||||
fun placeBarbarianUnit(tileToPlace: TileInfo?) {
|
fun placeBarbarianUnit(tileToPlace: TileInfo?) {
|
||||||
var tile = tileToPlace
|
var tile = tileToPlace
|
||||||
if(tileToPlace==null) {
|
if (tileToPlace == null) {
|
||||||
// Barbarians will only spawn in places that no one can see
|
// Barbarians will only spawn in places that no one can see
|
||||||
val allViewableTiles = civilizations.filterNot { it.isBarbarianCivilization() }
|
val allViewableTiles = civilizations.filterNot { it.isBarbarianCivilization() }
|
||||||
.flatMap { it.getViewableTiles() }.toHashSet()
|
.flatMap { it.getViewableTiles() }.toHashSet()
|
||||||
val viableTiles = tileMap.values.filterNot { allViewableTiles.contains(it) || it.militaryUnit != null || it.civilianUnit!=null}
|
val viableTiles = tileMap.values.filterNot { allViewableTiles.contains(it) || it.militaryUnit != null || it.civilianUnit != null }
|
||||||
if(viableTiles.isEmpty()) return // no place for more barbs =(
|
if (viableTiles.isEmpty()) return // no place for more barbs =(
|
||||||
tile=viableTiles.getRandom()
|
tile = viableTiles.getRandom()
|
||||||
}
|
}
|
||||||
tileMap.placeUnitNearTile(tile!!.position,"Warrior",getBarbarianCivilization())
|
tileMap.placeUnitNearTile(tile!!.position, "Warrior", getBarbarianCivilization())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTransients() {
|
fun setTransients() {
|
||||||
@ -99,10 +102,10 @@ class GameInfo {
|
|||||||
|
|
||||||
val cityConstructions = cityInfo.cityConstructions
|
val cityConstructions = cityInfo.cityConstructions
|
||||||
// As of 2.9.6, removed hydro plant, since it requires rivers, which we do not yet have
|
// As of 2.9.6, removed hydro plant, since it requires rivers, which we do not yet have
|
||||||
if("Hydro Plant" in cityConstructions.builtBuildings)
|
if ("Hydro Plant" in cityConstructions.builtBuildings)
|
||||||
cityConstructions.builtBuildings.remove("Hydro Plant")
|
cityConstructions.builtBuildings.remove("Hydro Plant")
|
||||||
if(cityConstructions.currentConstruction=="Hydro Plant") {
|
if (cityConstructions.currentConstruction == "Hydro Plant") {
|
||||||
cityConstructions.currentConstruction=""
|
cityConstructions.currentConstruction = ""
|
||||||
cityConstructions.chooseNextConstruction()
|
cityConstructions.chooseNextConstruction()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,10 +20,11 @@ class ImprovementPickerScreen(tileInfo: TileInfo) : PickerScreen() {
|
|||||||
|
|
||||||
rightSideButton.setText("Pick improvement")
|
rightSideButton.setText("Pick improvement")
|
||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
tileInfo.startWorkingOnImprovement(selectedImprovement!!, civInfo)
|
tileInfo.startWorkingOnImprovement(selectedImprovement!!, civInfo)
|
||||||
game.setWorldScreen()
|
if(tileInfo.civilianUnit!=null) tileInfo.civilianUnit!!.action=null // this is to "wake up" the worker if it's sleeping
|
||||||
dispose()
|
game.setWorldScreen()
|
||||||
}
|
dispose()
|
||||||
|
}
|
||||||
|
|
||||||
val regularImprovements = VerticalGroup()
|
val regularImprovements = VerticalGroup()
|
||||||
regularImprovements.space(10f)
|
regularImprovements.space(10f)
|
||||||
@ -31,7 +32,6 @@ class ImprovementPickerScreen(tileInfo: TileInfo) : PickerScreen() {
|
|||||||
if (!tileInfo.canBuildImprovement(improvement, civInfo) || improvement.name == tileInfo.improvement) continue
|
if (!tileInfo.canBuildImprovement(improvement, civInfo) || improvement.name == tileInfo.improvement) continue
|
||||||
val improvementButton = Button(skin)
|
val improvementButton = Button(skin)
|
||||||
|
|
||||||
|
|
||||||
if(improvement.name.startsWith("Remove"))
|
if(improvement.name.startsWith("Remove"))
|
||||||
improvementButton.add(ImageGetter.getImage("OtherIcons/Stop.png")).size(30f).pad(10f)
|
improvementButton.add(ImageGetter.getImage("OtherIcons/Stop.png")).size(30f).pad(10f)
|
||||||
else improvementButton.add(ImageGetter.getImprovementIcon(improvement.name,30f)).pad(10f)
|
else improvementButton.add(ImageGetter.getImprovementIcon(improvement.name,30f)).pad(10f)
|
||||||
|
Reference in New Issue
Block a user