Class ForceDescriptor

java.lang.Object
megamek.client.ratgenerator.ForceDescriptor

public class ForceDescriptor extends Object
Describes the characteristics of a force. May be changed during generation.
  • Field Details

  • Constructor Details

    • ForceDescriptor

      public ForceDescriptor()
  • Method Details

    • matches

      public boolean matches(ChassisRecord cRec)
      Checks whether the chassis matches the unit type for this node of the force tree. If a list of acceptable chassis has been assigned, checks whether the chassis is in the list. unit type.
      Parameters:
      cRec - A unit chassis record
      Returns:
      Whether the chassis is of the correct unit type and is on the list of acceptable chassis if it exists.
    • matches

      public boolean matches(ModelRecord mRec)
      If a list of acceptable chassis, models, or variants has been assigned, checks whether the model is among them.
      Parameters:
      mRec - A unit model record
      Returns:
      Whether the model is on the list of acceptable chassis, variants, or models.
    • generateUnits

      public void generateUnits(Ruleset.ProgressListener l, double progress)
      Goes through the force tree structure and generates units for all leaf nodes.
    • generateLance

      public void generateLance(List<ForceDescriptor> subs)
      Generates a lance or other end-level unit (star, level ii) by individual units rather than as an entire formation. Some unit cohesion is attempted for certain unit types, such as building vehicle lances out of the same model or pairing fighter chassis. The equipment rating has an effect on unit cohesion, such that lower rated units are more likely to have mismatched equipment.
      Parameters:
      subs - The sub forces that describe the individual elements of the lance
    • setUnit

      public void setUnit(ModelRecord unit)
      Assigns a specific model to this node of the force tree. If this is a leaf node it will be flagged as an element. If it has child nodes, they will all be made up of the same model unless changed by a rule at a lower level of organization.
      Parameters:
      unit - The unit to assign to this node.
    • generate

      public void generate(String level)
    • generate

      @Nullable public ModelRecord generate()
    • loadEntities

      public void loadEntities(Ruleset.ProgressListener l, double progress)
    • getCombinedDisplayName

      public String getCombinedDisplayName()
      Builds the display label for this force, combining the formal name (e.g. "A Company") with the weight + unit-type + formation-type descriptor (e.g. "Heavy Mek Company") into a single string.

      Matches the layout the ForceGeneratorViewUi tree renderer shows for the same node, so what the user sees in the Force Generator preview matches what the lobby Force View shows after transfer. For lances that lack an explicit name this is the only label available — without it the lobby would render them with a blank name.

      Returns:
      "Name (Descriptor)" when both sides are populated, otherwise whichever side is non-blank, or an empty string if neither is set.
    • assignForceIds

      public int assignForceIds(int nextId)
      Assigns a unique forceId to every formation node in this subtree - that is, every node from the lance/star/point level up. Leaf element nodes (the individual units) are skipped: they become entities in the game, not forces, so they need no force id. Must be run after the force tree is fully built and before loadEntities(megamek.client.ratgenerator.Ruleset.ProgressListener, double) so the force strings stamped onto entities are collision-free.
      Parameters:
      nextId - the first id to assign
      Returns:
      the next unused id, so a caller can continue numbering a later subtree (e.g. transports)
    • assignCommanders

      public void assignCommanders()
    • assignPositions

      public void assignPositions()
    • assignTransport

      public ForceDescriptor assignTransport()
      Calculates transport needs of the unit and generates enough drop-ships and jump ships to carry the indicated portion of the unit.
    • decodeWeightClass

      public static int decodeWeightClass(String code)
    • getWeightClassCode

      public String getWeightClassCode()
    • useWeightClass

      public boolean useWeightClass()
    • recalcWeightClass

      public double recalcWeightClass()
      Weight class can differ from the target once units are generated. Weight class is recalculated based on actual units present and echelon name is set.
      Returns:
      The weight class of this force node
    • getAllChildren

      public ArrayList<Object> getAllChildren()
    • tallyMekWeightClasses

      public int[] tallyMekWeightClasses()
      Recursively counts the weight class of every BattleMek leaf element in this descriptor, its subforces, and its attachments. Diagnostic helper for verifying that a requested force weight (e.g. an Assault regiment) actually produced the expected unit mix — compare the returned counts against the per-faction subforce tables in the ruleset XML.

      LandAirMeks are counted as Meks (Entity.isMek() is true for them). Non-Mek elements (vehicles, infantry, fighters) are ignored.

      Returns:
      an int array indexed by EntityWeightClass constant (0 = WEIGHT_ULTRA_LIGHT5 = WEIGHT_SUPER_HEAVY); each slot holds the number of Mek elements at that weight class
    • tallyWeightClassesByType

      public Map<Integer,int[]> tallyWeightClassesByType()
      Tallies every generated element's weight class, grouped by unit type. Like tallyMekWeightClasses() but for all of the weight-classed types the budget allocator governs (Mek, aerospace fighter, vehicle, battle armor), so each type's achieved mix can be measured and tuned independently.
      Returns:
      a map from UnitType constant to a per-weight-class count array, indexed by EntityWeightClass (0 = WEIGHT_ULTRA_LIGHT ... 5 = WEIGHT_SUPER_HEAVY)
    • getIndex

      public int getIndex()
    • setIndex

      public void setIndex(int index)
    • getName

      public String getName()
    • parseName

      public String parseName()
    • cardinalOrdinal

      public static String cardinalOrdinal(int n)
      Formats a positive integer as a numeric ordinal with the correct English suffix: 1 -> "1st", 2 -> "2nd", 3 -> "3rd", 4 -> "4th", 11/12/13 -> "th", 21 -> "21st", etc. Used by the {cardinalOrdinal} name token so cluster names read like the canon Touman ("38th Assault Cluster", "202nd Battle Cluster") with no upper bound, unlike the spelled {ordinal} token which stops at "Tenth".
    • getDescription

      public String getDescription()
    • setName

      public void setName(String name)
    • getFaction

      public String getFaction()
    • setFaction

      public void setFaction(String faction)
    • getFactionRec

      public FactionRecord getFactionRec()
    • getYear

      public Integer getYear()
    • setYear

      public void setYear(Integer year)
    • getEchelon

      public Integer getEchelon()
    • getEchelonCode

      public String getEchelonCode()
    • setEchelon

      public void setEchelon(Integer echelon)
    • getSizeMod

      public int getSizeMod()
    • setSizeMod

      public void setSizeMod(int sizeMod)
    • isAugmented

      public boolean isAugmented()
    • setAugmented

      public void setAugmented(boolean augmented)
    • getWeightClass

      public Integer getWeightClass()
    • setWeightClass

      public void setWeightClass(Integer weightClass)
    • getWeightTargets

      public Map<Integer,megamek.client.ratgenerator.WeightTarget> getWeightTargets()
      Per-cluster-type weight budget for this node, keyed by unit type, or null if none.
    • setWeightTargets

      public void setWeightTargets(Map<Integer,megamek.client.ratgenerator.WeightTarget> weightTargets)
    • getUnitType

      public Integer getUnitType()
    • setUnitType

      public void setUnitType(Integer unitType)
    • getUnitTypeName

      public String getUnitTypeName()
    • getMovementModes

      public HashSet<EntityMovementMode> getMovementModes()
    • getRating

      public String getRating()
    • setRating

      public void setRating(String rating)
    • ratGeneratorRating

      public String ratGeneratorRating()
      Translates between the rating codes used by the force generator and those used by the RAT Generator. The force generator uses abbreviations to make the formation rules more concise.
      Returns:
      The RATGenerator rating code corresponding to the same index as the force generator rating code.
    • getRatingLevel

      public int getRatingLevel()
    • getFormation

      public FormationType getFormation()
    • setFormationType

      public void setFormationType(FormationType ft)
    • getGenerationRule

      public String getGenerationRule()
    • setGenerationRule

      public void setGenerationRule(String rule)
    • getRoles

      public Set<MissionRole> getRoles()
    • getModels

      public Set<String> getModels()
    • getModelName

      public String getModelName()
    • getChassis

      public Set<String> getChassis()
    • getVariants

      public Set<String> getVariants()
    • getExperience

      public Integer getExperience()
    • setExperience

      public void setExperience(Integer experience)
    • getCoRank

      public Integer getCoRank()
    • setCoRank

      public void setCoRank(Integer coRank)
    • getRankSystem

      public Integer getRankSystem()
    • setRankSystem

      public void setRankSystem(Integer rankSystem)
    • getCo

      public CrewDescriptor getCo()
    • setCo

      public void setCo(CrewDescriptor co)
    • getXo

      public CrewDescriptor getXo()
    • setXo

      public void setXo(CrewDescriptor xo)
    • getCamo

      public String getCamo()
    • setCamo

      public void setCamo(String camo)
    • setNameNodes

      public void setNameNodes(List<ValueNode> nameNodes)
      Because some echelon names depend on knowing the actual weight class, we save a copy of the possibilities for this node and defer selection until after the final weight class determination.
    • getParent

      public ForceDescriptor getParent()
    • setParent

      public void setParent(ForceDescriptor parent)
    • shouldGenerateAttachments

      public boolean shouldGenerateAttachments()
    • setAttachments

      public void setAttachments(boolean attachments)
    • getSubForces

      public ArrayList<ForceDescriptor> getSubForces()
    • setSubForces

      public void setSubForces(ArrayList<ForceDescriptor> subForces)
    • addSubForce

      public void addSubForce(ForceDescriptor fd)
    • getAttached

      public ArrayList<ForceDescriptor> getAttached()
    • setAttached

      public void setAttached(ArrayList<ForceDescriptor> attached)
    • addAttached

      public void addAttached(ForceDescriptor forceDescriptor)
    • isFighterComplement

      public boolean isFighterComplement()
    • setFighterComplement

      public void setFighterComplement(boolean fighterComplement)
    • addFighterComplement

      public void addFighterComplement()
      Generates the carried Aerospace Fighter complement of every large craft (WarShip, DropShip, JumpShip, Space Station) in this force and nests it under the carrying ship, so a generated force that includes a carrier also includes the fighters it carries. Each carrier is filled to its ASF bay capacity.

      Run after unit generation but BEFORE commander/force-id/entity assignment, so the normal passes give the new fighters crews, ids, and entities. Fighters are added via addAttached(ForceDescriptor) rather than as subforces so the carrier keeps its own crew (assignCommanders only reassigns from subforces), while the ToE still nests them under the ship.

    • getDropshipPct

      public double getDropshipPct()
    • setDropshipPct

      public void setDropshipPct(double dropshipPct)
    • getJumpshipPct

      public double getJumpshipPct()
    • setJumpshipPct

      public void setJumpshipPct(double jumpshipPct)
    • getWarshipPct

      public double getWarshipPct()
    • setWarshipPct

      public void setWarshipPct(double warshipPct)
    • getCargo

      public double getCargo()
    • setCargo

      public void setCargo(double cargo)
    • getFlags

      public Set<String> getFlags()
    • isTopLevel

      public boolean isTopLevel()
    • setTopLevel

      public void setTopLevel(boolean topLevel)
    • isElement

      public boolean isElement()
    • setElement

      public void setElement(boolean element)
    • getNameIndex

      public int getNameIndex()
    • getFluffName

      public String getFluffName()
    • setFluffName

      public void setFluffName(String fluffName)
    • getEntity

      public Entity getEntity()
    • addAllEntities

      public void addAllEntities(List<Entity> list)
    • createChild

      public ForceDescriptor createChild(int index)