Skip to content

Commit

Permalink
Clean up some unnecessary params in placement code.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine committed Jul 26, 2023
1 parent cb3b86b commit 64173c5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public static boolean getCanTheseUnitsMoveWithoutViolatingStackingLimit(
final String limitType,
final Collection<Unit> unitsMoving,
final Territory toMoveInto,
final GamePlayer owner,
final GameState data) {
final GamePlayer owner) {
final PlayerAttachment pa = PlayerAttachment.get(owner);
if (pa == null) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.triplea.java.ChangeOnNextMajorRelease;
import org.triplea.java.collections.CollectionUtils;
import org.triplea.java.collections.IntegerMap;
import org.triplea.util.Triple;
import org.triplea.util.Tuple;

/**
Expand Down Expand Up @@ -2563,6 +2564,7 @@ public static int getMaximumNumberOfThisUnitTypeToReachStackingLimit(
final RelationshipTracker relationshipTracker,
final GameProperties properties) {
final UnitAttachment ua = ut.getUnitAttachment();
final GameProperties properties = t.getData().getProperties();
final Tuple<Integer, String> stackingLimit;
switch (limitType) {
case "movementLimit":
Expand Down Expand Up @@ -2604,7 +2606,6 @@ public static int getMaximumNumberOfThisUnitTypeToReachStackingLimit(
stackingMatch = Matches.unitIsOfType(ut);
break;
}
// else if (stackingType.equals("total"))
final int totalInTerritory = CollectionUtils.countMatches(t.getUnits(), stackingMatch);
return Math.max(0, max - totalInTerritory);
}
Expand Down Expand Up @@ -2729,9 +2730,8 @@ public void validate(final GameState data) throws GameParseException {
+ " in the xml before using it as a transport"
+ thisErrorMsg());
// Units may be considered transported if they are on a carrier, or if they are
// paratroopers, or if they are
// mech infantry. The "transporter" may not be an actual transport, so we should not check
// for that here.
// paratroopers, or if they are mech infantry. The "transporter" may not be an actual
// transport, so we should not check for that here.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,15 +855,13 @@ public String canUnitsBePlaced(
"placementLimit",
ut,
to,
player,
getData().getRelationshipTracker(),
getData().getProperties());
player);
if (CollectionUtils.countMatches(units, Matches.unitIsOfType(ut)) > maxForThisType) {
return "UnitType " + ut.getName() + " is over stacking limit of " + maxForThisType;
}
}
if (!PlayerAttachment.getCanTheseUnitsMoveWithoutViolatingStackingLimit(
"placementLimit", units, to, player, getData())) {
"placementLimit", units, to, player)) {
return "Units Cannot Go Over Stacking Limit";
}
// now return null (valid placement) if we have placement restrictions disabled in game options
Expand Down Expand Up @@ -985,11 +983,12 @@ protected Collection<Unit> getUnitsToBePlaced(
continue;
}
typesAlreadyChecked.add(ut);
int max = UnitAttachment.getMaximumNumberOfThisUnitTypeToReachStackingLimit(
"placementLimit", ut, to, player);
placeableUnits2.addAll(
CollectionUtils.getNMatches(
placeableUnits,
UnitAttachment.getMaximumNumberOfThisUnitTypeToReachStackingLimit(
"placementLimit", ut, to, player, getData().getRelationshipTracker(), properties),
max,
Matches.unitIsOfType(ut)));
}
if (!Properties.getUnitPlacementRestrictions(properties)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,7 @@ protected Collection<Unit> getUnitsToBePlaced(
CollectionUtils.getNMatches(
placeableUnits,
UnitAttachment.getMaximumNumberOfThisUnitTypeToReachStackingLimit(
"placementLimit",
ut,
to,
player,
getData().getRelationshipTracker(),
getData().getProperties()),
"placementLimit", ut, to, player),
Matches.unitIsOfType(ut)));
}
return placeableUnits2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,12 +815,7 @@ private MoveValidationResult validateBasic(
final UnitType ut = unit.getType();
int maxAllowed =
UnitAttachment.getMaximumNumberOfThisUnitTypeToReachStackingLimit(
"attackingLimit",
ut,
t,
player,
data.getRelationshipTracker(),
data.getProperties());
"attackingLimit", ut, t, player);
maxAllowed -= CollectionUtils.countMatches(unitsAllowedSoFar, Matches.unitIsOfType(ut));
if (maxAllowed > 0) {
unitsAllowedSoFar.add(unit);
Expand All @@ -830,20 +825,15 @@ private MoveValidationResult validateBasic(
}
}
if (!PlayerAttachment.getCanTheseUnitsMoveWithoutViolatingStackingLimit(
"attackingLimit", units, t, player, data)) {
"attackingLimit", units, t, player)) {
return result.setErrorReturnResult("Units Cannot Go Over Stacking Limit");
}
} else {
for (final Unit unit : unitsWithStackingLimits) {
final UnitType ut = unit.getType();
int maxAllowed =
UnitAttachment.getMaximumNumberOfThisUnitTypeToReachStackingLimit(
"movementLimit",
ut,
t,
player,
data.getRelationshipTracker(),
data.getProperties());
"movementLimit", ut, t, player);
maxAllowed -= CollectionUtils.countMatches(unitsAllowedSoFar, Matches.unitIsOfType(ut));
if (maxAllowed > 0) {
unitsAllowedSoFar.add(unit);
Expand All @@ -853,7 +843,7 @@ private MoveValidationResult validateBasic(
}
}
if (!PlayerAttachment.getCanTheseUnitsMoveWithoutViolatingStackingLimit(
"movementLimit", units, t, player, data)) {
"movementLimit", units, t, player)) {
return result.setErrorReturnResult("Units Cannot Go Over Stacking Limit");
}
}
Expand Down

0 comments on commit 64173c5

Please sign in to comment.