Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 12823 (EditPanel#sortUnitsToRemove) illegal argument exception #12829

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class NeighborGetter implements Function<Territory, Collection<Territory>
public Collection<Territory> apply(final Territory territory) {
final UnitAttachment unitAttachment = unitType.getUnitAttachment();
final PredicateBuilder<Territory> territoryPredicate = PredicateBuilder.trueBuilder();
if (unitAttachment.getIsSea()) {
if (unitAttachment.isSea()) {
territoryPredicate.and(Territory::isWater);
} else if (!unitAttachment.getIsAir()) {
} else if (!unitAttachment.isAir()) {
territoryPredicate.and(Predicate.not(Territory::isWater));
}
return gameMap.getNeighbors(territory, territoryPredicate.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private static void generatePerPlayer(final Parameters parameters, final GamePla
private static void generatePerPlayerAndUnit(
final Parameters parameters, final GamePlayer player, final UnitType unitType) {
final UnitAttachment unitAttachment = unitType.getUnitAttachment();
if (unitAttachment.getIsAaForCombatOnly()) {
if (unitAttachment.isAaForCombatOnly()) {
createAaUnitAbilities(parameters, player, unitType);
}
createUnitAbilities(parameters, player, unitType);
Expand Down Expand Up @@ -217,7 +217,7 @@ private static CombatUnitAbility.Suicide calculateSuicideType(
? unitAttachment.getIsSuicideOnAttack()
: unitAttachment.getIsSuicideOnDefense()) {
return CombatUnitAbility.Suicide.AFTER_FIRE;
} else if (unitAttachment.getIsSuicideOnHit()) {
} else if (unitAttachment.isSuicideOnHit()) {
return CombatUnitAbility.Suicide.AFTER_HIT;
} else {
return CombatUnitAbility.Suicide.NONE;
Expand Down Expand Up @@ -370,8 +370,7 @@ private static List<UnitType> getTargetsWithoutDestroyer(
}

private static Predicate<UnitType> isNotInfrastructure() {
return Predicate.not(
possibleTarget -> possibleTarget.getUnitAttachment().getIsInfrastructure());
return Predicate.not(possibleTarget -> possibleTarget.getUnitAttachment().isInfrastructure());
}

private static void createAntiFirstStrikeAbility(
Expand Down Expand Up @@ -402,7 +401,7 @@ private static void createAntiFirstStrikeAbility(

private static Collection<UnitType> getIsDestroyerUnitTypes(final UnitTypeList unitTypeList) {
return unitTypeList.stream()
.filter(unitType -> unitType.getUnitAttachment().getIsDestroyer())
.filter(unitType -> unitType.getUnitAttachment().isDestroyer())
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static float strength(
float strength = 0;
for (final Unit u : units) {
final UnitAttachment unitAttachment = u.getUnitAttachment();
if (!unitAttachment.getIsInfrastructure() && unitAttachment.getIsSea() == sea) {
if (!unitAttachment.isInfrastructure() && unitAttachment.isSea() == sea) {
// 2 points since we can absorb a hit
strength += 2;
// two hit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ private void determineUnitsToAttackWith(

// Set air units in any territory with no AA (don't move planes to empty territories)
for (final Unit unit : sortedUnitAttackOptions.keySet()) {
final boolean isAirUnit = unit.getUnitAttachment().getIsAir();
final boolean isAirUnit = unit.getUnitAttachment().isAir();
if (!isAirUnit) {
continue; // skip non-air units
}
Expand Down Expand Up @@ -965,7 +965,7 @@ private void determineUnitsToAttackWith(

// Add sea units to any territory that significantly increases TUV gain
for (final Unit unit : sortedUnitAttackOptions.keySet()) {
final boolean isSeaUnit = unit.getUnitAttachment().getIsSea();
final boolean isSeaUnit = unit.getUnitAttachment().isSea();
if (!isSeaUnit) {
continue; // skip non-sea units
}
Expand Down Expand Up @@ -1285,7 +1285,7 @@ private Map<Unit, Set<Territory>> tryToAttackTerritories(

// Try to set at least one destroyer in each sea territory with subs
for (final Unit unit : sortedUnitAttackOptions.keySet()) {
final boolean isDestroyerUnit = unit.getUnitAttachment().getIsDestroyer();
final boolean isDestroyerUnit = unit.getUnitAttachment().isDestroyer();
if (!isDestroyerUnit) {
continue; // skip non-destroyer units
}
Expand All @@ -1306,7 +1306,7 @@ private Map<Unit, Set<Territory>> tryToAttackTerritories(

// Set enough land and sea units in territories to have at least a chance of winning
for (final Unit unit : sortedUnitAttackOptions.keySet()) {
final boolean isAirUnit = unit.getUnitAttachment().getIsAir();
final boolean isAirUnit = unit.getUnitAttachment().isAir();
final boolean isExpensiveLandUnit =
Matches.unitIsLand().test(unit)
&& proData.getUnitValue(unit.getType()) > 2 * proData.getMinCostPerHitPoint();
Expand Down Expand Up @@ -1346,7 +1346,7 @@ private Map<Unit, Set<Territory>> tryToAttackTerritories(

// Set non-air units in territories that can be held
for (final Unit unit : sortedUnitAttackOptions.keySet()) {
final boolean isAirUnit = unit.getUnitAttachment().getIsAir();
final boolean isAirUnit = unit.getUnitAttachment().isAir();
if (isAirUnit || addedUnits.contains(unit)) {
continue; // skip air units
}
Expand Down Expand Up @@ -1383,7 +1383,7 @@ private Map<Unit, Set<Territory>> tryToAttackTerritories(

// Set air units in territories that can't be held (don't move planes to empty territories)
for (final Unit unit : sortedUnitAttackOptions.keySet()) {
final boolean isAirUnit = unit.getUnitAttachment().getIsAir();
final boolean isAirUnit = unit.getUnitAttachment().isAir();
if (!isAirUnit) {
continue; // skip non-air units
}
Expand Down Expand Up @@ -1455,7 +1455,7 @@ private Map<Unit, Set<Territory>> tryToAttackTerritories(
if (addedUnits.contains(unit)) {
continue;
}
final boolean isAirUnit = unit.getUnitAttachment().getIsAir();
final boolean isAirUnit = unit.getUnitAttachment().isAir();
Territory minWinTerritory = null;
double minWinPercentage = proData.getWinPercentage();
for (final Territory t : sortedUnitAttackOptions.get(unit)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private void moveUnitsToDefendTerritories(

// Set enough units in territories to have at least a chance of winning
for (final Unit unit : sortedUnitMoveOptions.keySet()) {
final boolean isAirUnit = unit.getUnitAttachment().getIsAir();
final boolean isAirUnit = unit.getUnitAttachment().isAir();
if (isAirUnit || Matches.unitIsCarrier().test(unit) || addedUnits.contains(unit)) {
continue; // skip air and carrier units
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ private static float strength(
}
for (final Unit u : units) {
final UnitAttachment unitAttachment = u.getUnitAttachment();
if (unitAttachment.getIsInfrastructure()) {
if (unitAttachment.getIsSea() == sea) {
if (unitAttachment.isInfrastructure()) {
if (unitAttachment.isSea() == sea) {
final int unitAttack = unitAttachment.getAttack(u.getOwner());
// BB = 6.0; AC=2.0/4.0; SUB=3.0; DS=4.0; TR=0.50/2.0; F=4.0/5.0; B=5.0/2.0;
// played with this value a good bit
Expand All @@ -330,7 +330,7 @@ private static float strength(
// only allow transport to have 0.35 on defense; none on attack
strength -= 0.50F;
}
} else if (unitAttachment.getIsAir() == sea) {
} else if (unitAttachment.isAir() == sea) {
strength += 1.00F;
if (attacking) {
strength +=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public class ProPurchaseOption {
final Resource pus = data.getResourceList().getResource(Constants.PUS);
cost = productionRule.getCosts().getInt(pus);
costs = productionRule.getCosts();
isConstruction = unitAttachment.getIsConstruction();
isConstruction = unitAttachment.isConstruction();
constructionType = unitAttachment.getConstructionType();
constructionTypePerTurn = unitAttachment.getConstructionsPerTerrPerTypePerTurn();
maxConstructionType = unitAttachment.getMaxConstructionsPerTypePerTerr();
movement = unitAttachment.getMovement(player);
quantity = productionRule.getResults().totalValues();
final boolean isInfra = unitAttachment.getIsInfrastructure();
final boolean isInfra = unitAttachment.isInfrastructure();
hitPoints = unitAttachment.getHitPoints() * quantity;
if (isInfra) {
hitPoints = 0;
Expand All @@ -91,9 +91,9 @@ public class ProPurchaseOption {
defense = (double) unitAttachment.getDefense(player) * quantity;
transportCost = unitAttachment.getTransportCost() * quantity;
carrierCost = unitAttachment.getCarrierCost() * quantity;
isAir = unitAttachment.getIsAir();
isAir = unitAttachment.isAir();
isSub = unitAttachment.getCanEvade();
isDestroyer = unitAttachment.getIsDestroyer();
isDestroyer = unitAttachment.isDestroyer();
isTransport = unitAttachment.getTransportCapacity() > 0;
isLandTransport = unitAttachment.isLandTransport();
isCarrier = unitAttachment.getCarrierCapacity() > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public ProPurchaseOptionMap(final GamePlayer player, final GameData data) {
final UnitType unitType = (UnitType) resourceOrUnit;

// Add rule to appropriate purchase option list
if (unitType.getUnitAttachment().getIsSuicideOnHit()
|| canUnitTypeSuicide(unitType, player)) {
if (unitType.getUnitAttachment().isSuicideOnHit() || canUnitTypeSuicide(unitType, player)) {
final ProPurchaseOption ppo = new ProPurchaseOption(rule, unitType, player, data);
specialOptions.add(ppo);
ProLogger.debug("Special: " + ppo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static Map<Unit, Set<Territory>> sortUnitNeededOptionsThenAttack(
final UnitType unitType2 = u2.getType();

// If unit types are equal and are air, then sort by average distance.
if (unitType1.equals(unitType2) && unitType1.getUnitAttachment().getIsAir()) {
if (unitType1.equals(unitType2) && unitType1.getUnitAttachment().isAir()) {
final Predicate<Territory> predicate =
ProMatches.territoryCanMoveAirUnitsAndNoAa(data, player, true);
final Territory territory1 = unitTerritoryMap.get(u1);
Expand Down Expand Up @@ -231,7 +231,7 @@ private static double calculateAttackEfficiency(
minPower = powerDifference;
}
}
if (unit.getUnitAttachment().getIsAir()) {
if (unit.getUnitAttachment().isAir()) {
minPower *= 10;
}
final double unitValue = proData.getUnitValue(unit.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private List<MoveDescription> calculateTransportLoad(
while (iter.hasNext() && free > 0) {
final Unit current = iter.next();
final UnitAttachment ua = current.getUnitAttachment();
if (ua.getIsAir()) {
if (ua.isAir()) {
continue;
}
if (ua.getTransportCost() <= free) {
Expand Down
Loading