Record Class Quartermaster

java.lang.Object
java.lang.Record
mekhq.campaign.Quartermaster

public record Quartermaster(Campaign campaign) extends Record
Manages machines and material for a campaign.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the Quartermaster class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAmmo(megamek.common.equipment.AmmoType ammoType, int shots)
    Adds ammo to the campaign.
    void
    addAmmo(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon infantryWeapon, int shots)
    Adds infantry ammo to the campaign.
    void
    addPart(Part part, int transitDays)
    Deprecated.
    Use addPart(Part, int, boolean) instead to explicitly indicate whether the part is brand new.
    void
    addPart(Part part, int transitDays, boolean isBrandNew)
    Adds a part to the campaign's warehouse, specifying the number of transit days for its arrival and whether the part is considered brand new.
    void
    Denotes that a part in-transit has arrived.
    boolean
    buyPart(Part part, double costMultiplier, int transitDays)
    Tries to buy a part with a cost multiplier, arriving in a given number of days.
    boolean
    buyPart(Part part, int transitDays)
    Tries to buy a part arriving in a given number of days.
    boolean
    Tries to buy a refurbishment for a given part.
    boolean
    buyUnit(megamek.common.units.Entity en, int days)
     
    boolean
    buyUnit(megamek.common.units.Entity en, int days, double valueMultiplier)
    Tries to buy a unit.
    Gets the Campaign being managed by the Quartermaster.
    static int
    convertShots(megamek.common.equipment.AmmoType from, int shots, megamek.common.equipment.AmmoType to)
    Converts shots from one ammo type to another.
    static int
    convertShotsNeeded(megamek.common.equipment.AmmoType target, int shotsNeeded, megamek.common.equipment.AmmoType source)
    Calculates the shots needed when converting from a source ammo to a target ammo.
    final boolean
    Indicates whether some other object is "equal to" this one.
    int
    getAmmoAvailable(megamek.common.equipment.AmmoType ammoType)
    Gets the amount of ammo available of a given type.
    int
    getAmmoAvailable(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon weaponType)
    Gets the amount of ammo available of a given type.
    final int
    Returns a hash code value for this object.
    void
    Removes one or more parts from its OmniPod.
    void
    remotePartFromPod(Part part, int quantity)
    Removes one or more parts from its OmniPod.
    int
    removeAmmo(megamek.common.equipment.AmmoType ammoType, int shotsNeeded)
    Removes ammo from the campaign, if available.
    int
    removeAmmo(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon infantryWeapon, int shotsNeeded)
    Removes infantry ammo from the campaign, if available.
    int
    removeCompatibleAmmo(megamek.common.equipment.AmmoType ammoType, int shotsNeeded)
    Removes compatible ammo from the campaign, if available.
    void
    Sell all the ammo on hand.
    void
    sellAmmo(AmmoStorage ammo, int shots)
    Sell one or more shots of ammo.
    void
    Sell all the armor on hand.
    void
    sellArmor(Armor armor, int points)
    Sell one or more points of armor
    void
    sellPart(Part part)
    Sell all the parts on hand.
    void
    sellPart(Part part, int quantity)
    Sell one or more units of a part.
    void
    sellUnit(Unit unit)
    Sells a unit.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Quartermaster

      public Quartermaster(Campaign campaign)
      Initializes a new instance of the Quartermaster class.
      Parameters:
      campaign - The campaign being managed by the Quartermaster.
  • Method Details

    • campaign

      public Campaign campaign()
      Gets the Campaign being managed by the Quartermaster.
    • addPart

      @Deprecated public void addPart(Part part, int transitDays)
      Deprecated.
      Use addPart(Part, int, boolean) instead to explicitly indicate whether the part is brand new.
      Adds a part to the campaign, arriving in a set number of days. By default, the part is treated as not brand new. This method is deprecated in favor of the overloaded method that explicitly accepts a flag to indicate whether the part is brand new.

      This method delegates its behavior to addPart(Part, int, boolean) with the isBrandNew flag set to false.

      Parameters:
      part - The part to add to the campaign. Cannot be null.
      transitDays - The number of days until the part arrives, or zero if the part is already here.
    • addPart

      public void addPart(Part part, int transitDays, boolean isBrandNew)
      Adds a part to the campaign's warehouse, specifying the number of transit days for its arrival and whether the part is considered brand new. The method validates the input and decides whether to skip the addition based on specific conditions, such as test units, spare ammo bins, or missing parts without associated units.

      Once validated, the part is marked as new or used, set to arrive in the specified number of days, processed for campaign addition, and added to the campaign's warehouse.

      Parameters:
      part - The part to add to the campaign. Cannot be null.
      transitDays - The number of days until the part arrives. If the value is negative, it will be adjusted to zero, indicating the part is already here.
      isBrandNew - A boolean indicating whether the part is brand new. true if the part is new, otherwise false.
      Throws:
      NullPointerException - If part is null.
    • addAmmo

      public void addAmmo(megamek.common.equipment.AmmoType ammoType, int shots)
      Adds ammo to the campaign.
      Parameters:
      ammoType - The type of ammo to add.
      shots - The number of rounds of ammo to add.
    • addAmmo

      public void addAmmo(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon infantryWeapon, int shots)
      Adds infantry ammo to the campaign.
      Parameters:
      ammoType - The type of ammo to add.
      infantryWeapon - The type of infantry weapon using the ammo.
      shots - The number of rounds of ammo to add.
    • removeAmmo

      public int removeAmmo(megamek.common.equipment.AmmoType ammoType, int shotsNeeded)
      Removes ammo from the campaign, if available.
      Parameters:
      ammoType - The type of ammo to remove.
      shotsNeeded - The number of rounds of ammo needed.
      Returns:
      The number of rounds of ammo removed from the campaign. This value may be less than or equal to shotsNeeded.
    • removeCompatibleAmmo

      public int removeCompatibleAmmo(megamek.common.equipment.AmmoType ammoType, int shotsNeeded)
      Removes compatible ammo from the campaign, if available.
      Parameters:
      ammoType - The type of ammo to remove.
      shotsNeeded - The number of rounds of ammo needed.
      Returns:
      The number of rounds of ammo removed from the campaign. This value may be less than or equal to shotsNeeded.
    • convertShots

      public static int convertShots(megamek.common.equipment.AmmoType from, int shots, megamek.common.equipment.AmmoType to)
      Converts shots from one ammo type to another. NB: it is up to the caller to ensure the ammo types are compatible.
      Parameters:
      from - The AmmoType for which shots represents.
      shots - The number of shots of from.
      to - The AmmoType which shots should be converted to.
      Returns:
      The value of shots when converted to a specific AmmoType.
    • convertShotsNeeded

      public static int convertShotsNeeded(megamek.common.equipment.AmmoType target, int shotsNeeded, megamek.common.equipment.AmmoType source)
      Calculates the shots needed when converting from a source ammo to a target ammo. NB: it is up to the caller to ensure the ammo types are compatible.
      Parameters:
      target - The target ammo type.
      shotsNeeded - The number of shots needed in the target ammo type.
      source - The source ammo type.
      Returns:
      The number of shots needed from the source ammo type.
    • getAmmoAvailable

      public int getAmmoAvailable(megamek.common.equipment.AmmoType ammoType)
      Gets the amount of ammo available of a given type.
      Parameters:
      ammoType - The type of ammo.
      Returns:
      The number of shots available of the given ammo type.
    • getAmmoAvailable

      public int getAmmoAvailable(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon weaponType)
      Gets the amount of ammo available of a given type.
      Parameters:
      ammoType - The type of ammo.
      Returns:
      The number of shots available of the given ammo type.
    • removeAmmo

      public int removeAmmo(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon infantryWeapon, int shotsNeeded)
      Removes infantry ammo from the campaign, if available.
      Parameters:
      ammoType - The type of ammo to remove.
      infantryWeapon - The infantry weapon using the ammo.
      shotsNeeded - The number of rounds of ammo needed.
      Returns:
      The number of rounds of ammo removed from the campaign. This value may be less than or equal to shotsNeeded.
    • arrivePart

      public void arrivePart(Part part)
      Denotes that a part in-transit has arrived. Should be called when a part goes from 1 daysToArrival to zero.
      Parameters:
      part - The part which has arrived.
    • buyUnit

      public boolean buyUnit(megamek.common.units.Entity en, int days)
    • buyUnit

      public boolean buyUnit(megamek.common.units.Entity en, int days, double valueMultiplier)
      Tries to buy a unit.
      Parameters:
      en - The entity which represents the unit.
      days - The number of days until the new unit arrives.
      valueMultiplier - A multiplier to apply to the unit's value.
      Returns:
      True if the unit was purchased, otherwise false.
    • sellUnit

      public void sellUnit(Unit unit)
      Sells a unit.
      Parameters:
      unit - The unit to sell.
    • sellPart

      public void sellPart(Part part)
      Sell all the parts on hand.
      Parameters:
      part - The part to sell.
    • sellPart

      public void sellPart(Part part, int quantity)
      Sell one or more units of a part.
      Parameters:
      part - The part to sell.
      quantity - The amount to sell of the part.
    • sellAmmo

      public void sellAmmo(AmmoStorage ammo)
      Sell all the ammo on hand.
      Parameters:
      ammo - The ammo to sell.
    • sellAmmo

      public void sellAmmo(AmmoStorage ammo, int shots)
      Sell one or more shots of ammo.
      Parameters:
      ammo - The ammo to sell.
      shots - The number of shots of ammo to sell.
    • sellArmor

      public void sellArmor(Armor armor)
      Sell all the armor on hand.
      Parameters:
      armor - The armor to sell.
    • sellArmor

      public void sellArmor(Armor armor, int points)
      Sell one or more points of armor
      Parameters:
      armor - The armor to sell.
      points - The number of points of armor to sell.
    • remotePartFromPod

      public void remotePartFromPod(Part part)
      Removes one or more parts from its OmniPod.
      Parameters:
      part - The OmniPodded part.
    • remotePartFromPod

      public void remotePartFromPod(Part part, int quantity)
      Removes one or more parts from its OmniPod.
      Parameters:
      part - The OmniPodded part.
      quantity - The number of OmniPodded parts to de-pod.
    • buyRefurbishment

      public boolean buyRefurbishment(Part part)
      Tries to buy a refurbishment for a given part.
      Parameters:
      part - The part being refurbished.
      Returns:
      True if the refurbishment was purchased, otherwise false.
    • buyPart

      public boolean buyPart(Part part, int transitDays)
      Tries to buy a part arriving in a given number of days.
      Parameters:
      part - The part to buy.
      transitDays - The number of days until the new part arrives.
      Returns:
      True if the part was purchased, otherwise false.
    • buyPart

      public boolean buyPart(Part part, double costMultiplier, int transitDays)
      Tries to buy a part with a cost multiplier, arriving in a given number of days.
      Parameters:
      part - The part to buy.
      costMultiplier - The cost multiplier for the purchase.
      transitDays - The number of days until the new part arrives.
      Returns:
      True if the part was purchased, otherwise false.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.