Class AtBContract

Direct Known Subclasses:
AtBContract.AtBContractRef

public class AtBContract extends Contract
Contract class for use with Against the Bot rules
  • Field Details

    • MINIMUM_INTENSITY

      public static final double MINIMUM_INTENSITY
      The minimum intensity below which no scenarios will be generated
      See Also:
    • parentContract

      protected AtBContract parentContract
    • employerCode

      protected String employerCode
    • enemyCode

      protected String enemyCode
    • enemyName

      protected String enemyName
    • contractType

      protected AtBContractType contractType
    • allySkill

      protected megamek.common.enums.SkillLevel allySkill
    • allyQuality

      protected int allyQuality
    • enemySkill

      protected megamek.common.enums.SkillLevel enemySkill
    • enemyQuality

      protected int enemyQuality
    • allyBotName

      protected String allyBotName
    • enemyBotName

      protected String enemyBotName
    • allyCamouflage

      protected megamek.common.icons.Camouflage allyCamouflage
    • allyColour

      protected megamek.client.ui.swing.util.PlayerColour allyColour
    • enemyCamouflage

      protected megamek.common.icons.Camouflage enemyCamouflage
    • enemyColour

      protected megamek.client.ui.swing.util.PlayerColour enemyColour
    • extensionLength

      protected int extensionLength
    • requiredCombatTeams

      protected int requiredCombatTeams
    • moraleLevel

      protected AtBMoraleLevel moraleLevel
    • routEnd

      protected LocalDate routEnd
    • partsAvailabilityLevel

      protected int partsAvailabilityLevel
    • sharesPct

      protected int sharesPct
    • playerMinorBreaches

      protected int playerMinorBreaches
    • employerMinorBreaches

      protected int employerMinorBreaches
    • contractScoreArbitraryModifier

      protected int contractScoreArbitraryModifier
    • moraleMod

      protected int moraleMod
    • priorLogisticsFailure

      protected boolean priorLogisticsFailure
    • specialEventScenarioDate

      protected LocalDate specialEventScenarioDate
      If the date is non-null, there will be a special scenario or big battle on that date, but the scenario is not generated until the other battle rolls for the week.
    • specialEventScenarioType

      protected int specialEventScenarioType
    • battleTypeMod

      protected int battleTypeMod
    • nextWeekBattleTypeMod

      protected int nextWeekBattleTypeMod
  • Constructor Details

    • AtBContract

      protected AtBContract()
    • AtBContract

      public AtBContract(String name)
    • AtBContract

      public AtBContract(Contract c, Campaign campaign)
  • Method Details

    • setRoutEndDate

      public void setRoutEndDate(LocalDate routEnd)
      Sets the end date of the rout. This should only be applied on contracts whose morale equals ROUTED
      Parameters:
      routEnd - the LocalDate representing the end date of the rout
    • initContractDetails

      public void initContractDetails(Campaign campaign)
    • pickRandomCamouflage

      public static megamek.common.icons.Camouflage pickRandomCamouflage(int currentYear, String factionCode)
      Selects a random camouflage for the given faction based on the faction code and year. If there are no available files in the faction directory, it logs a warning and uses default camouflage.
      Parameters:
      currentYear - the current year in the game.
      factionCode - the code representing the faction for which the camouflage is to be selected.
    • calculateLength

      public void calculateLength(boolean variable)
    • calculateRequiredLances

      public static int calculateRequiredLances(Campaign campaign)
      Calculates the number of lances required for this contract, based on [campaign].
      Parameters:
      campaign - The campaign to reference.
      Returns:
      The number of lances required.
    • getEffectiveNumUnits

      public static int getEffectiveNumUnits(Campaign campaign)
      Calculates the effective number of units available in the given campaign based on unit types and roles.

      This method iterates through all combat teams in the specified campaign, ignoring combat teams with the auxiliary role. For each valid combat team, it retrieves the associated force and evaluates all units within that force. The unit contribution to the total is determined based on its type:

      • TANK, VTOL, NAVAL, CONV_FIGHTER, AEROSPACEFIGHTER: Adds 1 for non-clan factions, and 0.5 for clan factions.
      • PROTOMEK: Adds 0.2 to the total.
      • BATTLE_ARMOR, INFANTRY: Adds 0 (excluded from the total).
      • Other types: Adds 1 to the total.

      Units that aren’t associated with a valid combat team or can’t be fetched due to missing data are ignored. The final result is returned as an integer by flooring the calculated total.

      Parameters:
      campaign - the campaign containing the combat teams and units to evaluate
      Returns:
      the effective number of units as an integer
    • isMinorPower

      @Deprecated(since="0.50.04", forRemoval=true) public static boolean isMinorPower(String factionCode)
      Deprecated, for removal: This API element is subject to removal in a future version.
      No indicated uses.
      Is not used.
      Since:
      0.50.04
    • checkMorale

      public void checkMorale(Campaign campaign, LocalDate today)
      Checks and updates the morale which depends on various conditions such as the rout end date, skill levels, victories, defeats, etc. This method also updates the enemy status based on the morale level.
      Parameters:
      today - The current date in the context.
    • getRepairLocation

      public int getRepairLocation(int unitRating)
      Retrieves the repair location based on the unit rating and contract type.
      Parameters:
      unitRating - The rating of the unit.
      Returns:
      The repair location.
    • addMoraleMod

      @Deprecated(since="0.50.04", forRemoval=true) public void addMoraleMod(int mod)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Not in use
      Since:
      0.50.04
    • getScore

      public int getScore()
    • getContractScoreArbitraryModifier

      public int getContractScoreArbitraryModifier()
    • doBonusRoll

      public boolean doBonusRoll(Campaign campaign, boolean isPostScenario)
      Performs a bonus roll to determine and execute a random campaign bonus. The roll is simulated using 1d6, and the outcome triggers different bonus effects based on the roll value. The effects may involve recruiting dependents, adding new units, or other benefits as determined by the campaign options and roll outcome.
      Parameters:
      campaign - the current Campaign instance.
      isPostScenario - a boolean indicating if this roll occurs post-scenario (used to determine specific behaviors for roll = 3).
      Returns:
      true if specific post-scenario behavior is triggered (roll = 3), otherwise false.
      Throws:
      IllegalStateException - if an unexpected roll value is encountered.
    • isSubcontract

      public boolean isSubcontract()
    • getParentContract

      public AtBContract getParentContract()
    • setParentContract

      public void setParentContract(AtBContract parent)
    • isMercSubcontract

      public boolean isMercSubcontract()
    • setMercSubcontract

      public void setMercSubcontract(boolean sub)
    • isAttacker

      public boolean isAttacker()
    • setAttacker

      public void setAttacker(boolean isAttacker)
    • checkEvents

      public void checkEvents(Campaign campaign)
    • getRandomDayOfMonth

      public LocalDate getRandomDayOfMonth(LocalDate today)
    • contractExtended

      public boolean contractExtended(Campaign campaign)
    • getMonthlyPayOut

      public Money getMonthlyPayOut()
      Overrides:
      getMonthlyPayOut in class Contract
    • writeToXMLBegin

      protected int writeToXMLBegin(PrintWriter pw, int indent)
      Overrides:
      writeToXMLBegin in class Contract
    • loadFieldsFromXmlNode

      public void loadFieldsFromXmlNode(Node wn) throws ParseException
      Overrides:
      loadFieldsFromXmlNode in class Contract
      Throws:
      ParseException
    • restore

      public void restore(Campaign c)
      Restores any references to other contracts.
      Parameters:
      c - The Campaign which holds this contract.
    • getEmployerFaction

      public Faction getEmployerFaction()
    • getEmployerCode

      public String getEmployerCode()
    • setEmployerCode

      @Deprecated(since="0.50.04") public void setEmployerCode(String code, LocalDate date)
      Deprecated.
      Since:
      0.50.04
    • setEmployerCode

      public void setEmployerCode(String code, int year)
    • getEmployerName

      public String getEmployerName(int year)
    • getEnemy

      public Faction getEnemy()
    • getEnemyCode

      public String getEnemyCode()
    • getEnemyName

      public String getEnemyName(int year)
      Retrieves the name of the enemy for this contract.
      Parameters:
      year - The current year in the game.
      Returns:
      The name of the enemy.
    • setEnemyCode

      public void setEnemyCode(String enemyCode)
    • getContractType

      public AtBContractType getContractType()
    • setContractType

      public void setContractType(AtBContractType contractType)
    • getAllySkill

      public megamek.common.enums.SkillLevel getAllySkill()
    • setAllySkill

      public void setAllySkill(megamek.common.enums.SkillLevel allySkill)
    • getEnemySkill

      public megamek.common.enums.SkillLevel getEnemySkill()
    • setEnemySkill

      public void setEnemySkill(megamek.common.enums.SkillLevel enemySkill)
    • getAllyQuality

      public int getAllyQuality()
    • setAllyQuality

      public void setAllyQuality(int allyQuality)
    • getEnemyQuality

      public int getEnemyQuality()
    • setEnemyQuality

      public void setEnemyQuality(int enemyQuality)
    • getAllyBotName

      public String getAllyBotName()
    • setAllyBotName

      public void setAllyBotName(String name)
    • getEnemyBotName

      public String getEnemyBotName()
    • setEnemyBotName

      public void setEnemyBotName(String name)
    • getAllyCamouflage

      public megamek.common.icons.Camouflage getAllyCamouflage()
    • setAllyCamouflage

      public void setAllyCamouflage(megamek.common.icons.Camouflage allyCamouflage)
    • getAllyColour

      public megamek.client.ui.swing.util.PlayerColour getAllyColour()
    • setAllyColour

      public void setAllyColour(megamek.client.ui.swing.util.PlayerColour allyColour)
    • getEnemyCamouflage

      public megamek.common.icons.Camouflage getEnemyCamouflage()
    • setEnemyCamouflage

      public void setEnemyCamouflage(megamek.common.icons.Camouflage enemyCamouflage)
    • getEnemyColour

      public megamek.client.ui.swing.util.PlayerColour getEnemyColour()
    • setEnemyColour

      public void setEnemyColour(megamek.client.ui.swing.util.PlayerColour enemyColour)
    • getRequiredCombatTeams

      public int getRequiredCombatTeams()
    • setRequiredCombatTeams

      public void setRequiredCombatTeams(int required)
    • getPartsAvailabilityLevel

      public int getPartsAvailabilityLevel()
    • setPartsAvailabilityLevel

      public void setPartsAvailabilityLevel(int partsAvailabilityLevel)
    • getMoraleLevel

      public AtBMoraleLevel getMoraleLevel()
    • setMoraleLevel

      public void setMoraleLevel(AtBMoraleLevel moraleLevel)
    • getSharesPercent

      public int getSharesPercent()
      Description copied from class: Contract
      Retrieves the percentage of shares for this contract. This currently returns a default value of 30.
      Overrides:
      getSharesPercent in class Contract
      Returns:
      the percentage of shares
    • setAtBSharesPercent

      public void setAtBSharesPercent(int pct)
    • isBatchallAccepted

      public boolean isBatchallAccepted()
      Checks if the Batchall has been accepted for the contract.
      Returns:
      true if the Batchall has been accepted, false otherwise.
    • setBatchallAccepted

      public void setBatchallAccepted(boolean batchallAccepted)
      Sets the batchallAccepted flag for this contract.
      Parameters:
      batchallAccepted - The value to set for the batchallAccepted flag.
    • addPlayerMinorBreach

      public void addPlayerMinorBreach()
    • addPlayerMinorBreaches

      public void addPlayerMinorBreaches(int num)
    • addEmployerMinorBreach

      @Deprecated(since="0.50.04", forRemoval=true) public void addEmployerMinorBreach()
      Deprecated, for removal: This API element is subject to removal in a future version.
      - Not in use.
      Since:
      0.50.04
    • addEmployerMinorBreaches

      public void addEmployerMinorBreaches(int num)
    • setContractScoreArbitraryModifier

      public void setContractScoreArbitraryModifier(int newModifier)
    • getBattleTypeMod

      public int getBattleTypeMod()
    • getStratconCampaignState

      public StratconCampaignState getStratconCampaignState()
    • setStratconCampaignState

      public void setStratconCampaignState(StratconCampaignState state)
    • acceptContract

      public void acceptContract(Campaign campaign)
      Description copied from class: Contract
      Calculations to be performed once the contract has been accepted.
      Overrides:
      acceptContract in class Contract
    • clanTechSalvageOverride

      public void clanTechSalvageOverride()
      Applies a salvage override rule for Clan technology based on the contract timeline and faction involvement. This method checks the factions of both the enemy and employer and determines if a salvage exchange should be forced based on whether the battle occurs before the Battle of Tukayyid.

      This rule was implemented to better match canon employer behavior during this period.

    • initiateBatchall

      public boolean initiateBatchall(Campaign campaign)
      This method initiates a batchall, a challenge/dialog to decide on the conduct of a campaign. Prompts the player with a message and options to accept or refuse the batchall.
      Parameters:
      campaign - The current campaign.
      Returns:
      true if the batchall is accepted, false otherwise.
    • getContractDifficultySkulls

      public JPanel getContractDifficultySkulls(Campaign campaign)
      This method returns a JPanel that represents the difficulty skulls for a given mission.
      Parameters:
      campaign - the campaign for which the difficulty skulls are calculated
      Returns:
      a JPanel with the difficulty skulls displayed
    • calculateContractDifficulty

      @Deprecated(since="0.50.04") public int calculateContractDifficulty(Campaign campaign)
      Calculates the difficulty of a contract based on the relative power of enemy forces, player forces, and any allied forces involved in the campaign.

      The method evaluates the enemy's estimated power against the player's strengths and considers allied contributions depending on the assigned command rights. The result is a difficulty level mapped between 1 and 10, where higher values represent more challenging contracts.

      Parameters:
      campaign - The Campaign object representing the current game state. Used to extract information about the player's forces, enemy forces, and allied forces.
      Returns:
      An integer representing the difficulty of the contract:
      • 1 = very easy
      • 10 = extremely difficult

      WARNING: Returns `-99` (defined as `ERROR`) if the enemy's power cannot be calculated.

      Mapped Result Explanation:

      The method divides the absolute percentage difference between enemy and player forces by 20 (rounding up), then adjusts the difficulty accordingly:
      • If the player's forces are stronger, the difficulty is adjusted downward from a baseline of 5.
      • If the enemy's forces are stronger, the difficulty is adjusted upward from a baseline of 5.
      • If an error is encountered, the difficulty is returned as -99
      The result is clamped to fit between the valid range of 1 and 10. Or -99 if an error is encountered.
      Since:
      0.50.04
    • calculateContractDifficulty

      public int calculateContractDifficulty(int gameYear, boolean useGenericBV, List<megamek.common.Entity> playerCombatUnits)
      Calculates the difficulty of a contract based on the relative power of enemy forces, player forces, and any allied forces involved in the campaign.

      The method evaluates the enemy's estimated power against the player's strengths and considers allied contributions depending on the assigned command rights. The result is a difficulty level mapped between 1 and 10, where higher values represent more challenging contracts.

      Parameters:
      gameYear - The current year in the campaign (e.g., from Campaign.getGameYear())
      useGenericBV - Whether "Use Generic BV" is enabled in the Campaign Options
      playerCombatUnits - List of Entities representing all combat units for the player. This can be obtained via Campaign.getAllCombatEntities().
      Returns:
      An integer representing the difficulty of the contract:
      • 1 = very easy
      • 10 = extremely difficult

      WARNING: Returns `-99` (defined as `ERROR`) if the enemy's power cannot be calculated.

      Mapped Result Explanation:

      The method divides the absolute percentage difference between enemy and player forces by 20 (rounding up), then adjusts the difficulty accordingly:
      • If the player's forces are stronger, the difficulty is adjusted downward from a baseline of 5.
      • If the enemy's forces are stronger, the difficulty is adjusted upward from a baseline of 5.
      • If an error is encountered, the difficulty is returned as -99
      The result is clamped to fit between the valid range of 1 and 10. Or -99 if an error is encountered.
    • getCommandRoll

      public int getCommandRoll()
      Returns:
      the command roll that was used to determine command rights. Only used by CamOps Contract Market.
    • setCommandRoll

      public void setCommandRoll(int roll)
      Parameters:
      roll - the command roll that was used to determine command rights. Only used by CamOps Contract Market.
    • getSalvageRoll

      public int getSalvageRoll()
      Returns:
      the salvage roll that was used to determine salvage rights. Only used by CamOps Contract Market.
    • setSalvageRoll

      public void setSalvageRoll(int roll)
      Parameters:
      roll - the salvage roll that was used to determine salvage rights. Only used by CamOps Contract Market.
    • getSupportRoll

      public int getSupportRoll()
      Returns:
      the support roll that was used to determine support rights. Only used by CamOps Contract Market.
    • setSupportRoll

      public void setSupportRoll(int roll)
      Parameters:
      roll - the support roll that was used to determine support rights. Only used by CamOps Contract Market.
    • getTransportRoll

      public int getTransportRoll()
      Returns:
      the transport roll that was used to determine transport rights. Only used by CamOps Contract Market.
    • setTransportRoll

      public void setTransportRoll(int roll)
      Parameters:
      roll - the transport roll that was used to determine transport rights. Only used by CamOps Contract Market.
    • getRoutedPayout

      @Nullable public Money getRoutedPayout()