Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Sleet01
Copy link
Collaborator

@Sleet01 Sleet01 commented May 21, 2025

This PR contains fixes for a number of advanced armors not preventing PSRs or piloting rolls as they should.
It also contains updates for some Aerospace and BA armor handling edge cases.
Finally, it implements a TWDamageManager class and moves the entirety of direct damage assignment function
damageEntity out of TWGameManager into a separate class that TWGameManager will configure through composition.

The rationale behind splitting damageEntity() out of TWGameManager is three-fold:

  1. It allows for switching between the current and new code with a single option, so that breaking bugs needn't hold up other testing or development;
  2. It allows refactoring of the original function into specialized functions which will simplify coding and unit testing;
  3. It moves code out of TWGameManager, which is bloated, monolithic, and handling far too much.

A new game option has been added to allow disabling the new damage manager code if desired / needed while further fixes are implemented.

Going Forward

There are a few more edge-case bugs that may need to be added to this PR but I would like to get the initial work in for testing purposes.

There is also a good argument for pulling more damage-adjacent handling code out of TWGameManager into TWDamageManager, but that is outside my remit - the work so far was in service of simplifying damageEntity so that specific issues around advanced armor could be fix, and no more.
If it makes sense to move functions out of TWGameManager then another PR may be in order.

Testing:

  • Added new unit tests specific to the reported issues;
  • Ran all 3 projects' existing unit tests;
  • Ran large bot-controlled battles for several hours each.

Fix: #2032
Fix: #2209
Fix: #3396

@Sleet01 Sleet01 requested a review from a team as a code owner May 21, 2025 23:41
@codecov
Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 13.02876% with 1028 lines in your changes missing coverage. Please review.

Project coverage is 30.79%. Comparing base (0cdf452) to head (7f4a883).
Report is 65 commits behind head on master.

Files with missing lines Patch % Lines
...c/megamek/server/totalwarfare/TWDamageManager.java 12.53% 903 Missing and 116 partials ⚠️
megamek/src/megamek/common/DamageInfo.java 53.84% 6 Missing ⚠️
...erver/totalwarfare/UnknownEntityTypeException.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7108      +/-   ##
============================================
+ Coverage     30.75%   30.79%   +0.03%     
- Complexity    16826    17029     +203     
============================================
  Files          2936     2940       +4     
  Lines        285817   287606    +1789     
  Branches      49726    50210     +484     
============================================
+ Hits          87901    88565     +664     
- Misses       191624   192536     +912     
- Partials       6292     6505     +213     

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

@Sleet01 Sleet01 force-pushed the Fix_2032_advanced_armors_handle_PSRs_incorrectly branch from dd1285d to aaab330 Compare May 21, 2025 23:58
@HammerGS HammerGS requested a review from Copilot May 22, 2025 00:04
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 issues with advanced armors preventing PSRs and piloting rolls and refactors damage application code by moving damageEntity into a dedicated damage manager module. It also updates several unit definition files and associated game options and localization files to support these changes.

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
megamek/testresources/megamek/common/units/*.mtf/.blk Added or updated unit definitions with new and revised unit attributes
megamek/src/megamek/server/IDamageManager.java Introduced a new damage manager interface to encapsulate damageEntity logic
megamek/src/megamek/common/options/OptionsConstants.java & BasicGameOptions.java Added new game option BASE_NEW_DAMAGE_MANAGER to toggle the new damage handling system
megamek/src/megamek/common/DamageInfo.java Updated the DamageInfo record with multiple overloaded constructors for enhanced flexibility
megamek/i18n/megamek/common/options/messages.properties Updated messages to include entries for the new damage manager option
Comments suppressed due to low confidence (1)

megamek/testresources/megamek/common/units/Flashman FLS-10E.mtf:5

  • [nitpick] Ensure that the casing of configuration keys (e.g., 'techbase' vs 'TechBase') is consistent across all unit definition files to improve readability and maintainability.
techbase:Mixed (IS Chassis)

@Sleet01 Sleet01 force-pushed the Fix_2032_advanced_armors_handle_PSRs_incorrectly branch from 4ffa5bc to 70094fb Compare May 22, 2025 00:16
@HammerGS
Copy link
Member

Asked AI about the Java Doc failure. Says this.

  1. Fix Javadoc Errors in Game.java
    Errors and warnings in Game.java include missing @param, @return, and @throws tags for certain methods.

Code Suggestions:
Method: getNextHiddenEntityNum Add the missing @param description for start.

/**
 * Retrieves the next hidden entity number.
 * 
 * @param turn the current game turn
 * @param start the starting point for the search
 * @return the next hidden entity number
 */
public int getNextHiddenEntityNum(GameTurn turn, int start) {
    // Method implementation
}

Method: removeFirstTurnFor Add the missing @param, @return, and @throws tags.

/**
 * Removes the first turn for the given entity.
 * 
 * @param entity the entity whose turn is to be removed
 * @return the removed game turn, or null if none exists
 * @throws Exception if an error occurs during removal
 */
public @Nullable GameTurn removeFirstTurnFor(final Entity entity) throws Exception {
    // Method implementation
}

Method: setAllReports Add the missing @param tag.

/**
 * Sets all reports for the game.
 * 
 * @param v a list of lists of reports to set
 */
public void setAllReports(List<List<Report>> v) {
    // Method implementation
}
  1. Fix XML Tag Issues in TWGameManager.java
    The error indicates improperly closed tags in the Javadoc comments.

Code Suggestions:
Replace the incorrect tags with properly closed ones.

/**
 * <code>Report</code>s to. It may be empty, but not null.
 */

@Sleet01 Sleet01 force-pushed the Fix_2032_advanced_armors_handle_PSRs_incorrectly branch from 4fe82a4 to 9a7289d Compare May 22, 2025 00:55
@Sleet01
Copy link
Collaborator Author

Sleet01 commented May 22, 2025

@HammerGS The Game.java stuff is outside my scope, but I can try fixing the tag error.

Copy link
Collaborator

@rjhancock rjhancock left a comment

Choose a reason for hiding this comment

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

My only sticking point is the copyright headers.

The rest are just requests along with... please do something about the variable names.

@Sleet01 Sleet01 force-pushed the Fix_2032_advanced_armors_handle_PSRs_incorrectly branch from 49c96d7 to c56cf2c Compare May 22, 2025 17:05
@Sleet01 Sleet01 requested a review from rjhancock May 22, 2025 19:19
@Sleet01 Sleet01 marked this pull request as draft May 22, 2025 19:50
@Sleet01
Copy link
Collaborator Author

Sleet01 commented May 22, 2025

One of the recent changes has introduced an OOM at the end of the firing phase on very large matches; I've confirmed it's not in the old damage code so I'm taking this to Draft to find the issue.

@Sleet01 Sleet01 force-pushed the Fix_2032_advanced_armors_handle_PSRs_incorrectly branch from 07431a9 to ff84f65 Compare May 22, 2025 23:14
@Sleet01 Sleet01 marked this pull request as ready for review May 22, 2025 23:23
@Sleet01
Copy link
Collaborator Author

Sleet01 commented May 22, 2025

Turns out early return escapes need to be replaced with something after they are removed.
Now with the deprecation updates as well.

@Sleet01 Sleet01 force-pushed the Fix_2032_advanced_armors_handle_PSRs_incorrectly branch from ff84f65 to a15c4ed Compare May 23, 2025 00:06
Copy link
Collaborator

@Scoppio Scoppio left a comment

Choose a reason for hiding this comment

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

If TWDamageManager needs both GameManager and Game... can't it use the game reference from the GameManager itself? Also, since it is so vital for it, would be best if the TWDamageManager had to be be initialized on its constructor with a TWGameManager, solving all possible error states because of bad initialization.

@Scoppio
Copy link
Collaborator

Scoppio commented May 23, 2025

Also, can you rename the "new" damage manager to something else?
Like "TWDamageManagerModular", the other one could be named "TWDamageManagerLegacy", this way we dont endup with any NTWDamageManagerNewNewThisOneFinal

@Sleet01
Copy link
Collaborator Author

Sleet01 commented May 23, 2025

If TWDamageManager needs both GameManager and Game... can't it use the game reference from the GameManager itself? Also, since it is so vital for it, would be best if the TWDamageManager had to be be initialized on its constructor with a TWGameManager, solving all possible error states because of bad initialization.

Are you familiar with the "Chicken and Egg" problem? 😸
I've created a mutual dependency between TWGameManager, which now cannot run a game without TWDamageManager, and TWDamageManager, which needs functions on TWGameManager to do its work.
This means that only one of them can instantiate the other within its constructor, not both.
Some languages would be able to resolve this with a double-pass approach under the hood, but it doesn't look like Java is one of them.
So one of the two classes cannot require the other for its constructor, and I decided that would be TWDamageManager as this seemed the simplest to deal with.

Further, while we currently automatically create a Game instance when instantiating TWGameManager, we may not always - and decoupling the Game instance from the TWGameManager instance makes for easier testing.

In the near future I plan to move more functionality out of TWGameManager into TWDamageManager, which should remove this mutual dependency, but for now I wanted to get the new damage handling code out and tested by players.

Sleet01 added 7 commits May 23, 2025 10:39
Removed merge conflicts due to Mech/Mek updates; these changes will be
reintroduced following the rebase.
Removed additional merge conflicts from subsequent updates.
Removed already-moved section.  Note: will need verification that
changes have been persisted between 03/04 and 03/20 versions.

Merge some updates, adapt/ignore some others.

Now with deprecation pass included.
Remove extraneous blocks moved/duplicated in this patch.
Redo some removal.  Note: again, will need to reconcile 03/04 and 03/20
versions.
Note: currently broken; should be fixed in next patch.
Sleet01 added 23 commits May 23, 2025 10:39
Now with deprecation pass included
Now with deprecation pass
@Sleet01
Copy link
Collaborator Author

Sleet01 commented May 23, 2025

Also, can you rename the "new" damage manager to something else? Like "TWDamageManagerModular", the other one could be named "TWDamageManagerLegacy", this way we dont endup with any NTWDamageManagerNewNewThisOneFinal

I can do this, but the "Legacy" TWDamageManager is going away once we're comfortable with the new code, and the new code will replace its innards. So we'll only have TWDamageManagerModular for 1~2 releases.

@Sleet01 Sleet01 force-pushed the Fix_2032_advanced_armors_handle_PSRs_incorrectly branch from 7efc44f to 2658385 Compare May 23, 2025 18:39
@Sleet01 Sleet01 requested a review from Scoppio May 23, 2025 18:42
@Sleet01 Sleet01 merged commit 8fe5224 into MegaMek:master May 23, 2025
7 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

4 participants