Ai uses bombardment.
This commit is contained in:
parent
0f16a25cc6
commit
a2764d7b91
3 changed files with 25 additions and 1 deletions
|
@ -20,7 +20,7 @@ class UnCivGame : Game() {
|
|||
val viewEntireMapForDebug = false
|
||||
|
||||
// For when you need to test something in an advanced game and don't have time to faff around
|
||||
val superchargedForDebug = true
|
||||
val superchargedForDebug = false
|
||||
|
||||
lateinit var worldScreen: WorldScreen
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.unciv.logic.automation
|
||||
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.trade.TradeLogic
|
||||
|
@ -15,6 +16,7 @@ class NextTurnAutomation{
|
|||
adoptPolicy(civInfo)
|
||||
exchangeLuxuries(civInfo)
|
||||
declareWar(civInfo)
|
||||
automateCityBombardment(civInfo)
|
||||
automateUnits(civInfo)
|
||||
reassignWorkedTiles(civInfo)
|
||||
trainSettler(civInfo)
|
||||
|
@ -116,6 +118,10 @@ class NextTurnAutomation{
|
|||
for (unit in generals) UnitAutomation().automateUnitMoves(unit)
|
||||
}
|
||||
|
||||
private fun automateCityBombardment(civInfo: CivilizationInfo) {
|
||||
for (city in civInfo.cities) UnitAutomation().tryBombardEnemy(city)
|
||||
}
|
||||
|
||||
private fun reassignWorkedTiles(civInfo: CivilizationInfo) {
|
||||
for (city in civInfo.cities) {
|
||||
city.workedTiles = hashSetOf()
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.unciv.UnCivGame
|
|||
import com.unciv.logic.HexMath
|
||||
import com.unciv.logic.battle.Battle
|
||||
import com.unciv.logic.battle.BattleDamage
|
||||
import com.unciv.logic.battle.CityCombatant
|
||||
import com.unciv.logic.battle.MapUnitCombatant
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
|
@ -285,6 +286,17 @@ class UnitAutomation{
|
|||
return false
|
||||
}
|
||||
|
||||
fun tryBombardEnemy(city: CityInfo): Boolean {
|
||||
val target = chooseBombardTarget(city)
|
||||
if (target == null) return false
|
||||
if (city.attacksThisTurn == 0) {
|
||||
val enemy = Battle(city.civInfo.gameInfo).getMapCombatantOfTile(target)!!
|
||||
Battle(city.civInfo.gameInfo).attack(CityCombatant(city), enemy)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun chooseAttackTarget(unit: MapUnit, attackableEnemies: List<AttackableTile>): AttackableTile? {
|
||||
val cityTilesToAttack = attackableEnemies.filter { it.tileToAttack.isCityCenter() }
|
||||
val nonCityTilesToAttack = attackableEnemies.filter { !it.tileToAttack.isCityCenter() }
|
||||
|
@ -304,6 +316,12 @@ class UnitAutomation{
|
|||
return enemyTileToAttack
|
||||
}
|
||||
|
||||
private fun chooseBombardTarget(city: CityInfo) : TileInfo? {
|
||||
val targets = getBombardTargets(city)
|
||||
if (targets.isEmpty()) return null
|
||||
return targets.minBy { Battle(city.civInfo.gameInfo).getMapCombatantOfTile(it)!!.getHealth() }
|
||||
}
|
||||
|
||||
private fun tryGarrisoningUnit(unit: MapUnit): Boolean {
|
||||
if(unit.type.isMelee() || unit.type.isWaterUnit()) return false // don't garrison melee units, they're not that good at it
|
||||
val citiesWithoutGarrison = unit.civInfo.cities.filter {
|
||||
|
|
Loading…
Reference in a new issue