Class RATGenerator

java.lang.Object
megamek.client.ratgenerator.RATGenerator

public class RATGenerator extends Object
Generates a random assignment table (RAT) dynamically based on a variety of criteria, including faction, era, unit type, weight class, equipment rating, faction subcommand, vehicle movement mode, and mission role.
  • Constructor Details

    • RATGenerator

      protected RATGenerator()
  • Method Details

    • getInstance

      public static RATGenerator getInstance()
    • isInitialized

      public boolean isInitialized()
    • reloadFromDir

      public void reloadFromDir(File dir)
      Clears all data and loads from the given directory
      Parameters:
      dir - The directory to load from
    • findChassisAvailabilityRecord

      public AvailabilityRating findChassisAvailabilityRecord(int era, String unit, String faction, int year)
    • findChassisAvailabilityRecord

      @Nullable public AvailabilityRating findChassisAvailabilityRecord(int era, String unit, FactionRecord factionRecord, int year)
      Return the availability rating for a given chassis. If the specific faction is not directly listed, the parents of the provided faction are used as a lookup. If multiple parent factions are provided, all of them are calculated and then averaged.
      Parameters:
      era - year for era
      unit - string with chassis name
      factionRecord - faction data
      year - year to test
      Returns:
      chassis availability rating, relative to other chassis in a collection
    • findModelAvailabilityRecord

      @Nullable public AvailabilityRating findModelAvailabilityRecord(int era, String unit, String faction)
    • findModelAvailabilityRecord

      @Nullable public AvailabilityRating findModelAvailabilityRecord(int era, String unit, @Nullable FactionRecord factionRecord)
      Generate the availability rating for a specific model
      Parameters:
      era - era designation
      unit - string full chassis-model name
      factionRecord - faction data
      Returns:
      the availability value relative to other models of the same chassis
    • findModelAvailabilityRecord

      @Nullable public AvailabilityRating findModelAvailabilityRecord(int era, String unit, @Nullable FactionRecord factionRecord, int year)
      Generate the availability rating for a specific model, honouring the year the model becomes available.

      An availability code can name a year, as in FS:5:3055: the unit exists in the era but the faction does not get it until that year. findChassisAvailabilityRecord(int, String, FactionRecord, int) has always applied that. The model lookup could not, because it had no year to apply, so a model's year was ignored and the unit turned up from the start of the era instead. Use this overload anywhere a table is being generated.

      Parameters:
      era - era designation
      unit - string full chassis-model name
      factionRecord - faction data
      year - the game year
      Returns:
      the availability rating, or null if the faction does not have this model yet in this year
    • findModelAvailabilityRecord

      @Nullable public AvailabilityRating findModelAvailabilityRecord(int era, String unit, String faction, int year)
      Generate the availability rating for a specific model, honouring the year the model becomes available.
      Parameters:
      era - era designation
      unit - string full chassis-model name
      faction - faction code
      year - the game year
      Returns:
      the availability rating, or null if the faction does not have this model yet in this year
    • getModelFactionRatings

      @Nullable public Collection<AvailabilityRating> getModelFactionRatings(int era, String unit)
      Provides a list of availability ratings for a unit in a given era. Used in editing and reporting.
      Parameters:
      era - The year of the record. This must be one of the years in the eraSet.
      unit - The lookup name of the unit to find records for.
      Returns:
      A Collection of all the availability ratings for the unit in the era, or null if there are no records for that era.
    • setModelFactionRating

      public void setModelFactionRating(int era, String unitKey, AvailabilityRating availabilityRating)
      Adds or changes an availability rating entry for a model.
      Parameters:
      era - The year of the record to change
      unitKey - The model key for the unit which is having its model record updated
      availabilityRating - The new AvailabilityRating for the unit in the era. This provides the faction.
    • removeModelFactionRating

      public void removeModelFactionRating(int era, String unit, String faction)
      Removes the availability rating entry.
      Parameters:
      era - The year of the record to remove.
      unit - The model to remove the record for.
      faction - The faction to remove the record for.
    • getChassisFactionRatings

      @Nullable public Collection<AvailabilityRating> getChassisFactionRatings(int era, String chassisKey)
      Provides a list of availability ratings for a chassis in a given era. Used in editing and reporting.
      Parameters:
      era - The year of the record. This must be one of the years in the eraSet.
      chassisKey - The chassis name to find records for.
      Returns:
      A Collection of all the availability ratings for the chassis in the era, or null if there are no records for that era.
    • setChassisFactionRating

      public void setChassisFactionRating(int era, String unit, AvailabilityRating availabilityRating)
      Adds or changes an availability rating entry for a chassis.
      Parameters:
      era - The year of the record to change
      unit - The name of the chassis for which to change the record
      availabilityRating - The new AvailabilityRating for the unit in the era. This provides the faction.
    • removeChassisFactionRating

      public void removeChassisFactionRating(int era, String unit, String faction)
      Removes the availability rating entry.
      Parameters:
      era - The year of the record to remove.
      unit - The chassis to remove the record for.
      faction - The faction to remove the record for.
    • getEraSet

      public TreeSet<Integer> getEraSet()
    • getModelList

      public Collection<ModelRecord> getModelList()
    • getModelRecord

      public ModelRecord getModelRecord(String key)
    • getChassisList

      public Collection<ChassisRecord> getChassisList()
    • getChassisRecord

      public ChassisRecord getChassisRecord(String key)
    • getFactionList

      public Collection<FactionRecord> getFactionList()
    • getFaction

      public FactionRecord getFaction(String key)
    • addFaction

      public void addFaction(FactionRecord rec)
    • removeFaction

      public void removeFaction(FactionRecord rec)
    • removeFaction

      @Deprecated(since="0.51.0", forRemoval=true) public void removeFaction(String key)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getFactionKeySet

      @Deprecated(since="0.51.0", forRemoval=true) public Collection<String> getFactionKeySet()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • eraForYear

      public int eraForYear(int year)
    • eraIsLoaded

      public boolean eraIsLoaded(int era)
    • mergeFactionAvailability

      public AvailabilityRating mergeFactionAvailability(String faction, List<AvailabilityRating> avList)
      Used for a faction with multiple parent factions (e.g. FC == FS + LA) to find the average availability among the parents. Based on average weight rather than av rating.
      Parameters:
      faction - The faction code to use for the new AvailabilityRecord
      avList - A list of ratings from the various parent factions
      Returns:
      A new availability rating with the average value from the various factions.
    • generateTable

      public List<UnitTable.TableEntry> generateTable(FactionRecord fRec, int unitType, int year, String rating, Collection<Integer> weightClasses, int networkMask, Collection<EntityMovementMode> movementModes, Collection<MissionRole> roles, int roleStrictness, FactionRecord user)
      Generate random selection table entries, given a range of parameters
      Parameters:
      fRec - faction data for selecting units
      unitType - type of unit (Mek, conventional infantry, etc.)
      year - current game year
      rating - equipment rating, typically A/B/C/D/F with A best and F worst
      weightClasses - which weight classes to select, empty or null for all
      networkMask - type of C3 system required, 0 for none
      movementModes - which movement types to select, empty or null for all
      roles - apply force generator roles when calculating random selection weights
      roleStrictness - how strictly to apply roles, 0 (none) or higher (more)
      user - used with OmniMek and salvage balancing
      Returns:
      list of entries suitable for building a random generation table, may be empty
    • dispose

      public void dispose()
    • loadYear

      public void loadYear(int year)
      If the year is equal to one of the era marks, it loads that era. If it is between two, it loads eras on both sides. Otherwise, just load the closest era.
    • initRemainingUnits

      public void initRemainingUnits()
      Creates model and chassis records for all units that don't already have entries. This should only be called after all availability records are loaded, otherwise they will be overwritten. Used for editing.
    • registerListener

      public void registerListener(ActionListener l)
    • removeListener

      public void removeListener(ActionListener l)
    • notifyListenersOfInitialization

      public void notifyListenersOfInitialization()
      Notifies all the listeners that initialization is finished
    • notifyListenersEraLoaded

      public void notifyListenersEraLoaded()
      Notifies all the listeners that era is loaded
    • exportRATGen

      public void exportRATGen(File dir)
    • getFactionLogo

      @Nullable public ImageIcon getFactionLogo(int gameYear, String factionCode, Color tintColor)
      Returns the logo ImageIcon for a specific faction and game year.

      This method resolves the appropriate logo file for the given factionCode and gameYear, accounting for historical changes in faction logos over time where applicable.

      The resulting image is loaded from the predefined directory as a PNG file and tinted black. For unknown or missing faction codes, a default logo is used.

      Parameters:
      gameYear - the year in the game context, potentially affecting logo selection for some factions
      factionCode - the code identifying the faction (e.g., "FS" for Federated Suns)
      Returns:
      an ImageIcon object for the specified faction, tinted black