Class Refit

java.lang.Object
mekhq.campaign.parts.Part
mekhq.campaign.parts.Refit
All Implemented Interfaces:
megamek.common.ITechnology, IAcquisitionWork, IPartWork, IWork

public class Refit extends Part implements IAcquisitionWork
This object tracks the refit of a given unit into a new unit. It has fields for the current entity and the new entity, and it uses these to calculate various characteristics of the refit.

It can then also be used to track the actual refit process, by attaching it to a Unit.

  • Field Details

  • Constructor Details

    • Refit

      public Refit()
      Blank refit constructor. Probably should not be used.
    • Refit

      public Refit(Unit oldUnit, megamek.common.Entity newEntity, boolean custom, boolean refurbish, boolean saveFile)
      Standard Refit Constructor
      Parameters:
      oldUnit - - The unit that is to be refit
      newEntity - - The target design for the unit to be refit into
      custom - - Is this custom work vs using a factory refit kit
      refurbish - - Are we refurbishing this unit rather than refitting it
      saveFile - - Does the new unit need to be saved to disk
  • Method Details

    • isSameArmorType

      public boolean isSameArmorType()
      Returns:
      Is the old unit using the same armor type as the new unit
    • getRefitClassName

      public static String getRefitClassName(int refitClass)
      Parameters:
      refitClass - - the integer representing the refit class
      Returns:
      the printable name of the refit class
    • getRefitClassName

      public String getRefitClassName()
      Returns:
      the printable name of our refit class
    • getRefitClass

      public int getRefitClass()
      Returns:
      the integer representing our refit class
    • getCost

      public Money getCost()
      Returns:
      The cost of carrying out this refit
    • getOldUnitParts

      @Deprecated(since="0.50.04") public List<Part> getOldUnitParts()
      Deprecated.
      - If only used in a Test file, do we need it?
      Returns a mutable list of parts for the old unit in the refit. This is intended to be mutated only be Campaign when merging parts.

      This is only used by RefitTest.java

      Returns:
      A mutable List of old parts in the refit.
      Since:
      0.50.04
    • getNewUnitParts

      @Deprecated(since="0.50.04") public List<Part> getNewUnitParts()
      Deprecated.
      - If only used in a Test file, do we need it?
      Returns a mutable list of parts for the new unit in the refit. This is intended to be mutated only be Campaign when merging parts.

      This is only used by RefitTest.java

      Returns:
      A mutable List of new part IDs in the refit.
      Since:
      0.50.04
    • getShoppingList

      public List<Part> getShoppingList()
      Returns:
      A list of parts required to make this refit happen
    • getShoppingListDescription

      public String[] getShoppingListDescription()
      Returns:
      Printable list of shopping items for display
    • getTime

      public int getTime()
      Returns:
      the time this refit will take
    • calculate

      public void calculate()
      Do all the grunt work to determine what parts are being added, removed, moved, and what other manipulations are happening in this refit.
    • begin

      public void begin() throws megamek.common.loaders.EntityLoadingException, IOException
      Begins the refit after it's been calculated and configured.
      Throws:
      megamek.common.loaders.EntityLoadingException
      IOException
    • reserveNewParts

      public void reserveNewParts()
      Goes through the required parts and marks them as reserved in the warehouse
    • partsInTransit

      public boolean partsInTransit()
      Returns:
      if any of our parts are still in transit.
    • acquireParts

      public boolean acquireParts()
      Actually order the parts we need for this refit
      Returns:
      true when the shopping list is empty and there's nothing left to buy
    • orderArmorSupplies

      public void orderArmorSupplies()
      Orders armor that is required for this refit
    • getExistingArmorSupplies

      @Nullable public Armor getExistingArmorSupplies()
      Returns:
      Armor that's in our warehouse already, if there is any
    • cancel

      public void cancel()
      Aborts this refit and releases the various marked parts to be used for other purposes.

      TODO: WeaverThree - Is it safe to call this on an un-started refit? Looks like no.

    • saveCustomization

      public void saveCustomization() throws megamek.common.loaders.EntityLoadingException
      Writes the configuration for the new side of the refit to a .mtf or .blk file in the customs directory.
      Throws:
      megamek.common.loaders.EntityLoadingException
    • getOriginalEntity

      public megamek.common.Entity getOriginalEntity()
      Returns:
      The entity we're refitting FROM
    • getNewEntity

      public megamek.common.Entity getNewEntity()
      Returns:
      The entity that we're refitting TO.
    • getOriginalUnit

      public Unit getOriginalUnit()
      Returns:
      The unit we're refitting FROM
    • hasFailedCheck

      public boolean hasFailedCheck()
      Returns:
      Have we failed a refit check? If so, the quality of the parts will decrease. unless it's a refurbishment, at least.
    • needsFixing

      public boolean needsFixing()
      We always need fixing until the refit is done
      Specified by:
      needsFixing in interface IWork
    • getDifficulty

      public int getDifficulty()
      Specified by:
      getDifficulty in interface IWork
      Returns:
      The difficulty modifier for our refit class
    • getAllMods

      public megamek.common.TargetRoll getAllMods(Person tech)
      Specified by:
      getAllMods in interface IWork
      Overrides:
      getAllMods in class Part
      Parameters:
      tech - - a Person whose attribute may modify this roll
      Returns:
      a TargetRoll describing all of our difficulty modifiers
    • succeed

      public String succeed()
      Specified by:
      succeed in interface IWork
      Overrides:
      succeed in class Part
      Returns:
      string describing our already-decided success
    • fail

      public String fail(int rating)
      Specified by:
      fail in interface IWork
      Overrides:
      fail in class Part
      Parameters:
      rating - - ignored
      Returns:
      string describing our already-decided failure
    • resetTimeSpent

      public void resetTimeSpent()
      Reset time spent on this refit to zero minutes.
      Specified by:
      resetTimeSpent in interface IPartWork
      Overrides:
      resetTimeSpent in class Part
    • getPartName

      public String getPartName()
      Specified by:
      getPartName in interface IPartWork
      Overrides:
      getPartName in class Part
      Returns:
      Name of the refit item
    • getAcquisitionName

      public String getAcquisitionName()
      Specified by:
      getAcquisitionName in interface IAcquisitionWork
      Returns:
      Name of the refit item
    • getName

      public String getName()
      Overrides:
      getName in class Part
      Returns:
      Name of the refit item
    • getSkillMin

      public int getSkillMin()
      Anyone can do a refit, even if it's a bad idea. The skill required doesn't change.
      Specified by:
      getSkillMin in interface IPartWork
      Overrides:
      getSkillMin in class Part
      Returns:
      EXP_GREEN
    • getBaseTime

      public int getBaseTime()
      A refit has the same base and actual time
      Specified by:
      getBaseTime in interface IPartWork
      Returns:
      minutes to complete refit
    • getActualTime

      public int getActualTime()
      A refit has the same base and actual time
      Specified by:
      getActualTime in interface IPartWork
      Overrides:
      getActualTime in class Part
      Returns:
      minutes to complete refit
    • getTimeSpent

      public int getTimeSpent()
      Specified by:
      getTimeSpent in interface IPartWork
      Overrides:
      getTimeSpent in class Part
      Returns:
      how many minutes have already been spent on this refit
    • getTimeLeft

      public int getTimeLeft()
      Specified by:
      getTimeLeft in interface IPartWork
      Overrides:
      getTimeLeft in class Part
      Returns:
      how many minutes are left to go on this refit
    • addTimeSpent

      public void addTimeSpent(int time)
      Specified by:
      addTimeSpent in interface IPartWork
      Overrides:
      addTimeSpent in class Part
      Parameters:
      time - - minutes to add to time spent on this refit
    • getTech

      @Nullable public Person getTech()
      Specified by:
      getTech in interface IWork
      Overrides:
      getTech in class Part
      Returns:
      tech Person assigned to this refit
    • setTech

      public void setTech(@Nullable Person tech)
      Specified by:
      setTech in interface IPartWork
      Overrides:
      setTech in class Part
      Parameters:
      tech - - tech Person to assign to this refit
    • hasWorkedOvertime

      public boolean hasWorkedOvertime()
      We don't do overtime
      Specified by:
      hasWorkedOvertime in interface IPartWork
      Overrides:
      hasWorkedOvertime in class Part
      Returns:
      false
    • setWorkedOvertime

      public void setWorkedOvertime(boolean b)
      We don't do overtime
      Specified by:
      setWorkedOvertime in interface IPartWork
      Overrides:
      setWorkedOvertime in class Part
      Parameters:
      b - - ignored
    • getShorthandedMod

      public int getShorthandedMod()
      We don't do short handedness
      Specified by:
      getShorthandedMod in interface IPartWork
      Overrides:
      getShorthandedMod in class Part
    • setShorthandedMod

      public void setShorthandedMod(int i)
      We don't do short handedness
      Specified by:
      setShorthandedMod in interface IPartWork
      Overrides:
      setShorthandedMod in class Part
    • updateConditionFromEntity

      public void updateConditionFromEntity(boolean checkForDestruction)
      We don't do this
      Specified by:
      updateConditionFromEntity in interface IPartWork
      Parameters:
      checkForDestruction - - ignored
    • updateConditionFromPart

      public void updateConditionFromPart()
      We don't do this
      Specified by:
      updateConditionFromPart in interface IPartWork
    • fix

      public void fix()
      We don't do this
      Specified by:
      fix in interface IPartWork
      Overrides:
      fix in class Part
    • remove

      public void remove(boolean salvage)
      We don't do this
      Specified by:
      remove in interface IPartWork
      Parameters:
      salvage - - ignored
    • getMissingPart

      @Nullable public MissingPart getMissingPart()
      There is no missing part version of a refit
      Specified by:
      getMissingPart in interface IPartWork
      Returns:
      null
    • getDesc

      public String getDesc()
      This should never come up for us
      Specified by:
      getDesc in interface IPartWork
      Overrides:
      getDesc in class Part
      Returns:
      a description string
    • getDetails

      public String getDetails()
      Get the details for this item. Always includes repair details that don't exist here.
      Specified by:
      getDetails in interface IPartWork
      Overrides:
      getDetails in class Part
      Returns:
      Full details string
    • getDetails

      public String getDetails(boolean includeRepairDetails)
      Get the details for this item. Repair details optional but don't exist here.
      Specified by:
      getDetails in interface IPartWork
      Overrides:
      getDetails in class Part
      Parameters:
      includeRepairDetails - - ignored
      Returns:
      Full details string
    • getUnit

      public Unit getUnit()
      Specified by:
      getUnit in interface IAcquisitionWork
      Specified by:
      getUnit in interface IPartWork
      Overrides:
      getUnit in class Part
      Returns:
      Always the unit we're refitting FROM
    • isSalvaging

      public boolean isSalvaging()
      We don't do salvage
      Specified by:
      isSalvaging in interface IPartWork
      Overrides:
      isSalvaging in class Part
      Returns:
      false
    • checkFixable

      @Nullable public String checkFixable()
      Is there anything blocking the refit?
      Specified by:
      checkFixable in interface IPartWork
      Returns:
      String detailing blockers
    • writeToXML

      public void writeToXML(PrintWriter pw, int indent)
      Dumps this object into XML for the save file
      Specified by:
      writeToXML in class Part
      Parameters:
      pw - - output writer
      indent - - current indent level in the XML
    • generateInstanceFromXML

      @Nullable public static Refit generateInstanceFromXML(Node wn, megamek.Version version, Campaign campaign, Unit unit)
      Recreates a refit from the save data
      Parameters:
      wn - - our XML node
      version - - save file version ?
      campaign - - campaign we're loading into
      unit - - unit this refit is attached to
      Returns:
      a brand-new Refit
    • reCalc

      public void reCalc()
      Used after loading from a save.
    • getNewEquipment

      public Part getNewEquipment()
      We are the new equipment
      Specified by:
      getNewEquipment in interface IAcquisitionWork
    • getAcquisitionDesc

      public String getAcquisitionDesc()
      We don't use this
      Specified by:
      getAcquisitionDesc in interface IAcquisitionWork
    • getAcquisitionDisplayName

      public String getAcquisitionDisplayName()
      We don't use this
      Specified by:
      getAcquisitionDisplayName in interface IAcquisitionWork
    • getAcquisitionExtraDesc

      public String getAcquisitionExtraDesc()
      We don't use this
      Specified by:
      getAcquisitionExtraDesc in interface IAcquisitionWork
    • getAcquisitionBonus

      public String getAcquisitionBonus()
      We don't use this
      Specified by:
      getAcquisitionBonus in interface IAcquisitionWork
    • getAcquisitionPart

      public Part getAcquisitionPart()
      We don't use this
      Specified by:
      getAcquisitionPart in interface IAcquisitionWork
    • getStickerPrice

      public Money getStickerPrice()
      Description copied from interface: IPartWork
      Sticker price is the value of the part according to the rulebooks
      Specified by:
      getStickerPrice in interface IPartWork
      Returns:
      Cost of carrying otu the refit (mostly relevant for refurbishment)
    • getActualValue

      public Money getActualValue()
      Description copied from class: Part
      This is the value of the part that may be affected by characteristics and campaign options
      Specified by:
      getActualValue in interface IPartWork
      Overrides:
      getActualValue in class Part
      Returns:
      Cost of carrying otu the refit (mostly relevant for refurbishment)
    • getBuyCost

      public Money getBuyCost()
      Specified by:
      getBuyCost in interface IAcquisitionWork
      Returns:
      Cost of carrying otu the refit (mostly relevant for refurbishment)
    • addRefitKitParts

      public void addRefitKitParts(int transitDays)
      Fixes up some special parts and clears the shopping list when we've found the refit kit
      Parameters:
      transitDays - - How long will it take to acquire kit
    • find

      public String find(int transitDays)
      You found the refit kit, now attempt to purchase it
      Specified by:
      find in interface IAcquisitionWork
      Parameters:
      transitDays - - how long it's going to take to get here
      Returns:
      string for report explaining how it went
    • failToFind

      public String failToFind()
      You failed to find the kit
      Specified by:
      failToFind in interface IAcquisitionWork
      Returns:
      string describing this
    • getAllAcquisitionMods

      public megamek.common.TargetRoll getAllAcquisitionMods()
      Get acquisition difficulty based on hardest to find part in the kit
      Specified by:
      getAllAcquisitionMods in interface IAcquisitionWork
      Returns:
      TargetRoll describing modifiers to roll
    • getNewArmorSupplies

      @Nullable public Armor getNewArmorSupplies()
    • resetOvertime

      public void resetOvertime()
      We don't do this
      Specified by:
      resetOvertime in interface IPartWork
      Overrides:
      resetOvertime in class Part
    • getTechLevel

      public int getTechLevel()
      We don't do this
      Specified by:
      getTechLevel in interface IAcquisitionWork
      Overrides:
      getTechLevel in class Part
      Returns:
      TechConstants tech level
    • getTechBase

      public megamek.common.ITechnology.TechBase getTechBase()
      Tech base is basically irrelevant for a refit kit
      Specified by:
      getTechBase in interface IAcquisitionWork
      Specified by:
      getTechBase in interface megamek.common.ITechnology
      Overrides:
      getTechBase in class Part
    • isRightTechType

      public boolean isRightTechType(String skillType)
      We don't care what tech type it is, at least not here
      Specified by:
      isRightTechType in interface IPartWork
      Overrides:
      isRightTechType in class Part
    • suggestNewName

      public void suggestNewName()
      Suggest a new name for the unit being refit. Only works for infantry.
    • getShoppingListReport

      public String getShoppingListReport(int quantity)
      Specified by:
      getShoppingListReport in interface IAcquisitionWork
      Overrides:
      getShoppingListReport in class Part
      Parameters:
      quantity - - ignored
      Returns:
      string for report about listing this refit
    • getTonnage

      public double getTonnage()
      Refits don't have a weight
      Specified by:
      getTonnage in class Part
      Returns:
      0
    • getTechRating

      public megamek.common.ITechnology.TechRating getTechRating()
      We don't have a tech rating
      Specified by:
      getTechRating in interface megamek.common.ITechnology
      Overrides:
      getTechRating in class Part
      Returns:
      0
    • isSamePartType

      public boolean isSamePartType(Part part)
      We don't compare refits
      Specified by:
      isSamePartType in class Part
      Returns:
      false
    • loadFieldsFromXmlNode

      protected void loadFieldsFromXmlNode(Node wn)
      We handle this in generateInstanceFromXML
      Specified by:
      loadFieldsFromXmlNode in class Part
      Parameters:
      wn - - ignored
    • clone

      public Part clone()
      You can't clone a refit
      Specified by:
      clone in class Part
      Returns:
      null
    • isCustomJob

      public boolean isCustomJob()
      Gets a value indicating whether this refit is a custom job. If false, this is a Refit Kit (CamOps 212).\
      Returns:
      is custom job?
    • kitFound

      public boolean kitFound()
      Returns:
      Has a refit kit for this refit been found (if applicable).
    • getLocationName

      public String getLocationName()
      Refits have no location
      Specified by:
      getLocationName in class Part
      Returns:
      null
    • getLocation

      public int getLocation()
      Refits have no location
      Specified by:
      getLocation in interface IPartWork
      Returns:
      LOC_NONE
    • getTechAdvancement

      public megamek.common.TechAdvancement getTechAdvancement()
      Tech Advancement doesn't matter for refit kits
      Specified by:
      getTechAdvancement in class Part
      Returns:
      TA_GENERIC
    • isBeingRefurbished

      public boolean isBeingRefurbished()
      Returns:
      are we doing a refurbishment?
    • isIntroducedBy

      public boolean isIntroducedBy(int year, boolean clan, megamek.common.ITechnology.Faction techFaction)
      Refits are a meta item that has no introduction
      Specified by:
      isIntroducedBy in interface IAcquisitionWork
      Returns:
      should probably always be true
    • isExtinctIn

      public boolean isExtinctIn(int year, boolean clan, megamek.common.ITechnology.Faction techFaction)
      Refits are a meta item that never goes extinct
      Specified by:
      isExtinctIn in interface IAcquisitionWork
      Returns:
      should probably always be false
    • fixReferences

      public void fixReferences(Campaign campaign)
      Make sure all of our units' parts are properly accounted for
      Overrides:
      fixReferences in class Part
      Parameters:
      campaign - - campaign that owns the parts