Skip to content

Fix: Pilots from ammo-detonated OpFor units missing in AAR (#6497)#8857

Merged
HammerGS merged 3 commits into
MegaMek:mainfrom
VicenteCartas:vc/6497
Apr 6, 2026
Merged

Fix: Pilots from ammo-detonated OpFor units missing in AAR (#6497)#8857
HammerGS merged 3 commits into
MegaMek:mainfrom
VicenteCartas:vc/6497

Conversation

@VicenteCartas

@VicenteCartas VicenteCartas commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Enemy pilots whose units were destroyed by ammo detonation were absent from the capturable personnel list in the After Action Report (AAR).

Root Cause

In ResolveScenarioTracker.processGame(), entities are categorized into three post-battle groups:

  • Surviving (getEntities()) — enemy units correctly added to potentialSalvage
  • Wrecked (getGraveyardEntities()) — enemy units correctly added to potentialSalvage
  • Devastated (getDevastatedEntities()) — enemy units not processed at all

Units destroyed by ammo explosion are flagged as REMOVE_DEVASTATED and go into the devastated category. Since there was no else if branch for enemy devastated entities, their crews were never fed into processPrisonerCapture(), making those pilots invisible in the AAR.

The alternate code path (loadUnitsAndPilots(), used when loading from MUL files) already handled this correctly, with an explicit comment: "completely destroyed units (such as from an ammo explosion) need to be kept track of, as mekwarriors may eject from them, etc."

Fix

Added an else if branch for enemy devastated entities in processGame() that:

  • Routes EjectedCrew instances to enemyEjections (matching the graveyard handling pattern)
  • Creates a TestUnit for other enemy units and adds them to devastatedEnemyUnits, allowing processPrisonerCapture() to generate capturable personnel from their crews (similar to loadUnitsAndPilots())

Testing

Couldn't repro with the original campaign in the bug. I migrated it to 50.06, then 50.11 and then open in my local environment, but the save game attached for the battle does not have the conditions to repro the issue. The other saves attached to the bug are missing the campaign information to be usable.

So added ResolveScenarioTrackerTest with a test that mocks PostGameResolution.getDevastatedEntities() returning an enemy entity and verifies it ends up in devastatedEnemyUnits and salvageStatus. The test fails without the fix and passes with it.

Added also a second test to test the ejection code path based on code review feedback.

Copilot AI review requested due to automatic review settings April 3, 2026 06:54
@VicenteCartas VicenteCartas requested a review from a team as a code owner April 3, 2026 06:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes an AAR prisoner-capture tracking gap where OpFor units destroyed via ammo detonation (i.e., “devastated” entities) were not being processed in ResolveScenarioTracker.processGame(), causing their pilots/crew to be absent from the capturable personnel list.

Changes:

  • Extend ResolveScenarioTracker.processGame() to process enemy devastated entities by recording ejected crews and tracking completely destroyed enemy units for prisoner capture.
  • Add a unit test to ensure enemy devastated entities are added to devastatedEnemyUnits and registered in salvageStatus.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
MekHQ/src/mekhq/campaign/ResolveScenarioTracker.java Adds processing for enemy devastated entities so crews can be considered for prisoner capture (mirrors MUL-loading behavior).
MekHQ/unittests/mekhq/campaign/ResolveScenarioTrackerTest.java Introduces a regression test validating devastated enemy units are tracked for downstream prisoner-capture processing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread MekHQ/src/mekhq/campaign/ResolveScenarioTracker.java
@codecov

codecov Bot commented Apr 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 13.42%. Comparing base (cdf579c) to head (2e99add).
⚠️ Report is 38 commits behind head on main.

Files with missing lines Patch % Lines
...kHQ/src/mekhq/campaign/ResolveScenarioTracker.java 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8857      +/-   ##
============================================
+ Coverage     13.33%   13.42%   +0.09%     
- Complexity     7966     8007      +41     
============================================
  Files          1309     1310       +1     
  Lines        169452   169507      +55     
  Branches      25511    25524      +13     
============================================
+ Hits          22588    22761     +173     
+ Misses       144642   144479     -163     
- Partials       2222     2267      +45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@IllianiBird IllianiBird left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks right but this area of the code is notoriously cranky so I recommend flagging for testing with the Test Pilots when it's merged.

@HammerGS HammerGS merged commit f10b1f3 into MegaMek:main Apr 6, 2026
9 checks passed
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.

4 participants