use of games.strategy.triplea.delegate.dataObjects.BattleListing in project triplea by triplea-game.
the class TripleAPlayer method battle.
private void battle() {
if (getPlayerBridge().isGameOver()) {
return;
}
final IBattleDelegate battleDel;
try {
battleDel = (IBattleDelegate) getPlayerBridge().getRemoteDelegate();
} catch (final ClassCastException e) {
final String errorContext = "PlayerBridge step name: " + getPlayerBridge().getStepName() + ", Remote class name: " + getPlayerBridge().getRemoteDelegate().getClass();
// TODO: this code is triplicated in the code..
ClientLogger.logQuietly(errorContext, e);
throw new IllegalStateException(errorContext, e);
}
final PlayerID id = getPlayerId();
while (true) {
if (getPlayerBridge().isGameOver()) {
return;
}
final BattleListing battles = battleDel.getBattles();
if (battles.isEmpty()) {
final IBattle battle = battleDel.getCurrentBattle();
if (battle != null) {
// this should never happen, but it happened once....
System.err.println("Current battle exists but is not on pending list: " + battle.toString());
battleDel.fightCurrentBattle();
}
return;
}
if (!soundPlayedAlreadyBattle) {
ClipPlayer.play(SoundPath.CLIP_PHASE_BATTLE, id);
soundPlayedAlreadyBattle = true;
}
final FightBattleDetails details = ui.getBattle(id, battles.getBattles());
if (getPlayerBridge().isGameOver()) {
return;
}
if (details != null) {
final String error = battleDel.fightBattle(details.getWhere(), details.isBombingRaid(), details.getBattleType());
if (error != null) {
ui.notifyError(error);
}
}
}
}
Aggregations