Resolved #6559 - Air units with no space in the city cannot be selected for construction

This commit is contained in:
Yair Morgenstern 2022-04-18 12:26:35 +03:00
parent e296604b24
commit dbaf4edb2f
3 changed files with 11 additions and 3 deletions

View File

@ -129,7 +129,8 @@ class RejectionReasons: HashSet<RejectionReasonInstance>() {
RejectionReason.PopulationRequirement,
RejectionReason.ConsumesResources,
RejectionReason.CanOnlyBePurchased,
RejectionReason.MaxNumberBuildable
RejectionReason.MaxNumberBuildable,
RejectionReason.NoPlaceToPutUnit
)
}
}
@ -184,7 +185,8 @@ enum class RejectionReason(val shouldShow: Boolean, val errorMessage: String) {
PopulationRequirement(true, "Requires more population"),
NoSettlerForOneCityPlayers(false, "No settlers for city-states or one-city challengers");
NoSettlerForOneCityPlayers(false, "No settlers for city-states or one-city challengers"),
NoPlaceToPutUnit(true, "No space to place this unit");
fun toInstance(errorMessage: String = this.errorMessage,
shouldShow: Boolean = this.shouldShow): RejectionReasonInstance {

View File

@ -1008,7 +1008,7 @@ class MapUnit {
fun canTransport(unit: MapUnit): Boolean {
if (owner != unit.owner) return false
if (!isTransportTypeOf(unit)) return false
if (unit.getMatchingUniques(UniqueType.CannotBeCarriedBy).any{matchesFilter(it.params[0])}) return false
if (unit.getMatchingUniques(UniqueType.CannotBeCarriedBy).any { matchesFilter(it.params[0]) }) return false
if (currentTile.airUnits.count { it.isTransported } >= carryCapacity(unit)) return false
return true
}

View File

@ -351,6 +351,12 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
val rejectionReasons = RejectionReasons()
if (isWaterUnit() && !cityConstructions.cityInfo.isCoastal())
rejectionReasons.add(RejectionReason.WaterUnitsInCoastalCities)
if (isAirUnit()) {
val fakeUnit = getMapUnit(cityConstructions.cityInfo.civInfo)
val canUnitEnterTile = fakeUnit.movement.canMoveTo(cityConstructions.cityInfo.getCenterTile())
if (!canUnitEnterTile)
rejectionReasons.add(RejectionReason.NoPlaceToPutUnit)
}
val civInfo = cityConstructions.cityInfo.civInfo
for (unique in uniqueObjects) {
@Suppress("NON_EXHAUSTIVE_WHEN")