Search in sources :

Example 6 with BattleResults

use of games.strategy.triplea.oddsCalculator.ta.BattleResults in project triplea by triplea-game.

the class StrategicBombingRaidBattle method endBeforeRolling.

private void endBeforeRolling(final IDelegateBridge bridge) {
    getDisplay(bridge).battleEnd(m_battleID, "Bombing raid does no damage");
    m_whoWon = WhoWon.DRAW;
    m_battleResultDescription = BattleRecord.BattleResultDescription.NO_BATTLE;
    m_battleTracker.getBattleRecords().addResultToBattle(m_attacker, m_battleID, m_defender, m_attackerLostTUV, m_defenderLostTUV, m_battleResultDescription, new BattleResults(this, m_data));
    m_isOver = true;
    m_battleTracker.removeBattle(StrategicBombingRaidBattle.this);
}
Also used : BattleResults(games.strategy.triplea.oddsCalculator.ta.BattleResults)

Example 7 with BattleResults

use of games.strategy.triplea.oddsCalculator.ta.BattleResults in project triplea by triplea-game.

the class StrategicBombingRaidBattle method end.

private void end(final IDelegateBridge bridge) {
    if (isDamageFromBombingDoneToUnitsInsteadOfTerritories()) {
        getDisplay(bridge).battleEnd(m_battleID, "Raid causes " + m_bombingRaidTotal + " damage total." + (m_bombingRaidDamage.size() > 1 ? (" To units: " + MyFormatter.integerUnitMapToString(m_bombingRaidDamage, ", ", " = ", false)) : ""));
    } else {
        getDisplay(bridge).battleEnd(m_battleID, "Bombing raid cost " + m_bombingRaidTotal + " " + MyFormatter.pluralize("PU", m_bombingRaidTotal));
    }
    if (m_bombingRaidTotal > 0) {
        m_whoWon = WhoWon.ATTACKER;
        m_battleResultDescription = BattleRecord.BattleResultDescription.BOMBED;
    } else {
        m_whoWon = WhoWon.DEFENDER;
        m_battleResultDescription = BattleRecord.BattleResultDescription.LOST;
    }
    m_battleTracker.getBattleRecords().addResultToBattle(m_attacker, m_battleID, m_defender, m_attackerLostTUV, m_defenderLostTUV, m_battleResultDescription, new BattleResults(this, m_data));
    m_isOver = true;
    m_battleTracker.removeBattle(this);
}
Also used : BattleResults(games.strategy.triplea.oddsCalculator.ta.BattleResults)

Example 8 with BattleResults

use of games.strategy.triplea.oddsCalculator.ta.BattleResults in project triplea by triplea-game.

the class MustFightBattle method attackerWins.

private void attackerWins(final IDelegateBridge bridge) {
    m_whoWon = WhoWon.ATTACKER;
    getDisplay(bridge).battleEnd(m_battleID, m_attacker.getName() + " win");
    if (m_headless) {
        return;
    }
    // do we need to change ownership
    if (m_attackingUnits.stream().anyMatch(Matches.unitIsNotAir())) {
        if (Matches.isTerritoryEnemyAndNotUnownedWater(m_attacker, m_data).test(m_battleSite)) {
            m_battleTracker.addToConquered(m_battleSite);
        }
        m_battleTracker.takeOver(m_battleSite, m_attacker, bridge, null, m_attackingUnits);
        m_battleResultDescription = BattleRecord.BattleResultDescription.CONQUERED;
    } else {
        m_battleResultDescription = BattleRecord.BattleResultDescription.WON_WITHOUT_CONQUERING;
    }
    // Clear the transported_by for successfully off loaded units
    final Collection<Unit> transports = CollectionUtils.getMatches(m_attackingUnits, Matches.unitIsTransport());
    if (!transports.isEmpty()) {
        final CompositeChange change = new CompositeChange();
        final Collection<Unit> dependents = getTransportDependents(transports);
        if (!dependents.isEmpty()) {
            for (final Unit unit : dependents) {
                // clear the loaded by ONLY for Combat unloads. NonCombat unloads are handled elsewhere.
                if (Matches.unitWasUnloadedThisTurn().test(unit)) {
                    change.add(ChangeFactory.unitPropertyChange(unit, null, TripleAUnit.TRANSPORTED_BY));
                }
            }
            bridge.addChange(change);
        }
    }
    bridge.getHistoryWriter().addChildToEvent(m_attacker.getName() + " win", new ArrayList<>(m_attackingUnits));
    showCasualties(bridge);
    if (!m_headless) {
        m_battleTracker.getBattleRecords().addResultToBattle(m_attacker, m_battleID, m_defender, m_attackerLostTUV, m_defenderLostTUV, m_battleResultDescription, new BattleResults(this, m_data));
    }
    if (!m_headless) {
        if (Matches.territoryIsWater().test(m_battleSite)) {
            if (!m_attackingUnits.isEmpty() && m_attackingUnits.stream().allMatch(Matches.unitIsAir())) {
                bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_BATTLE_AIR_SUCCESSFUL, m_attacker);
            } else {
                bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_BATTLE_SEA_SUCCESSFUL, m_attacker);
            }
        } else {
            // have capture sounds for that
            if (!m_attackingUnits.isEmpty() && m_attackingUnits.stream().allMatch(Matches.unitIsAir())) {
                bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_BATTLE_AIR_SUCCESSFUL, m_attacker);
            }
        }
    }
}
Also used : BattleResults(games.strategy.triplea.oddsCalculator.ta.BattleResults) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 9 with BattleResults

use of games.strategy.triplea.oddsCalculator.ta.BattleResults in project triplea by triplea-game.

the class MustFightBattle method unitsLostInPrecedingBattle.

@Override
public void unitsLostInPrecedingBattle(final IBattle battle, final Collection<Unit> units, final IDelegateBridge bridge, final boolean withdrawn) {
    Collection<Unit> lost = getDependentUnits(units);
    lost.addAll(CollectionUtils.intersection(units, m_attackingUnits));
    // if all the amphibious attacking land units are lost, then we are no longer a naval invasion
    m_amphibiousLandAttackers.removeAll(lost);
    if (m_amphibiousLandAttackers.isEmpty()) {
        m_isAmphibious = false;
        m_bombardingUnits.clear();
    }
    m_attackingUnits.removeAll(lost);
    // now that they are definitely removed from our attacking list, make sure that they were not already removed from
    // the territory by the previous battle's remove method
    lost = CollectionUtils.getMatches(lost, Matches.unitIsInTerritory(m_battleSite));
    if (!withdrawn) {
        remove(lost, bridge, m_battleSite, false);
    }
    if (m_attackingUnits.isEmpty()) {
        final IntegerMap<UnitType> costs = TuvUtils.getCostsForTuv(m_attacker, m_data);
        final int tuvLostAttacker = (withdrawn ? 0 : TuvUtils.getTuv(lost, m_attacker, costs, m_data));
        m_attackerLostTUV += tuvLostAttacker;
        m_whoWon = WhoWon.DEFENDER;
        if (!m_headless) {
            m_battleTracker.getBattleRecords().addResultToBattle(m_attacker, m_battleID, m_defender, m_attackerLostTUV, m_defenderLostTUV, BattleRecord.BattleResultDescription.LOST, new BattleResults(this, m_data));
        }
        m_battleTracker.removeBattle(this);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) BattleResults(games.strategy.triplea.oddsCalculator.ta.BattleResults) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit)

Example 10 with BattleResults

use of games.strategy.triplea.oddsCalculator.ta.BattleResults in project triplea by triplea-game.

the class NonFightingBattle method fight.

@Override
public void fight(final IDelegateBridge bridge) {
    if (!m_battleTracker.getDependentOn(this).isEmpty()) {
        throw new IllegalStateException("Must fight battles that this battle depends on first");
    }
    // create event
    bridge.getHistoryWriter().startEvent("Battle in " + m_battleSite, m_battleSite);
    // if any attacking non air units then win
    final boolean someAttacking = hasAttackingUnits();
    if (someAttacking) {
        m_whoWon = WhoWon.ATTACKER;
        m_battleResultDescription = BattleRecord.BattleResultDescription.BLITZED;
        m_battleTracker.takeOver(m_battleSite, m_attacker, bridge, null, null);
        m_battleTracker.addToConquered(m_battleSite);
    } else {
        m_whoWon = WhoWon.DEFENDER;
        m_battleResultDescription = BattleRecord.BattleResultDescription.LOST;
    }
    m_battleTracker.getBattleRecords().addResultToBattle(m_attacker, m_battleID, m_defender, m_attackerLostTUV, m_defenderLostTUV, m_battleResultDescription, new BattleResults(this, m_data));
    end();
}
Also used : BattleResults(games.strategy.triplea.oddsCalculator.ta.BattleResults)

Aggregations

BattleResults (games.strategy.triplea.oddsCalculator.ta.BattleResults)12 Unit (games.strategy.engine.data.Unit)6 TripleAUnit (games.strategy.triplea.TripleAUnit)5 PlayerID (games.strategy.engine.data.PlayerID)3 CompositeChange (games.strategy.engine.data.CompositeChange)2 GameData (games.strategy.engine.data.GameData)2 Territory (games.strategy.engine.data.Territory)2 UnitType (games.strategy.engine.data.UnitType)2 ArrayList (java.util.ArrayList)2 Change (games.strategy.engine.data.Change)1 RelationshipTracker (games.strategy.engine.data.RelationshipTracker)1 Resource (games.strategy.engine.data.Resource)1 ResourceCollection (games.strategy.engine.data.ResourceCollection)1 RouteScripted (games.strategy.engine.data.RouteScripted)1 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)1 TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)1 ITripleAPlayer (games.strategy.triplea.player.ITripleAPlayer)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1