mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 06:51:30 -04:00
Domination-victory AI declare war on close civs even when having an advantage that isn't an absolute advantage,
and declare war on civs that are situated far away if they are weak enough and there's no one close by
This commit is contained in:
parent
275fa5842a
commit
4d5f3a51e3
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.app"
|
applicationId "com.unciv.app"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 264
|
versionCode 266
|
||||||
versionName "2.17.11"
|
versionName "2.17.12-patch1"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Had to add this crap for Travis to build, it wanted to sign the app
|
// Had to add this crap for Travis to build, it wanted to sign the app
|
||||||
|
@ -261,7 +261,7 @@ class Automation {
|
|||||||
fun square(x:Int) = x*x
|
fun square(x:Int) = x*x
|
||||||
val unitStrength = civInfo.getCivUnits().map { square(max(it.baseUnit().strength, it.baseUnit().rangedStrength)) }.sum()
|
val unitStrength = civInfo.getCivUnits().map { square(max(it.baseUnit().strength, it.baseUnit().rangedStrength)) }.sum()
|
||||||
val cityStrength = civInfo.cities.map { square(CityCombatant(it).getCityStrength()) }.sum()
|
val cityStrength = civInfo.cities.map { square(CityCombatant(it).getCityStrength()) }.sum()
|
||||||
return (sqrt(unitStrength.toDouble()) /*+ sqrt(cityStrength.toDouble())*/).toInt() + 1 //avoid 0
|
return (sqrt(unitStrength.toDouble()) /*+ sqrt(cityStrength.toDouble())*/).toInt() + 1 //avoid 0, becaus we divide by the result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun threatAssessment(assessor:CivilizationInfo, assessed: CivilizationInfo): ThreatLevel {
|
fun threatAssessment(assessor:CivilizationInfo, assessed: CivilizationInfo): ThreatLevel {
|
||||||
|
@ -329,30 +329,36 @@ class NextTurnAutomation{
|
|||||||
|
|
||||||
private fun declareWar(civInfo: CivilizationInfo) {
|
private fun declareWar(civInfo: CivilizationInfo) {
|
||||||
if (civInfo.isCityState()) return
|
if (civInfo.isCityState()) return
|
||||||
if (civInfo.victoryType()==VictoryType.Cultural)
|
if (civInfo.victoryType() == VictoryType.Cultural) return
|
||||||
return
|
if (civInfo.cities.isEmpty() || civInfo.diplomacy.isEmpty()) return
|
||||||
|
if (civInfo.isAtWar() || civInfo.getHappiness() <= 0) return
|
||||||
|
|
||||||
if (civInfo.cities.isNotEmpty() && civInfo.diplomacy.isNotEmpty()) {
|
val ourMilitaryUnits = civInfo.getCivUnits().filter { !it.type.isCivilian() }.size
|
||||||
val ourMilitaryUnits = civInfo.getCivUnits().filter { !it.type.isCivilian() }.size
|
if (ourMilitaryUnits < civInfo.cities.size) return
|
||||||
if (!civInfo.isAtWar() && civInfo.getHappiness() > 0
|
|
||||||
&& ourMilitaryUnits >= civInfo.cities.size) { //evaluate war
|
|
||||||
val ourCombatStrength = Automation().evaluteCombatStrength(civInfo)
|
|
||||||
val enemyCivsByDistanceToOurs = civInfo.getKnownCivs()
|
|
||||||
.filterNot { it == civInfo || it.cities.isEmpty() || !civInfo.getDiplomacyManager(it).canDeclareWar() }
|
|
||||||
.groupBy { getMinDistanceBetweenCities(civInfo, it) }
|
|
||||||
.toSortedMap()
|
|
||||||
|
|
||||||
for (group in enemyCivsByDistanceToOurs) {
|
//evaluate war
|
||||||
if (group.key > 7) break
|
val enemyCivs = civInfo.getKnownCivs()
|
||||||
for (otherCiv in group.value) {
|
.filterNot { it == civInfo || it.cities.isEmpty() || !civInfo.getDiplomacyManager(it).canDeclareWar() }
|
||||||
if (Automation().evaluteCombatStrength(otherCiv) * 2 < ourCombatStrength) {
|
if (enemyCivs.isEmpty()) return
|
||||||
civInfo.getDiplomacyManager(otherCiv).declareWar()
|
|
||||||
return
|
var enemyCivsToEvaluate = enemyCivs.filter { getMinDistanceBetweenCities(civInfo, it) <= 7 }
|
||||||
}
|
|
||||||
}
|
var isFightingFarAway = false
|
||||||
}
|
if (enemyCivsToEvaluate.isEmpty()) { // so, there ARE civs we can declare war on, just not close by
|
||||||
}
|
if (civInfo.victoryType() != VictoryType.Domination) return // No point in attacking civs that are too far away
|
||||||
|
enemyCivsToEvaluate = enemyCivs
|
||||||
|
isFightingFarAway = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val weakestCloseCiv = enemyCivsToEvaluate.minBy { Automation().evaluteCombatStrength(it) }!!
|
||||||
|
val weakestCloseCivCombatStrength = Automation().evaluteCombatStrength(weakestCloseCiv)
|
||||||
|
val ourCombatStrength = Automation().evaluteCombatStrength(civInfo)
|
||||||
|
|
||||||
|
val amountWeNeedToBeStronger =
|
||||||
|
if (civInfo.victoryType() == VictoryType.Domination && !isFightingFarAway) 1.5f else 2f
|
||||||
|
|
||||||
|
if (weakestCloseCivCombatStrength * amountWeNeedToBeStronger < ourCombatStrength)
|
||||||
|
civInfo.getDiplomacyManager(weakestCloseCiv).declareWar()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun automateUnits(civInfo: CivilizationInfo) {
|
private fun automateUnits(civInfo: CivilizationInfo) {
|
||||||
|
@ -11,7 +11,7 @@ import com.badlogic.gdx.utils.Array
|
|||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
import java.util.LinkedHashMap
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
@ -26,7 +26,7 @@ class Tutorials{
|
|||||||
|
|
||||||
|
|
||||||
fun displayTutorials(name: String, stage: Stage) {
|
fun displayTutorials(name: String, stage: Stage) {
|
||||||
if (UnCivGame.Current.settings.showTutorials) return
|
if (!UnCivGame.Current.settings.showTutorials) return
|
||||||
if (UnCivGame.Current.settings.tutorialsShown.contains(name)) return
|
if (UnCivGame.Current.settings.tutorialsShown.contains(name)) return
|
||||||
val texts = getTutorials(name, UnCivGame.Current.settings.language)
|
val texts = getTutorials(name, UnCivGame.Current.settings.language)
|
||||||
tutorialTexts.add(Tutorial(name,texts))
|
tutorialTexts.add(Tutorial(name,texts))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user