Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R2: Refit Refit #5178

Draft
wants to merge 50 commits into
base: master
Choose a base branch
from
Draft

R2: Refit Refit #5178

wants to merge 50 commits into from

Conversation

WeaverThree
Copy link
Collaborator

@WeaverThree WeaverThree commented Nov 6, 2024

Rebuild the entire refit system from the ground up to use a list of RefitStep objects that represent the, well, steps that you have to go through to make the refit happen. This makes it (i think) easier to analyze the units involved in the refit and then carry out the refit when the time comes.

Work completed so far includes:

  • A couple of large enums to represent refit classes and refit step types, that encapsulate as many lookup-table type features as possible.
  • Analysis of differences between starting and target units for refits. (The hardest part)
    • Including dealing with things like CASE that aren't represented well.
    • Ammobins and Armor are a special pain too
    • Dealing with damaged locations not accepting new parts unless they're being replaced. So you can replace damaged endo steel without replacing it, but not weasel around repairing your broken shoulders in other cases.
    • Should cover all your part needs from warships to LAMs, but I'm not sure every single thing is accounted for properly yet.
    • Omni refit analysis, finding which refits are able to be omni repods and which need to be factory level recustomizations.
    • Omni refits ignore armor damage when applicable. (On a normal refit, armor gets refreshed as a bonus, since we might have been changing it anyway).
  • Optimization of parts needed and parts taken off of the unit.
  • A whole new window to manage refits in. It's full of slide views! More stuff than can even fit in view at once too, so we have tabs. A lot of work on making the display as good as possible.

Things left to do:

  • Double check omni-pod handling on non-omni refits.
  • A class to represent a refit kit, that can contain the items/value required for a kit refit. Not going to be using the Refit class itself because that seems to be an easy way to cause problems.
  • Actually ordering goods to initiate the refit
  • Saving/loading refit status and the steps list
  • Dealing with loading older save data and converting old refits in progress
  • Actually carrying out the change in units when the refit completes
  • Refurbishment, which should be an alternate code path that is easier
  • Canceling refits
  • Saving customization files, which may get punted over to MekLab
  • MekLab integration. (Adding a tab to it with all this info, hopefully)
  • Rewrite all the refit tests?

At this stage it should be possible to examine any possible refit and see if the steps are what they should be, but actually attempting to carry out a refit will probably set something on fire.

Here are some screenshots that show how it works, to some degree.

2024-11-05_214855
2024-11-05_214919
2024-11-05_215211
2024-11-05_215429
2024-11-05_215907
2024-11-05_215728

Node wn2 = nl.item(x);

if (wn2.getNodeName().equalsIgnoreCase("type")) {
type = Integer.parseInt(wn2.getTextContent());

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
MekHQ/src/mekhq/campaign/parts/RefitStep.java Fixed Show fixed Hide fixed
MekHQ/src/mekhq/campaign/parts/RefitStep.java Fixed Show fixed Hide fixed
MekHQ/src/mekhq/campaign/parts/RefitStep.java Fixed Show fixed Hide fixed
MekHQ/src/mekhq/campaign/parts/RefitStep.java Fixed Show fixed Hide fixed
MekHQ/src/mekhq/campaign/parts/RefitStep.java Fixed Show fixed Hide fixed
MekHQ/src/mekhq/campaign/unit/Unit.java Fixed Show fixed Hide fixed
TestEntity testEntity;

if (getEntity() instanceof Tank) {
testEntity = new TestTank((Tank) getEntity(), verifier.tankOption, null);

Check warning

Code scanning / CodeQL

Expression always evaluates to the same value Warning

Expression always evaluates to the same value.
return toReturn;

} else if (getEntity() instanceof ConvFighter) {
testEntity = new TestAero((Aero) getEntity(), verifier.aeroOption, null);

Check warning

Code scanning / CodeQL

Expression always evaluates to the same value Warning

Expression always evaluates to the same value.
return;
}

isFixedEquipmentChange = !(oldPart.isOmniPodded() && newPart.isOmniPodded());

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.

} else if ((oldPart instanceof Part) || (newPart instanceof MissingPart)) {

returnsPart = !(oldPart instanceof MissingPart) ? oldPart.clone() : null;

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Variable
oldPart
may be null at this access as suggested by
this
null guard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants