diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index 0bbe9bce..44016499 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -27,12 +27,13 @@ object Automation { rank += stats.production rank += stats.science / 2 rank += stats.culture / 2 - rank += stats.gold / 5 // it's barely worth anything at this points + rank += stats.gold / 5 // it's barely worth anything at this point } else { 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 + 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 rank += stats.production @@ -91,7 +92,7 @@ object Automation { // Since units become exponentially stronger per combat strength increase, we square em all fun square(x:Int) = x*x val unitStrength = civInfo.getCivUnits().map { square(max(it.baseUnit().strength, it.baseUnit().rangedStrength)) }.sum() - return (sqrt(unitStrength.toDouble())).toInt() + 1 //avoid 0, becaus we divide by the result + return sqrt(unitStrength.toDouble()).toInt() + 1 //avoid 0, because we divide by the result } fun threatAssessment(assessor:CivilizationInfo, assessed: CivilizationInfo): ThreatLevel { diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index 72c08744..1f8e0b7c 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -18,7 +18,7 @@ import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.translations.tr import kotlin.math.min -object NextTurnAutomation{ +object NextTurnAutomation { /** Top-level AI turn tasklist */ fun automateCivMoves(civInfo: CivilizationInfo) { @@ -30,8 +30,8 @@ object NextTurnAutomation{ if(civInfo.isMajorCiv()) { if(!civInfo.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)) { declareWar(civInfo) -// offerDeclarationOfFriendship(civInfo) offerPeaceTreaty(civInfo) +// offerDeclarationOfFriendship(civInfo) } offerResearchAgreement(civInfo) exchangeLuxuries(civInfo) diff --git a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt index 84a5be67..e95f302c 100644 --- a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt @@ -1,8 +1,8 @@ package com.unciv.logic.automation import com.unciv.logic.battle.MapUnitCombatant +import com.unciv.logic.city.CityInfo import com.unciv.logic.civilization.CivilizationInfo -import com.unciv.logic.civilization.GreatPersonManager import com.unciv.logic.civilization.diplomacy.DiplomacyFlags import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers import com.unciv.logic.map.MapUnit @@ -10,8 +10,6 @@ import com.unciv.logic.map.TileInfo import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.TileResource import com.unciv.models.stats.Stats -import com.unciv.models.translations.equalsPlaceholderText -import com.unciv.models.translations.getPlaceholderParameters import com.unciv.ui.worldscreen.unit.UnitActions object SpecificUnitAutomation { @@ -204,7 +202,16 @@ object SpecificUnitAutomation { for (bonus in it.cityStats.statPercentBonusList.values) stats.add(bonus) stats.toHashMap()[relatedStat]!! } + + for (city in citiesByStatBoost) { + val applicableTiles = city.getWorkableTiles().filter { + it.isLand && it.resource == null && !it.isCityCenter() + && (unit.currentTile == it || unit.movement.canMoveTo(it)) + && !it.containsGreatImprovement() + } + if (applicableTiles.none()) continue + val pathToCity = unit.movement.getShortestPath(city.getCenterTile()) if (pathToCity.isEmpty()) continue @@ -214,14 +221,9 @@ object SpecificUnitAutomation { } // if we got here, we're pretty close, start looking! - val chosenTile = city.getTiles() - .filter { - it.isLand && it.resource == null && !it.isCityCenter() - && (unit.currentTile == it || unit.movement.canMoveTo(it)) - && !it.containsGreatImprovement() - }.sortedByDescending { Automation.rankTile(it, unit.civInfo) } - .firstOrNull { unit.movement.canReach(it) } // to another city - if (chosenTile == null) continue + val chosenTile = applicableTiles.sortedByDescending { Automation.rankTile(it, unit.civInfo) } + .firstOrNull { unit.movement.canReach(it) } + if (chosenTile == null) continue // to another city unit.movement.headTowards(chosenTile) if (unit.currentTile == chosenTile)