Class RandomOperationNameGenerator

java.lang.Object
mekhq.campaign.mission.contract.contractGeneration.RandomOperationNameGenerator

public class RandomOperationNameGenerator extends Object
Supplies the two word pools used to build a contract's operation codename (for example, 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 populated on background threads 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.

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 Details

    • getWeightedDescriptor

      public static megamek.common.util.weightedMaps.WeightedIntMap<String> getWeightedDescriptor()
    • setWeightedDescriptor

      public static void setWeightedDescriptor(megamek.common.util.weightedMaps.WeightedIntMap<String> weightedDescriptor)
    • getWeightedNoun

      public static megamek.common.util.weightedMaps.WeightedIntMap<String> getWeightedNoun(ContractObjectiveType objectiveType)
    • getInstance

      public static RandomOperationNameGenerator getInstance()
      Returns the singleton instance, creating and kicking off initialization of every word pool on first use. Applies the double-checked locking pattern so only one instance is ever created.
      Returns:
      the RandomOperationNameGenerator instance
    • generateDescriptor

      @Nullable public String generateDescriptor()
      Draws a random descriptor (the leading modifier word).
      Returns:
      a weighted-random descriptor, or null if the pool is not yet initialized or is empty
    • generateNoun

      @Nullable public String generateNoun(ContractObjectiveType objectiveType)
      Draws a random noun (the head word) themed to the given objective. Falls back to the ContractObjectiveType.UNDEFINED pool 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 null if no pool is available or initialized