Package megamek.client.ratgenerator
Class FormationType.Constraint
java.lang.Object
megamek.client.ratgenerator.FormationType.Constraint
- Direct Known Subclasses:
FormationType.CountConstraint,FormationType.GroupingConstraint
- Enclosing class:
FormationType
Abstract base class for a secondary requirement on a formation: a predicate that some number of units must
satisfy.
Constraints support an OR-style "paired" mechanism for cases where the rule allows one of two
alternatives (e.g., Assault Lance requires 1 Juggernaut OR 2 Snipers). Mark the first alternative
with setPairedWithNext(boolean) and the second with setPairedWithPrevious(boolean); the
pair must be added consecutively to FormationType.getOtherCriteria().
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstraint(Predicate<MekSummary> criterion, String description) -
Method Summary
Modifier and TypeMethodDescriptionabstract intgetMinimum(int unitSize) booleanbooleanbooleanmatches(MekSummary ms) voidsetPairedWithNext(boolean paired) Marks this constraint as the first alternative in an OR pair.voidsetPairedWithPrevious(boolean paired) Marks this constraint as the second alternative in an OR pair.
-
Constructor Details
-
Constraint
- Parameters:
criterion- predicate identifying units that satisfy this constraintdescription- human-readable rule description, used in the qualifications report
-
-
Method Details
-
getMinimum
public abstract int getMinimum(int unitSize) - Parameters:
unitSize- the total number of units in the formation- Returns:
- the minimum number of units that must satisfy
matches(MekSummary)for this constraint to be considered met. May depend onunitSize(e.g., percent constraints).
-
getDescription
- Returns:
- the human-readable description of this constraint
-
matches
- Parameters:
ms- the unit to test- Returns:
- whether the unit satisfies this constraint's predicate
-
isPairedWithPrevious
public boolean isPairedWithPrevious()- Returns:
trueif this constraint represents the second alternative in an OR pair; the constraint is then evaluated only if the preceding constraint's minimum is not met
-
setPairedWithPrevious
public void setPairedWithPrevious(boolean paired) Marks this constraint as the second alternative in an OR pair. -
isPairedWithNext
public boolean isPairedWithNext()- Returns:
trueif this constraint is the first alternative in an OR pair; the next constraint in the list is evaluated when this one falls short
-
setPairedWithNext
public void setPairedWithNext(boolean paired) Marks this constraint as the first alternative in an OR pair.
-