Package mekhq.campaign
Record Class Quartermaster
java.lang.Object
java.lang.Record
mekhq.campaign.Quartermaster
Manages machines and material for a campaign.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionQuartermaster(Campaign campaign) Initializes a new instance of the Quartermaster class. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAmmo(megamek.common.equipment.AmmoType ammoType, int shots) Adds ammo to the campaign.voidaddAmmo(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon infantryWeapon, int shots) Adds infantry ammo to the campaign.voidDeprecated.voidAdds a part to the campaign's warehouse, specifying the number of transit days for its arrival and whether the part is considered brand new.voidarrivePart(Part part) Denotes that a part in-transit has arrived.booleanTries to buy a part with a cost multiplier, arriving in a given number of days.booleanTries to buy a part arriving in a given number of days.booleanbuyRefurbishment(Part part) Tries to buy a refurbishment for a given part.booleanbuyUnit(megamek.common.units.Entity en, int days) booleanbuyUnit(megamek.common.units.Entity en, int days, double valueMultiplier) Tries to buy a unit.campaign()Gets the Campaign being managed by the Quartermaster.static intconvertShots(megamek.common.equipment.AmmoType from, int shots, megamek.common.equipment.AmmoType to) Converts shots from one ammo type to another.static intconvertShotsNeeded(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 booleanIndicates whether some other object is "equal to" this one.intgetAmmoAvailable(megamek.common.equipment.AmmoType ammoType) Gets the amount of ammo available of a given type.intgetAmmoAvailable(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon weaponType) Gets the amount of ammo available of a given type.final inthashCode()Returns a hash code value for this object.voidremotePartFromPod(Part part) Removes one or more parts from its OmniPod.voidremotePartFromPod(Part part, int quantity) Removes one or more parts from its OmniPod.intremoveAmmo(megamek.common.equipment.AmmoType ammoType, int shotsNeeded) Removes ammo from the campaign, if available.intremoveAmmo(megamek.common.equipment.AmmoType ammoType, megamek.common.weapons.infantry.InfantryWeapon infantryWeapon, int shotsNeeded) Removes infantry ammo from the campaign, if available.intremoveCompatibleAmmo(megamek.common.equipment.AmmoType ammoType, int shotsNeeded) Removes compatible ammo from the campaign, if available.voidsellAmmo(AmmoStorage ammo) Sell all the ammo on hand.voidsellAmmo(AmmoStorage ammo, int shots) Sell one or more shots of ammo.voidSell all the armor on hand.voidSell one or more points of armorvoidSell all the parts on hand.voidSell one or more units of a part.voidSells a unit.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Quartermaster
Initializes a new instance of the Quartermaster class.- Parameters:
campaign- The campaign being managed by the Quartermaster.
-
-
Method Details
-
campaign
Gets the Campaign being managed by the Quartermaster. -
addPart
Deprecated.UseaddPart(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 theisBrandNewflag set tofalse.- Parameters:
part- The part to add to the campaign. Cannot benull.transitDays- The number of days until the part arrives, or zero if the part is already here.
-
addPart
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 benull.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- Abooleanindicating whether the part is brand new.trueif the part is new, otherwisefalse.- Throws:
NullPointerException- Ifpartisnull.
-
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 whichshotsrepresents.shots- The number of shots offrom.to- The AmmoType whichshotsshould be converted to.- Returns:
- The value of
shotswhen 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
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
Sells a unit.- Parameters:
unit- The unit to sell.
-
sellPart
Sell all the parts on hand.- Parameters:
part- The part to sell.
-
sellPart
Sell one or more units of a part.- Parameters:
part- The part to sell.quantity- The amount to sell of the part.
-
sellAmmo
Sell all the ammo on hand.- Parameters:
ammo- The ammo to sell.
-
sellAmmo
Sell one or more shots of ammo.- Parameters:
ammo- The ammo to sell.shots- The number of shots of ammo to sell.
-
sellArmor
Sell all the armor on hand.- Parameters:
armor- The armor to sell.
-
sellArmor
Sell one or more points of armor- Parameters:
armor- The armor to sell.points- The number of points of armor to sell.
-
remotePartFromPod
Removes one or more parts from its OmniPod.- Parameters:
part- The OmniPodded part.
-
remotePartFromPod
Removes one or more parts from its OmniPod.- Parameters:
part- The OmniPodded part.quantity- The number of OmniPodded parts to de-pod.
-
buyRefurbishment
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
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
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
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. -
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. -
equals
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 withObjects::equals(Object,Object).
-
addPart(Part, int, boolean)instead to explicitly indicate whether the part is brand new.