Class FormationType.GroupingConstraint

java.lang.Object
megamek.client.ratgenerator.FormationType.Constraint
megamek.client.ratgenerator.FormationType.GroupingConstraint
Enclosing class:
FormationType

public static class FormationType.GroupingConstraint extends FormationType.Constraint
A FormationType.Constraint that requires a subset of the formation to form one or more matched groups (typically pairs) of units sharing a chassis or model. Used for rules like "two matched pairs of heavy vehicles" or "fighters operate in identical pairs".

A grouping is described by:

  • unitTypes — which FLAG_* categories the rule applies to (other unit types in the formation are ignored by the grouping check);
  • groupSize — how many units make up one group (typically 2 for "pairs");
  • numGroups — how many such groups are required;
  • a per-unit generalConstraint (e.g., "must be Heavy") and a pairwise groupConstraint (e.g., "same chassis").
  • Constructor Details

    • GroupingConstraint

      public GroupingConstraint(Predicate<MekSummary> generalConstraint, BiFunction<MekSummary,MekSummary,Boolean> groupConstraint, String description)
      Constructs a grouping constraint that applies to all unit types (FormationType.FLAG_ALL), with the default groupSize=2 and numGroups=1.
      Parameters:
      generalConstraint - per-unit predicate (which units the rule applies to)
      groupConstraint - pairwise predicate testing whether two units belong to the same group
      description - human-readable rule description
    • GroupingConstraint

      public GroupingConstraint(int unitTypes, int groupSize, int numGroups, Predicate<MekSummary> generalConstraint, BiFunction<MekSummary,MekSummary,Boolean> groupConstraint, String description)
      Parameters:
      unitTypes - bitwise-OR of FLAG_* masks identifying which unit-type categories this grouping applies to (units of other types are exempt)
      groupSize - number of units per group (e.g., 2 for pairs)
      numGroups - number of groups required
      generalConstraint - per-unit predicate (which units the rule applies to)
      groupConstraint - pairwise predicate testing whether two units belong to the same group
      description - human-readable rule description
  • Method Details

    • appliesTo

      public boolean appliesTo(int unitType)
      Parameters:
      unitType - a UnitType constant
      Returns:
      whether this grouping constraint applies to the given unit type
    • getNumGroups

      public int getNumGroups()
      Returns:
      the required number of groups
    • getGroupSize

      public int getGroupSize()
      Returns:
      the required number of units per group (e.g., 2 for pairs)
    • matches

      public boolean matches(MekSummary ms)
      Tests whether the unit satisfies the per-unit ("general") predicate. Unlike the base FormationType.Constraint.matches(MekSummary), returns true when no general predicate is set.
      Overrides:
      matches in class FormationType.Constraint
      Parameters:
      ms - the unit to test
      Returns:
      whether the unit satisfies this constraint's predicate
    • matches

      public boolean matches(MekSummary ms1, MekSummary ms2)
      Parameters:
      ms1 - first unit
      ms2 - second unit
      Returns:
      whether the two units belong to the same group under the pairwise predicate (e.g., same chassis)
    • getMinimum

      public int getMinimum(int unitSize)
      Specified by:
      getMinimum in class FormationType.Constraint
      Parameters:
      unitSize - the formation size
      Returns:
      groupSize * numGroups, clamped so the requirement does not exceed the formation size
    • hasGeneralCriteria

      public boolean hasGeneralCriteria()
      Returns:
      whether a per-unit ("general") predicate is set; if not, every unit is eligible for grouping
    • copy

      Returns:
      an independent copy of this grouping constraint, used for per-call overrides during generation