Class Faction2
To limit the changes, the original Faction and FactionRecord classes are - at least for now - kept largely unchanged, but they now use the data of this class instead of loading their own data.
The alternate faction codes and parent factions properties of the two original faction types have been lumped together. They were sometimes equal, sometimes not. Both were used for RAT generation purposes. The alternate names feature (independent of year) of MHQ factions has been dropped as it was not used anywhere. Currency codes are currently not part of this Faction class as there was no data for it
Notes for future improvements: There are multiple fallback factions. This may be useful for providing entertaining fallback RATs but a single chain of parent factions may be more useful for other data. Commands could be given a list of specific camos. Specific dates could be used instead of years. Rating levels could be gathered from fallback to avoid repetition.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the historical faction-code aliases for this faction, keyed by the year each alias became active.getBackground(int year) Returns the faction's background image path for the given year, honoring any era-basedbackground changes.getCamosFolder(int year) getColor()int[]getFactionLeaderForYear(int year) Retrieves the faction leader in power during the specified year.Returns the list of leaders for this faction.intReturns the size of the lowest formation type (lance).intReturns the grouping multiplier for accumulated formations such as company, galaxy or level 3.getKey()getLogo()getLogo(int year) Returns the faction's logo image path for the given year, honoring any era-basedlogo changes.getName()getName(int year) Returns the key of the command that declared this faction as one of itssubunits, if any.Calculates and returns the effective post-invasion honor rating for this faction.Returns the post-invasion honor rating assigned to this faction, if any.Calculates and returns the effective pre-invasion honor rating for this faction.Returns the pre-invasion honor rating assigned to this faction, if any.Retrieves the rank system identifier for this faction.Returns the subordinate formations declared inside this faction's own file, keyed by the short identifier used in the YAML file rather than by their full key.Returns the SUCS (Sarna Unified Cartography Kit) faction codes that map to this MegaMek faction.getTags()booleanis(FactionTag tag) booleanisActiveInYear(int year) booleanbooleanisAresConventionsSignatory(int year) Whether this faction was a signatory of the Ares Conventions - and thus observed their restrictions on targeting population centers - in the given year.booleanisClan()booleanbooleanbooleanReturns whether this faction was declared inside another faction's file rather than having a file of its own.isUsesMercenaries(int year) booleanvoidWrites this faction as YAML to the standard directories in data/universe/factions or data/universe/commands with the standard name (key).yml, depending on whether the key contains a "."voidsaveToFile(File file) Writes this faction as YAML to the given file.voidsaveToFile(FactionRecord updatedRecord) Writes this faction with updates from a changed FactionRecord as YAML to the given file.voidsetFactionLeaders(List<FactionLeaderData> factionLeaders) Sets the list of leaders for this faction.toString()
-
Constructor Details
-
Faction2
public Faction2()
-
-
Method Details
-
getRatingLevels
-
getSubunits
Returns the subordinate formations declared inside this faction's own file, keyed by the short identifier used in the YAML file rather than by their full key. A command such as the St. Ives Lancers declares its regiments here instead of each regiment needing a separate file:key: CC.SIL name: St. Ives Lancers subunits: 1st: name: 1st St. Ives LancersSubunits are a file-organisation convenience only. At load time
SubunitRegistrarregisters each one as a full faction in its own right under the composed keyCC.SIL.1st, so everything that consumes factions - the lobby, RAT generation, MekHQ - sees a flat list and needs no knowledge of the nesting.- Returns:
- The subunits declared in this faction's file, in declaration order. Never
null.
-
getParentCommand
Returns the key of the command that declared this faction as one of itssubunits, if any.This is set only for factions that came from inside another faction's file, such as the 1st St. Ives Lancers declared inside
CC.SIL. A command written in its own file returnsnulleven when it falls back to another command, because falling back is not the same as being declared inside it.- Returns:
- The declaring command's key, or
nullwhen this faction has its own file
-
isSubunit
public boolean isSubunit()Returns whether this faction was declared inside another faction's file rather than having a file of its own.Useful where only whole commands should be offered rather than their individual regiments - the Force Generator's sub-faction list, for example, shows the St. Ives Lancers but not their seven regiments.
- Returns:
trueif this faction is a subunit of another
-
getKey
-
getName
-
getName
-
getSucsCodes
Returns the SUCS (Sarna Unified Cartography Kit) faction codes that map to this MegaMek faction. A single MegaMek faction may correspond to multiple SUCS codes when SUCS uses different identifiers across historical eras of the same political entity (e.g.LCfor the Lyran Commonwealth andLAfor its successor the Lyran Alliance, both of which map to MegaMek'sLA).Used by SUCS data import tooling to translate SUCS faction codes into MegaMek codes. An empty set means no SUCS equivalent has been identified.
- Returns:
- The SUCS codes that map to this faction, in insertion order. Never
null.
-
getTags
-
getYearsActive
-
getBackground
-
getBackground
Returns the faction's background image path for the given year, honoring any era-basedbackground changes. Falls back to the basebackgroundwhen no change applies for the year.- Parameters:
year- the game year to resolve the background for- Returns:
- the era-appropriate background image path, or the base background when none applies
-
getBackgroundChanges
-
getLogo
-
getLogo
Returns the faction's logo image path for the given year, honoring any era-basedlogo changes. Falls back to the baselogowhen no change applies for the year. Used to keep a consolidated rename lineage (for example Clan Goliath Scorpion becoming the Escorpion Imperio in 3080) visually era-correct after its faction files are merged into one.- Parameters:
year- the game year to resolve the logo for- Returns:
- the era-appropriate logo image path, or the base logo when none applies
-
getLogoChanges
-
getEraMods
public int[] getEraMods() -
getSuccessor
-
getCapital
-
getColor
-
getNameGenerator
-
getPreInvasionHonorRatingDirect
Returns the pre-invasion honor rating assigned to this faction, if any.This method provides direct access to the stored
HonorRatingvalue representing the faction's honor rating before the invasion period. No default or fallback value is applied.Usage: this method is for directly retrieving the value stored in
preInvasionHonorRating, generally you'll want to usegetPreInvasionHonorRating()instead, as that includes essential fallback values.- Returns:
- the pre-invasion
HonorRating, ornullif not set
-
getPreInvasionHonorRating
Calculates and returns the effective pre-invasion honor rating for this faction.For Clan factions, returns the stored honor rating if it is set and not
HonorRating.NONE; otherwise, returnsHonorRating.STRICTas the default. For non-Clan factions, this simply returns the stored honor rating, which will likely beHonorRating.NONE.Usage: this method is the primary way to retrieve a faction's pre-invasion honor rating. However, as it includes fallback values, if you want to directly access the value stored in
preInvasionHonorRatingyou will want to callgetPreInvasionHonorRatingDirect(), instead.- Returns:
- the effective pre-invasion
HonorRatingfor the faction
-
getPostInvasionHonorRatingDirect
Returns the post-invasion honor rating assigned to this faction, if any.This method provides direct access to the stored
HonorRatingvalue representing the faction's honor rating after the invasion period. No default or fallback value is applied.Usage: this method is for directly retrieving the value stored in
postInvasionHonorRating, generally you'll want to usegetPostInvasionHonorRating()instead, as that includes essential fallback values.- Returns:
- the pre-invasion
HonorRating, ornullif not set
-
getPostInvasionHonorRating
Calculates and returns the effective post-invasion honor rating for this faction.For Clan factions, returns the stored honor rating if it is set and not
HonorRating.NONE; otherwise, returnsHonorRating.OPPORTUNISTICas the default. For non-Clan factions, this simply returns the stored honor rating, which will likely beHonorRating.NONE.Usage: this method is the primary way to retrieve a faction's post-invasion honor rating. However, as it includes fallback values, if you want to directly access the value stored in
postInvasionHonorRatingyou will want to callgetPostInvasionHonorRatingDirect(), instead.- Returns:
- the effective post-invasion
HonorRatingfor the faction
-
getCamosFolder
-
getCamosChanges
-
getNameChanges
-
getAliases
Returns the historical faction-code aliases for this faction, keyed by the year each alias became active. When a faction is the consolidation of an earlier faction that was renamed (for example Clan Goliath Scorpion becoming the Escorpion Imperio in 3080), the retired faction code is kept here as an alias of the surviving key, so that saved games, planetary ownership and RAT availability tables that still reference the old code continue to resolve to this faction.Aliases are for rename lineages only - a single entity renamed over time, with disjoint date ranges. They must not be used for a merger of two distinct factions (for example Clan Snow Raven and the Outworlds Alliance both becoming the Raven Alliance); those relationships belong in
getFallBackFactions()instead.- Returns:
- The alias codes keyed by the year each became active, in ascending year order. Never
null.
-
getCapitalChanges
-
getUsesMercenaries
-
getAresConventionsSignatory
-
getFallBackFactions
-
getFormationBaseSize
public int getFormationBaseSize()Returns the size of the lowest formation type (lance). If this faction gives the size directly (formationBaseSize) this value is returned. Otherwise, the fallback Factions are called recursively. When there is no callback Faction, 5 is returned for a clan faction and 4 otherwise.This means that the Word of Blake Faction will give a value of 6 and WoB subcommands do not have to give any value as long as their fallback Faction is WoB.
- Returns:
- The size of a lance, point or analogous formation type
-
getFormationGrouping
public int getFormationGrouping()Returns the grouping multiplier for accumulated formations such as company, galaxy or level 3. If this faction gives the value directly (formationGrouping) this value is returned. Otherwise, the fallback Factions are called recursively. When there is no callback Faction, 5 is returned for a clan faction and 3 otherwise (3 lances form a company, 3 companies form a battalion etc.)This means that the Word of Blake Faction will give a value of 6 and WoB subcommands do not have to give any value as long as their fallback Faction is WoB.
- Returns:
- How many formations form a formation of a higher type (e.g., lances in a company)
-
getRankSystem
Retrieves the rank system identifier for this faction.The method checks the `rankSystem` field; if it is set and not
null, its value is returned directly.If the rank system is unspecified but there are fallback factions, the method iterates through each fallback faction, returning the first available rank system found among them.
If no fallback faction provides a rank system, the method returns a default value based on whether the faction is a clan or not.
- Returns:
- the rank system identifier for this faction, or a default value (
DEFAULT_RANK_SYSTEM_CLANfor Clan factions,DEFAULT_RANK_SYSTEM_INNER_SPHEREfor non-Clan factions) if not specified. - Since:
- 0.50.07
-
getFactionLeaders
Returns the list of leaders for this faction.- Returns:
- a list containing all
FactionLeaderDataobjects associated with this faction - Since:
- 0.50.07
-
setFactionLeaders
Sets the list of leaders for this faction.- Parameters:
factionLeaders- the list ofFactionLeaderDatato associate with this faction- Since:
- 0.50.07
-
getFactionLeaderForYear
Retrieves the faction leader in power during the specified year.- Parameters:
year- the year to check for a valid leader- Returns:
- the
FactionLeaderDatafor the leader valid in the given year, ornullif none found - Since:
- 0.50.07
-
isClan
public boolean isClan() -
isPeriphery
public boolean isPeriphery() -
isMinorPower
public boolean isMinorPower() -
is
-
isActiveInYear
public boolean isActiveInYear(int year) - Returns:
- True when this faction is active in the given year.
-
saveToFile
Writes this faction as YAML to the given file.- Parameters:
file- The file to write to.- Throws:
IOException- When an error occurs
-
saveToFile
Writes this faction as YAML to the standard directories in data/universe/factions or data/universe/commands with the standard name (key).yml, depending on whether the key contains a "."- Throws:
IOException- When an error occurs
-
saveToFile
Writes this faction with updates from a changed FactionRecord as YAML to the given file. This method is hopefully temporary; it is used for RatGeneratorEditor changes while FactionRecord stays a separate class. Note that this method applies the changes to the "real" faction and keeps the change for the present runtime.- Parameters:
updatedRecord- A FactionRecord with changes to apply to the present faction and save to file- Throws:
IOException- When an error occurs
-
performsBatchalls
public boolean performsBatchalls()- Returns:
- True if this faction performs BatchAlls.
-
isAggregate
public boolean isAggregate()- Returns:
trueif the faction is an aggregate of independent 'factions', rather than a singular organization.For example, "PIR" (pirates) is used to abstractly represent all pirates, not individual pirate groups.
- Since:
- 0.50.07
-
isUsesMercenaries
-
isAresConventionsSignatory
public boolean isAresConventionsSignatory(int year) Whether this faction was a signatory of the Ares Conventions - and thus observed their restrictions on targeting population centers - in the given year. Defaults tofalsefor years with no recorded signatory status.- Parameters:
year- the year to check- Returns:
trueif the faction observed the Ares Conventions in that year
-
toString
-