mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -04:00
Resolved #1782 - air units are no longer sent to join non-transporting units exiting the city
Transportation logic cleanup
This commit is contained in:
parent
7b5e1e3cbf
commit
daa3c8fcec
@ -50,7 +50,7 @@ class WorkerAutomation(val unit: MapUnit) {
|
|||||||
&& tileCanBeImproved(it, unit.civInfo) }
|
&& tileCanBeImproved(it, unit.civInfo) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val mostUndevelopedCity = unit.civInfo.cities
|
val mostUndevelopedCity = unit.civInfo.cities.asSequence()
|
||||||
.filter { citiesToNumberOfUnimprovedTiles[it.id]!! > 0 }
|
.filter { citiesToNumberOfUnimprovedTiles[it.id]!! > 0 }
|
||||||
.sortedByDescending { citiesToNumberOfUnimprovedTiles[it.id] }
|
.sortedByDescending { citiesToNumberOfUnimprovedTiles[it.id] }
|
||||||
.firstOrNull { unit.movement.canReach(it.getCenterTile()) } //goto most undeveloped city
|
.firstOrNull { unit.movement.canReach(it.getCenterTile()) } //goto most undeveloped city
|
||||||
|
@ -568,6 +568,25 @@ class MapUnit {
|
|||||||
return percent
|
return percent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun canTransport(mapUnit: MapUnit): Boolean {
|
||||||
|
if(type!=UnitType.WaterAircraftCarrier && type!=UnitType.WaterMissileCarrier)
|
||||||
|
return false
|
||||||
|
if(!mapUnit.type.isAirUnit()) return false
|
||||||
|
if(type==UnitType.WaterMissileCarrier && mapUnit.type!=UnitType.Missile)
|
||||||
|
return false
|
||||||
|
if(type==UnitType.WaterAircraftCarrier && mapUnit.type==UnitType.Missile)
|
||||||
|
return false
|
||||||
|
if(owner!=mapUnit.owner) return false
|
||||||
|
|
||||||
|
var unitCapacity = 0
|
||||||
|
if (getUniques().contains("Can carry 2 aircraft")) unitCapacity=2
|
||||||
|
unitCapacity += getUniques().count { it == "Can carry 1 extra air unit" }
|
||||||
|
|
||||||
|
if(currentTile.airUnits.filter { it.isTransported }.size>=unitCapacity) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
fun interceptDamagePercentBonus():Int{
|
fun interceptDamagePercentBonus():Int{
|
||||||
var sum=0
|
var sum=0
|
||||||
for(unique in getUniques().filter { it.startsWith("Bonus when intercepting") }){
|
for(unique in getUniques().filter { it.startsWith("Bonus when intercepting") }){
|
||||||
|
@ -239,15 +239,16 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
unit.action=null // unfortify/setup after moving
|
unit.action=null // unfortify/setup after moving
|
||||||
|
|
||||||
// If this unit is a carrier, keep record of its air payload whereabouts.
|
// If this unit is a carrier, keep record of its air payload whereabouts.
|
||||||
var origin = unit.getTile()
|
val origin = unit.getTile()
|
||||||
|
|
||||||
unit.removeFromTile()
|
unit.removeFromTile()
|
||||||
unit.putInTile(destination)
|
unit.putInTile(destination)
|
||||||
|
|
||||||
for(payload in origin.getUnits().filter { it.isTransported }){ // bring along the payloads
|
for(payload in origin.getUnits().filter { it.isTransported }){ // bring along the payloads
|
||||||
payload.removeFromTile()
|
if(unit.canTransport(payload)) {
|
||||||
payload.putInTile(destination)
|
payload.removeFromTile()
|
||||||
payload.isTransported = true // restore the flag to not leave the payload in the city
|
payload.putInTile(destination)
|
||||||
|
payload.isTransported = true // restore the flag to not leave the payload in the city
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unit maintenance changed
|
// Unit maintenance changed
|
||||||
@ -295,15 +296,9 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
|
|
||||||
if (tile.militaryUnit != null) {
|
if (tile.militaryUnit != null) {
|
||||||
val unitAtDestination = tile.militaryUnit!!
|
val unitAtDestination = tile.militaryUnit!!
|
||||||
|
return unitAtDestination.canTransport(unit)
|
||||||
var unitCapacity = if (unitAtDestination.getUniques().contains("Can carry 2 aircraft")) 2 else 0
|
}
|
||||||
unitCapacity += unitAtDestination.getUniques().count { it == "Can carry 1 extra air unit" }
|
return false
|
||||||
|
|
||||||
return ((unitAtDestination.type.isAircraftCarrierUnit() && !unit.type.isMissileUnit()) ||
|
|
||||||
(unitAtDestination.type.isMissileCarrierUnit() && unit.type.isMissileUnit()))
|
|
||||||
&& unitAtDestination.owner == unit.owner && tile.airUnits.filter { it.isTransported }.size < unitCapacity
|
|
||||||
} else
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,9 +72,6 @@ enum class UnitType{
|
|||||||
|| this==Missile
|
|| this==Missile
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isMissileUnit():Boolean{
|
|
||||||
return this == Missile
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isAircraftCarrierUnit():Boolean{
|
fun isAircraftCarrierUnit():Boolean{
|
||||||
return this == WaterAircraftCarrier
|
return this == WaterAircraftCarrier
|
||||||
|
@ -130,7 +130,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
unitList.addAll(tileInfo.getCity()!!.getCenterTile().getUnits())
|
unitList.addAll(tileInfo.getCity()!!.getCenterTile().getUnits())
|
||||||
} else if (tileInfo.militaryUnit!=null &&
|
} else if (tileInfo.militaryUnit!=null &&
|
||||||
(tileInfo.militaryUnit!!.type.isAircraftCarrierUnit() || tileInfo.militaryUnit!!.type.isMissileCarrierUnit()) &&
|
(tileInfo.militaryUnit!!.type.isAircraftCarrierUnit() || tileInfo.militaryUnit!!.type.isMissileCarrierUnit()) &&
|
||||||
tileInfo.militaryUnit!!.civInfo==worldScreen.viewingCiv && !tileInfo.airUnits.isEmpty()) {
|
tileInfo.militaryUnit!!.civInfo==worldScreen.viewingCiv && tileInfo.airUnits.isNotEmpty()) {
|
||||||
unitList.addAll(tileInfo.getUnits())
|
unitList.addAll(tileInfo.getUnits())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user