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

Overhauled CamOps Unit Reputation Calculations and Report #4605

Merged
merged 50 commits into from
Aug 13, 2024

Conversation

IllianiCBT
Copy link
Collaborator

@IllianiCBT IllianiCBT commented Aug 11, 2024

As requested by Hammer, this PR goes through and rewrites how we handle CamOps Reputation (previously known as Unit Rating). This incorporates current errata and streamlines a lot of the calculations.

Furthermore, CamOps reputation was detached from IUnitRating, as this gave me a lot more freedom in how I could implement the new system.

The second reason was that I wanted to isolate FM:Mr's Unit Rating calculations entirely. While FM:Mr is considered deprecated at this point, by isolating it it's my hope that we can reduce the likelihood of some future change breaking FM:Mr's Unit Rating, which would then potentially result in its' removal. While CamOps rules are current and what we will be supporting, moving forward, I recognize that some users prefer to use FM:Mr. I wanted to make one last gesture of support before 50.0 ships and FM:Mr becomes visible as 'deprecated' to the wider userbase.

I also added Crime Tracking, because it amused me to do so. Right now it only tracks whether the campaign is a Pirate faction, but I intend to have some fun with this at a later date.

Closes #3475

Simplified the method for retrieving unit rating modifiers by implementing a new utility. Introduced the ReputationController class and the AverageExperienceRating class to manage reputation and experience ratings, respectively, facilitating better campaign management.
Added a new CommandRating class to calculate commander ratings based on skills and personality traits. Integrated this functionality into the ReputationController, storing the calculated ratings in a map and updating the total commander rating.
Replaced `getFinalSkillValue` with `getExperienceLevel` for skill assessment. This change ensures skill levels reflect experience more accurately.
Added null checks in getSkillValue and getPersonalityValue methods to ensure the functions return 0 when the Person object is null. This prevents potential NullPointerExceptions.
Integrated detailed logging to track commander rating calculations within CommandRating. Corrected logger instantiation in AverageExperienceRating for consistency and accuracy.
Renamed `commanderRating` to `commandRating` for clarity and consistency. Adjusted the logger statement for improved readability.
Introduced `retainerStartDate` to track the start date of a retainer. Added `CombatRecordRating` class to calculate and store ratings based on mission outcomes, and updated `ReputationController` to use this new rating.
Implemented the TransportationRating class to compute transportation metrics for a Campaign. Updated ReputationController to include transportation rating in reputation calculations and added isFullyCrewed method in Unit class.
Adjusted ratings for support personnel, JumpShip and WarShip presence, and docking collar requirements. Implemented a method to count non-unit personnel for accurate transport requirements.
Renamed the CamOpsRatingV2 package and its classes to CamOpsReputation for better clarity and alignment with the new naming conventions. Updated all relevant import statements to reflect these changes.
Introduced FinancialRating class with a method to calculate financial ratings based on current financial status. Updated ReputationController to integrate financial rating calculations into the reputation initialization process.
Introduced CrimeRating class and integrated crime rating calculation into the Campaign and ReputationController. Updated Campaign's XML handling to serialize and deserialize crime rating and date of last crime.
Modified the crime rating increment from 3 to 2 in the `updateCimeRating` method within the `Campaign` class.
Simplified the condition in processUnitReputation by removing the check for empty active missions. This change focuses the function on processing unit reputation solely based on the day of the month.
Introduced `OtherModifiers` class to calculate additional reputation modifiers considering inactive years. Updated `ReputationController` to integrate these calculations, storing results in `otherModifiersMap` and applying the total modifier to `reputationRating`.
Implemented a method to calculate the total reputation by aggregating various ratings and modifiers. This update ensures the reputationRating variable is properly updated with all relevant components.
Included getter and setter methods for average skill level, experience rating, commander map, and other attributes in ReputationController. These methods were added to improve encapsulation and allow external access to these fields while maintaining control over their modification.
Improved transportation rating calculations by fixing key mismatches and optimizing aggregation. Introduced detailed logging in ReputationController and improved experience calculation methods for better accuracy. Removed redundant methods in CombatRecordRating and streamlined imports.
Updated the comment format in Skill.java to use HTML tags and removed an unused variable from AverageExperienceRating.java. These changes improve code readability and eliminate unnecessary variables.
Enhanced the logging mechanism by tracking individual transportation values. Each transportation category now logs its rating, improving the debugging and analysis capabilities. Additionally, the method `calculateRating` was changed to protected for extended accessibility.
Added logic to set the date of the last crime if the faction is pirate. This ensures accurate crime tracking and proper update of the crime rating. Removed redundant initialization of ReputationController within the same method.
Added `getDescription` method to generate a comprehensive HTML summary of unit reputation, including experience, command, combat record, transportation, financial, and crime ratings. Also added helper methods to format mission and transport strings and updated `initializeReputation` to include transportation values.
Deleted the entire CampaignOpsReputation.java file as it is no longer needed. All references and related code have been purged to streamline project structure and eliminate unused code.
Changed the reputation calculation method to directly set rather than increment the initial value. Updated various UI elements to reflect the new terminology, replacing "Unit Rating" with "Reputation".
Deleted the AtB CamOps Division label, spinner, and associated properties from the CampaignOptionsPane. Updated the labeling for unit rating methods to emphasize reputation instead. Removed the feature's impact on the options setup and persistence logic.
Introduced a new `ReputationReportDialog` to handle non-FMMR unit ratings. Updated `CampaignGUI` and `CommandCenterTab` to dynamically choose between `UnitRatingReportDialog` and `ReputationReportDialog` based on campaign options. Adjusted `UnitRatingReportDialog` to use fixed font settings.
Refactored the `Person` class to separate different tech roles into distinct methods. Enhanced support rating calculations in `SupportRating` to include detailed requirements and added new methods for administration and technician requirements. Updated reputation handling to incorporate support ratings.
Implemented resource bundles to facilitate localization of the unit reputation descriptions. Refactored the existing string literals to use keys from the new CamOpsReputation.properties file.
Resolved errors in DropShip rating calculations by correctly referencing resources for text values. Added new text properties for transport and DropShip strings, improving display formatting and consistency.
Revised the crime rating method to return detailed crime metrics in a map. Introduced a separate piracy modifier to handle pirate crimes, allowing for more granular control and accurate logging. Updated related properties and XML handling to support these changes.
@pheonixstorm
Copy link
Collaborator

@IllianiCBT if you haven't already you may also want to check out #3610 as it also deals with the Cam Ops rating.

Consolidated skill level summation logic using a Consumer for code reuse and clarity. This change eliminates redundant code and improves the maintainability of the AverageExperienceRating class.
@repligator
Copy link
Collaborator

repligator commented Aug 12, 2024

My unit Rep Report shows (+-10) for 1 failed mission. Is that meant to be read as 'plus negative ten', and if so could it be re-written as '-10' the same way No Dropship is -5?
Screenshot_20240812_100641

@repligator
Copy link
Collaborator

repligator commented Aug 12, 2024

NPE on first day of the month

11:10:55,807 ERROR [mekhq.MekHQ] {AWT-EventQueue-0}
mekhq.MekHQ.lambda$main$1(MekHQ.java:294) - Uncaught Exception Detected
java.lang.NullPointerException: temporal
	at java.base/java.util.Objects.requireNonNull(Objects.java:235)
	at java.base/java.time.LocalDate.from(LocalDate.java:394)
	at java.base/java.time.LocalDate.until(LocalDate.java:1641)
	at java.base/java.time.temporal.ChronoUnit.between(ChronoUnit.java:272)
	at mekhq.campaign.Campaign.processUnitReputation(Campaign.java:3805)

mekhq.log
Omega Galaxy31540201.cpnx.gz

EDIT: Happened first day of the next month as well.

@HammerGS
Copy link
Member

I think we go with the CodeQL has the sanity check and merge this. Then it's easier for QA to test in the nightlies up to release.

@IllianiCBT
Copy link
Collaborator Author

IllianiCBT commented Aug 12, 2024

Updated the mission string format to display the correct sign and added a null check for dateOfLastCrime

Updated the mission string format to display the correct multiplier and added a null check for dateOfLastCrime in the `Campaign` class.
@IllianiCBT
Copy link
Collaborator Author

This is the updated Action: https://github.com/MegaMek/mekhq/actions/runs/10357521893

IllianiCBT and others added 2 commits August 12, 2024 18:44
Renamed `processUnitReputation` to `updateCrimeRating` to better reflect its functionality.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm leery of deleting an entire unit test file without at least attempting to replicate its coverage. Is there a plan to implement unit tests of the new code at some point in the near future?

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.

A couple questions, but overall looks good!

Eliminated several unused setter methods from `ReputationController.java` to improve code maintainability and readability.
Replaced reputationController with reputationRecord across multiple classes to improve modularity and clarity. Added static methods for initializing and fetching reputation reports. Reduced code duplication and improved encapsulation, ensuring all related data is now managed within the ReputationRecord. Fixed average experience and support requirement calculations for empty campaigns. Adjusting Reputation to only update on Monday.
Updated the Campaign class and related dialogs to use the new ReputationController methods and structure. Replaced all instances of getReputationController and setReputationController with getReputation and setReputation. Added XML serialization and deserialization for reputation data in the ReputationController class.
Added try-catch blocks to handle NumberFormatException and NullPointerException during parsing of TechnicianRequirements. Logged errors to assist in debugging and prevent application crashes due to malformed input.
Changed from catching NullPointerException to catching all exceptions. This ensures that unanticipated exceptions are properly logged, improving error tracking and debugging.
@IllianiCBT IllianiCBT merged commit cb75889 into MegaMek:master Aug 13, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.49.10 Unit rating off due to imaginary tech shortage caused by having large craft.
7 participants