Class Ranks

java.lang.Object
megamek.common.universe.Ranks

public final class Ranks extends Object
Lightweight loader for data/universe/ranks.xml. Surfaces faction-specific officer titles to MegaMek consumers that need to display them without depending on the full MekHQ rank-system stack.

The integer rank value used by the ratgen pipeline (CrewDescriptor.getRank()) is the same scheme MekHQ stores on Persons, so a lookup by (rankSystemIndex, rankInt) returns the canonical short title — e.g. (8, 34) → "Tai-i" for a DCMS Captain-equivalent.

The lookup is lazy and fault-tolerant: callers should fall back to a generic prefix when the loader returns empty (the data file is optional from MegaMek's perspective — it is canonically owned by mm-data).

  • Method Details

    • getInstance

      public static Ranks getInstance()
    • getByCode

      public Optional<RankSystem> getByCode(@Nullable String code)
      Parameters:
      code - A rank-system code from ranks.xml, e.g. "LAAF" or "DCMS".
      Returns:
      The matching rank system, or empty if none.
    • getByRatgenIndex

      public Optional<RankSystem> getByRatgenIndex(int ratgenIndex)
      Parameters:
      ratgenIndex - The integer the ratgen ruleset stores in <rankSystem> (0-17 in the current data).
      Returns:
      The matching rank system, or empty if the index is unknown or unmapped (e.g. RANK_CUSTOM).
    • resolveRankName

      public Optional<String> resolveRankName(@Nullable Integer ratgenIndex, int rankInt)
      Convenience accessor combining getByRatgenIndex(int) with RankSystem.nameAt(int).
      Parameters:
      ratgenIndex - The ratgen rank-system integer; tolerates null so callers can pass fd.getRankSystem() directly.
      rankInt - The zero-based rank index.
      Returns:
      The short title (e.g. "Tai-i"), or empty if the system or rank cannot be resolved.