Fix missing "Swap ammo" menu for some units (Fixes #8714)#8727
Open
Fix missing "Swap ammo" menu for some units (Fixes #8714)#8727
Conversation
Branch: fix/8714-missing-ammo-bins Root Cause: Some units (like the Zeus ZEU-6A Mk II) are missing AmmoBin parts from their parts list even though their entity has ammo equipment. This causes getWorkingAmmoBins() to return an empty list, which means the "Swap ammo" menu doesn't appear. Why it happens: The exact cause is unclear, but likely related to: - Units created/modified via refits that didn't properly preserve AmmoBin parts - Save files from older versions that didn't track AmmoBin parts - Some edge case in parts initialization The Fix: Modified getWorkingAmmoBins() to detect when no AmmoBin parts exist but the entity has ammo equipment, and automatically call initializeParts(true) to create the missing parts. Files Changed: - MekHQ/src/mekhq/campaign/unit/Unit.java - Added self-healing logic to getWorkingAmmoBins() and new helper method entityHasAmmoEquipment()
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #8714 where some units (e.g., Zeus ZEU-6A Mk II) were missing the "Swap ammo" context menu option. The root cause was that these units had no AmmoBin parts in their parts list despite having ammo equipment on their entity, which can occur with units from older save files or after certain refits.
Changes:
- Added self-healing logic to
getWorkingAmmoBins()that detects missing AmmoBin parts and reinitializes them - Added helper method
entityHasAmmoEquipment()to check if an entity has AmmoType equipment
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
Some units (e.g., Zeus ZEU-6A Mk II) are missing
AmmoBinparts from their parts list even though their entity hasammo equipment. When
getWorkingAmmoBins()returns an empty list, the "Swap ammo" context menu is not displayed.This can occur with units from older save files, after certain refits, or due to parts initialization edge cases.
Changes
Unit.getWorkingAmmoBins()- Added self-healing logic that detects when no AmmoBin parts exist but the entity hasammo equipment, and calls
initializeParts(true)to create the missing partsentityHasAmmoEquipment()to check if an entity has AmmoType equipmentFiles Changed
MekHQ/src/mekhq/campaign/unit/Unit.java- Self-healing AmmoBin initializationTesting
The.Expired.Licenses30350214_Flamberge.cpnx)Fixes #8714