use of games.strategy.util.PredicateBuilder in project triplea by triplea-game.
the class MovePanel method getMovableMatch.
private Predicate<Unit> getMovableMatch(final Route route, final Collection<Unit> units) {
final PredicateBuilder<Unit> movableBuilder = PredicateBuilder.trueBuilder();
if (!BaseEditDelegate.getEditMode(getData())) {
movableBuilder.and(Matches.unitIsOwnedBy(getCurrentPlayer()));
}
/*
* if you do not have selection of zero-movement units enabled,
* this will restrict selection to units with 1 or more movement
*/
if (!Properties.getSelectableZeroMovementUnits(getData())) {
movableBuilder.and(Matches.unitCanMove());
}
if (!nonCombat) {
movableBuilder.and(Matches.unitCanNotMoveDuringCombatMove().negate());
}
if (route != null) {
final Predicate<Unit> enoughMovement = u -> BaseEditDelegate.getEditMode(getData()) || TripleAUnit.get(u).getMovementLeft() >= route.getMovementCost(u);
if (route.isUnload()) {
final Predicate<Unit> notLandAndCanMove = enoughMovement.and(Matches.unitIsNotLand());
final Predicate<Unit> landOrCanMove = Matches.unitIsLand().or(notLandAndCanMove);
movableBuilder.and(landOrCanMove);
} else {
movableBuilder.and(enoughMovement);
}
}
if (route != null && route.getEnd() != null) {
final boolean water = route.getEnd().isWater();
if (water && !route.isLoad()) {
movableBuilder.and(Matches.unitIsNotLand());
}
if (!water) {
movableBuilder.and(Matches.unitIsNotSea());
}
}
if (units != null && !units.isEmpty()) {
// force all units to have the same owner in edit mode
final PlayerID owner = getUnitOwner(units);
if (BaseEditDelegate.getEditMode(getData())) {
movableBuilder.and(Matches.unitIsOwnedBy(owner));
}
movableBuilder.and(areOwnedUnitsOfType(units, owner));
}
return movableBuilder.build();
}
Aggregations