Class RandomOperationNameGenerator
RED and EAGLE
in "Operation RED EAGLE"). One shared, objective-agnostic descriptor pool provides the leading modifier; a
per-ContractObjectiveType noun pool provides the head word, which is where the objective flavor
lives. A name is one weighted draw from the descriptor pool combined with one weighted draw from the objective's noun
pool, so a pool of D descriptors and N nouns yields D * N distinct names per objective.
Structured after RandomCompanyNameGenerator: a lazily created,
double-checked singleton whose pools are loaded from word,weight CSV files (a base file plus an optional
userdata/ override merged on top). The file paths are the explicit per-pool constants in
MHQConstants. The singleton is created during startup data loading so the pools are normally ready long
before the first contract is generated.
Thread safety: a single background thread builds every pool into local maps that no other thread can see, then
publishes them all at once through volatile fields before marking the generator initialized. Published
pools are never modified afterwards, so readers only ever see complete pools. A draw that arrives while loading is
still in progress waits (up to LOAD_WAIT_SECONDS) for it to finish rather than failing straight away.
Save File Formatting: word,weight. The word is a String that does not include a ',';
weight is an integer weight used during generation. The first line of each file is a header and is skipped.
-
Method Summary
Modifier and TypeMethodDescriptionDraws a random descriptor (the leading modifier word).generateNoun(ContractObjectiveType objectiveType) Draws a random noun (the head word) themed to the given objective.static RandomOperationNameGeneratorReturns the singleton instance, creating it and starting the background load of every word pool on first use.static megamek.common.util.weightedMaps.WeightedIntMap<String> static megamek.common.util.weightedMaps.WeightedIntMap<String> getWeightedNoun(ContractObjectiveType objectiveType)
-
Method Details
-
getWeightedDescriptor
-
getWeightedNoun
public static megamek.common.util.weightedMaps.WeightedIntMap<String> getWeightedNoun(ContractObjectiveType objectiveType) -
getInstance
Returns the singleton instance, creating it and starting the background load of every word pool on first use. Applies the double-checked locking pattern so only one instance is ever created.- Returns:
- the
RandomOperationNameGeneratorinstance
-
generateDescriptor
Draws a random descriptor (the leading modifier word).- Returns:
- a weighted-random descriptor, or
nullif the pool did not finish loading in time or is empty
-
generateNoun
Draws a random noun (the head word) themed to the given objective. Falls back to theContractObjectiveType.UNDEFINEDpool when the objective's own pool is empty (for example, when its data file is missing).- Parameters:
objectiveType- the contract's objective, selecting the noun pool- Returns:
- a weighted-random noun, or
nullif no pool is available or the pools did not finish loading in time
-