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

Various code clean ups. #11901

Merged
merged 2 commits into from
Aug 22, 2023
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 @@ -1068,15 +1068,10 @@ private IntegerMap<Territory> getMaxUnitsToBePlacedMap(
final Collection<Territory> notUsableAsOtherProducers = new ArrayList<>(producers);
final Map<Territory, Integer> currentAvailablePlacementForOtherProducers = new HashMap<>();
for (final Territory producerTerritory : producers) {
final Collection<Unit> unitsCanBePlacedByThisProducer =
(Properties.getUnitPlacementRestrictions(getData().getProperties())
? CollectionUtils.getMatches(
units, unitWhichRequiresUnitsHasRequiredUnits(producerTerritory, true))
: new ArrayList<>(units));
final int prodT =
getMaxUnitsToBePlacedFrom(
producerTerritory,
unitsCanBePlacedByThisProducer,
units,
to,
player,
true,
Expand Down Expand Up @@ -1152,8 +1147,7 @@ units, unitWhichRequiresUnitsHasRequiredUnits(producer, true))
return Math.max(0, ra.getMaxPlacePerTerritory() - unitCountAlreadyProduced);
}
// a factory can produce the same number of units as the number of PUs the territory generates
// each turn (or not, if
// it has canProduceXUnits)
// each turn (or not, if it has canProduceXUnits)
final int maxConstructions =
howManyOfEachConstructionCanPlace(to, producer, unitsCanBePlacedByThisProducer, player)
.totalValues();
Expand Down Expand Up @@ -1590,7 +1584,7 @@ public Collection<Unit> unitsAtStartOfStepInTerritory(final Territory to) {
return new ArrayList<>();
}
final Collection<Unit> unitsPlacedAlready = getAlreadyProduced(to);
if (Matches.territoryIsWater().test(to)) {
if (to.isWater()) {
for (final Territory current : getAllProducers(to, player, null, true)) {
unitsPlacedAlready.addAll(getAlreadyProduced(current));
}
Expand Down Expand Up @@ -1626,7 +1620,7 @@ private boolean wasOwnedUnitThatCanProduceUnitsOrIsFactoryInTerritoryAtStartOfSt
// land factories in water can't produce, and sea factories in land can't produce.
// air can produce like land if in land, and like sea if in water.
.and(to.isWater() ? Matches.unitIsLand().negate() : Matches.unitIsSea().negate());
return CollectionUtils.countMatches(unitsAtStartOfTurnInTo, factoryMatch) > 0;
return unitsAtStartOfTurnInTo.stream().anyMatch(factoryMatch);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ private void defenderWins(final IDelegateBridge bridge) {
whoWon = WhoWon.DEFENDER;
bridge.getDisplayChannelBroadcaster().battleEnd(battleId, defender.getName() + " win");
if (Properties.getAbandonedTerritoriesMayBeTakenOverImmediately(gameData.getProperties())) {
if (CollectionUtils.countMatches(defendingUnits, Matches.unitIsNotInfrastructure()) == 0) {
if (defendingUnits.stream().noneMatch(Matches.unitIsNotInfrastructure())) {
final List<Unit> allyOfAttackerUnits =
battleSite.getUnitCollection().getMatches(Matches.unitIsNotInfrastructure());
if (!allyOfAttackerUnits.isEmpty()) {
Expand All @@ -1378,14 +1378,12 @@ private void defenderWins(final IDelegateBridge bridge) {
+ " as there are no defenders left",
allyOfAttackerUnits);
// should we create a new battle records to show the ally capturing the territory (in the
// case where they
// didn't already own/allied it)?
// case where they didn't already own/allied it)?
battleTracker.takeOver(battleSite, abandonedToPlayer, bridge, null, allyOfAttackerUnits);
}
} else {
// should we create a new battle records to show the defender capturing the territory (in
// the case where they
// didn't already own/allied it)?
// the case where they didn't already own/allied it)?
battleTracker.takeOver(battleSite, defender, bridge, null, defendingUnits);
}
}
Expand Down
Loading