Class AbstractForce

java.lang.Object
mekhq.campaign.force.AbstractForce
Direct Known Subclasses:
PlayerForce

public abstract class AbstractForce extends Object
Base class holding the force-level state and logic extracted from Campaign: faction identity and appearance, finances, reputation/standing, the TO&E, and force options.

The located resources (hangar, warehouse, personnel, location) are not owned by the force — they belong to its Detachment(s). A force is not itself a location node; getDetachments() is the detachment-count-agnostic way to reach them, and the aggregate helpers (allUnits(), allPersonnel()) project across every detachment. Convenience accessors that assume a single detachment live on SingleDetachmentForce; force-internal operations that still assume one go through requireSingleDetachment().

A force holds no reference back to its Campaign. Campaign-level concerns — the current date, and writing daily-report lines — are the campaign's responsibility: it passes values such as the date in as method parameters and does its own reporting around the force's state changes.

  • Constructor Details

  • Method Details

    • getDetachments

      public abstract Collection<Detachment> getDetachments()
      The Detachments this force is currently split across. A PlayerForce tracks exactly one; the located resources (hangar, warehouse, personnel, location) are owned by the detachment(s), not the force.
    • allUnits

      public Collection<Unit> allUnits()
      All units across every Detachment of this force. Multi-detachment-safe.
    • allPersonnel

      public Collection<Person> allPersonnel()
      All personnel across every Detachment of this force. Multi-detachment-safe.
    • requireSingleDetachment

      protected Detachment requireSingleDetachment()
      The sole Detachment, asserting the single-detachment assumption. Throws IllegalStateException if the force does not have exactly one detachment.

      This is the internal counterpart to SingleDetachmentForce: grep requireSingleDetachment to find the force-internal operations that are not yet multi-detachment-safe and must be reworked before a multi-detachment force can use them.

    • getHumanResources

      public ForceHumanResources getHumanResources()
    • setHumanResources

      public void setHumanResources(ForceHumanResources humanResources)
    • getShoppingList

      public ForceShoppingList getShoppingList()
    • setShoppingList

      public void setShoppingList(ForceShoppingList shoppingList)
    • getForceOptions

      public ForceOptions getForceOptions()
    • getFaction

      public Faction getFaction()
    • setFaction

      public void setFaction(Faction faction)
    • setFactionDirect

      public void setFactionDirect(Faction faction)
    • getTechFaction

      public megamek.common.enums.Faction getTechFaction()
    • updateTechFactionCode

      public void updateTechFactionCode()
    • getName

      public String getName()
    • setName

      public void setName(String name)
    • getRankSystem

      public RankSystem getRankSystem()
    • setRankSystem

      public void setRankSystem(@Nullable RankSystem rankSystem)
    • setRankSystemDirect

      public void setRankSystemDirect(RankSystem rankSystem)
    • getCamouflage

      public megamek.common.icons.Camouflage getCamouflage()
    • setCamouflage

      public void setCamouflage(megamek.common.icons.Camouflage camouflage)
    • getColour

      public megamek.client.ui.util.PlayerColour getColour()
    • setColour

      public void setColour(megamek.client.ui.util.PlayerColour colour)
    • getUnitIcon

      public StandardFormationIcon getUnitIcon()
    • setUnitIcon

      public void setUnitIcon(StandardFormationIcon unitIcon)
    • getRetainerEmployerCode

      public String getRetainerEmployerCode()
    • setRetainerEmployerCode

      public void setRetainerEmployerCode(String code)
    • getRetainerStartDate

      public LocalDate getRetainerStartDate()
    • setRetainerStartDate

      public void setRetainerStartDate(LocalDate retainerStartDate)
    • getFinances

      public Finances getFinances()
    • setFinances

      public void setFinances(Finances finances)
    • getFunds

      public Money getFunds()
    • addFunds

      public void addFunds(TransactionType type, LocalDate date, Money quantity, String description)
      Credits quantity to this force's finances. The campaign is responsible for defaulting the description and writing any daily-report line.
    • removeFunds

      public void removeFunds(TransactionType type, LocalDate date, Money quantity, String description)
      Debits quantity from this force's finances. The campaign is responsible for defaulting the description and writing any daily-report line.
    • getReputation

      public ForceReputationController getReputation()
    • setReputation

      public void setReputation(ForceReputationController reputation)
    • getFactionStandings

      public FactionStandings getFactionStandings()
    • setFactionStandings

      public void setFactionStandings(FactionStandings factionStandings)
    • getRawCrimeRating

      public int getRawCrimeRating()
    • setCrimeRating

      public void setCrimeRating(int crimeRating)
    • changeCrimeRating

      public void changeCrimeRating(int change)
    • getCrimePirateModifier

      public int getCrimePirateModifier()
    • setCrimePirateModifier

      public void setCrimePirateModifier(int crimePirateModifier)
    • changeCrimePirateModifier

      public void changeCrimePirateModifier(int change)
    • getAdjustedCrimeRating

      public int getAdjustedCrimeRating()
    • getDateOfLastCrime

      @Nullable public LocalDate getDateOfLastCrime()
    • setDateOfLastCrime

      public void setDateOfLastCrime(LocalDate dateOfLastCrime)
    • getInitiativeBonus

      public int getInitiativeBonus()
    • setInitiativeBonus

      public void setInitiativeBonus(int bonus)
    • applyInitiativeBonus

      public void applyInitiativeBonus(int bonus)
    • initiativeBonusIncrement

      public void initiativeBonusIncrement(boolean change)
    • getInitiativeMaxBonus

      public int getInitiativeMaxBonus()
    • setInitiativeMaxBonus

      public void setInitiativeMaxBonus(int bonus)
    • isAvoidingEmptySystems

      public boolean isAvoidingEmptySystems()
    • setIsAvoidingEmptySystems

      public void setIsAvoidingEmptySystems(boolean isAvoidingEmptySystems)
    • isOverridingCommandCircuitRequirements

      public boolean isOverridingCommandCircuitRequirements()
    • setIsOverridingCommandCircuitRequirements

      public void setIsOverridingCommandCircuitRequirements(boolean isOverridingCommandCircuitRequirements)
    • getIgnoreMothballed

      public boolean getIgnoreMothballed()
    • setIgnoreMothballed

      public void setIgnoreMothballed(boolean ignoreMothballed)
    • getTopUpWeekly

      public boolean getTopUpWeekly()
    • setTopUpWeekly

      public void setTopUpWeekly(boolean topUpWeekly)
    • getIgnoreSparesUnderQuality

      public PartQuality getIgnoreSparesUnderQuality()
    • setIgnoreSparesUnderQuality

      public void setIgnoreSparesUnderQuality(PartQuality ignoreSparesUnderQuality)
    • getTemporaryPrisonerCapacity

      public int getTemporaryPrisonerCapacity()
    • setTemporaryPrisonerCapacity

      public void setTemporaryPrisonerCapacity(int temporaryPrisonerCapacity)
    • changeTemporaryPrisonerCapacity

      public void changeTemporaryPrisonerCapacity(int delta)
      Adjusts the temporary prisoner capacity by delta, clamped to at least PrisonerEventManager.MINIMUM_TEMPORARY_CAPACITY.
    • getCachedMashTheaterCapacity

      public int getCachedMashTheaterCapacity()
    • setMashTheatreCapacity

      public void setMashTheatreCapacity(int mashTheatreCapacity)
    • getMashTheatresWithinCapacity

      public boolean getMashTheatresWithinCapacity(Campaign campaign)
      Whether the force's MASH theatre capacity covers its patients assigned to doctors. Off-contract or in transit there is no cap. Takes a Campaign for the contract/location context the force does not hold.
    • calculateMASHTheaterCapacity

      public int calculateMASHTheaterCapacity(Campaign campaign)
    • getFieldKitchenWithinCapacity

      public boolean getFieldKitchenWithinCapacity()
    • setFieldKitchenWithinCapacity

      public void setFieldKitchenWithinCapacity(boolean fieldKitchenWithinCapacity)
    • getRepairBaysRented

      public int getRepairBaysRented()
    • setRepairBaysRented

      public void setRepairBaysRented(int repairBaysRented)
    • changeRepairBaysRented

      public void changeRepairBaysRented(int delta)
    • getAutomatedMothballUnits

      public List<UUID> getAutomatedMothballUnits()
    • setAutomatedMothballUnits

      public void setAutomatedMothballUnits(List<UUID> automatedMothballUnits)
    • getFormations

      public Formation getFormations()
    • setFormations

      public void setFormations(Formation formations)
    • getAllFormations

      public List<Formation> getAllFormations()
    • getFormationIds

      public TreeMap<Integer,Formation> getFormationIds()
    • getLastFormationId

      public int getLastFormationId()
    • getCombatTeamsMap

      public Hashtable<Integer,CombatTeam> getCombatTeamsMap()
      The raw, unsanitized combat-team table (keyed by formation id); used for serialization and iteration.
    • getFormation

      @Nullable public Formation getFormation(int id)
    • getAllUnitsInTheTOE

      public List<UUID> getAllUnitsInTheTOE(boolean standardFormationsOnly)
      Retrieves all units in the Table of Organization and Equipment (TOE).
      Parameters:
      standardFormationsOnly - if true, returns only units in FormationType.STANDARD formations; if false, returns all units.
      Returns:
      a List of UUID objects representing all units in the TOE according to the specified filter
    • addCombatTeam

      public void addCombatTeam(CombatTeam combatTeam)
    • removeCombatTeam

      public void removeCombatTeam(int formationId)
    • getCombatTeamsAsMap

      public Hashtable<Integer,CombatTeam> getCombatTeamsAsMap(Campaign campaign)
      Returns the Hashtable keyed by the combat team's formationId, after removing ineligible teams. The sanitization removes the need for isEligible() checks whenever the table is fetched.
    • getCombatTeamsAsList

      public List<CombatTeam> getCombatTeamsAsList(Campaign campaign)
    • addFormation

      public void addFormation(Formation formation, Formation superFormation, Campaign campaign)
      Add formation to an existing superformation. This method will also assign the formation an id and place it in the formationId hash.
    • moveFormation

      public void moveFormation(Formation formation, Formation superFormation, Campaign campaign)
      Moves formation to sit directly under superFormation in the TOE, detaching it from its current parent and inheriting the target's scenario assignment. Formation-type standardization is then applied per the moved formation's FormationType (parents may be standardized, children may inherit), and formation levels are repopulated across the TOE. No-ops if formation is null or equals superFormation. The Campaign is supplied as a parameter for the scenario and TOE updates this drives.
    • importFormation

      public void importFormation(Formation formation)
      This is used by the XML loader. The id should already be set for this formation so don't increment.
    • addUnitToFormation

      public void addUnitToFormation(@Nullable Unit unit, Formation formation, Campaign campaign)
    • addUnitToFormation

      public void addUnitToFormation(@Nullable Unit unit, int id, Campaign campaign)
      Add unit to an existing formation. This method will also assign that formation's id to the unit.
    • addAllCombatTeams

      public void addAllCombatTeams(Formation formation, Campaign campaign)
      Adds formation and all its sub-formations to the Combat Teams table.
    • removeFormation

      public void removeFormation(Formation formation, Campaign campaign)
      Removes formation from the TOE: unassigns its units (clearing their scenario if it was deployed), removes it from any scenario it was deployed to and from its parent formation, and clears any StratCon track assignments. The Campaign is supplied as a parameter for the scenario, contract, and combat-team updates this drives.
    • removeUnitFromFormation

      public void removeUnitFromFormation(Unit unit, Campaign campaign)
      Removes u from its current formation, clearing its formation and scenario assignments and detaching it from any C3 networks. When StratCon is enabled and this empties the formation, the formation is dropped from the combat-teams table. The Campaign is supplied as a parameter for the game and combat-team updates this drives.
    • getFormationFor

      @Nullable public Formation getFormationFor(@Nullable Unit unit)
      Returns:
      the Formation unit is currently assigned to, or null if unit is null or unassigned
    • getFormationFor

      @Nullable public Formation getFormationFor(Person person)
      Resolves the Formation a person belongs to: the formation of their assigned unit if they crew one, otherwise — for techs — the formation they are the assigned tech of.
      Returns:
      the person's formation, or null if none applies
    • refreshNetworks

      public void refreshNetworks(megamek.common.game.Game game)
      Rebuilds this force's C3, Naval C3, and C3i networks from the units' stored C3 UUIDs. The MegaMek Game is supplied as a parameter (the force holds no game reference) because network membership is resolved against the live game entities.
    • disbandNetworkOf

      public void disbandNetworkOf(Unit u, megamek.common.game.Game game)
      Disbands the entire C3i/Naval C3 network that u belongs to, clearing the stored next-node UUIDs of every unit on that network and refreshing networks against the supplied Game.
    • removeUnitsFromNetwork

      public void removeUnitsFromNetwork(Vector<Unit> removedUnits, megamek.common.game.Game game)
      Removes removedUnits from their shared C3i/Naval C3 network and rebuilds the remaining members' node UUIDs so the network stays contiguous, refreshing networks against the supplied Game. All removed units are assumed to share the first unit's network id.
    • addUnitsToNetwork

      public void addUnitsToNetwork(Vector<Unit> addedUnits, String networkID, megamek.common.game.Game game)
      Adds addedUnits to the C3i/Naval C3 network identified by networkID, rebuilding every member's node UUIDs, and refreshes networks against the supplied Game.
    • getAvailableC3iNetworks

      public Vector<String[]> getAvailableC3iNetworks()
      Returns:
      one entry per C3i network in the TOE that has at least one free node; each entry is a {networkId, freeNodeCount} pair
    • getAvailableNC3Networks

      public Vector<String[]> getAvailableNC3Networks()
      Returns:
      one entry per Naval C3 network in the TOE that has at least one free node; each entry is a {networkId, freeNodeCount} pair. Naval C3 mirrors C3i, so this parallels getAvailableC3iNetworks().
    • getAvailableNovaCEWSNetworks

      public Vector<String[]> getAvailableNovaCEWSNetworks()
      Returns:
      one entry per Nova CEWS network in the TOE that has at least one free node; each entry is a {networkId, freeNodeCount} pair. Nova CEWS networks hold at most three units.
    • getAvailableC3MastersForSlaves

      public Vector<String[]> getAvailableC3MastersForSlaves()
      Returns:
      the C3 masters in the TOE that can accept a slave (have a free C3 node), excluding company-level masters whose free-node count is unreliable; each entry is a {c3UUID, freeNodeCount, shortName} triple
    • getAvailableC3MastersForMasters

      public Vector<String[]> getAvailableC3MastersForMasters()
      Returns:
      the C3 masters in the TOE that can accept another master (have a free C3-M node); each entry is a {c3UUID, freeMasterNodeCount, shortName} triple
    • removeUnitsFromC3Master

      public void removeUnitsFromC3Master(Unit master, megamek.common.game.Game game)
      Detaches every unit slaved to master from it, clearing their C3 master reference and refreshing networks against the supplied Game.
    • detachUnitFromC3Networks

      public void detachUnitFromC3Networks(Unit u, megamek.common.game.Game game)
      Detaches u from any C3 network it participates in (Naval C3, C3i, Nova CEWS, or a C3 master), refreshing the affected networks against the supplied Game.