Class TeamLoadOutGenerator

java.lang.Object
megamek.client.generator.TeamLoadOutGenerator

public class TeamLoadOutGenerator extends Object
Notes: check out - RATGenerator.java - ForceDescriptor.java for era-based search examples
  • Field Details

    • LOAD_OUT_SETTINGS_PATH

      public static final String LOAD_OUT_SETTINGS_PATH
    • weightMap

      public static LinkedHashMap<String,Object> weightMap
    • UNSET_FILL_RATIO

      public static float UNSET_FILL_RATIO
    • AP_MUNITIONS

      public static final ArrayList<String> AP_MUNITIONS
    • FLAK_MUNITIONS

      public static final ArrayList<String> FLAK_MUNITIONS
    • ACCURATE_MUNITIONS

      public static final ArrayList<String> ACCURATE_MUNITIONS
    • HIGH_POWER_MUNITIONS

      public static final ArrayList<String> HIGH_POWER_MUNITIONS
    • ANTI_INF_MUNITIONS

      public static final ArrayList<String> ANTI_INF_MUNITIONS
    • ANTI_BA_MUNITIONS

      public static final ArrayList<String> ANTI_BA_MUNITIONS
    • HEAT_MUNITIONS

      public static final ArrayList<String> HEAT_MUNITIONS
    • ILLUMINATION_MUNITIONS

      public static final ArrayList<String> ILLUMINATION_MUNITIONS
    • UTILITY_MUNITIONS

      public static final ArrayList<String> UTILITY_MUNITIONS
    • ARTILLERY_UTILITY_MUNITIONS

      public static final ArrayList<String> ARTILLERY_UTILITY_MUNITIONS
    • GUIDED_MUNITIONS

      public static final ArrayList<String> GUIDED_MUNITIONS
    • TAG_GUIDED_MUNITIONS

      public static final ArrayList<String> TAG_GUIDED_MUNITIONS
    • NARC_GUIDED_MUNITIONS

      public static final ArrayList<String> NARC_GUIDED_MUNITIONS
    • SEEKING_MUNITIONS

      public static final ArrayList<String> SEEKING_MUNITIONS
    • AMMO_REDUCING_MUNITIONS

      public static final ArrayList<String> AMMO_REDUCING_MUNITIONS
    • TYPE_LIST

      public static final ArrayList<String> TYPE_LIST
    • TYPE_MAP

      public static final Map<String,List<String>> TYPE_MAP
    • gameOptions

      protected GameOptions gameOptions
    • allowedYear

      protected int allowedYear
    • gameTechLevel

      protected int gameTechLevel
    • legalLevel

      protected SimpleTechLevel legalLevel
    • eraBasedTechLevel

      protected boolean eraBasedTechLevel
    • advAeroRules

      protected boolean advAeroRules
    • showExtinct

      protected boolean showExtinct
    • trueRandom

      protected boolean trueRandom
    • defaultBotMunitionsFile

      protected String defaultBotMunitionsFile
  • Constructor Details

    • TeamLoadOutGenerator

      public TeamLoadOutGenerator(Game ownerGame)
  • Method Details

    • updateOptionValues

      public void updateOptionValues()
    • updateOptionValues

      public void updateOptionValues(GameOptions gameOpts)
    • checkLegality

      public boolean checkLegality(AmmoType aType, String faction, String techBase, boolean mixedTech)
      Calculates legality of ammo types given a faction, tech base (IS/CL), mixed tech, and the instance's already-set year, tech level, and option for showing extinct equipment.
      Parameters:
      aType - the AmmoType of the munition under consideration. q.v.
      faction - MM-style faction code, per factions.xml and FactionRecord keys
      techBase - either 'IS' or 'CL', used for clan boolean check.
      mixedTech - makes munitions checks more lenient by allowing faction to access both IS and CL tech bases.
      Returns:
      boolean true if legal for combination of inputs, false otherwise. Determines if an AmmoType is loaded.
    • checkLegality

      public static boolean checkLegality(AmmoType aType, String faction, String techBase, boolean mixedTech, int allowedYear, SimpleTechLevel legalLevel, boolean eraBasedTechLevel, boolean showExtinct, boolean allowNukes)
    • searchMap

      public static Object searchMap(String keyPath) throws Exception
      Simple Map search for new Yaml-based config file
      Parameters:
      keyPath - Dotted path (e.g. "Overrides.Tandem-Charge.Clan"; max depth of 3.
      Returns:
      entry at the provided path (should be Map of String, Object or String, Int, Double as Object)
      Throws:
      Exception - if any part of path is not found.
    • searchMap

      @Nullable protected static Object searchMap(String keyPath, Map<String,Object> map) throws Exception
      For sub-Map search and testing purposes
      Parameters:
      keyPath - Dotted path (e.g. "Overrides.Tandem-Charge.Clan"; max depth of 3.
      map - Root-level map reference; can be passed a lower-level node to restrict searches
      Returns:
      entry at the provided path (should be Map of String, Object or String, Int, Double as Object)
      Throws:
      Exception
    • subMap

      @Nullable protected static HashMap<String,Object> subMap(String key, HashMap<String,Object> map)
      Return sub-map from the requested key
      Parameters:
      key - String dotted path of the submap within the larger map, usually only a top-level key
      map - HashMap within which to search
      Returns:
      HashMap (of String, Object) sub-map found at the provided path, or null
    • subList

      @Nullable protected static List<String> subList(String key, HashMap<String,Object> map)
      Return list from provided key
      Parameters:
      key - List of strings found at the provided dotted path, usually only a top-level key
      map - HashMap within which to search
      Returns:
      List of strings, or null
    • castPropertyDouble

      public static Double castPropertyDouble(String keyPath, Double defValue)
      Use values from the YAML file defined in TeamLoadOutGenerator class if available; else use provided default
      Parameters:
      keyPath - dotted path to desired value, e.g. "Defaults.Munitions.Dead-Fire.IS"
      defValue - Default value to use
      Returns:
      Double read value or default
    • castPropertyInt

      public static int castPropertyInt(String keyPath, int defValue)
      Use values from the YAML file defined in TeamLoadOutGenerator class if available; else use provided default
      Parameters:
      keyPath - dotted path to desired value, e.g. "Defaults.Factors.pirateMaxAllowedBinFillRatio"
      defValue - Default value to use
      Returns:
      Int read value or default
    • setTrueRandom

      public void setTrueRandom(boolean value)
    • generateValidMunitionsForFactionAndEra

      public HashMap<String,Object> generateValidMunitionsForFactionAndEra(String faction)
      Creates a lookup table of weapon system type -> munition type -> available bins, for the average force This method requires configuring a TeamLoadOutGenerator instance; for other uses, see the static class method below this one.
      Parameters:
      faction - Two-letter (MM) faction code of the force we are checking
      Returns:
      HashMap containing per-weapon entries, that contain per-munition entries of "bin counts"
    • generateValidMunitionsForFactionAndEra

      public static HashMap<String,Object> generateValidMunitionsForFactionAndEra(List<EquipmentType> types, String faction, int year, SimpleTechLevel legalLevel, boolean allowMixed, boolean eraBased, boolean showExtinct, boolean allowNukes)
      Creates a lookup table of weapon system type -> munition type -> available bins, for the average force
      Parameters:
      types - The set of all equipment types within which to search for AmmoTypes
      faction - Two-letter (MM) faction code of the force we are checking
      year - Year in which the game will take place, for availability checks
      legalLevel - SimpleTechLevel representing the allowed technology for the game
      allowMixed - Whether all munitions are considered mixed tech for this game
      eraBased - Use era-based (year-based) validity checks, allowing some leeway on intro years
      showExtinct - Flag setting whether extinct munitions should be considered available
      allowNukes - Set it to true, I dare you.
      Returns:
      HashMap containing per-weapon entries, that contain per-munition entries of "bin counts"
    • determineBinCount

      protected static int determineBinCount(AmmoType exemplar, Faction faction, int year, SimpleTechLevel legalLevel, boolean allowMixed, boolean eraBased, boolean showExtinct, boolean allowNukes)
      Decides the number of bins a "typical force" would get, for a specific type of ammo. (This count will later be scaled by several factors to fit the actual forces provided)
      Parameters:
      exemplar - AmmoType to check
      faction - Faction instance representing the force using this ammo
      year - int, year of the game / game options, for legality / availability checks
      legalLevel - SimpleTechLevel of the game; max tech level allowed.
      allowMixed - boolean, treat all ammo as mixed tech, so Clans can use IS ammo and vice-versa?
      eraBased - boolean, allow adjusting availability for year/faction/era/prototype period?
      showExtinct - boolean, allow extinct ammo?
      allowNukes - boolean, allow nukes for this specific player/bot/force?
      Returns:
      int count of bins available for this ammo.
    • scaleAvailabilityMap

      protected static void scaleAvailabilityMap(HashMap<String,Object> availMap, double factor)
      Scale all bins in a munitions availability map by a factor
      Parameters:
      availMap - An already-constructed munitions availability map
      factor - The value to multiply the existing bin counts by.
    • generateParameters

      public ReconfigurationParameters generateParameters(Team team)
    • generateParameters

      public ReconfigurationParameters generateParameters(ArrayList<Entity> ownEntities, String ownFaction, Team t)
    • generateParameters

      public static ReconfigurationParameters generateParameters(Game g, GameOptions gOpts, ArrayList<Entity> ownEntities, String friendlyFaction, Team team)
      Create the parameters that will determine how to configure ammo loadouts for this team
      Parameters:
      g - Game Object
      gOpts - GameOptions Object
      ownEntities - Entity List of own entities
      friendlyFaction - Friendly Faction Name
      team - Team Object
      Returns:
      ReconfigurationParameters with information about enemy and friendly forces
    • generateParameters

      public static ReconfigurationParameters generateParameters(Game g, GameOptions gOpts, ArrayList<Entity> ownEntities, String friendlyFaction, ArrayList<Entity> enemyEntities, ArrayList<String> enemyFactions, int rating, float fillRatio)
    • generateParameters

      public static ReconfigurationParameters generateParameters(ArrayList<Entity> ownTeamEntities, ArrayList<Entity> etEntities, String friendlyFaction, ArrayList<String> enemyFactions, boolean blind, boolean darkEnvironment, boolean groundMap, boolean spaceEnvironment, int rating, float fillRatio)
    • generateMunitionTree

      public static MunitionTree generateMunitionTree(ReconfigurationParameters reconfigurationParameters, ArrayList<Entity> entities, String defaultSettingsFile)
    • generateMunitionTree

      public static MunitionTree generateMunitionTree(ReconfigurationParameters reconfigurationParameters, ArrayList<Entity> ownTeamEntities, String defaultSettingsFile, megamek.client.generator.MunitionWeightCollection munitionWeightCollection)
      Generate the list of desired ammo load-outs for this team. TODO: implement generateDetailedMunitionTree with more complex breakdowns per unit type NOTE: if sub-classing this generator, should only need to override this method.
      Parameters:
      reconfigurationParameters - ReconfigurationParameters Object
      defaultSettingsFile - File name to settings file.
      Returns:
      generated MunitionTree with imperatives for each weapon type
    • modifyIncendiaryLRMWeights

      public static void modifyIncendiaryLRMWeights(megamek.client.generator.MunitionWeightCollection munitionWeightCollection)
    • applyModifiersToWeights

      public static void applyModifiersToWeights(ReconfigurationParameters reconfigurationParameters, megamek.client.generator.MunitionWeightCollection munitionWeightCollection, HashMap<String,Object> overrides, List<String> prohibited)
      Apply global and specific modifiers to the generated weight values. This is where Overrides and Prohibitions are applied.
      Parameters:
      reconfigurationParameters - Already Created ReconfigurationParameters instance
      munitionWeightCollection - Already Adjusted MunitionWeightCollection instance
      overrides - From "Overides" section of YAML configuration file
      prohibited - From "Prohibited" section of YAML configuration file
    • applyWeightsToMunitionTree

      public static void applyWeightsToMunitionTree(megamek.client.generator.MunitionWeightCollection mwc, MunitionTree mt)
      Turn a selection of the computed munition weights into imperatives to load in the MunitionTree
      Parameters:
      mt - MunitionTree Object
      mwc - MunitionWeightCollection Object
    • reconfigureTeam

      public void reconfigureTeam(Team team, String faction, String adfFile)
      Wrapper to load a file of preset munition imperatives
      Parameters:
      team - Team Object
      faction - Related Faction
      adfFile - Munitions File.
    • reconfigureEntities

      public void reconfigureEntities(ArrayList<Entity> entities, String faction, MunitionTree mt, ReconfigurationParameters reconfigurationParameters, @Nullable HashMap<String,Object> availMap)
      More generic reconfiguration function that acts on sets of units, not teams
      Parameters:
      entities - ArrayList of entities, including ground and air units
      faction - String code for entities' main faction
      mt - MunitionTree defining all applicable load out imperatives
    • randomizeBotTeamConfiguration

      public void randomizeBotTeamConfiguration(Team team, String faction)
      Configure Bot Team with all munitions randomized
      Parameters:
      team - Team Object
      faction - Related Faction to team
    • generateRandomizedMT

      public static MunitionTree generateRandomizedMT()
    • reconfigureEntity

      public void reconfigureEntity(Entity e, MunitionTree mt, HashMap<String,Object> availMap)
      Wrapper that assumes full bins, mostly for testing
      Parameters:
      e - Entity with Ammo Bins
      mt - MunitionTree Ammo used
    • reconfigureEntity

      public void reconfigureEntity(Entity entity, MunitionTree mt, HashMap<String,Object> availMap, float binFillRatio)
      Method to apply a MunitionTree to a specific unit. Main application logic
      Parameters:
      entity - Entity with Ammo Bins
      mt - MunitionTree Ammo used
      binFillRatio - float setting the max fill rate for all bins in this entity (mostly for Pirates)
    • clampAmmoShots

      protected void clampAmmoShots(Entity entity, float binFillRatio)
      Applies specified ammo fill ratio to all bins
      Parameters:
      entity - Entity Unit tow work with.
      binFillRatio - How full to make bins.
    • reconfigureAero

      public void reconfigureAero(Entity entity, MunitionTree munitionTree, String faction)
      TODO: implement in 0.50.1 with other new errata changes This method should mirror reconfigureEntity but with more restrictions based on the types of alternate munitions allowed by Aerospace rules.
      Parameters:
      entity - Entity Unit to work with.
      munitionTree - MunitionTree Ammo Tree
      faction - Related Faction
    • populateAeroBombs

      public void populateAeroBombs(List<Entity> entityList, int year, boolean hasGroundTargets, int quality, boolean isPirate, String faction)
      Helper function to load bombs onto a random portion of units that can carry them
      Parameters:
      entityList - The list of entities to process
      hasGroundTargets - true to select air-to-ground ordnance, false for air-to-air only
      quality - IUnitRating enum for force quality (A/A* through F)
      isPirate - true to use specific pirate ordnance loadouts
    • generateExternalOrdnance

      public BombLoadout generateExternalOrdnance(int bombUnits, boolean airOnly, boolean isPirate, int quality, int year, String faction, String techBase, boolean mixedTech)
      Randomly generate a set of external ordnance up to the number of indicated bomb units. Lower rated forces are more likely to get simpler types (HE and rockets). Because TAG is only useful as one-per-fighter, it should be handled elsewhere.
      Parameters:
      bombUnits - how many bomb units to generate, some types count as more than one unit so returned counts may be lower than this but never higher
      airOnly - true to only select air-to-air ordnance
      isPirate - true if force is pirate, specific low-tech/high chaos selections
      quality - force rating to work with
      year - current year, for tech filter
      Returns:
      BombLoadout of integers, with each element being a bomb count using BombUnit enums as the lookup e.g. [BombUnit.HE] will get the number of HE bombs.