Merge pull request #386 from ninjatao/worker_automate
Worker automation uses more resource.
This commit is contained in:
commit
7f9ca0fd3d
3 changed files with 22 additions and 10 deletions
|
@ -30,7 +30,7 @@ class WorkerAutomation(val unit: MapUnit) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (tile.improvementInProgress == null && tile.isLand()) {
|
if (tile.improvementInProgress == null && tile.isLand()) {
|
||||||
val improvement = chooseImprovement(tile)
|
val improvement = chooseImprovement(tile, unit.civInfo)
|
||||||
if (tile.canBuildImprovement(improvement, unit.civInfo)) {
|
if (tile.canBuildImprovement(improvement, unit.civInfo)) {
|
||||||
// What if we're stuck on this tile but can't build there?
|
// What if we're stuck on this tile but can't build there?
|
||||||
tile.startWorkingOnImprovement(improvement, unit.civInfo)
|
tile.startWorkingOnImprovement(improvement, unit.civInfo)
|
||||||
|
@ -98,10 +98,10 @@ class WorkerAutomation(val unit: MapUnit) {
|
||||||
val workableTiles = currentTile.getTilesInDistance(4)
|
val workableTiles = currentTile.getTilesInDistance(4)
|
||||||
.filter {
|
.filter {
|
||||||
(it.civilianUnit== null || it == currentTile)
|
(it.civilianUnit== null || it == currentTile)
|
||||||
&& it.improvement == null
|
&& (it.improvement == null || (it.hasViewableResource(unit.civInfo) && !it.containsGreatImprovement() && it.getTileResource().improvement != it.improvement))
|
||||||
&& it.isLand()
|
&& it.isLand()
|
||||||
&& !it.getBaseTerrain().impassable
|
&& !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
|
&& {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()
|
}.sortedByDescending { getPriority(it, unit.civInfo) }.toMutableList()
|
||||||
|
|
||||||
|
@ -131,14 +131,21 @@ class WorkerAutomation(val unit: MapUnit) {
|
||||||
return priority
|
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 {
|
val improvementString = when {
|
||||||
tile.improvementInProgress != null -> tile.improvementInProgress
|
tile.improvementInProgress != null -> tile.improvementInProgress
|
||||||
|
improvementStringForResource != null -> improvementStringForResource
|
||||||
tile.terrainFeature == "Jungle" -> "Trading post"
|
tile.terrainFeature == "Jungle" -> "Trading post"
|
||||||
tile.terrainFeature == "Marsh" -> "Remove Marsh"
|
tile.terrainFeature == "Marsh" -> "Remove Marsh"
|
||||||
tile.terrainFeature == "Forest" &&
|
tile.terrainFeature == "Forest" -> "Lumber mill"
|
||||||
(tile.resource == null || tile.getTileResource().improvement!="Camp") -> "Lumber mill"
|
|
||||||
tile.resource != null -> tile.getTileResource().improvement
|
|
||||||
tile.baseTerrain == "Hill" -> "Mine"
|
tile.baseTerrain == "Hill" -> "Mine"
|
||||||
tile.baseTerrain in listOf("Grassland","Desert","Plains") -> "Farm"
|
tile.baseTerrain in listOf("Grassland","Desert","Plains") -> "Farm"
|
||||||
tile.baseTerrain == "Tundra" -> "Trading post"
|
tile.baseTerrain == "Tundra" -> "Trading post"
|
||||||
|
|
|
@ -44,6 +44,11 @@ open class TileInfo {
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun containsGreatImprovement(): Boolean {
|
||||||
|
if (getTileImprovement() == null) return false
|
||||||
|
return getTileImprovement()!!.name in listOf("Academy", "Landmark", "Manufactory", "Customs house")
|
||||||
|
}
|
||||||
|
|
||||||
//region pure functions
|
//region pure functions
|
||||||
fun getUnits(): List<MapUnit> {
|
fun getUnits(): List<MapUnit> {
|
||||||
val list = ArrayList<MapUnit>(2)
|
val list = ArrayList<MapUnit>(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.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"))
|
if (improvement.name == "Trading post" && city != null && city.civInfo.policies.isAdopted("Free Thought"))
|
||||||
stats.science += 1f
|
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
|
stats.add(improvement) // again, for the double effect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,8 +155,8 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci
|
||||||
val ourCombatStrength = Automation().evaluteCombatStrength(ourCivilization)
|
val ourCombatStrength = Automation().evaluteCombatStrength(ourCivilization)
|
||||||
val theirCombatStrength = Automation().evaluteCombatStrength(otherCivilization)
|
val theirCombatStrength = Automation().evaluteCombatStrength(otherCivilization)
|
||||||
if(ourCombatStrength==theirCombatStrength) return 0
|
if(ourCombatStrength==theirCombatStrength) return 0
|
||||||
if(ourCombatStrength==0) return 1000
|
if(ourCombatStrength==0) return -1000
|
||||||
if(theirCombatStrength==0) return -1000 // Chumps got no cities or units
|
if(theirCombatStrength==0) return 1000 // Chumps got no cities or units
|
||||||
if(ourCombatStrength>theirCombatStrength){
|
if(ourCombatStrength>theirCombatStrength){
|
||||||
val absoluteAdvantage = ourCombatStrength-theirCombatStrength
|
val absoluteAdvantage = ourCombatStrength-theirCombatStrength
|
||||||
val percentageAdvantage = absoluteAdvantage / theirCombatStrength.toFloat()
|
val percentageAdvantage = absoluteAdvantage / theirCombatStrength.toFloat()
|
||||||
|
|
Loading…
Reference in a new issue