Package megamek.client.ratgenerator
Class RATGenerator
java.lang.Object
megamek.client.ratgenerator.RATGenerator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFaction(FactionRecord rec) voiddispose()interaForYear(int year) booleaneraIsLoaded(int era) voidexportRATGen(File dir) findChassisAvailabilityRecord(int era, String unit, String faction, int year) findChassisAvailabilityRecord(int era, String unit, FactionRecord factionRecord, int year) Return the availability rating for a given chassis.findModelAvailabilityRecord(int era, String unit, String faction) findModelAvailabilityRecord(int era, String unit, String faction, int year) Generate the availability rating for a specific model, honouring the year the model becomes available.findModelAvailabilityRecord(int era, String unit, FactionRecord factionRecord) Generate the availability rating for a specific modelfindModelAvailabilityRecord(int era, String unit, FactionRecord factionRecord, int year) Generate the availability rating for a specific model, honouring the year the model becomes available.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 parametersgetChassisFactionRatings(int era, String chassisKey) Provides a list of availability ratings for a chassis in a given era.getChassisRecord(String key) getFaction(String key) Deprecated, for removal: This API element is subject to removal in a future version.getFactionLogo(int gameYear, String factionCode, Color tintColor) Returns the logo ImageIcon for a specific faction and game year.static RATGeneratorgetModelFactionRatings(int era, String unit) Provides a list of availability ratings for a unit in a given era.getModelRecord(String key) voidCreates model and chassis records for all units that don't already have entries.booleanvoidloadYear(int year) If the year is equal to one of the era marks, it loads that era.mergeFactionAvailability(String faction, List<AvailabilityRating> avList) Used for a faction with multiple parent factions (e.g.voidNotifies all the listeners that era is loadedvoidNotifies all the listeners that initialization is finishedvoidvoidreloadFromDir(File dir) Clears all data and loads from the given directoryvoidremoveChassisFactionRating(int era, String unit, String faction) Removes the availability rating entry.voidremoveFaction(String key) Deprecated, for removal: This API element is subject to removal in a future version.voidvoidvoidremoveModelFactionRating(int era, String unit, String faction) Removes the availability rating entry.voidsetChassisFactionRating(int era, String unit, AvailabilityRating availabilityRating) Adds or changes an availability rating entry for a chassis.voidsetModelFactionRating(int era, String unitKey, AvailabilityRating availabilityRating) Adds or changes an availability rating entry for a model.
-
Constructor Details
-
RATGenerator
protected RATGenerator()
-
-
Method Details
-
getInstance
-
isInitialized
public boolean isInitialized() -
reloadFromDir
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 eraunit- string with chassis namefactionRecord- faction datayear- 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 designationunit- string full chassis-model namefactionRecord- 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 designationunit- string full chassis-model namefactionRecord- faction datayear- the game year- Returns:
- the availability rating, or
nullif 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 designationunit- string full chassis-model namefaction- faction codeyear- the game year- Returns:
- the availability rating, or
nullif the faction does not have this model yet in this year
-
getModelFactionRatings
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 theeraSet.unit- The lookup name of the unit to find records for.- Returns:
- A
Collectionof all the availability ratings for the unit in the era, or null if there are no records for that era.
-
setModelFactionRating
Adds or changes an availability rating entry for a model.- Parameters:
era- The year of the record to changeunitKey- The model key for the unit which is having its model record updatedavailabilityRating- The newAvailabilityRatingfor the unit in the era. This provides the faction.
-
removeModelFactionRating
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 theeraSet.chassisKey- The chassis name to find records for.- Returns:
- A
Collectionof all the availability ratings for the chassis in the era, or null if there are no records for that era.
-
setChassisFactionRating
Adds or changes an availability rating entry for a chassis.- Parameters:
era- The year of the record to changeunit- The name of the chassis for which to change the recordavailabilityRating- The newAvailabilityRatingfor the unit in the era. This provides the faction.
-
removeChassisFactionRating
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
-
getModelList
-
getModelRecord
-
getChassisList
-
getChassisRecord
-
getFactionList
-
getFaction
-
addFaction
-
removeFaction
-
removeFaction
Deprecated, for removal: This API element is subject to removal in a future version. -
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
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 AvailabilityRecordavList- 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 unitsunitType- type of unit (Mek, conventional infantry, etc.)year- current game yearrating- equipment rating, typically A/B/C/D/F with A best and F worstweightClasses- which weight classes to select, empty or null for allnetworkMask- type of C3 system required, 0 for nonemovementModes- which movement types to select, empty or null for allroles- apply force generator roles when calculating random selection weightsroleStrictness- 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
-
removeListener
-
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
-
getFactionLogo
Returns the logo ImageIcon for a specific faction and game year.This method resolves the appropriate logo file for the given
factionCodeandgameYear, 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 factionsfactionCode- the code identifying the faction (e.g., "FS" for Federated Suns)- Returns:
- an
ImageIconobject for the specified faction, tinted black
-