Class UnitTable

java.lang.Object
megamek.client.ratgenerator.UnitTable

public class UnitTable extends Object
Manages random assignment table generated by RATGenerator.
  • Constructor Details

    • UnitTable

      protected UnitTable(Parameters key)
      Initializes table based on restrictions provided by a Parameters object
      Parameters:
      key - a Parameters structure providing the parameters for generating the table
  • Method Details

    • findTable

      public static UnitTable findTable(FactionRecord faction, int unitType, int year, String rating, Collection<Integer> weightClasses, int networkMask, Collection<EntityMovementMode> movementModes, Collection<MissionRole> roles, int roleStrictness, FactionRecord deployingFaction)
      Checks the cache for a previously generated table meeting the criteria. If none is found, generates it and adds it to the cache. This method is provided as a convenience for when there are no excluded roles.
      Parameters:
      faction - The faction the table filters for
      unitType - UnitType constant with the type of unit
      year - the game year
      rating - the unit's equipment rating; if null, the table is not adjusted for unit rating.
      weightClasses - a collection of EntityWeightClass constants to include in the table; if null or empty all weight classes are included
      networkMask - One of the ModelRecord NETWORK constants, for filtering various C3 systems
      movementModes - the movement modes covered by the table, null/empty for all modes
      roles - MissionRole types the units should qualify for, null/empty for no role filtering
      roleStrictness - how strongly to apply roles, zero for none/minimal with higher being more restrictive; typically no higher than 5
      deployingFaction - when using the salvage/isorla mechanism, any omni unit will select the configuration based on the faction actually deploying
      Returns:
      table containing units which fit all parameters and their relative weights
    • findTable

      public static UnitTable findTable(FactionRecord faction, int unitType, int year, String rating, Collection<Integer> weightClasses, int networkMask, Collection<EntityMovementMode> movementModes, Collection<MissionRole> roles, Collection<MissionRole> rolesExcluded, int roleStrictness, FactionRecord deployingFaction)
      Overloaded method, with additional argument for excluded roles
      Parameters:
      faction - The faction the table filters for
      unitType - UnitType constant with the type of unit
      year - the game year
      rating - the unit's equipment rating; if null, the table is not adjusted for unit rating.
      weightClasses - collection of EntityWeightClass constants to include in the table; if null or empty all weight classes are included
      networkMask - One of the ModelRecord NETWORK constants, for filtering various C3 systems
      movementModes - the movement modes covered by the table, null/empty for all modes
      roles - MissionRole types the units should qualify for, null/empty for no role filtering
      rolesExcluded - MissionRole types the units should not contain, null empty to allow all roles
      roleStrictness - how strongly to apply roles, zero for none/minimal with higher being more restrictive; typically no higher than 5
      deployingFaction - when using the salvage/isorla mechanism, any omni unit will select the configuration based on the faction actually deploying
      Returns:
      table containing units which fit all parameters and their relative weights
    • findTable

      public static UnitTable findTable(FactionRecord faction, int unitType, int year, String rating, Collection<Integer> weightClasses, int networkMask, Collection<EntityMovementMode> movementModes, Collection<MissionRole> roles, int roleStrictness)
      Provided as a convenience to call findTable while using the faction parameter as the deploying faction
    • findTable

      public static UnitTable findTable(Parameters params)
      Checks cache for a unit table with the given parameters. If none is found, generates one and adds to the cache using a copy of the Parameters object as a key.
      Parameters:
      params - - the parameters to use in generating the table.
      Returns:
      a generated table matching the parameters
    • getNumEntries

      public int getNumEntries()
      Returns:
      - number of entries in the table
    • getEntryWeight

      public int getEntryWeight(int index)
      Parameters:
      index - index of the Weight
      Returns:
      - the weight value for the entry at the indicated index
    • getEntryText

      public String getEntryText(int index)
      Parameters:
      index - index of the Text
      Returns:
      - a string representing the entry at the indicated index for use in the table
    • getTechBase

      public String getTechBase(int index)
      Parameters:
      index - index of the Tech Base
      Returns:
      - a string representing the entry at the indicated index for use in the table
    • getUnitRole

      public String getUnitRole(int index)
      Parameters:
      index - index of the Unit Role
      Returns:
      - a string representing the entry at the indicated index for use in the table
    • getMekSummary

      public MekSummary getMekSummary(int index)
      Parameters:
      index - of the MekSummary
      Returns:
      - the MekSummary entry for the indicated index, or null if this is a salvage entry
    • getBV

      public int getBV(int index)
      Parameters:
      index - of the BV
      Returns:
      - the BV of the unit at the indicated index, or 0 if this is a salvage entry
    • hasUnits

      public boolean hasUnits()
      Returns:
      true if the generated table has any unit entries
    • generateUnit

      public MekSummary generateUnit()
      Selects a unit from the full table.
      Returns:
      the selected unit
    • generateUnit

      @Nullable public MekSummary generateUnit(UnitTable.UnitFilter filter)
      Selects a unit from the entries in the table that pass the filter
      Parameters:
      filter - - the function that determines which units are permitted; if null, no filter is applied.
      Returns:
      - the selected unit, or null if no units pass the filter.
    • generateUnits

      public ArrayList<MekSummary> generateUnits(int num)
      Selects a number of units from the table.
      Parameters:
      num - - the number of units to be generated.
      Returns:
      - a list of randomly generated units
    • generateUnits

      public ArrayList<MekSummary> generateUnits(int num, UnitTable.UnitFilter filter)
      Selects a number of units from the table with a filter.
      Parameters:
      num - - the number of units to be generated.
      filter - - the function that determines which units are permitted; if null, no filter is applied.
      Returns:
      - a list of randomly generated units