Skip to content

Fix missing "Swap ammo" menu for some units (Fixes #8714)#8727

Open
HammerGS wants to merge 1 commit intomainfrom
fix/8714-missing-ammo-bins
Open

Fix missing "Swap ammo" menu for some units (Fixes #8714)#8727
HammerGS wants to merge 1 commit intomainfrom
fix/8714-missing-ammo-bins

Conversation

@HammerGS
Copy link
Member

@HammerGS HammerGS commented Feb 5, 2026

Root Cause

Some units (e.g., Zeus ZEU-6A Mk II) are missing AmmoBin parts from their parts list even though their entity has
ammo 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

  1. Unit.getWorkingAmmoBins() - Added self-healing logic that detects when no AmmoBin parts exist but the entity has
    ammo equipment, and calls initializeParts(true) to create the missing parts
  2. Added new helper method entityHasAmmoEquipment() to check if an entity has AmmoType equipment

Files Changed

  • MekHQ/src/mekhq/campaign/unit/Unit.java - Self-healing AmmoBin initialization

Testing

  1. Load the provided save file (The.Expired.Licenses30350214_Flamberge.cpnx)
  2. Right-click on Zeus ZEU-6A Mk II
  3. Verify "Swap ammo" submenu now appears with SRM-6 ammo options
  4. Verify swapping ammo works correctly
  5. Compare with Stalker STK-4N Mk II which already had working ammo swap

Fixes #8714

  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()
@HammerGS HammerGS requested a review from a team as a code owner February 5, 2026 02:52
Copilot AI review requested due to automatic review settings February 5, 2026 02:52
@HammerGS HammerGS added the AI Generated Code AI-generated fix. Requires human testing and review before merging. label Feb 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Code AI-generated fix. Requires human testing and review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue] Some meks no longer have the option to swap ammo.

1 participant