From c8e68842e941063155c7f5fc485a9e98fa2f8f33 Mon Sep 17 00:00:00 2001 From: Duan Tao Date: Fri, 11 Oct 2019 17:46:57 +0800 Subject: [PATCH 1/2] Added setting about auto-build roads. (#1181) * Added setting about auto-build roads. * AI tries to keep population growing if possible. --- .../com/unciv/logic/automation/Automation.kt | 12 ++++++------ .../unciv/logic/automation/WorkerAutomation.kt | 12 ++++++++---- core/src/com/unciv/logic/city/CityInfo.kt | 17 ++++++++++++----- .../com/unciv/logic/city/PopulationManager.kt | 6 +++--- .../com/unciv/models/metadata/GameSettings.kt | 1 + .../optionstable/WorldScreenOptionsTable.kt | 6 ++++++ 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index 227a8b1e52..30851a6d17 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -23,24 +23,24 @@ class Automation { return rank } - fun rankTileForCityWork(tile:TileInfo, city: CityInfo): Float { + fun rankTileForCityWork(tile:TileInfo, city: CityInfo, foodWeight: Float = 1f): Float { val stats = tile.getTileStats(city, city.civInfo) - return rankStatsForCityWork(stats, city) + return rankStatsForCityWork(stats, city, foodWeight) } - private fun rankStatsForCityWork(stats: Stats, city: CityInfo): Float { + private fun rankStatsForCityWork(stats: Stats, city: CityInfo, foodWeight: Float = 1f): Float { var rank = 0f if(city.population.population < 5){ // "small city" - we care more about food and less about global problems like gold science and culture - rank += stats.food * 1.2f + rank += stats.food * 1.2f * foodWeight rank += stats.production rank += stats.science/2 rank += stats.culture/2 rank += stats.gold / 5 // it's barely worth anything at this points } else{ - if (stats.food <= 2 || city.civInfo.getHappiness() > 5) rank += (stats.food * 1.2f) //food get more value to keep city growing - else rank += (2.4f + (stats.food - 2) / 2) // 1.2 point for each food up to 2, from there on half a point + if (stats.food <= 2 || city.civInfo.getHappiness() > 5) rank += (stats.food * 1.2f * foodWeight) //food get more value to keep city growing + else rank += ((2.4f + (stats.food - 2) / 2) * foodWeight) // 1.2 point for each food up to 2, from there on half a point if (city.civInfo.gold < 0 && city.civInfo.statsForNextTurn.gold <= 0) rank += stats.gold // we have a global problem else rank += stats.gold / 3 // 3 gold is worse than 2 production diff --git a/core/src/com/unciv/logic/automation/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/WorkerAutomation.kt index 914ab30334..65a3cfc85f 100644 --- a/core/src/com/unciv/logic/automation/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/WorkerAutomation.kt @@ -2,6 +2,7 @@ package com.unciv.logic.automation import com.badlogic.gdx.graphics.Color import com.unciv.Constants +import com.unciv.UnCivGame import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.map.BFS import com.unciv.logic.map.MapUnit @@ -24,7 +25,7 @@ class WorkerAutomation(val unit: MapUnit) { val tileToWork = findTileToWork() if (getPriority(tileToWork, unit.civInfo) < 3) { // building roads is more important - if (tryConnectingCities()) return + if (tryConnectingCities(unit)) return } if (tileToWork != currentTile) { @@ -41,7 +42,7 @@ class WorkerAutomation(val unit: MapUnit) { } } if (currentTile.improvementInProgress != null) return // we're working! - if (tryConnectingCities()) return //nothing to do, try again to connect cities + if (tryConnectingCities(unit)) return //nothing to do, try again to connect cities val citiesToNumberOfUnimprovedTiles = HashMap() for (city in unit.civInfo.cities) { @@ -53,7 +54,7 @@ class WorkerAutomation(val unit: MapUnit) { .filter { citiesToNumberOfUnimprovedTiles[it.name]!! > 0 } .sortedByDescending { citiesToNumberOfUnimprovedTiles[it.name] } .firstOrNull { unit.movement.canReach(it.ccenterTile) } //goto most undeveloped city - if (mostUndevelopedCity != null) { + if (mostUndevelopedCity != null && mostUndevelopedCity != unit.currentTile.owningCity) { val reachedTile = unit.movement.headTowards(mostUndevelopedCity.ccenterTile) if (reachedTile != currentTile) unit.doPreTurnAction() // since we've moved, maybe we can do something here - automate return @@ -64,7 +65,10 @@ class WorkerAutomation(val unit: MapUnit) { - private fun tryConnectingCities():Boolean { // returns whether we actually did anything + private fun tryConnectingCities(unit: MapUnit):Boolean { // returns whether we actually did anything + //Player can choose not to auto-build roads & railroads. + if (unit.civInfo.isPlayerCivilization() && !UnCivGame.Current.settings.autoBuildingRoads) + return false val targetRoad = unit.civInfo.tech.getBestRoadAvailable() diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 65d4e60ed2..61ac51f389 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -229,11 +229,18 @@ class CityInfo { } fun reassignWorkers() { - workedTiles = hashSetOf() - population.specialists.clear() - for (i in 0..population.population) - population.autoAssignPopulation() - cityStats.update() + var foodWeight = 1f + var foodPerTurn = 0f + while (foodWeight < 3 && foodPerTurn <= 0) { + workedTiles = hashSetOf() + population.specialists.clear() + for (i in 0..population.population) + population.autoAssignPopulation(foodWeight) + cityStats.update() + + foodPerTurn = cityStats.currentCityStats.food + foodWeight += 0.5f + } } fun endTurn() { diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index c204d4f48f..747fe3d64f 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -73,16 +73,16 @@ class PopulationManager { // todo - change tile choice according to city! // if small city, favor production above all, ignore gold! // if larger city, food should be worth less! - internal fun autoAssignPopulation() { + internal fun autoAssignPopulation(foodWeight: Float = 1f) { if(getFreePopulation()==0) return //evaluate tiles val bestTile: TileInfo? = cityInfo.getTiles() .filter { it.arialDistanceTo(cityInfo.getCenterTile()) <= 3 } .filterNot { cityInfo.workedTiles.contains(it.position) || cityInfo.location==it.position} - .maxBy { Automation().rankTileForCityWork(it,cityInfo) } + .maxBy { Automation().rankTileForCityWork(it,cityInfo, foodWeight) } val valueBestTile = if(bestTile==null) 0f - else Automation().rankTileForCityWork(bestTile, cityInfo) + else Automation().rankTileForCityWork(bestTile, cityInfo, foodWeight) //evaluate specialists val maxSpecialistsMap = getMaxSpecialists().toHashMap() diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index 16cefafd5c..2111450218 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -17,6 +17,7 @@ class GameSettings { var tileSet:String = "FantasyHex" var showTutorials: Boolean = true var autoAssignCityProduction: Boolean = true + var autoBuildingRoads: Boolean = true var showMinimap: Boolean = true var userName:String="" diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index 033e88bed5..8d2821f820 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -80,6 +80,12 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr update() } + innerTable.add("Auto-build roads".toLabel()) + innerTable.addButton(if(settings.autoBuildingRoads) "Yes".tr() else "No".tr()) { + settings.autoBuildingRoads= !settings.autoBuildingRoads + update() + } + innerTable.add("Show minimap".toLabel()) innerTable.addButton(if(settings.showMinimap) "Yes".tr() else "No".tr()) { settings.showMinimap= !settings.showMinimap From 6fdfc5a72cc6e5ccacdcb7268f4ef4e59586ddcb Mon Sep 17 00:00:00 2001 From: Smashfanful <41149920+Smashfanful@users.noreply.github.com> Date: Fri, 11 Oct 2019 11:47:18 +0200 Subject: [PATCH 2/2] Update Techs.json (#1183) --- android/assets/jsons/Translations/Techs.json | 1 + 1 file changed, 1 insertion(+) diff --git a/android/assets/jsons/Translations/Techs.json b/android/assets/jsons/Translations/Techs.json index 7b3d767b90..ee15f6285c 100644 --- a/android/assets/jsons/Translations/Techs.json +++ b/android/assets/jsons/Translations/Techs.json @@ -1014,6 +1014,7 @@ } "'The introduction of so powerful an agent as steam to a carriage on wheels will make a great change in the situation of man.' - Thomas Jefferson":{//"Railroad" Technology quotes, it has been translated somewhere. + Italian: "'L'introduzione sui carri a ruote di un agente potente come il vapore apporterà un grande cambiamento alla condizione dell'uomo.' - Thomas Jefferson" Simplified_Chinese:"“引入蒸汽这样一个强大的助手来驱动车轮进行运输,将极大地改变人类的境地。”——托马斯·杰斐逊" }