Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if Edge is enabled in Game Options before using it #5855

Merged
merged 6 commits into from
Aug 5, 2024

Conversation

Algebro7
Copy link
Collaborator

@Algebro7 Algebro7 commented Aug 5, 2024

When determining whether to roll edge on crits, the game only checked whether crews had Edge points remaining and not whether Edge was actually enabled. This led to weird situations where pilots who had edge points assigned would still roll edge even though it was disabled (as described in #5587).

This PR adds an additional check to see if Edge is enabled before checking whether the crew has edge points. I wish there was a cleaner way to do this than at each call site but it would've required more substantial refactoring which I was afraid to do. I looked at implementing it in the Crew object but it doesn't extend Entity and thus does not have access to game.

I tested in a game with all Mechs and they stopped rolling Edge when it was disabled, and rolled Edge when it was enabled, as expected.

Closes #5587

Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 28.98%. Comparing base (9399938) to head (c470153).
Report is 116 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5855      +/-   ##
============================================
- Coverage     29.05%   28.98%   -0.08%     
+ Complexity    13911    13909       -2     
============================================
  Files          2507     2512       +5     
  Lines        266366   267229     +863     
  Branches      47621    47780     +159     
============================================
+ Hits          77402    77462      +60     
- Misses       185025   185817     +792     
- Partials       3939     3950      +11     

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

Comment on lines 1974 to 1975
if (game.getOptions().booleanOption(OptionsConstants.EDGE)
&& (getCrew().hasEdgeRemaining()
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we just have a bunch of this conditional repeated throughout Mech.java (and its inheritors), just with different boolean options.
Would it be viable to add, e.g.

public boolean shouldUseEdge(String option) {
    return (
                      game.getOptions().booleanOption(OptionsConstants.EDGE)
                                && getCrew().hasEdgeRemaining()
                                && getCrew().getOptions().booleanOption(option)
                );

or something? Then each check becomes something like this:

    case 2:
        if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC)
        && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC))

Which is somewhat cleaner when spread across all these cases.

Copy link
Collaborator Author

@Algebro7 Algebro7 Aug 5, 2024

Choose a reason for hiding this comment

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

Would it make sense to implement that method in the Entity base class all the various Mech and Aero units extend? Looks like it has a crew member so I think it should have all the information it needs, but I'm not sure if any other objects extend Entity that shouldn't have this method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's acceptable; the downside is you would also have to check that getCrew() doesn't return null prior to calling .hasEdgeRemaining() or .getOptions(), because while an Entity subclass like Mech must have crew, there's no guarantee that a bare Entity will.

@@ -1282,7 +1290,8 @@ && getCrew().getOptions().booleanOption(
case 11:
return new HitData(Mech.LOC_LARM, true);
case 12:
if (getCrew().hasEdgeRemaining()
if (game.getOptions().booleanOption(OptionsConstants.EDGE)
&& getCrew().hasEdgeRemaining()
&& getCrew().getOptions().booleanOption(
"edge_when_headhit")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably take this opportunity to replace all of these with EDGE_WHEN_HEADHIT

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call, done in 62ec6e8

Copy link
Collaborator

@Sleet01 Sleet01 left a comment

Choose a reason for hiding this comment

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

Functionally looks good, could use a little cleanup.

@Sleet01 Sleet01 merged commit 51f7dea into MegaMek:master Aug 5, 2024
5 checks passed
@Algebro7 Algebro7 deleted the ignore-edge-when-disabled branch August 5, 2024 16:38
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.

[Nightly] Edge being used despite being disabled in both MHQ and MM
3 participants