Class FactionRecord

java.lang.Object
megamek.client.ratgenerator.FactionRecord

public class FactionRecord extends Object
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).
  • Field Details

  • Constructor Details

    • FactionRecord

      public FactionRecord()
    • FactionRecord

      public FactionRecord(String key)
    • FactionRecord

      public FactionRecord(String key, String name)
    • FactionRecord

      public FactionRecord(Faction2 faction2)
  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • getKey

      public String 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:
      true if 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

      public TreeMap<Integer,String> getAltNames()
    • getAliases

      public TreeMap<Integer,String> getAliases()
    • addAlias

      public void addAlias(int year, String aliasCode)
      Adds a historical faction-code alias effective from the given year. See getAliases().
      Parameters:
      year - the year the alias code became active
      aliasCode - the retired faction code that resolves to this faction
    • getLineageCodesForYear

      public List<String> 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 the alias date 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 to CEI from 3080 and SE from 3141) generating in 3100 this yields [CEI, CGS, SE] - so the era-appropriate CEI availability is preferred while units still listed only under the legacy CGS code remain reachable.

      Parameters:
      year - the game year the availability is being resolved for
      Returns:
      the ordered, de-duplicated lineage codes to try. Never null or empty.
    • getRatingLevels

      public ArrayList<String> getRatingLevels()
      Get the tech levels appropriate for this faction
    • getRatingLevelSystem

      public ArrayList<String> 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

      public String getName()
    • getName

      public String getName(int year)
    • setName

      public void setName(String name)
    • setName

      public void setName(int era, String name)
    • setNames

      public void setNames(String names)
    • 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:
      true if the faction is active at or after that year
    • setYears

      public void setYears(String formattedRange) throws ParseException
      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

      public Integer getPctSalvage(int era)
    • setPctSalvage

      public void setPctSalvage(int era, Integer pct)
    • getSalvage

      public HashMap<String,Integer> getSalvage(int era)
    • setSalvage

      public void setSalvage(int era, String faction, Integer wt)
    • removeSalvage

      public void removeSalvage(int era, String faction)
    • getPctTech

      @Nullable public Integer 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.
      Parameters:
      category - the category (Clan, SL/advanced IS, Omni) and unit type to look up
      era - the year for which the percentage was recorded
      rating - equipment rating expressed in this faction's rating level system, typically F (0) to A (4)
      Returns:
      the declared percentage, or null if this faction records none for that category and era
    • findPctTech

      public Integer findPctTech(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.
      Parameters:
      category - controls which of the three categories, and unit types to lookup
      era - current year
      rating - 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

      public void setRatings(String str)
    • setPctTech

      public void setPctTech(FactionRecord.TechCategory category, int era, String percentages)
      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 percentage
      percentages - A comma-separated list of percentages from the highest unit rating to the lowest.
    • setPctTech

      public void setPctTech(FactionRecord.TechCategory category, int era, int rating, int pct)
      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 percentage
      rating - The unit rating for which to set the tech percentage
      pct - 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

      @Nullable public ArrayList<Integer> getWeightDistribution(int era, int unitType)
    • setWeightDistribution

      public void setWeightDistribution(int era, int unitType, String dist)
    • getParentFactions

      public ArrayList<String> getParentFactions()
    • setParentFactions

      public void setParentFactions(String factions)
    • loadEra

      public void loadEra(Node node, int era)
    • saveIfChanged

      public void saveIfChanged() throws IOException
      Throws:
      IOException
    • writeToXml

      public void writeToXml(PrintWriter pw, int era)
    • 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

      public Object 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

      public String getYearsAsString()
      Returns:
      CSV String of all date ranges in which the faction is active.
    • getWeightDistributionAsString

      public String getWeightDistributionAsString(int era, int unitType)
      Formats the weight distribution for a given unit type in an era as a String.
      Parameters:
      era - The game year
      unitType - The type of unit
      Returns:
      A formatted String
    • getYears

      public List<FactionRecord.DateRange> getYears()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasDifferences

      public boolean hasDifferences(FactionRecord other)
      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