Search in sources :

Example 1 with FightBattleDetails

use of games.strategy.triplea.delegate.dataObjects.FightBattleDetails 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);
            }
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) FightBattleDetails(games.strategy.triplea.delegate.dataObjects.FightBattleDetails) IBattle(games.strategy.triplea.delegate.IBattle) IBattleDelegate(games.strategy.triplea.delegate.remote.IBattleDelegate) BattleListing(games.strategy.triplea.delegate.dataObjects.BattleListing)

Aggregations

PlayerID (games.strategy.engine.data.PlayerID)1 IBattle (games.strategy.triplea.delegate.IBattle)1 BattleListing (games.strategy.triplea.delegate.dataObjects.BattleListing)1 FightBattleDetails (games.strategy.triplea.delegate.dataObjects.FightBattleDetails)1 IBattleDelegate (games.strategy.triplea.delegate.remote.IBattleDelegate)1