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

Auto-select battle calc sides when using 'ctrl+A' and 'ctrl+D' #9012

Merged
merged 1 commit into from
Mar 14, 2021

Conversation

DanVanAtta
Copy link
Member

This update adds two behaviors for the battle calculator when using
the hotkeys 'ctrl+A' and 'ctrl+D' to add attackers or defenders
to reduce having to switch the current attacker or defender
in the battle calc.

When adding attackers, if there are no matching attackers with
the current side, and there is a defender present in the battle
calc, then the attacking side is automatically set to the player
whith the most units in that territory. For example, if a player
has set up 1 defending UK infantry, and there is a territory
with 1 german tank, and the battle calc has italy set as the
attacker, then using control-a will automatically add the tank
and set the attacker to germany.

For defenders, if there are no units added to the battle calcuator
at all, then if a player uses 'ctrl+d', the defending side will
be set to match any unit that is in the current territory. For
example if a default calculator has germany as the defender, and
a player uses 'ctrl+d' in a russian territory with russian units,
then those units will be added to defenders and the defending
side will be automatically set to russia.

Testing

Screens Shots

Additional Notes to Reviewer

Release Note

UPDATE|Battle calculator 'ctrl+A' and 'ctrl+D' will automatically set defending and attacking sides if there are no units currently set as the attacker or defender. For example, if there are UK attacking troops in a territory and the calculator has Russia selected as the attacker but no units were added to the calculator, then using 'ctrl+A' on the UK territory will change the attacker from Russia to UK and will add the UK units.

This update adds two behaviors for the battle calculator when using
the hotkeys 'ctrl+A' and 'ctrl+D' to add attackers or defenders
to reduce having to switch the current attacker or defender
in the battle calc.

When adding attackers, if there are no matching attackers with
the current side, and there is a defender present in the battle
calc, then the attacking side is automatically set to the player
whith the most units in that territory. For example, if a player
has set up 1 defending UK infantry, and there is a territory
with 1 german tank, and the battle calc has italy set as the
attacker, then using control-a will automatically add the tank
and set the attacker to germany.

For defenders, if there are no units added to the battle calcuator
at all, then if a player uses 'ctrl+d', the defending side will
be set to match any unit that is in the current territory. For
example if a default calculator has germany as the defender, and
a player uses 'ctrl+d' in a russian territory with russian units,
then those units will be added to defenders and the defending
side will be automatically set to russia.
@codecov
Copy link

codecov bot commented Mar 8, 2021

Codecov Report

Merging #9012 (ac9b28e) into master (39b7bd7) will decrease coverage by 0.01%.
The diff coverage is 9.75%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #9012      +/-   ##
============================================
- Coverage     28.39%   28.37%   -0.02%     
  Complexity     8369     8369              
============================================
  Files          1302     1302              
  Lines         80952    80988      +36     
  Branches      11050    11054       +4     
============================================
- Hits          22984    22983       -1     
- Misses        55788    55827      +39     
+ Partials       2180     2178       -2     
Impacted Files Coverage Δ Complexity Δ
...a/games/strategy/triplea/ai/AbstractBuiltInAi.java 0.90% <0.00%> (ø) 2.00 <0.00> (ø)
...riplea/odds/calculator/BattleCalculatorDialog.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...triplea/odds/calculator/BattleCalculatorPanel.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...tegy/triplea/odds/calculator/PlayerUnitsPanel.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...es/strategy/triplea/odds/calculator/UnitPanel.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
.../java/org/triplea/java/collections/IntegerMap.java 58.57% <36.36%> (-4.15%) 25.00 <1.00> (+1.00) ⬇️
.../strategy/triplea/odds/calculator/DummyPlayer.java 50.54% <0.00%> (-5.50%) 16.00% <0.00%> (-1.00%)
.../main/java/games/strategy/net/ClientMessenger.java 62.50% <0.00%> (-2.09%) 17.00% <0.00%> (-1.00%)
.../src/main/java/games/strategy/net/nio/Decoder.java 74.13% <0.00%> (-1.73%) 13.00% <0.00%> (-1.00%)
...ine/message/unifiedmessenger/UnifiedMessenger.java 72.04% <0.00%> (+1.24%) 27.00% <0.00%> (+1.00%)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39b7bd7...497fbf9. Read the comment docs.

@Cernelius
Copy link
Contributor

As is, the behaviour for the D one would need related refinements like being able to add multi-player defenses manually. Missing that, I'd skip the D part of this change for now, and do only the A part.

@Cernelius
Copy link
Contributor

Ignoring the D part, I suggest the A part (switching when clicking with 0 units of the current selected offender to add) applying only when there are no offenders already in the battlecalculator. Especially in confusing maps, I may be A-clicking on zones around just to make sure I'm not missing anything to add after I already have one or more offenders added in the battle-calculator.

@DanVanAtta
Copy link
Member Author

As is, the behaviour for the D one would need related refinements like being able to add multi-player defenses manually.

Interesting point. That would be a another feature beyond what is here. Getting a good UI for that would be tricky, I think it would need some design work. I wonder though if it's common enough that you can't just "ctrl+D" units in question and perhaps have done with it, whether it's really needed.

The defender part is so that you don't have to manually toggle the defenders if you clear the battle calc and then select new defenders. I believe there is a use for that.

I suggest the A part (switching when clicking with 0 units of the current selected offender to add) applying only when there are no offenders already in the battlecalculator.

I believe that is what I have described, the switch only happens if there are no attacking units in the battle calc. So if you select only defenders, then if you use "ctrl+A" and there are any enemies in the territory not matching the current attacker selection, it will switch to them. For example, if the current attacker is Russia with Germany defending, and no Russian units listed, then using "Ctrl+A" with UK units would select them. OTOH if there is a territory with 2 Russian units and 4 UK units, because Russia is already selected, the 2 Russian would be added.

@Cernelius
Copy link
Contributor

If by

When adding attackers, if there are no matching attackers with
the current side, and there is a defender present in the battle
calc, then the attacking side is automatically set to the player
whith the most units in that territory.

you mean "upon clicking Ctrl+A on a zone, the attacking side is automatically set to the player or to one of the players with the greatest number of additionable units in the zone if there are one or more defenders present in the battle-calculator and neither are there matching attackers with the current attacking side in the clicked zone nor are there one or more attackers already present in the battle-calculator", yes, but I don't see a reason for it not working with zero defenders present in the battle-calculator too.

@DanVanAtta
Copy link
Member Author

@Cernelius actually I was incorrect to say it depended on defending units being added. This is the condition: https://github.com/triplea-game/triplea/pull/9012/files#diff-e14a5a9de984a7af6b0ed30380538343e4e373f3148db551c3d4cd1cc918ae58R113-R116

The auto-attacker switch has three parts:

  • no attacking units added
  • current attacker selection does not match any units in the territory
  • territory has at least one enemy unit

@Cernelius
Copy link
Contributor

@Cernelius actually I was incorrect to say it depended on defending units being added. This is the condition: https://github.com/triplea-game/triplea/pull/9012/files#diff-e14a5a9de984a7af6b0ed30380538343e4e373f3148db551c3d4cd1cc918ae58R113-R116

The auto-attacker switch has three parts:

  • no attacking units added
  • current attacker selection does not match any units in the territory
  • territory has at least one enemy unit

Maybe I'm being overly precise and I guess developers are just going to look at the code, but, just to make sure: do you mean:

The auto-attacker switch happens only if all following conditions apply:

  • no attacking units are already present in the battle-calculator
  • the current attacker selection does not match any units each of which is present in the zone and can be present as an attacker in the battle-calculator (for example, excluding "fort" units in my 270BC Wars game as they can never attack and the battle-calculator correctly does not offer you the option to add them as attackers (so, if I Ctrl+A on a territory with Rome forts and no other Rome units in it, the switch may happen like the forts are not there))
  • the zone has at least one unit which may be added as an attacker to the battle-calculator and belongs to a player which can be matched against the current defending player selected in the battle-calculator

About the last part, a side note is how that is determined. For example, if you add only "enemy", as you say, then you are making me impossible to calculate against current allied or neutral countries in a game with politics in which they may be enemy in the future and maybe on their very coming turn. An example is Germans and Russians being neutral in Global but possibly enemy on the next turn (and there may be custom games in which you go from allied to war at once).

@DanVanAtta
Copy link
Member Author

. For example, if you add only "enemy", as you say, then you are making me impossible to calculate against current allied or neutral countries in a game with politics in which they may be enemy in the future and maybe on their very coming turn.

Hopefully not impossible beyond the limitations of the calc today. One can certainly manually select a given faction and input the units. That scenario perhaps does not change compared to what we have today.

@DanVanAtta DanVanAtta merged commit f90439c into master Mar 14, 2021
@DanVanAtta DanVanAtta deleted the battle-calc-auto-select-attacker branch March 14, 2021 20:45
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.

2 participants