Class FormationIconBuilder

java.lang.Object
mekhq.campaign.universe.commandGeneration.ratgen.FormationIconBuilder

public final class FormationIconBuilder extends Object
Builds layered formation icons for the Force Generator pipeline, covering every FormationLevel the engine can produce — not just the lance / company pair the legacy AbstractCompanyGenerator supported.

For each non-leaf Formation, the icon stacks three layers:

  • TYPE — a weight-class-based 'Mek silhouette computed from the units in the formation's subtree (Light / Medium / Heavy / Assault / Super-Heavy).
  • FORMATION — a shape file matching the formation's FormationLevel and faction family (IS / Clan / ComStar). All echelons from Team / Point / Level I up through Brigade / Galaxy / Level VI are covered.
  • BACKGROUND — the faction's standard background, when defined.

The campaign root Formation additionally gets a LOGO layer (or a generic-'Mek TYPE fallback) driven by CommandGenerationOptions.isUseOriginNodeFormationIconLogo().

This is the spiritual replacement for AbstractCompanyGenerator.createLayeredFormationIcon scaled up to the full FormationLevel space.

  • Method Details

    • applyIcons

      public static void applyIcons(Formation root, Campaign campaign, CommandGenerationOptions options)
      Walks the campaign's Formation tree rooted at root and applies a layered icon to every non-leaf Formation. Honors the icon-related toggles on CommandGenerationOptions: if isGenerateFormationIcons() is off, returns immediately.
      Parameters:
      root - the campaign's top-level Formation (typically campaign.getPlayerForce().getFormations())
      campaign - the campaign whose units feed the weight-class math
      options - the options driving icon-generation toggles
    • applyIconsToSubtree

      public static int applyIconsToSubtree(@Nullable Formation root, @Nullable Campaign campaign)
      Decorates one existing formation and everything under it, using the campaign's own faction.

      The generation pass above needs CommandGenerationOptions because it also decides the origin node's icon. Support teams organized after generation - a campaign that switched the option on - have no generation options to consult, but their formations should look like the generated ones, so this is the same builder without the origin-node question.

      Parameters:
      root - the formation to decorate, along with its subtree
      campaign - the campaign the formation belongs to
      Returns:
      the number of formations decorated
    • applyIconsToFormations

      public static int applyIconsToFormations(List<Formation> formations, @Nullable Campaign campaign)
      Decorates the named formations and everything under them, using the campaign's own faction.

      Used by the support-team conversion, which knows exactly which formations it created and must not touch the player's own - their icons are their business.

      Parameters:
      formations - the formations to decorate, each along with its subtree
      campaign - the campaign the formations belong to
      Returns:
      the number of formations decorated
    • refreshEchelonPiece

      public static boolean refreshEchelonPiece(@Nullable Formation formation, @Nullable Campaign campaign)
      Brings the echelon symbol on a formation's icon into line with its level, and leaves the rest of the icon alone.

      Support formations are re-sized as their teams and vehicles change, long after their icons were drawn. A Medical section drawn while it held one MASH truck kept the Team symbol after ten more trucks made it a company. Only an icon whose formation layer is a single echelon shape from this builder's folder is touched, so an icon the player designed is never overwritten.

      Parameters:
      formation - the formation whose icon may be stale
      campaign - the campaign, for the faction family that decides the shape set
      Returns:
      true if the symbol was changed
    • decorateUndecorated

      public static int decorateUndecorated(@Nullable Formation root, @Nullable Campaign campaign)
      Draws the icon of root and every formation under it that still carries the blank default icon, and leaves every other icon alone.

      Support formations granted mid-campaign - a convoy when StratCon is switched on, canteens under fatigue, the security detail - were filed with no icon at all, because only command generation and the Support Teams conversion drew them. A formation already decorated, by this builder or by the player, is never redrawn.

      Parameters:
      root - the formation to decorate, along with its subtree
      campaign - the campaign the formation belongs to
      Returns:
      the number of formations decorated
    • refreshPurposePiece

      public static boolean refreshPurposePiece(@Nullable Formation formation, @Nullable Campaign campaign)
      Swaps the generic 'Mek silhouette on a formation's icon for its support job's icon, once its vehicles show what that job is. Only the fallback silhouette this builder draws is replaced, so an icon the player chose is left alone.
      Parameters:
      formation - the formation whose icon may predate its vehicles
      campaign - the campaign
      Returns:
      true if the icon was changed