mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-25 12:54:06 -04:00
Simplified automated unit order
This commit is contained in:
parent
1b8c98eed3
commit
166b8ff2bf
@ -21,7 +21,6 @@ import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.logic.map.BFS
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.trade.Trade
|
||||
import com.unciv.logic.trade.TradeEvaluation
|
||||
@ -861,31 +860,16 @@ object NextTurnAutomation {
|
||||
|
||||
|
||||
private fun automateUnits(civInfo: CivilizationInfo) {
|
||||
val rangedUnits = mutableListOf<MapUnit>()
|
||||
val meleeUnits = mutableListOf<MapUnit>()
|
||||
val civilianUnits = mutableListOf<MapUnit>()
|
||||
val generals = mutableListOf<MapUnit>()
|
||||
|
||||
for (unit in civInfo.getCivUnits()) {
|
||||
if (unit.promotions.canBePromoted()) {
|
||||
val availablePromotions = unit.promotions.getAvailablePromotions()
|
||||
if (availablePromotions.any())
|
||||
unit.promotions.addPromotion(availablePromotions.toList().random().name)
|
||||
}
|
||||
|
||||
val sortedUnits = civInfo.getCivUnits().sortedBy { unit ->
|
||||
when {
|
||||
unit.baseUnit.isRanged() -> rangedUnits.add(unit)
|
||||
unit.baseUnit.isMelee() -> meleeUnits.add(unit)
|
||||
unit.isGreatPersonOfType("War")
|
||||
-> generals.add(unit) // Generals move after military units
|
||||
else -> civilianUnits.add(unit)
|
||||
unit.baseUnit.isAirUnit() -> 2
|
||||
unit.baseUnit.isRanged() -> 3
|
||||
unit.baseUnit.isMelee() -> 4
|
||||
unit.isGreatPersonOfType("War") -> 5 // Generals move after military units
|
||||
else -> 1 // Civilian
|
||||
}
|
||||
}
|
||||
|
||||
for (unit in civilianUnits) UnitAutomation.automateUnitMoves(unit) // They move first so that combat units can accompany a settler
|
||||
for (unit in rangedUnits) UnitAutomation.automateUnitMoves(unit)
|
||||
for (unit in meleeUnits) UnitAutomation.automateUnitMoves(unit)
|
||||
for (unit in generals) UnitAutomation.automateUnitMoves(unit)
|
||||
for (unit in sortedUnits) UnitAutomation.automateUnitMoves(unit)
|
||||
}
|
||||
|
||||
private fun automateCityBombardment(civInfo: CivilizationInfo) {
|
||||
|
@ -241,7 +241,7 @@ object SpecificUnitAutomation {
|
||||
}
|
||||
|
||||
fun automateImprovementPlacer(unit: MapUnit) {
|
||||
var improvementBuildingUniques = unit.getMatchingUniques(UniqueType.ConstructImprovementConsumingUnit)
|
||||
val improvementBuildingUniques = unit.getMatchingUniques(UniqueType.ConstructImprovementConsumingUnit)
|
||||
|
||||
val improvementName = improvementBuildingUniques.first().params[0]
|
||||
val improvement = unit.civInfo.gameInfo.ruleSet.tileImprovements[improvementName]
|
||||
@ -415,6 +415,7 @@ object SpecificUnitAutomation {
|
||||
.flatMap { it.airUnits.asSequence() }.filter { it.civInfo.isAtWarWith(unit.civInfo) }
|
||||
|
||||
if (enemyAirUnitsInRange.any()) return // we need to be on standby in case they attack
|
||||
|
||||
if (BattleHelper.tryAttackNearbyEnemy(unit)) return
|
||||
|
||||
if (tryRelocateToCitiesWithEnemyNearBy(unit)) return
|
||||
|
@ -137,6 +137,12 @@ object UnitAutomation {
|
||||
// Might die next turn - move!
|
||||
if (unit.health <= unit.getDamageFromTerrain() && tryHealUnit(unit)) return
|
||||
|
||||
if (unit.promotions.canBePromoted()) {
|
||||
val availablePromotions = unit.promotions.getAvailablePromotions()
|
||||
if (availablePromotions.any())
|
||||
unit.promotions.addPromotion(availablePromotions.toList().random().name)
|
||||
}
|
||||
|
||||
if (unit.isCivilian()) {
|
||||
if (tryRunAwayIfNeccessary(unit)) return
|
||||
|
||||
@ -441,8 +447,7 @@ object UnitAutomation {
|
||||
.filter { unit.civInfo.isAtWarWith(it) && it.cities.isNotEmpty() }
|
||||
|
||||
val closestEnemyCity = enemies
|
||||
.map { NextTurnAutomation.getClosestCities(unit.civInfo, it) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { NextTurnAutomation.getClosestCities(unit.civInfo, it) }
|
||||
.minByOrNull { it.aerialDistance }?.city2
|
||||
?: return false // no attackable cities found
|
||||
|
||||
|
@ -672,16 +672,17 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
||||
OneTimeAmountFreeTechs("[amount] Free Technologies", UniqueTarget.Triggerable), // used in Policy
|
||||
OneTimeFreeTechRuins("[amount] free random researchable Tech(s) from the [era]", UniqueTarget.Ruins),
|
||||
OneTimeRevealEntireMap("Reveals the entire map", UniqueTarget.Triggerable), // used in tech
|
||||
OneTimeFreeBelief("Gain a free [beliefType] belief", UniqueTarget.Triggerable),
|
||||
OneTimeTriggerVoting("Triggers voting for the Diplomatic Victory", UniqueTarget.Triggerable), // used in Building
|
||||
|
||||
OneTimeGainStat("Gain [amount] [stat]", UniqueTarget.Ruins),
|
||||
OneTimeGainStatRange("Gain [amount]-[amount] [stat]", UniqueTarget.Ruins),
|
||||
OneTimeGainPantheon("Gain enough Faith for a Pantheon", UniqueTarget.Ruins),
|
||||
OneTimeFreeBelief("Gain a free [beliefType] belief", UniqueTarget.Triggerable),
|
||||
OneTimeGainProphet("Gain enough Faith for [amount]% of a Great Prophet", UniqueTarget.Ruins),
|
||||
// todo: The "up to [All]" used in vanilla json is not nice to read. Split?
|
||||
// Or just reword it without the 'up to', so it reads "Reveal [amount/'all'] [tileFilter] tiles within [amount] tiles"
|
||||
OneTimeRevealSpecificMapTiles("Reveal up to [amount/'all'] [tileFilter] within a [amount] tile radius", UniqueTarget.Ruins),
|
||||
OneTimeRevealCrudeMap("From a randomly chosen tile [amount] tiles away from the ruins, reveal tiles up to [amount] tiles away with [amount]% chance", UniqueTarget.Ruins),
|
||||
OneTimeTriggerVoting("Triggers voting for the Diplomatic Victory", UniqueTarget.Triggerable), // used in Building
|
||||
OneTimeGlobalAlert("Triggers the following global alert: [comment]", UniqueTarget.Policy), // used in Policy
|
||||
OneTimeGlobalSpiesWhenEnteringEra("Every major Civilization gains a spy once a civilization enters this era", UniqueTarget.Era),
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user