Class FormationType
Each instance represents one named formation: its allowed unit types, weight class bounds, ideal role, main
filter (getMainCriteria()), secondary FormationType.Constraints (getOtherCriteria()), and an optional
FormationType.GroupingConstraint for paired or matched-chassis subsets. Instances are registered in a static lookup
table populated lazily on first access by createFormationTypes(); client code retrieves a formation by
name through getFormationType(String) or iterates all of them with getAllFormations().
The two main entry points are:
generateFormation(Parameters, int, int, boolean)(and its overloads) — builds a list ofMekSummaryunits that satisfy the formation's rules, sampled from aUnitTable.qualifies(List)— tests whether an existing list of units already meets the formation's rules.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract base class for a secondary requirement on a formation: a predicate that some number of units must satisfy.static classAFormationType.Constraintrequiring a fixed minimum number of units to satisfy the criterion, regardless of formation size.static classAFormationType.Constraintthat requires a subset of the formation to form one or more matched groups (typically pairs) of units sharing a chassis or model. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBit flag identifyingUnitType.AEROSPACE_FIGHTERunits.static final intComposite flag covering all airborne categories (fighters, small craft, dropships).static final intComposite flag covering every supported unit type.static final intBit flag identifyingUnitType.BATTLE_ARMORunits.static final intBit flag identifyingUnitType.CONV_FIGHTERunits.static final intBit flag identifyingUnitType.DROPSHIPunits.static final intComposite flag covering aerospace and conventional fighters.static final intComposite flag covering all ground unit types (Mek, Tank, BA, Infantry, ProtoMek, VTOL, Naval).static final intComposite flag covering ground unit types excluding Infantry and VTOL.static final intBit flag identifyingUnitType.INFANTRYunits.static final intBit flag identifyingUnitType.MEKunits.static final intBit flag identifyingUnitType.NAVALunits.static final intBit flag identifyingUnitType.PROTOMEKunits.static final intBit flag identifyingUnitType.SMALL_CRAFTunits.static final intBit flag identifyingUnitType.TANKunits.static final intComposite flag covering combat vehicles (Tank, Naval, VTOL).static final intBit flag identifyingUnitType.VTOLunits. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFormationType(String name) Constructs a formation whose category is the same as its name (used for top-level formations that are not a variant of another).protectedFormationType(String name, String category) Constructs a formation with an explicit category. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidInitializes (or reinitializes) the static registry of all known formation types, registering each formation defined by thecreate*Lance()/create*Squadron()factories below.generateFormation(List<Parameters> params, List<Integer> numUnits, int networkMask, boolean bestEffort) Overload ofgenerateFormation(List, List, int, boolean, int, int)that uses the formation's own grouping configuration without per-call overrides.generateFormation(List<Parameters> params, List<Integer> numUnits, int networkMask, boolean bestEffort, int groupSize, int nGroups) Builds a list of units that satisfy this formation's rules, sampled fromUnitTables derived from the provided parameters.generateFormation(Parameters params, int numUnits, int networkMask, boolean bestEffort) Convenience overload ofgenerateFormation(List, List, int, boolean, int, int)for formations whose units all share a single set ofParameters(the common single-unit-type case).static Collection<FormationType> Returns every registered formation, lazily initializing the registry on first call.static FormationTypegetFormationType(String key) Returns the formation registered under the given name, lazily initializing the registry on first call.intintgetName()getReportMetric(String key) Returns a stable resource-bundle key for this formation's tooltip text, suitable for lookup inmegamek.client.messages.booleanisAllowedUnitType(int ut) Tests whether the givenUnitTypevalue is included in this formation's allowed unit types.booleanisGround()qualificationReport(List<MekSummary> units) Tests whether a list of units qualifies for the formation type.booleanqualifies(List<MekSummary> units) Tests whether a list of units qualifies for the formation type.
-
Field Details
-
FLAG_MEK
public static final int FLAG_MEKBit flag identifyingUnitType.MEKunits.- See Also:
-
FLAG_TANK
public static final int FLAG_TANKBit flag identifyingUnitType.TANKunits.- See Also:
-
FLAG_BATTLE_ARMOR
public static final int FLAG_BATTLE_ARMORBit flag identifyingUnitType.BATTLE_ARMORunits.- See Also:
-
FLAG_INFANTRY
public static final int FLAG_INFANTRYBit flag identifyingUnitType.INFANTRYunits.- See Also:
-
FLAG_PROTOMEK
public static final int FLAG_PROTOMEKBit flag identifyingUnitType.PROTOMEKunits.- See Also:
-
FLAG_VTOL
public static final int FLAG_VTOLBit flag identifyingUnitType.VTOLunits.- See Also:
-
FLAG_NAVAL
public static final int FLAG_NAVALBit flag identifyingUnitType.NAVALunits.- See Also:
-
FLAG_CONV_FIGHTER
public static final int FLAG_CONV_FIGHTERBit flag identifyingUnitType.CONV_FIGHTERunits.- See Also:
-
FLAG_AERO
public static final int FLAG_AEROBit flag identifyingUnitType.AEROSPACE_FIGHTERunits.- See Also:
-
FLAG_SMALL_CRAFT
public static final int FLAG_SMALL_CRAFTBit flag identifyingUnitType.SMALL_CRAFTunits.- See Also:
-
FLAG_DROPSHIP
public static final int FLAG_DROPSHIPBit flag identifyingUnitType.DROPSHIPunits.- See Also:
-
FLAG_GROUND
public static final int FLAG_GROUNDComposite flag covering all ground unit types (Mek, Tank, BA, Infantry, ProtoMek, VTOL, Naval).- See Also:
-
FLAG_GROUND_NO_LIGHT
public static final int FLAG_GROUND_NO_LIGHTComposite flag covering ground unit types excluding Infantry and VTOL. Used by formations whose rules implicitly assume armored/heavy ground forces (e.g., Battle Lance variants). Note: the_NO_LIGHTsuffix refers to omitting these unit-type categories, not weight class.- See Also:
-
FLAG_FIGHTER
public static final int FLAG_FIGHTERComposite flag covering aerospace and conventional fighters.- See Also:
-
FLAG_AIR
public static final int FLAG_AIRComposite flag covering all airborne categories (fighters, small craft, dropships).- See Also:
-
FLAG_VEHICLE
public static final int FLAG_VEHICLEComposite flag covering combat vehicles (Tank, Naval, VTOL).- See Also:
-
FLAG_ALL
public static final int FLAG_ALLComposite flag covering every supported unit type.- See Also:
-
-
Constructor Details
-
FormationType
Constructs a formation whose category is the same as its name (used for top-level formations that are not a variant of another). Subclasses populate the remaining fields by direct access before registering.- Parameters:
name- the formation name; also used as the category
-
FormationType
Constructs a formation with an explicit category. Used for variants (e.g.,"Heavy Battle"in category"Battle"). Subclasses populate the remaining fields by direct access before registering.- Parameters:
name- the formation namecategory- the parent/grouping category for organizational purposes
-
-
Method Details
-
getFormationType
Returns the formation registered under the given name, lazily initializing the registry on first call.- Parameters:
key- the formation name (e.g.,"Assault","Recon","Aerospace Superiority Squadron")- Returns:
- the matching
FormationType, ornullif no formation is registered under that name
-
getAllFormations
Returns every registered formation, lazily initializing the registry on first call. The returned collection is backed by the registry; callers should treat it as read-only.- Returns:
- all registered formation types
-
getName
- Returns:
- the formation's display name (e.g.,
"Heavy Battle").
-
getCategory
- Returns:
- the formation's category, which groups variants (e.g.,
"Battle"for"Heavy Battle"). Top-level formations have a category equal to their name.
-
isAllowedUnitType
public boolean isAllowedUnitType(int ut) Tests whether the givenUnitTypevalue is included in this formation's allowed unit types.- Parameters:
ut- aUnitTypeconstant (the int value, not aFLAG_*mask)- Returns:
trueif units of that type may participate in this formation
-
isGround
public boolean isGround()- Returns:
trueif this formation does not allow aerospace fighters; that is, it is a ground formation. Convenience for distinguishing ground lances from aerospace squadrons.
-
getNameWithFaction
- Returns:
- the formation name, suffixed with the faction key in parentheses if the formation is exclusive to a
single faction (e.g.,
"Anvil (FWL)"). Returns just the name if not faction-exclusive.
-
getTooltipKey
Returns a stable resource-bundle key for this formation's tooltip text, suitable for lookup inmegamek.client.messages. The key has the formFormationType.<sanitizedName>.tooltip, where spaces and forward slashes in the formation name are replaced with underscores so the key is a valid properties identifier.UI code is expected to call
Messages.getString(ft.getTooltipKey())(with a missing-key fallback) rather than constructing the key inline. This keepsFormationTypeignorant of the UI Messages bundle while letting per-formation tooltip strings live inmessages.properties.- Returns:
- the resource-bundle key for this formation's tooltip
-
getMinWeightClass
public int getMinWeightClass()- Returns:
- the minimum allowed
EntityWeightClassfor units in this formation;0(no minimum) by default
-
getMaxWeightClass
public int getMaxWeightClass()- Returns:
- the maximum allowed
EntityWeightClassfor units in this formation;EntityWeightClass.WEIGHT_COLOSSAL(no maximum) by default
-
getMissionRoles
- Returns:
- mission roles applied to RAT generation for this formation. Some formations admit units in normally
non-combat roles (e.g.,
MissionRole.MIXED_ARTILLERYfor Anti-Air and Artillery Fire Lances).
-
getIdealRole
- Returns:
- the ideal
UnitRolefor this formation. If every unit in a candidate force has this role, the formation's other constraints are bypassed (CamOps "ideal role" loophole). ReturnsUnitRole.UNDETERMINEDfor formations without an ideal role.
-
getMainCriteria
- Returns:
- the predicate every unit must satisfy to participate in this formation.
-
getMainDescription
- Returns:
- a human-readable description of the main criteria (e.g.,
"Armor 105+"), suitable for UI display. May benullif no main criteria are imposed.
-
getOtherCriteria
- Returns:
- an iterator over secondary
FormationType.Constraints — count, percent, and paired-OR rules that a portion of the force must satisfy
-
getGroupingCriteria
- Returns:
- the optional
FormationType.GroupingConstraintfor paired or matched-chassis subsets, ornullif this formation does not impose grouping
-
getReportMetricKeys
- Returns:
- iterator over the keys of report-metric extractors registered for this formation. Used by UI to display per-unit diagnostic columns alongside the formation's qualifications report.
-
getReportMetric
- Parameters:
key- a report-metric key fromgetReportMetricKeys()- Returns:
- the function that extracts the metric value for a given unit, or
nullif no such metric is registered
-
generateFormation
public List<MekSummary> generateFormation(Parameters params, int numUnits, int networkMask, boolean bestEffort) Convenience overload ofgenerateFormation(List, List, int, boolean, int, int)for formations whose units all share a single set ofParameters(the common single-unit-type case).- Parameters:
params- the RAT generation parametersnumUnits- the number of units to generatenetworkMask- C3/C3i/Nova network requirement (useModelRecord.NETWORK_NONEfor no requirement)bestEffort- iftrue, returns a partial result when not all constraints can be met- Returns:
- the generated units, or an empty list if the formation could not be built and
bestEffortisfalse
-
generateFormation
public List<MekSummary> generateFormation(List<Parameters> params, List<Integer> numUnits, int networkMask, boolean bestEffort) Overload ofgenerateFormation(List, List, int, boolean, int, int)that uses the formation's own grouping configuration without per-call overrides.- Parameters:
params- oneParametersper unit-type groupnumUnits- one count perParameters, parallel toparamsnetworkMask- C3/C3i/Nova network requirementbestEffort- iftrue, returns a partial result when not all constraints can be met- Returns:
- the generated units, or an empty list if the formation could not be built and
bestEffortisfalse
-
generateFormation
public List<MekSummary> generateFormation(List<Parameters> params, List<Integer> numUnits, int networkMask, boolean bestEffort, int groupSize, int nGroups) Builds a list of units that satisfy this formation's rules, sampled fromUnitTables derived from the provided parameters. Handles paired-OR constraints, network role distribution (C3 master/slave, C3i, Nova), mixed unit types via parallel parameter sets, and movement-mode resolution for vehicles/infantry whose mode is left unspecified.If the formation defines an
ideal roleand direct generation falls short of all constraints, falls back to attempting an all-ideal-role formation (CamOps loophole).- Parameters:
params- oneParametersper unit-type group; size must matchnumUnitsnumUnits- the count of units to generate per parameter groupnetworkMask- the C3/C3i/Nova network requirement encoded as aModelRecordNETWORK_*bitmask; passModelRecord.NETWORK_NONEto skip network requirementsbestEffort- iftrue, returns whatever could be generated when constraints cannot be fully met; iffalse, returns an empty list on failuregroupSize- override for the formation's grouping constraint group size; pass-1to use the formation's own valuenGroups- override for the formation's grouping constraint group count; pass-1to use the formation's own value- Returns:
- the generated units (concatenated across parameter groups, in input order), or an empty list on failure
when
bestEffortisfalse - Throws:
IllegalArgumentException- ifparamsandnumUnitshave different sizes or are empty
-
qualifies
Tests whether a list of units qualifies for the formation type. Note that unit roles are not available for all units.- Parameters:
units- A list of units to test- Returns:
- Whether the list of units meets the qualifications for this formation.
-
qualificationReport
Tests whether a list of units qualifies for the formation type. Note that unit roles are not available for all units.- Parameters:
units- A list of units to test- Returns:
- Whether the list of units meets the qualifications for this formation.
-
createFormationTypes
public static void createFormationTypes()Initializes (or reinitializes) the static registry of all known formation types, registering each formation defined by thecreate*Lance()/create*Squadron()factories below. Called lazily bygetFormationType(String)andgetAllFormations()on first access; rarely invoked directly.
-