Class SubunitRegistrar
subunits declared inside a faction file into standalone factions.
Commands are frequently a parent formation with several subordinate regiments - the St. Ives Lancers and their 1st through 7th regiments, or the Lyran Guards and their forty-five. Giving every regiment its own file makes the relationship invisible in the data and multiplies the file count, so a parent may instead declare them inline:
key: CC.SIL
name: St. Ives Lancers
fallBackFactions:
- CC.SIAC
subunits:
1st:
name: 1st St. Ives Lancers
yearsActive:
- start: 2300
MegaMek's runtime model is a flat map of factions, because a regiment has to be selectable and generatable in
its own right. This class therefore registers each subunit under the composed key CC.SIL.1st, so the
nesting is purely a convenience in the file and every consumer continues to see one flat list.
A subunit inherits from its parent only what it cannot otherwise obtain:
fallBackFactionsdefaults to the parent, which is what makes rating levels, formation sizes and the rank system resolve up the chain - those already recurse through the fallback factions.tagsandnameGeneratorare copied down when the subunit declares none, becauseFaction2.isClan()andFaction2.getNameGenerator()read their field directly with no fallback. Without this a Clan regiment would be treated as Inner Sphere and get a lance of four rather than a point of five.
Anything the subunit declares for itself always wins over the inherited value.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidregisterSubunits(Faction2 parent) Registers every subunit of the given faction, and their subunits in turn, into the faction map.
-
Constructor Details
-
SubunitRegistrar
- Parameters:
factions- The flat faction map to register subunits into; typically the map owned byFactions2
-
-
Method Details
-
registerSubunits
Registers every subunit of the given faction, and their subunits in turn, into the faction map.Nesting may go as deep as the data requires: a brigade may declare regiments which themselves declare battalions. Each level composes its key from the level above it.
- Parameters:
parent- The faction whose subunits should be registered; its own entry must already be in the map
-