Search in sources :

Example 1 with PredicateBuilder

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();
}
Also used : BaseEditDelegate(games.strategy.triplea.delegate.BaseEditDelegate) KeyListener(java.awt.event.KeyListener) GameStepPropertiesHelper(games.strategy.triplea.delegate.GameStepPropertiesHelper) UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) Point(java.awt.Point) HashMap(java.util.HashMap) TechAttachment(games.strategy.triplea.attachments.TechAttachment) PredicateBuilder(games.strategy.util.PredicateBuilder) Properties(games.strategy.triplea.Properties) UnitSeperator(games.strategy.triplea.util.UnitSeperator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Route(games.strategy.engine.data.Route) TransportTracker(games.strategy.triplea.delegate.TransportTracker) UnitCategory(games.strategy.triplea.util.UnitCategory) MoveValidator(games.strategy.triplea.delegate.MoveValidator) Map(java.util.Map) MoveType(games.strategy.triplea.delegate.AbstractMoveDelegate.MoveType) UnitType(games.strategy.engine.data.UnitType) TripleAUnit(games.strategy.triplea.TripleAUnit) LinkedHashSet(java.util.LinkedHashSet) CollectionUtils(games.strategy.util.CollectionUtils) IntegerMap(games.strategy.util.IntegerMap) Unit(games.strategy.engine.data.Unit) Iterator(java.util.Iterator) Image(java.awt.Image) Predicate(java.util.function.Predicate) Collection(java.util.Collection) UnitComparator(games.strategy.triplea.delegate.UnitComparator) Set(java.util.Set) Territory(games.strategy.engine.data.Territory) KeyEvent(java.awt.event.KeyEvent) JOptionPane(javax.swing.JOptionPane) MouseEvent(java.awt.event.MouseEvent) ClientLogger(games.strategy.debug.ClientLogger) GameData(games.strategy.engine.data.GameData) MoveDescription(games.strategy.triplea.delegate.dataObjects.MoveDescription) List(java.util.List) PlayerID(games.strategy.engine.data.PlayerID) Matches(games.strategy.triplea.delegate.Matches) MoveValidationResult(games.strategy.triplea.delegate.dataObjects.MoveValidationResult) AbstractMoveDelegate(games.strategy.triplea.delegate.AbstractMoveDelegate) Comparator(java.util.Comparator) Collections(java.util.Collections) MustMoveWithDetails(games.strategy.triplea.delegate.dataObjects.MustMoveWithDetails) TransportUtils(games.strategy.triplea.util.TransportUtils) PlayerID(games.strategy.engine.data.PlayerID) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit)

Aggregations

ClientLogger (games.strategy.debug.ClientLogger)1 GameData (games.strategy.engine.data.GameData)1 PlayerID (games.strategy.engine.data.PlayerID)1 Route (games.strategy.engine.data.Route)1 Territory (games.strategy.engine.data.Territory)1 Unit (games.strategy.engine.data.Unit)1 UnitType (games.strategy.engine.data.UnitType)1 Properties (games.strategy.triplea.Properties)1 TripleAUnit (games.strategy.triplea.TripleAUnit)1 TechAttachment (games.strategy.triplea.attachments.TechAttachment)1 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)1 AbstractMoveDelegate (games.strategy.triplea.delegate.AbstractMoveDelegate)1 MoveType (games.strategy.triplea.delegate.AbstractMoveDelegate.MoveType)1 BaseEditDelegate (games.strategy.triplea.delegate.BaseEditDelegate)1 GameStepPropertiesHelper (games.strategy.triplea.delegate.GameStepPropertiesHelper)1 Matches (games.strategy.triplea.delegate.Matches)1 MoveValidator (games.strategy.triplea.delegate.MoveValidator)1 TransportTracker (games.strategy.triplea.delegate.TransportTracker)1 UnitComparator (games.strategy.triplea.delegate.UnitComparator)1 MoveDescription (games.strategy.triplea.delegate.dataObjects.MoveDescription)1