Skip to content

Conversation

@HammerGS
Copy link
Member

@HammerGS HammerGS commented Jan 2, 2026

Fixes #7852

Command Console mechs with only one crew member were applying head hit damage twice to the single pilot instead of once.

Root Cause

The damageCrew() method in TWGameManager.java iterates through all crew slots based on getSlotCount(), but did not check if a slot was actually occupied. For Command Console cockpits (which have 2 slots: Pilot + Commander), when only one crew member is present, the loop would still process both slots - applying damage to the missing slot as well.

Fix

Added a check for crew.isMissing(pos) to skip empty crew slots when applying damage. This is consistent with how other crew iteration loops handle missing slots (e.g., Crew.java:932-935).

if (crew.isMissing(pos)) {
    continue;
}

Behavior

| Scenario           | Before Fix         | After Fix         |
|--------------------|--------------------|-------------------|
| Both crew present  | Both take 1 hit    | Both take 1 hit   |
| Only pilot present | Pilot takes 2 hits | Pilot takes 1 hit |

This aligns with the Command Console rules: "damage done to the cockpit location does affect both warriors" - meaning all present warriors, not empty slots.

Test Plan

- Load Command Console mech with single pilot, take head hit - verify 1 injury
- Load Command Console mech with both crew, take head hit - verify both take 1 injury
- Verify other multi-crew cockpits (Tripod, Dual) behave correctly

  File: megamek/src/megamek/server/totalWarfare/TWGameManager.java:17270-17272

  Change: Added check to skip missing crew slots when applying damage:

  if (crew.isMissing(pos)) {
      continue;
  }

  Result:
  - Command Console mechs with both crew members: both take damage from head hits (correct per rules)
  - Command Console mechs with only one crew member: only the present crew member takes damage (fixed)
Copilot AI review requested due to automatic review settings January 2, 2026 04:23
@HammerGS HammerGS requested a review from a team as a code owner January 2, 2026 04:23
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 a bug (#7852) where Command Console mechs with a single crew member were receiving double head hit damage instead of single damage. The issue occurred because the damageCrew() method iterated through all crew slots without checking if they were actually occupied.

Key Changes:

  • Added a check for missing crew slots in the damage application loop
  • Ensures damage is only applied to present crew members

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

Comment on lines +17270 to +17272
if (crew.isMissing(pos)) {
continue;
}
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

This fix correctly prevents damage from being applied to missing crew positions in multi-crew cockpits. However, there are no unit tests covering the damageCrew method to verify this behavior. Consider adding test cases for:

  1. Command Console mech with single pilot taking head damage (should receive 1 hit)
  2. Command Console mech with both crew members taking head damage (both should receive 1 hit)
  3. Other multi-crew cockpits (Tripod, Dual) with missing crew members

This would ensure the fix works as intended and prevent regressions.

Copilot uses AI. Check for mistakes.
@HammerGS HammerGS added AI Generated Fix AI-generated fix. Requires human testing and review before merging. AI ready for Review Indicates that is has been in game tested and is ready for review as it can be labels Jan 2, 2026
@HammerGS HammerGS changed the title Fix #7852 Summary Fix #7852 Command Console mechs with only one crew member were applying head hit damage twice to the single pilot instead of once. Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Fix AI-generated fix. Requires human testing and review before merging. AI ready for Review Indicates that is has been in game tested and is ready for review as it can be

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue] Command Console mechs take double pilot injury on head hits

3 participants