Skip to content

Permanent injuries can't be replaced with temporal ones#8803

Merged
rjhancock merged 7 commits intoMegaMek:mainfrom
VicenteCartas:vicentecartas/7565
Mar 13, 2026
Merged

Permanent injuries can't be replaced with temporal ones#8803
rjhancock merged 7 commits intoMegaMek:mainfrom
VicenteCartas:vicentecartas/7565

Conversation

@VicenteCartas
Copy link
Collaborator

@VicenteCartas VicenteCartas commented Mar 10, 2026

Fixes #7565

The bug report explains the issue pretty well: the worsening of a permanent injury could replace it by a temporal one. This happens in multiple injuries types, not just concussions.

This fix takes the decision that permanent injuries are chronic damage, so combat stress cannot affect them. But non-permanent injuries (representing non chronic injuries) can be made worse by stress. By not returning any GameEffect, the permanent injuries will be left alone.

Added also a parametrized unit test to validate this based on PR feedback.

@VicenteCartas VicenteCartas requested a review from a team as a code owner March 10, 2026 05:25
Copilot AI review requested due to automatic review settings March 10, 2026 05:25
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

Fixes a regression in the advanced medical system where post-combat stress effects could cause a permanent injury to be replaced by a temporary (healing) injury, resulting in the permanent injury effectively disappearing once the temporary one healed.

Changes:

  • Short-circuits genStressEffect(...) for several injury types when the current injury is permanent, returning no GameEffects.
  • Prevents stress-driven recovery timer resets and stress-driven “upgrade/replace” injury transitions from applying to permanent injuries.
Comments suppressed due to low confidence (3)

MekHQ/src/mekhq/campaign/personnel/medical/advancedMedical/InjuryTypes.java:546

  • The displayed chance is always shown as 100% here: for hits < 5, (1 + hits) * 100 / 6 is at most ~83, so Math.max(..., 100) will always return 100. This makes the user-facing stress effect text misleading; use a cap (e.g., Math.min(..., 100)) or compute the percentage directly from the actual 1d6 + hits >= 5 probability.
            String secondEffectFluff = "development of a chronic traumatic encephalopathy";
            if (hits < 5) {
                int worseningChance = Math.max((int) Math.round((1 + hits) * 100.0 / 6.0), 100);
                secondEffectFluff = worseningChance + "% chance of " + secondEffectFluff;
            }

MekHQ/src/mekhq/campaign/personnel/medical/advancedMedical/InjuryTypes.java:710

  • The computed "worseningChance" is always 100% for hits < 5 because Math.max(..., 100) forces a minimum of 100. This causes the effect description to be incorrect relative to the real probability check (rnd.applyAsInt(6) + hits >= 5). Consider switching to a cap (Math.min) or deriving the percent from the same condition used in the effect.
            String secondEffectFluff = (i.getHits() < 3) ? "internal bleeding worsening" : "death";
            if (hits < 5) {
                int worseningChance = Math.max((int) Math.round((1 + hits) * 100.0 / 6.0), 100);
                secondEffectFluff = worseningChance + "% chance of " + secondEffectFluff;
            }

MekHQ/src/mekhq/campaign/personnel/medical/advancedMedical/InjuryTypes.java:922

  • Same as elsewhere: this percentage calculation always yields 100% for hits < 5 due to Math.max(..., 100), so the effect text will always claim a 100% chance even when the underlying roll is not guaranteed. Adjust the calculation (e.g., cap with Math.min or compute from the 1d6 + hits >= 5 threshold) so the message matches behavior.
            String secondEffectFluff = (injury.getHits() == 1) ?
                                             "concussion worsening" :
                                             "development of a cerebral contusion";
            if (hits < 5) {
                int worseningChance = Math.max((int) Math.round((1 + hits) * 100.0 / 6.0), 100);
                secondEffectFluff = worseningChance + "% chance of " + secondEffectFluff;
            }

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

@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 43.47826% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 13.22%. Comparing base (f0cdb63) to head (86a54f9).
⚠️ Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
...personnel/medical/advancedMedical/InjuryTypes.java 43.47% 6 Missing and 7 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8803      +/-   ##
============================================
+ Coverage     13.20%   13.22%   +0.02%     
- Complexity     7862     7873      +11     
============================================
  Files          1306     1306              
  Lines        169146   169162      +16     
  Branches      25445    25452       +7     
============================================
+ Hits          22340    22378      +38     
+ Misses       144643   144606      -37     
- Partials       2163     2178      +15     

☔ 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.

Copy link
Member

@psikomonkie psikomonkie left a comment

Choose a reason for hiding this comment

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

Amazing, thank you!

@rjhancock rjhancock merged commit c8428b3 into MegaMek:main Mar 13, 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.

[Issue] New non-permanent injuries can overwrite permanent injuries

4 participants