Class AutomaticRankAssigner

java.lang.Object
mekhq.campaign.personnel.ranks.AutomaticRankAssigner

public final class AutomaticRankAssigner extends Object
Utility class responsible for automatically assigning ranks to personnel. It can apply a faction's rank system and select a valid rank for an individual, or assign missing ranks across a Unit's crew.

When assigning a unit's crew, rank assignment follows a hierarchy: the unit commander receives the highest rank index, squad leaders (if applicable) receive an intermediate rank, and remaining crew members are assigned the next available rank below the leaders. Clan and ComStar/Word of Blake factions use simplified, flat rank assignments rather than the standard graduated system.

Only crew members who do not already hold a rank are affected; existing ranks are always preserved.

Since:
0.51.0
  • Constructor Details

    • AutomaticRankAssigner

      public AutomaticRankAssigner()
  • Method Details

    • assignRanks

      public static void assignRanks(Campaign campaign, Unit unit, Faction faction)
      Assigns ranks to all unranked crew members of the given Unit, respecting faction-specific rules and distributing ranks by experience level.

      The assignment process proceeds as follows:

      1. The crew is sorted in descending order of experience so that more experienced personnel receive higher ranks.
      2. The unit commander is always assigned COMMANDER_RANK_INDEX.
      3. For Clan factions, conventional infantry members receive CLAN_RANK; non-military-caste members receive no rank.
      4. For ComStar and Word of Blake factions, every crew member receives COMSTAR_RANK (Acolyte).
      5. For all other factions, a number of crew members equal to the squad leader count (or 1, if not a conventional infantry unit) receive a leader-level rank, and the remaining crew receive the next rank below.

      Personnel who already hold a rank are skipped entirely.

      Parameters:
      campaign - the active Campaign, used to retrieve campaign options and determine experience levels
      unit - the Unit whose crew will be ranked
      faction - the Faction governing the unit, used to apply faction-specific rank rules
      Since:
      0.51.0
    • assignAscendingRank

      public static void assignAscendingRank(@Nullable Person person, int startIndex)
      Assigns the lowest valid rank to the given person, starting from the specified index and ascending until a valid rank is found or Rank.RO_MAX is reached.
      Parameters:
      person - the Person to assign a rank to; must not be null
      startIndex - the rank value to begin searching from (inclusive)
      Since:
      0.51.0
    • assignRankSystemFromFaction

      public static void assignRankSystemFromFaction(@Nullable Person person, int rankLevel)