Skip to content

Commit

Permalink
Small code cleanups. No functional changes. (#11836)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine authored Jul 31, 2023
1 parent 1b2bba1 commit 3950527
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ public static String getAnnotation(
final Territory territory,
final int battleRound) {
// Note: This pattern is parsed when loading saved games to restore dice stats to get the player
// name via the
// getPlayerNameFromAnnotation() function above. When changing this format, update
// getPlayerNameFromAnnotation(),
// preferably in a way that is backwards compatible (can parse previous formats too).
// name via the getPlayerNameFromAnnotation() function above. When changing this format, update
// getPlayerNameFromAnnotation(), preferably in a way that is backwards compatible (can parse
// previous formats too).
return player.getName()
+ " roll dice for "
+ MyFormatter.unitsToTextNoOwner(units)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ private void endBattle(final IDelegateBridge bridge) {
isOver = true;
battleTracker.removeBattle(this, bridge.getData());

// Must clear transportedby for allied air on carriers for both attacking units and retreating
// units
// Must clear transportedBy for allied air on carriers for both attacking and retreating units
final CompositeChange clearAlliedAir =
TransportTracker.clearTransportedByForAlliedAirOnCarrier(
attackingUnits, battleSite, attacker, gameData);
Expand All @@ -515,22 +514,16 @@ public void clearWaitingToDieAndDamagedChangesInto(
final IDelegateBridge bridge, final BattleState.Side... sides) {
for (final Side side : sides) {
if (side == OFFENSE) {
damagedChangeInto(
attacker,
attackingUnits,
CollectionUtils.getMatches(killedDuringCurrentRound, Matches.unitIsOwnedBy(attacker)),
bridge,
side);
Collection<Unit> killed =
CollectionUtils.getMatches(killedDuringCurrentRound, Matches.unitIsOwnedBy(attacker));
damagedChangeInto(attacker, attackingUnits, killed, bridge, side);
removeUnits(attackingWaitingToDie, bridge, battleSite, side);
attackingWaitingToDie.clear();
} else {
damagedChangeInto(
defender,
defendingUnits,
Collection<Unit> killed =
CollectionUtils.getMatches(
killedDuringCurrentRound, Matches.unitIsOwnedBy(attacker).negate()),
bridge,
side);
killedDuringCurrentRound, Matches.unitIsOwnedBy(attacker).negate());
damagedChangeInto(defender, defendingUnits, killed, bridge, side);
removeUnits(defendingWaitingToDie, bridge, battleSite, side);
defendingWaitingToDie.clear();
}
Expand Down Expand Up @@ -852,10 +845,10 @@ public Collection<Territory> getAttackerRetreatTerritories() {
}

// the air unit may have come from a conquered or enemy territory, don't allow retreating
final Predicate<Territory> conqueuredOrEnemy =
final Predicate<Territory> conqueredOrEnemy =
Matches.isTerritoryEnemyAndNotUnownedWaterOrImpassableOrRestricted(attacker)
.or(Matches.territoryIsWater().and(Matches.territoryWasFoughtOver(battleTracker)));
possible.removeAll(CollectionUtils.getMatches(possible, conqueuredOrEnemy));
possible.removeAll(CollectionUtils.getMatches(possible, conqueredOrEnemy));

// the battle site is in the attacking from if sea units are fighting a submerged sub
possible.remove(battleSite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import games.strategy.engine.delegate.IDelegateBridge;
import games.strategy.engine.display.IDisplay;
import games.strategy.triplea.delegate.DiceRoll;
import games.strategy.triplea.delegate.ExecutionStack;
import games.strategy.triplea.delegate.battle.BattleDelegate;
import games.strategy.triplea.delegate.battle.BattleState;
Expand Down Expand Up @@ -56,27 +57,19 @@ public Order getOrder() {

@Override
public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
final DiceRoll diceRoll = fireRoundState.getDice();
final String stepName =
MarkCasualties.getPossibleOldNameForNotifyingBattleDisplay(
battleState, firingGroup, side, getName());
if (ClientSetting.useWebsocketNetwork.getValue().orElse(false)) {
bridge.sendMessage(
new IDisplay.NotifyDiceMessage(
fireRoundState.getDice(),
MarkCasualties.getPossibleOldNameForNotifyingBattleDisplay(
battleState, firingGroup, side, getName()),
fireRoundState.getDice().getPlayerName()));
new IDisplay.NotifyDiceMessage(diceRoll, stepName, diceRoll.getPlayerName()));
} else {
bridge
.getDisplayChannelBroadcaster()
.notifyDice(
fireRoundState.getDice(),
MarkCasualties.getPossibleOldNameForNotifyingBattleDisplay(
battleState, firingGroup, side, getName()));
bridge.getDisplayChannelBroadcaster().notifyDice(diceRoll, stepName);
}

final CasualtyDetails details = selectCasualties.apply(bridge, this);

fireRoundState.setCasualties(details);

BattleDelegate.markDamaged(
fireRoundState.getCasualties().getDamaged(), bridge, battleState.getBattleSite());
BattleDelegate.markDamaged(details.getDamaged(), bridge, battleState.getBattleSite());
}
}

0 comments on commit 3950527

Please sign in to comment.