Class FormationType.Constraint

java.lang.Object
megamek.client.ratgenerator.FormationType.Constraint
Direct Known Subclasses:
FormationType.CountConstraint, FormationType.GroupingConstraint
Enclosing class:
FormationType

public abstract static class FormationType.Constraint extends Object
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 Details

    • Constraint

      protected Constraint(Predicate<MekSummary> criterion, String description)
      Parameters:
      criterion - predicate identifying units that satisfy this constraint
      description - 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 on unitSize (e.g., percent constraints).
    • getDescription

      public String getDescription()
      Returns:
      the human-readable description of this constraint
    • matches

      public boolean matches(MekSummary ms)
      Parameters:
      ms - the unit to test
      Returns:
      whether the unit satisfies this constraint's predicate
    • isPairedWithPrevious

      public boolean isPairedWithPrevious()
      Returns:
      true if 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:
      true if 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.