Package megamek.client.ratgenerator
Class FactionRecord
java.lang.Object
megamek.client.ratgenerator.FactionRecord
Stores data about factions used for building RATs, including parent factions, factions to salvage from, and
percentages of Clan/SL/Omni tech. Keys are compatible with those used by MekHQ, with various subcommands indicated by
a period and an additional key (e.g. DC.SL for Draconis Combine/Sword of Light).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic enumProportions of Clan/SL/Omni tech are given for major commands in the various sourcebooks such as the Field Manual series. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFactionRecord(String key) FactionRecord(String key, String name) FactionRecord(Faction2 faction2) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a historical faction-code alias effective from the given year.booleanfindPctTech(FactionRecord.TechCategory category, int era, int rating) Get the desired percentage of Clan, Star League/advanced IS tech, or Omni-units that should be present as part of the overall random generation table.getKey()getLineageCodesForYear(int year) Returns the faction codes under which this faction's unit availability may be recorded, for the given year, ordered so the era-active code (per thealiasdate map) is tried first, then this faction's own key, then any remaining historical alias codes.getName()getName(int year) intgetOmniMargin(int era) getPctSalvage(int era) getPctTech(FactionRecord.TechCategory category, int era, int rating) Get the C/SL/O percentage this faction declares for the given rating, without consulting parent factions.Get the tech levels appropriate for this factionChecks the faction parent hierarchy as necessary to find a set of ratings with at least two values.getSalvage(int era) intgetTechMargin(int era) intgetUpgradeMargin(int era) getWeightDistribution(int era, int unitType) getWeightDistributionAsString(int era, int unitType) Formats the weight distribution for a given unit type in an era as a String.getYears()booleanhasDifferences(FactionRecord other) Returns true when there's a difference between this and the given other FactionRecord.inthashCode()booleanisActiveInOrAfterYear(int year) Whether the faction is active in the given year or becomes active in some later year.booleanisActiveInYear(int year) Check for whether the faction is active in a given yearbooleanisClan()booleanisInEra(int era) Checks whether the faction is active at any point from the given year to the next referencebooleanisMinor()booleanbooleanReturns whether this record is a subordinate formation declared inside another command's file, such as an individual regiment of the St.voidvoidremoveSalvage(int era, String faction) voidvoidsetClan(boolean clan) voidsetMinor(boolean minor) voidvoidvoidvoidsetParentFactions(String factions) voidsetPctSalvage(int era, Integer pct) voidsetPctTech(FactionRecord.TechCategory category, int era, int rating, int pct) Sets the target percentage for a tech category for a particular rating.voidsetPctTech(FactionRecord.TechCategory category, int era, String percentages) Sets the target percentage for a tech category.voidsetPeriphery(boolean periphery) voidsetRatings(String str) voidsetSalvage(int era, String faction, Integer wt) voidsetSubunit(boolean subunit) voidsetWeightDistribution(int era, int unitType, String dist) voidSets one or more ranges of years the faction is active.toString()voidwriteToXml(PrintWriter pw, int era)
-
Field Details
-
ALWAYS_ACTIVE
- See Also:
-
IS_GENERAL_KEY
- See Also:
-
CL_GENERAL_KEY
- See Also:
-
PER_GENERAL_KEY
- See Also:
-
GENERAL_KEY
The catch-all availability key, used when a unit is equally available to everyone.- See Also:
-
-
Constructor Details
-
FactionRecord
public FactionRecord() -
FactionRecord
-
FactionRecord
-
FactionRecord
-
-
Method Details
-
hashCode
public int hashCode() -
equals
-
getKey
-
isMinor
public boolean isMinor() -
setMinor
public void setMinor(boolean minor) -
isClan
public boolean isClan() -
setClan
public void setClan(boolean clan) -
isSubunit
public boolean isSubunit()Returns whether this record is a subordinate formation declared inside another command's file, such as an individual regiment of the St. Ives Lancers, rather than a command in its own right.Subunits are fully generatable, but callers that offer a choice of whole commands should leave them out - otherwise a single faction's sub-faction list grows by every regiment of every command it owns.
- Returns:
trueif this record came from another command's subunit declaration
-
setSubunit
public void setSubunit(boolean subunit) -
isPeriphery
public boolean isPeriphery() -
setPeriphery
public void setPeriphery(boolean periphery) -
getAltNames
-
getAliases
-
addAlias
Adds a historical faction-code alias effective from the given year. SeegetAliases().- Parameters:
year- the year the alias code became activealiasCode- the retired faction code that resolves to this faction
-
getLineageCodesForYear
Returns the faction codes under which this faction's unit availability may be recorded, for the given year, ordered so the era-active code (per thealiasdate map) is tried first, then this faction's own key, then any remaining historical alias codes.For a faction with no aliases this is simply a single-element list of
the key, so availability resolution is unchanged. For a consolidated rename lineage (for example Clan Goliath Scorpion, aliased toCEIfrom 3080 andSEfrom 3141) generating in 3100 this yields[CEI, CGS, SE]- so the era-appropriateCEIavailability is preferred while units still listed only under the legacyCGScode remain reachable.- Parameters:
year- the game year the availability is being resolved for- Returns:
- the ordered, de-duplicated lineage codes to try. Never
nullor empty.
-
getRatingLevels
Get the tech levels appropriate for this faction -
getRatingLevelSystem
Checks the faction parent hierarchy as necessary to find a set of ratings with at least two values. If ratingLevels is empty, this faction inherits the parent's system. If ratingLevels has one member, it indicates a set value for this faction within the parent faction's system.- Returns:
- The list of available equipment ratings for the faction.
-
getName
-
getName
-
setName
-
setName
-
setNames
-
isActiveInYear
public boolean isActiveInYear(int year) Check for whether the faction is active in a given year- Parameters:
year- The year to check- Returns:
- Whether the faction is active
- See Also:
-
isActiveInOrAfterYear
public boolean isActiveInOrAfterYear(int year) Whether the faction is active in the given year or becomes active in some later year. Used to offer a unit factions that do not exist yet at its introduction date but will field it later, such as the Republic of the Sphere for a unit built before 3081.- Parameters:
year- the earliest year of interest- Returns:
trueif the faction is active at or after that year
-
setYears
Sets one or more ranges of years the faction is active.- Parameters:
formattedRange- The range of years the faction is active, as YYYY-YYYY. The start or end year can be omitted to make the range open at that end. Factions that vanish and reappear can provide multiple ranges separated by a comma.- Throws:
ParseException- If the date range format is invalid
-
getPctSalvage
-
setPctSalvage
-
getSalvage
-
setSalvage
-
removeSalvage
-
getPctTech
Get the C/SL/O percentage this faction declares for the given rating, without consulting parent factions.- Parameters:
category- the category (Clan, SL/advanced IS, Omni) and unit type to look upera- the year for which the percentage was recordedrating- equipment rating expressed in this faction's rating level system, typically F (0) to A (4)- Returns:
- the declared percentage, or
nullif this faction records none for that category and era
-
findPctTech
Get the desired percentage of Clan, Star League/advanced IS tech, or Omni-units that should be present as part of the overall random generation table.- Parameters:
category- controls which of the three categories, and unit types to lookupera- current yearrating- equipment rating based on available range, typically F (0)/D/C/B/A (4)- Returns:
- integer with the percentage (0 - 100) of units that should meet these criteria. Returns null if the era data contains no C/SL/O data for that unit type.
-
setRatings
-
setPctTech
Sets the target percentage for a tech category.- Parameters:
category- The category (Clan, SL/advanced IS, Omni)era- The year for which to set the tech percentagepercentages- A comma-separated list of percentages from the highest unit rating to the lowest.
-
setPctTech
Sets the target percentage for a tech category for a particular rating.- Parameters:
category- The category (omni, clan, SL/upgraded)era- The year for which to set the tech percentagerating- The unit rating for which to set the tech percentagepct- The percentage of the force that should match the given tech category
-
getOmniMargin
public int getOmniMargin(int era) -
getTechMargin
public int getTechMargin(int era) -
getUpgradeMargin
public int getUpgradeMargin(int era) -
getWeightDistribution
-
setWeightDistribution
-
getParentFactions
-
setParentFactions
-
loadEra
-
saveIfChanged
- Throws:
IOException
-
writeToXml
-
isInEra
public boolean isInEra(int era) Checks whether the faction is active at any point from the given year to the next reference- Parameters:
era- The era start year- Returns:
- Whether the faction is active
- See Also:
-
getNamesAsString
- Returns:
- CSV of all names of the faction, with the original name given first followed by name changes in the format year:name
-
getYearsAsString
- Returns:
- CSV String of all date ranges in which the faction is active.
-
getWeightDistributionAsString
Formats the weight distribution for a given unit type in an era as a String.- Parameters:
era- The game yearunitType- The type of unit- Returns:
- A formatted String
-
getYears
-
toString
-
hasDifferences
Returns true when there's a difference between this and the given other FactionRecord. This is intentionally not overriding equals() as FactionRecord equals() is based on a comparison of the key only.- Parameters:
other- The FactionRecord to compare this to- Returns:
- True when there's a save-worthy difference, false otherwise
-