mirror of
https://github.com/yairm210/Unciv.git
synced 2025-08-04 09:09:21 +07:00
Resolved #469 - AI Great General tries to maximize effect on troops
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.6 KiB |
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 885 KiB After Width: | Height: | Size: 879 KiB |
@ -17,7 +17,7 @@ class UnCivGame : Game() {
|
||||
* This exists so that when debugging we can see the entire map.
|
||||
* Remember to turn this to false before commit and upload!
|
||||
*/
|
||||
val viewEntireMapForDebug = false
|
||||
val viewEntireMapForDebug = true
|
||||
|
||||
// For when you need to test something in an advanced game and don't have time to faff around
|
||||
val superchargedForDebug = false
|
||||
|
@ -31,7 +31,7 @@ class UnitAutomation{
|
||||
}
|
||||
|
||||
if (unit.name == "Great General")
|
||||
return SpecificUnitAutomation().automateGeneral(unit)
|
||||
return SpecificUnitAutomation().automateGreatGeneral(unit)
|
||||
|
||||
if(unit.name.startsWith("Great")
|
||||
&& unit.name in GreatPersonManager().statToGreatPersonMapping.values){ // So "Great War Infantry" isn't caught here
|
||||
@ -463,28 +463,33 @@ class SpecificUnitAutomation{
|
||||
else UnitAutomation().explore(unit, unit.getDistanceToTiles())
|
||||
}
|
||||
|
||||
fun automateGeneral(unit: MapUnit){
|
||||
fun automateGreatGeneral(unit: MapUnit){
|
||||
//try to follow nearby units. Do not garrison in city if possible
|
||||
val militantToCompany = unit.getDistanceToTiles().map { it.key }
|
||||
.firstOrNull {val militant = it.militaryUnit
|
||||
val militaryUnitTilesInDistance = unit.getDistanceToTiles().map { it.key }
|
||||
.filter {val militant = it.militaryUnit
|
||||
militant != null && militant.civInfo == unit.civInfo
|
||||
&& (it.civilianUnit == null || it.civilianUnit == unit)
|
||||
&& militant.getMaxMovement() <= 2.0f && !it.isCityCenter()}
|
||||
&& militant.getMaxMovement() <= 2 && !it.isCityCenter()}
|
||||
|
||||
if(militantToCompany!=null) {
|
||||
unit.movementAlgs().headTowards(militantToCompany)
|
||||
if(militaryUnitTilesInDistance.isNotEmpty()) {
|
||||
val tilesSortedByAffectedTroops = militaryUnitTilesInDistance
|
||||
.sortedByDescending { it.getTilesInDistance(2).count {
|
||||
val militaryUnit = it.militaryUnit
|
||||
militaryUnit!=null && militaryUnit.civInfo==unit.civInfo
|
||||
} }
|
||||
unit.movementAlgs().headTowards(tilesSortedByAffectedTroops.first())
|
||||
return
|
||||
}
|
||||
|
||||
//if no unit to follow, take refuge in city.
|
||||
val cityToGarison = unit.civInfo.cities.map {it.getCenterTile()}
|
||||
.filter {it.civilianUnit == null && unit.canMoveTo(it) && unit.movementAlgs().canReach(it)}
|
||||
.minBy { it.arialDistanceTo(unit.currentTile) }
|
||||
if (cityToGarison != null) {
|
||||
unit.movementAlgs().headTowards(cityToGarison)
|
||||
val cityToGarrison = unit.civInfo.cities.map {it.getCenterTile()}
|
||||
.sortedBy { it.arialDistanceTo(unit.currentTile) }
|
||||
.firstOrNull { it.civilianUnit == null && unit.canMoveTo(it) && unit.movementAlgs().canReach(it)}
|
||||
|
||||
if (cityToGarrison != null) {
|
||||
unit.movementAlgs().headTowards(cityToGarrison)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
fun rankTileAsCityCenter(tileInfo: TileInfo, nearbyTileRankings: Map<TileInfo, Float>): Float {
|
||||
|
Reference in New Issue
Block a user