From 922a29e60f668e5cada7b6367b4aef203a4a3080 Mon Sep 17 00:00:00 2001 From: Duan Tao Date: Sun, 30 Dec 2018 11:46:27 +0800 Subject: [PATCH 1/3] Worker automation uses more resource. --- .../logic/automation/WorkerAutomation.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/com/unciv/logic/automation/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/WorkerAutomation.kt index f71d2dc900..24713acd5b 100644 --- a/core/src/com/unciv/logic/automation/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/WorkerAutomation.kt @@ -30,7 +30,7 @@ class WorkerAutomation(val unit: MapUnit) { return } if (tile.improvementInProgress == null && tile.isLand()) { - val improvement = chooseImprovement(tile) + val improvement = chooseImprovement(tile, unit.civInfo) if (tile.canBuildImprovement(improvement, unit.civInfo)) { // What if we're stuck on this tile but can't build there? tile.startWorkingOnImprovement(improvement, unit.civInfo) @@ -98,10 +98,10 @@ class WorkerAutomation(val unit: MapUnit) { val workableTiles = currentTile.getTilesInDistance(4) .filter { (it.civilianUnit== null || it == currentTile) - && it.improvement == null + && (it.improvement == null || (it.hasViewableResource(unit.civInfo) && it.getTileResource().improvement != it.improvement)) && it.isLand() && !it.getBaseTerrain().impassable - && it.canBuildImprovement(chooseImprovement(it), unit.civInfo) + && it.canBuildImprovement(chooseImprovement(it, unit.civInfo), unit.civInfo) && {val city=it.getCity(); city==null || it.getCity()?.civInfo == unit.civInfo}() // don't work tiles belonging to another civ }.sortedByDescending { getPriority(it, unit.civInfo) }.toMutableList() @@ -131,14 +131,21 @@ class WorkerAutomation(val unit: MapUnit) { return priority } - private fun chooseImprovement(tile: TileInfo): TileImprovement { + private fun chooseImprovement(tile: TileInfo, civInfo: CivilizationInfo): TileImprovement { + val improvementStringForResource : String ?= when { + tile.resource == null || !tile.hasViewableResource(civInfo) -> null + tile.terrainFeature == "Marsh" -> "Remove Marsh" + tile.terrainFeature == "Jungle" -> "Remove Jungle" + tile.terrainFeature == "Forest" && tile.getTileResource().improvement!="Camp" -> "Remove Forest" + else -> tile.getTileResource().improvement + } + val improvementString = when { tile.improvementInProgress != null -> tile.improvementInProgress + improvementStringForResource != null -> improvementStringForResource tile.terrainFeature == "Jungle" -> "Trading post" tile.terrainFeature == "Marsh" -> "Remove Marsh" - tile.terrainFeature == "Forest" && - (tile.resource == null || tile.getTileResource().improvement!="Camp") -> "Lumber mill" - tile.resource != null -> tile.getTileResource().improvement + tile.terrainFeature == "Forest" -> "Lumber mill" tile.baseTerrain == "Hill" -> "Mine" tile.baseTerrain in listOf("Grassland","Desert","Plains") -> "Farm" tile.baseTerrain == "Tundra" -> "Trading post" From be80aaecdab3e3cbba4eadb67dd34f0875602ed8 Mon Sep 17 00:00:00 2001 From: Duan Tao Date: Sun, 30 Dec 2018 19:19:06 +0800 Subject: [PATCH 2/3] Worker automation leaves great tile improvement alone. --- core/src/com/unciv/logic/automation/WorkerAutomation.kt | 2 +- core/src/com/unciv/logic/map/TileInfo.kt | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/automation/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/WorkerAutomation.kt index 24713acd5b..cf022f8cbe 100644 --- a/core/src/com/unciv/logic/automation/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/WorkerAutomation.kt @@ -98,7 +98,7 @@ class WorkerAutomation(val unit: MapUnit) { val workableTiles = currentTile.getTilesInDistance(4) .filter { (it.civilianUnit== null || it == currentTile) - && (it.improvement == null || (it.hasViewableResource(unit.civInfo) && it.getTileResource().improvement != it.improvement)) + && (it.improvement == null || (it.hasViewableResource(unit.civInfo) && !it.containsGreatImprovement() && it.getTileResource().improvement != it.improvement)) && it.isLand() && !it.getBaseTerrain().impassable && it.canBuildImprovement(chooseImprovement(it, unit.civInfo), unit.civInfo) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 16edd89db1..b1430f4d26 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -44,6 +44,11 @@ open class TileInfo { return toReturn } + fun containsGreatImprovement(): Boolean { + if (getTileImprovement() == null) return false + return getTileImprovement()!!.name in listOf("Academy", "Landmark", "Manufactory", "Customs house") + } + //region pure functions fun getUnits(): List { val list = ArrayList(2) @@ -162,7 +167,7 @@ open class TileInfo { if (improvement.improvingTech != null && observingCiv.tech.isResearched(improvement.improvingTech!!)) stats.add(improvement.improvingTechStats!!) // eg Chemistry for mines if (improvement.name == "Trading post" && city != null && city.civInfo.policies.isAdopted("Free Thought")) stats.science += 1f - if (improvement.name in listOf("Academy", "Landmark", "Manufactory", "Customs house") && observingCiv.policies.isAdopted("Freedom Complete")) + if (containsGreatImprovement() && observingCiv.policies.isAdopted("Freedom Complete")) stats.add(improvement) // again, for the double effect } From 5f3da79484febec9ac109c8e2f6bb20d125b12e8 Mon Sep 17 00:00:00 2001 From: Duan Tao Date: Sun, 30 Dec 2018 19:22:40 +0800 Subject: [PATCH 3/3] Fix evalutate peace treaty bug. --- core/src/com/unciv/logic/trade/TradeLogic.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index abccc618bc..d80e534980 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -155,8 +155,8 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci val ourCombatStrength = Automation().evaluteCombatStrength(ourCivilization) val theirCombatStrength = Automation().evaluteCombatStrength(otherCivilization) if(ourCombatStrength==theirCombatStrength) return 0 - if(ourCombatStrength==0) return 1000 - if(theirCombatStrength==0) return -1000 // Chumps got no cities or units + if(ourCombatStrength==0) return -1000 + if(theirCombatStrength==0) return 1000 // Chumps got no cities or units if(ourCombatStrength>theirCombatStrength){ val absoluteAdvantage = ourCombatStrength-theirCombatStrength val percentageAdvantage = absoluteAdvantage / theirCombatStrength.toFloat()