Package megamek.client.ratgenerator
Class FormationType.GroupingConstraint
java.lang.Object
megamek.client.ratgenerator.FormationType.Constraint
megamek.client.ratgenerator.FormationType.GroupingConstraint
- Enclosing class:
FormationType
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— whichFLAG_*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 pairwisegroupConstraint(e.g., "same chassis").
-
Constructor Summary
ConstructorsConstructorDescriptionGroupingConstraint(int unitTypes, int groupSize, int numGroups, Predicate<MekSummary> generalConstraint, BiFunction<MekSummary, MekSummary, Boolean> groupConstraint, String description) 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 defaultgroupSize=2andnumGroups=1. -
Method Summary
Modifier and TypeMethodDescriptionbooleanappliesTo(int unitType) copy()intintgetMinimum(int unitSize) intbooleanbooleanmatches(MekSummary ms) Tests whether the unit satisfies the per-unit ("general") predicate.booleanmatches(MekSummary ms1, MekSummary ms2) Methods inherited from class megamek.client.ratgenerator.FormationType.Constraint
getDescription, isPairedWithNext, isPairedWithPrevious, setPairedWithNext, setPairedWithPrevious
-
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 defaultgroupSize=2andnumGroups=1.- Parameters:
generalConstraint- per-unit predicate (which units the rule applies to)groupConstraint- pairwise predicate testing whether two units belong to the same groupdescription- 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 ofFLAG_*masks identifying which unit-type categories this grouping applies to (units of other types are exempt)groupSize- number of units per group (e.g.,2for pairs)numGroups- number of groups requiredgeneralConstraint- per-unit predicate (which units the rule applies to)groupConstraint- pairwise predicate testing whether two units belong to the same groupdescription- human-readable rule description
-
-
Method Details
-
appliesTo
public boolean appliesTo(int unitType) - Parameters:
unitType- aUnitTypeconstant- 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.,
2for pairs)
-
matches
Tests whether the unit satisfies the per-unit ("general") predicate. Unlike the baseFormationType.Constraint.matches(MekSummary), returnstruewhen no general predicate is set.- Overrides:
matchesin classFormationType.Constraint- Parameters:
ms- the unit to test- Returns:
- whether the unit satisfies this constraint's predicate
-
matches
- Parameters:
ms1- first unitms2- 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:
getMinimumin classFormationType.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
-