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

Clamp OpFor Unit Rating within FM:M Bounds #3914

Closed
wants to merge 9 commits into from

Conversation

IllianiCBT
Copy link
Collaborator

@IllianiCBT IllianiCBT commented Mar 27, 2024

Current Implementation

Currently, CamOps Unit Rating is uncapped. AtB relies on Unit Rating to generate TN modifiers to a number of different functions.

Problem

With CamOps being uncapped there is no upper or lower boundary to the modifiers it can create undesirable effects. Such as...

  • Only generating Relief missions
  • Making Retirement checks impossible to pass/fail.
  • Making Ship Search checks impossible to pass/fail.
  • Influencing what large craft are found, through the Ship Search.
  • Influencing the arrival/departure of Dependents.
  • Influencing enemy Morale Checks, causing enemy morale to snowball towards Invincible/Rout.
  • Influencing part availability, during contracts. Potentially making the availability of parts much easier/harder than intended.
  • Influencing where units are placed, after scenarios (Field Repair, Repair Bay, etc).
  • Influencing the hiring hall, making better pilots more/less common than intended.

Solution

Using MathUtility.clamp() I have bound UnitRating so fit within the lower/upper bounds of the FM:M Dragoon Rating System (F-A*). This is only limited to the above instances, so things like Unit Report are unaffected.

All issues listed under 'Problems' have been closed by this PR.

Credit

Credit for this solution goes to https://github.com/SuperStucco. All I did was go through the code to find other examples of where this was a problem, and applied their fix where appropriate.

Closes

Closes #3729
Closes #3817
Closes #3753

@IllianiCBT
Copy link
Collaborator Author

Addendum

It's worth noting that there may well be other instances of unbounded Unit Rating causing issues, these were just the ones I found.

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

Attention: Patch coverage is 18.75000% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 10.60%. Comparing base (0a2b4e4) to head (bf0fa72).
Report is 8 commits behind head on master.

Files Patch % Lines
MekHQ/src/mekhq/campaign/Campaign.java 0.00% 5 Missing ⚠️
...ekHQ/src/mekhq/campaign/market/ContractMarket.java 50.00% 3 Missing ⚠️
...campaign/personnel/RetirementDefectionTracker.java 0.00% 2 Missing ⚠️
...kHQ/src/mekhq/campaign/ResolveScenarioTracker.java 0.00% 1 Missing ⚠️
...mekhq/campaign/againstTheBot/AtBConfiguration.java 0.00% 1 Missing ⚠️
...src/mekhq/campaign/market/PersonnelMarketFMMr.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3914   +/-   ##
=========================================
  Coverage     10.60%   10.60%           
  Complexity     5487     5487           
=========================================
  Files           836      836           
  Lines        114266   114270    +4     
  Branches      17182    17182           
=========================================
+ Hits          12121    12122    +1     
- Misses       100935   100938    +3     
  Partials       1210     1210           

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

@@ -173,8 +175,9 @@ public Map<UUID, TargetRoll> calculateTargetNumbers(final @Nullable AtBContract
}

TargetRoll target = new TargetRoll(3, "Target");
target.addModifier(p.getExperienceLevel(campaign, false) - campaign.getUnitRatingMod(),
"Experience");
target.addModifier(p.getExperienceLevel(campaign, false)
Copy link
Member

Choose a reason for hiding this comment

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

What I would suggest instead is to modify the "getUnitRatingMod" function, so that instead of changing six files you're only changing one. And it also guarantees that you don't miss any other usages of that function.

Copy link
Collaborator Author

@IllianiCBT IllianiCBT Mar 27, 2024

Choose a reason for hiding this comment

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

I considered that approach, however there is at least one instance (that I found) where getUnitRatingMod shouldn't be capped:

MekHQ/src/mekhq/campaign/mission/Contract.java
Lines 606-616
image

I also suspect it'll impact the Unit Report, though that's currently unconfirmed.

Any suggestions?

@IllianiCBT IllianiCBT changed the title [#3817] [#3729] [#5275] [Bugfix] Clamp OpFor Unit Rating within FM:M Bounds Clamp OpFor Unit Rating within FM:M Bounds Mar 29, 2024
@IllianiCBT IllianiCBT added the Bug label Mar 29, 2024
@IllianiCBT IllianiCBT self-assigned this Mar 29, 2024
@IllianiCBT IllianiCBT closed this Mar 30, 2024
@IllianiCBT IllianiCBT deleted the CamOps_ClampUnitRating branch March 30, 2024 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment