Skip to content

Commit

Permalink
Clean up some unnecessary params in placement code. (#11825)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine authored Jul 26, 2023
1 parent a51a18b commit cafb104
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 45 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 @@ -8,7 +8,6 @@
import games.strategy.engine.data.GamePlayer;
import games.strategy.engine.data.GameState;
import games.strategy.engine.data.MutableProperty;
import games.strategy.engine.data.RelationshipTracker;
import games.strategy.engine.data.Resource;
import games.strategy.engine.data.Territory;
import games.strategy.engine.data.TerritoryEffect;
Expand Down Expand Up @@ -2556,13 +2555,9 @@ public void resetCanRetreatOnStalemate() {
* @return {@link Integer#MAX_VALUE} if there is no stacking limit for the specified conditions.
*/
public static int getMaximumNumberOfThisUnitTypeToReachStackingLimit(
final String limitType,
final UnitType ut,
final Territory t,
final GamePlayer owner,
final RelationshipTracker relationshipTracker,
final GameProperties properties) {
final String limitType, final UnitType ut, final Territory t, final GamePlayer owner) {
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 +2599,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 +2723,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 @@ -852,18 +852,13 @@ public String canUnitsBePlaced(
typesAlreadyChecked.add(ut);
final int maxForThisType =
UnitAttachment.getMaximumNumberOfThisUnitTypeToReachStackingLimit(
"placementLimit",
ut,
to,
player,
getData().getRelationshipTracker(),
getData().getProperties());
"placementLimit", ut, to, 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,12 +980,11 @@ 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),
Matches.unitIsOfType(ut)));
CollectionUtils.getNMatches(placeableUnits, max, Matches.unitIsOfType(ut)));
}
if (!Properties.getUnitPlacementRestrictions(properties)) {
return placeableUnits2;
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 cafb104

Please sign in to comment.