Class RandomUnitGenerator

java.lang.Object
megamek.client.generator.RandomUnitGenerator
All Implemented Interfaces:
Serializable

public class RandomUnitGenerator extends Object implements Serializable
This class sets up a random unit generator that can then be used to read in user-created input files of random assignment tables

Files must be located in the directory defined by Configuration.armyTablesDir(). All files should comma-delimited text files.

The first line of the file should contain the title of the RAT The second line of the file should give the unit type number corresponding to UnitType.java The remaining lines should be comma split. The first field should give the frequency of that unit and the second line should give the name of that unit written as { Model } { Chassis }. Comment lines can also be added with "#".

See Also:
  • Constructor Details

    • RandomUnitGenerator

      public RandomUnitGenerator()
  • Method Details

    • initRatTree

      protected void initRatTree()
    • populateUnits

      public void populateUnits()
    • registerListener

      public void registerListener(ActionListener l)
    • notifyListenersOfInitialization

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

      protected void addRat(String ratName, RatEntry ratEntry)
    • generate

      public ArrayList<MekSummary> generate(int numRolls, String ratName)
      Generate a list of units from the RAT
      Returns:
      - a string giving the name
    • generate

      public ArrayList<MekSummary> generate(int numRolls, String ratName, Predicate<MekSummary> filter)
      Generate a list of units from the RAT.
      Parameters:
      numRolls - - the number of units to roll from the RAT
      ratName - - name of the RAT to roll on
      filter - - entries in the RAT must pass this condition to be included. If null, no filter is applied.
      Returns:
      - a list of units determined by the random rolls
    • getMekByName

      protected MekSummary getMekByName(String name)
    • getRandom

      protected double getRandom()
    • generate

      public ArrayList<MekSummary> generate(int numRolls)
    • generate

      public ArrayList<MekSummary> generate(int numRolls, Predicate<MekSummary> filter)
    • getRatMap

      public Map<String,RatEntry> getRatMap()
    • getChosenRAT

      public String getChosenRAT()
    • setChosenRAT

      public void setChosenRAT(String s)
    • getRatList

      public Iterator<String> getRatList()
    • getRatTree

      public RandomUnitGenerator.RatTreeNode getRatTree()
    • getInstance

      public static RandomUnitGenerator getInstance()
    • isInitialized

      public boolean isInitialized()