-
Notifications
You must be signed in to change notification settings - Fork 173
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
Improved Unit Substitution #5314
base: master
Are you sure you want to change the base?
Conversation
Improved the handling of unit type mismatch by refactoring the code to enhance readability and maintainability. Extracted substitution logic into a separate method, ensuring a cleaner approach to the entity generation process. Additionally, added logging to provide better tracking of the substitution attempts and outcomes.
Refactored entity generation logic in AtBDynamicScenarioFactory.java to improve substitution and weight checking. Modified XML scenario templates to adjust allowed unit types and role configuration, enhancing scenario consistency and functionality.
Addressed an issue where weights starting with 'U' and length two were not correctly decoded. Updated the condition to properly handle these specific cases and ensure accurate weight determination. This change improves scenario generation by accommodating more diverse weight inputs.
Simplified and clarified the handling of substitution logic for unit types in scenario generation. Removed redundant code paths and streamlined fallback processes, improving readability and maintainability. Adjusted the handling of the SPECIAL_UNIT_TYPE_ATB_AERO_MIX to reduce verbosity and improve consistency.
The substitution logic for generating entities was refactored to include more detailed documentation and enhanced functionality. Added Javadocs to clarify the purpose, parameters, and return values for the methods `substituteEntity` and `attemptSubstitutionViaWeight`. This improves code readability and maintainability by providing clear guidance on the methods' behaviors and usage.
Implemented additional fallback logic in AtBDynamicScenarioFactory to ensure entity generation proceeds smoothly even when initial strategies fail. This includes attempts to substitute with both a set unit type and null roles when necessary. Improved logging and handling of entity creation failures to prevent abrupt termination of the generation process.
Reorganized the entity substitution process to enhance code clarity and streamline entity generation based on the scenario and unit type. Removed redundant substitution attempts and ensured that fallback mechanisms are clearly defined for each scenario type, improving the maintainability of the code.
Duplicated SUPPORT and CARGO force roles, and added APC role to enhance the variety and flexibility in Convoy Escort, Critical Convoy Escort, and Convoy Interdiction templates. These changes aimed to improve gameplay dynamics and scenario versatility.
if (type != null) { | ||
Collection<MissionRole> roleByType = rolesByType.get(type); | ||
if (roleByType != null) { | ||
role = roleByType.toString(); |
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning
roleByType
this
Collection<MissionRole> roles; | ||
|
||
if (rolesByType != null) { | ||
roles = rolesByType.getOrDefault(unitTypes.get(i), new ArrayList<>()); | ||
if (unitTypes.size() == 1) { | ||
roles = rolesByType.getOrDefault(unitTypes.get(0), new ArrayList<>()); |
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning
rolesByType
this
if (unitTypes.size() == 1) { | ||
roles = rolesByType.getOrDefault(unitTypes.get(0), new ArrayList<>()); | ||
} else { | ||
roles = rolesByType.getOrDefault(unitTypes.get(unitIndex), new ArrayList<>()); |
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning
rolesByType
this
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5314 +/- ##
============================================
- Coverage 10.47% 10.45% -0.03%
+ Complexity 6069 6051 -18
============================================
Files 959 959
Lines 135559 135589 +30
Branches 19750 19757 +7
============================================
- Hits 14204 14179 -25
- Misses 119997 120052 +55
Partials 1358 1358 ☔ View full report in Codecov by Sentry. |
As a part of our FG3 push, we included a 'unit substitution' system to try and resolve the old issue of 0 entity forces. This system goes through multiple layers of failure, attempting to substitute failed entities, step-by-step loosening generation restrictions until we find something, even if that something isn't quite what we wanted.
At some point prior I included a much simpler system that did the same thing, but worse. That older system simply tried to generate a unit and if it failed it tried again, this time without any role requirements.
Because both of these systems existed at the same time what would happen is we'd try and generate a unit, fail for whatever reason, then abandon all attempts to match role requirements. Essentially bypassing unit substitution entirely. This meant that convoy scenarios would constantly fail to generate entities - because of the very narrow pool of non-combat units for many factions - and then just give up on roles entirely and just generate a combat unit.
While I was addressing the above (by removing the errant code) I also took the opportunity to improve unit substitution. Now we only drop roles after all other options have been explored.
It should be noted that military units can still appear in convoy forces. This is particularly likely with Clan factions who have no civilian units (insofar as I can tell). I have mitigated this by decreasing the likelihood that a convoy formation will use the CIVILIAN role from 1in4 to 1in8.
Closes #5302