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

Fix duplicate territory listed for amphib bombardment #12009

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

asvitkine
Copy link
Contributor

@asvitkine asvitkine commented Oct 2, 2023

Change Summary & Additional Notes

This would happen when there's both an air and a land battle at the territory.
The cause was this coding pattern:

    for (final Territory t : battleTracker.getPendingBattleSites(false)) {
      final IBattle battle = battleTracker.getPendingBattle(t, BattleType.NORMAL);

Since getPendingBattleSites() would return battle sites for all (non-bombard) battles, it would list the same territory twice when that territory had both an air and a regular battle. But then, we'd retrieve the same NORMAL battle for that territory, processing it twice.

The fix is to get rid of the above pattern (which was also inefficient) and instead add a getPendingBattles(type) API.

Several other call sites are converted to the new pattern. It's possible they also exhibited related bugs.
The new pattern is also more efficient since it's no longer O(n^2) as the getPendingBattle() call is removed.

This PR also cleans up a few other things, such as grammar in comments that IntelliJ warns about.
Fixes #11999.

Release Note

FIX|Duplicate naval bombard territory listed when there's an air battle

@asvitkine asvitkine merged commit c5c1cbd into triplea-game:master Oct 2, 2023
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.

TripleA-2.6+14513 Bombardment TT repeated
1 participant