-
Notifications
You must be signed in to change notification settings - Fork 171
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
[WIP] Resupply Module #5158
base: master
Are you sure you want to change the base?
[WIP] Resupply Module #5158
Conversation
Created the SupplyDrop class to handle collecting, processing, and delivering supply drops within the campaign. Includes methods for initializing parts pools, generating part weightings, managing drop rewards, and displaying the supply drop dialog to users.
Created SupplyDrops.properties to support in-game supply drop scenarios. Integrated the feature into the campaign with imports and constants for various morale levels.
Removed the bonus parts labels, related configurations, and methods from various classes. Adjusted relevant logic to accommodate these changes and simplified related processes.
Updated the ResolveScenarioWizardDialog constructor to accept `Campaign` as a parameter. This change ensures consistency across different parts of the application and improves code clarity.
Updated the copyright years in various files across the project to reflect the year 2024. This change ensures all legal notices are up-to-date and consistent.
Updated the getWeight method to only take a Part object, removing the dependency on Unit. Adjusted the weighting logic to increase the weight multiplier for MissingPart objects to 5.
Implemented the conversion of remaining support points to supply drops for AtB Contracts when strategic operations are used. This ensures that any leftover points are utilized effectively, enhancing campaign dynamics and resource management.
Adjusted supply drops to respect faction tech sharing restrictions before the Battle of Tukayyid. Fixed a bug with calculating the value and quantity of certain parts. Increased logging and added new reference imports for future functionality.
Revised SupplyDrops to incorporate enemy faction units and parts. Updated methods to handle separate fetching and displaying logic for unit drops and part drops. Altered the initialization process based on whether it is a LosTechCache.
Introduced a mechanic that triggers suspicious deaths related to ComStar interest levels, particularly on Mondays. Also added detailed error logging for these events to improve traceability. Updated resource file with new dud dialog descriptions.
Removed ComStar interest and suspicious death condition from AbstractDeath. Renamed the SupplyDrops package path for better organization. Updated relevant imports and logic to reflect these changes.
Created new `starLeagueCache` and `comStarInterest` classes in supplyDrops package. Renamed SupplyDrops to SupplyDrop and modified related imports and logic in BriefingTab. Updated SupplyDrops.properties to SupplyDrop.properties with new supply drop messages.
# Conflicts: # MekHQ/src/mekhq/campaign/Campaign.java
Removed redundant supply drop texts and streamlined the file by introducing new, organized texts for various operational statuses. This improves the clarity and relevance of messages received during different situational contexts.
Refactored the handling of dialog interactions in the SupplyDrop class to improve code maintainability. Introduced the `processConvoy`, `createConvoyMessage`, and `pickLogisticsRepresentative` methods to manage dialog creation and message processing more effectively. Simplified the message retrieval logic and updated logistic messages in the resource file.
Lowered the interception random number range from 50 to 25 to adjust event frequency. Consolidated and simplified supply drop descriptions to enhance readability and maintain consistency.
Renamed the SupplyDrop class to Resupply and updated related references across the project for clarity. The package was also reorganized from supplyDrops to resupplyAndCaches to better reflect its contents.
Refactored the resupply mission logic to improve readability and efficiency. Added morale level checks and updated message formatting for intercepted supplies. Renamed the properties file from `SupplyDrop.properties` to `Resupply.properties` and updated relevant messages.
Moved resupply logic to correct conditional block for clarity. Ensured resupply parts are calculated and obtained immediately after adding the report. This change improves code organization and readability.
Refactored the convoy message creation logic in the `Resupply` class to ensure intercepted messages are generated correctly. Consolidated duplicate code, adjusted the ordering of condition checks, and introduced an overloaded `createConvoyMessage` method for clarity and simplicity.
Inserted 'UNEDITED' placeholder tags to various status update messages for better identification and tracking. This change will facilitate easier referencing during future edits and improvements.
Renamed resupplyAndCaches package by removing 'atb' for better organization. Added more detailed supply logic to accommodate ration packs and medical supplies based on personnel roles.
Eliminated unnecessary commented-out code related to resupply operations in Campaign.java. This cleanup ensures the final step before returning true remains clear and concise, improving code readability.
Refactored the resupply process to handle convoy interceptions instead of destruction. Added new messages for both StratCon and AtB scenarios to indicate that a special defense scenario has been added.
Consolidated import statements in the Resupply.java class and introduced a Logger for debugging. Modified the Stratcon track selection logic along with adjustments in reporting methods. Updated Resupply.properties for better readability and maintainability.
# Conflicts: # MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java
MekHQ/src/mekhq/campaign/mission/resupplyAndCaches/StarLeagueCache.java
Dismissed
Show dismissed
Hide dismissed
MekHQ/src/mekhq/campaign/mission/resupplyAndCaches/StarLeagueCache.java
Dismissed
Show dismissed
Hide dismissed
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5158 +/- ##
============================================
- Coverage 10.52% 10.40% -0.13%
+ Complexity 6042 6040 -2
============================================
Files 956 960 +4
Lines 134346 135814 +1468
Branches 19514 19781 +267
============================================
- Hits 14145 14136 -9
- Misses 118851 120325 +1474
- Partials 1350 1353 +3 ☔ View full report in Codecov by Sentry. |
Added proposal dialogs for valid hidden Star League caches when faction is "SL". Refined dialog management and updated resource strings to improve positioning and process clarity.
Simplified resupply handling by eliminating unit-related logic and merging functionalities. Modified parts collection and processing to focus exclusively on parts, applying relevant weight adjustments and quality settings. Improved code readability and maintainability by consolidating methods and updating documentation.
Eliminated unnecessary boolean parameters from Resupply constructor calls across multiple classes. This refactoring simplified the method signatures, enhancing readability and maintainability of the code.
Error popped up. I'm guessing it's because I had my supply convoy assigned elsewhere at the end of the month. |
Refactored the contract start message generation to a dedicated method, supporting different contract types and resupply details. Added new text entries for various contract scenarios and improved the handling of player convoys in resupply calculations.
Fixed. Thanks for the report :) |
Changed arrival turn in "Emergency Convoy Defense" scenario template, removed unused properties, and updated resupply functionality across multiple classes. Refactored convoy message creation, negotiation calculation, and excluded specific parts from resupply.
Reformatted string concatenation for better readability in `StarLeagueCache.java`. Replaced traditional switch case with enhanced switch expression in `ScenarioObjectiveProcessor.java` for clarity. Removed an unused logger in `StratconContractInitializer.java`.
Ensured that ceiling function result is cast to an integer before the loop in order to prevent repeated evaluation. This change maintains consistent resupply quality in well-stocked campaigns.
Previously, the resupply multiplier for AmmoBin parts was not explicitly defined, resulting in potentially incorrect resupply calculations. This change set the multiplier to 4 to ensure accurate resupply estimations for AmmoBins.
|
||
// I really don't like checking against a String here, but I couldn't find a way to | ||
// fetch the scenario's original template | ||
if (Objects.equals(scenario.getName(), "Emergency Convoy Defense")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new enum that works as a kind of "descriptive type", but that does not necessarily substitute whatever type the scenario is (meaning you can have a raid or extraction that count as Emergency Convoy Defense later on, which may be very relevant for a narrative someone is creating), and add types as needed, start with one specific that is for "rescue/protection convoy operation" and the rest are, initially, just the generic.
With that you can avoid the very fragile string comparsion.
Also, because you would be just adding it as something new, it becomes backwards compatible because it considers that it must be a "generic/non-interesting" scenario if it lacks the value by default, or simply the default is applied when the object is created.
private void processAbandonedConvoy(AtBContract contract, AtBDynamicScenario scenario) { | ||
convoyFinalMessageDialog(this, contract.getEmployerFaction()); | ||
|
||
if (contract.getCommandRights().isIndependent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: I prefer an early exit here instead, makes absolutelly no difference in how the code operates, but reduces one tab level.
for (Integer forceId : scenario.getPlayerTemplateForceIDs()) { | ||
Force force = getForce(forceId); | ||
|
||
if (force != null && force.isConvoyForce()) { | ||
for (UUID unitID : new ArrayList<>(force.getUnits())) { | ||
Unit unit = getUnit(unitID); | ||
if (unit != null) { | ||
List<Person> crew = new ArrayList<>(unit.getCrew()); | ||
for (Person crewMember : crew) { | ||
PersonnelStatus status = KIA; | ||
// We're using the CamOps rules for infantry survival here and | ||
// assuming anyone who isn't dead has been captured. | ||
if (Compute.d6(2) > 7) { | ||
status = PersonnelStatus.POW; | ||
} | ||
crewMember.changeStatus(this, currentDay, status); | ||
} | ||
} | ||
removeUnit(unitID); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a suggestion on how to use modern java with streams for data manipulation and reduce the number of branching operation in the CPU.
The following code was not tested and possibly has bug (like the simultaneos removal of units while iterate over its list), probably need to keep new ArrayList in there (commented out, and probably slightly wrong).
/**
* Processes an abandoned convoy. The player is presented with a defeat dialog,
* and if they have independent command rights, it checks each player template force in the scenario
* for being a convoy force. If it is a convoy force, its units are treated as abandoned units.
* Each crew member of these units is set as either KIA or POW based on a die roll.
* It finally removes each unit from the campaign.
*
* @param contract The current {@link AtBContract}.
* @param scenario The relevant {@link AtBDynamicScenario}.
*/
private void processAbandonedConvoy(AtBContract contract, AtBDynamicScenario scenario) {
convoyFinalMessageDialog(this, contract.getEmployerFaction());
if (!contract.getCommandRights().isIndependent()) {
return;
}
scenario.getPlayerTemplateForceIDs().stream()
.map(this::getForce).filter(Objects::nonNull)
.filter(Force::isConvoyForce)
.map(Force::getUnits)
// .flatMap(new::ArrayList) ??? maybe this is necessary here? I cant test this case now
.map(this::decideCrewFate)
.forEach(this::removeUnit);
}
/**
* decideCrewFate
* <p>
* Decide the fate of the crew of a unit that was abandoned in a time of need
* </p>
* @param unitID
* @return
*
*/
private UUID decideCrewFate(UUID unitID) {
Optional.of(getUnit(unitID)).ifPresent(unit -> unit.getCrew().forEach(this::decideCrewmemberFate));
return unitID;
}
/**
* decidePersonFate
* <p>
* We're using the CamOps rules for infantry survival here and
* assuming anyone who isn't dead has been captured.
* </p>
* @param person The person to decide the fate of.
*/
private void decideCrewmemberFate(Person person) {
PersonnelStatus status = KIA;
if (Compute.d6(2) > 7) {
status = PersonnelStatus.POW;
}
person.changeStatus(this, currentDay, status);
}
*/ | ||
private void processResupply(AtBContract contract) { | ||
if (!contract.getContractType().isGuerrillaWarfare() || Compute.d6(1) > 4) { | ||
int maximumResupplySize = (int) Math.max(1, Math.floor((double) contract.getRequiredLances() / 3)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line is a good candidate to be its own function, so we have a place that is easy to find and change the max resuply size.
this.convoyForce = convoyForce; | ||
if (setForSubForces) { | ||
for (Force force : subForces) { | ||
force.setConvoyForce(convoyForce, true); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.convoyForce = convoyForce; | |
if (setForSubForces) { | |
for (Force force : subForces) { | |
force.setConvoyForce(convoyForce, true); | |
} | |
} | |
this.convoyForce = convoyForce; | |
if (setForSubForces) { | |
subForces.forEach(force -> force.setConvoyForce(convoyForce, true)); | |
} |
Removed an unused error message about player convoy fetching from Resupply.properties. Refactored `Resupply` class to improve convoy resupply handling, adjusted cargo capacity calculations, streamlined dialog generation, and enhanced interception logic.
Introduced the `Procurement` class to encapsulate parts availability checks, enhancing the resupply process. Updated the `Resupply` code to handle different part types more accurately and to streamline procurement using a skill-based system. Added handling for unsuccessful convoy scenarios.
Updated nullability annotations in several methods to ensure consistent syntax across the StratconRulesManager and Resupply classes. This improves code readability and aligns the codebase with standard practices.
Added new scenario templates for VTOL and low-atmosphere convoy defenses. Updated the code to select appropriate scenario templates based on the convoy's unit composition. Adjusted some map parameters and renamed the independent convoy defense template to align with player-oriented scenarios.
Ensured convoy messages are only created if intercepted or contain non-aerial and non-VTOL units. Added `forceContainsOnlyVTOLForces` method to properly check for VTOL units and handled null values in convoy validation methods.
Fixed grammatical errors in the comments to improve readability and clarity. The updates ensure consistency and better understanding of the interception chance conditions in the resupply logic.
Implemented scenario type classification and handling for resupply and LosTech scenarios. Added roleplay items to resupply reports and updated various classes to utilize new scenario types for better organization and functionality.
Changed stratConScenarioType to private and provided a getter method. Updated references to use the new getter to maintain encapsulation and ensure null safety.
Replaced direct `Random` instantiation with class-level instance in `Resupply.java` to standardize random operations. Introduced a variable for array length in `Procurement.java` for clarity and potential optimization.
Revised resupply tonnage calculations and removed specific condition checks. Updated scenario templates with new strategic context types to improve mission briefing clarity and alignment with gameplay objectives.
This is the test branch for the upcoming Resupply Module. For more information please see here