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

Unit Values Change after Save and Load for GM Added Units #2873

Closed
HoneySkull opened this issue Sep 11, 2021 · 3 comments · Fixed by #2875
Closed

Unit Values Change after Save and Load for GM Added Units #2873

HoneySkull opened this issue Sep 11, 2021 · 3 comments · Fixed by #2875

Comments

@HoneySkull
Copy link
Collaborator

Environment

MekHQ 0.49.3
Java vendor Eclipse Foundation
Java version 11.0.12
Platform Windows 10 10.0 (amd64)
Total memory available to MegaMek: 1,048,576 kB

Description

When adding a unit through the 'Add (GM)' or GM Tools RAT generator, the unit value in the finance tab, hangar, and TO&E is approximately half the value of the list price of the mech. Then doing a 'Save' and then 'Load' of the campaign file, the value changes after the load. The value displayed after the load is approximately the unit list price but is off by about 1%. The initial value displayed in the 'Purchase Unit' dialog appears to match the Master Unit List value but is slightly different than what is shown in the Hangar and Finance Tab. The issue in this report is the fact that the value displayed is different after the save and load.

  1. Create a new campaign
  2. Click GM Mode
  3. Marketplace->Purchace Unit
  4. Search for Warhammer and select Warhammer
  5. Click 'Add (GM)' to add the unit. The unit is added to the hangar.
  6. Observe that the price in the hangar and in the finance tab is half of the list value.
  7. Save the campaign file.
  8. Load the campaign file.
  9. The unit price is double the price prior to the save in the finance tab and hangar.
  10. The value shown after the reload is off by ~1%?
  11. If you add another unit after the save, the unit value is wrong until saved and reloaded.

Versions

This issue has been reproduced in:

  1. 48.0 Stable
  2. 49.3 Dev
  3. 49.4 Local

AddUnit
MasterUnitList
HangarTab
FinanceTab
FinanceTabPostSave
HangarPostSave

Files

logs.zip
Test Merc - SaveGlitch30670101.cpnx.gz

@HoneySkull
Copy link
Collaborator Author

HoneySkull commented Sep 13, 2021

Some investigation in the code in Unit.java:1092: [0.49.4 - snapshot as of 9/11/2021]

image

When units are added, and the campaign options indicate value is determined by 'sell value' - the sum of the units parts are added up and then multiplied by 1 + (weight / tonnage) for mechs.

The sum of the parts for a unit loaded from a save file are doubled for a unit that is added within the active session.

I don't believe this issue is with this code, but something is off on the value of the parts for a unit from being added in-game compared to loaded from a save file. I'm not sure which one is correct. Should the sell value for a Warhammer-6R quality D be 3M or 6M?

@HoneySkull
Copy link
Collaborator Author

I think I found the issue: When a unit is added through 'Add (GM)' - all the 'parts' for the newly added unit are marked as brandNew = false. When the campaign is saved and loaded the parts are loaded as brandNew = true.

Non brandNew parts are modified by the quality modifier. In this case Quality D (default) which as a 0.5 making it look like GM added units show up as half price.

The question is: When should the Part.brandNew be set to true vs. false. My gut tells me when adding a unit as a GM - the parts should default to brandNew = true, not brandNew = false. But also - the unit should save with the actual Part.brandNew value and load with the value that was saved.

I believe this is also happening with GM adding parts from the parts in use report.

@HoneySkull
Copy link
Collaborator Author

HoneySkull commented Sep 13, 2021

Looks like Quartermaster.addPart() sets the part newness to not-new when units are added. I wonder if this then is impacting maintenance cost and opfor strengths as these are treated as new once the file re-loaded effectively doubling the sell price for Quality D parts.

HoneySkull added a commit to HoneySkull/mekhq that referenced this issue Sep 13, 2021
When saving the parts list for GM added units, the tag is only saved
when the 'brandNew' property is TRUE and leave the tag out if the
property is FALSE.  Because the default constructor sets the property to
TRUE, false values re never saved and loaded.
Windchild292 added a commit that referenced this issue Sep 14, 2021
…oad_state

Proposed fix for #2873 - saving the part new flag correctly
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 a pull request may close this issue.

1 participant