Search in sources :

Example 1 with TerritoryEffect

use of games.strategy.engine.data.TerritoryEffect in project triplea by triplea-game.

the class TriggerAttachment method setTerritoryEffects.

private void setTerritoryEffects(final String names) throws GameParseException {
    final String[] s = names.split(":");
    for (final String element : s) {
        final TerritoryEffect effect = getData().getTerritoryEffectList().get(element);
        if (effect == null) {
            throw new GameParseException("Could not find territoryEffect. name:" + element + thisErrorMsg());
        }
        m_territoryEffects.add(effect);
    }
}
Also used : TerritoryEffect(games.strategy.engine.data.TerritoryEffect) GameParseException(games.strategy.engine.data.GameParseException)

Example 2 with TerritoryEffect

use of games.strategy.engine.data.TerritoryEffect in project triplea by triplea-game.

the class PacificTest method testJapanAttackFirstRound.

@Test
public void testJapanAttackFirstRound() {
    bridge.setStepName("japaneseBattle");
    while (!gameData.getSequence().getStep().getName().equals("japaneseBattle")) {
        gameData.getSequence().next();
    }
    // >>> After patch normal to-hits will miss <<<
    // Defending US infantry miss on a 2 (0 base)
    final List<Unit> infantryUs = infantry.create(1, americans);
    final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(queensland);
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    DiceRoll roll = DiceRoll.rollDice(infantryUs, true, americans, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(0, roll.getHits());
    // Defending US marines miss on a 2 (0 base)
    final List<Unit> marineUs = marine.create(1, americans);
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    roll = DiceRoll.rollDice(marineUs, true, americans, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(0, roll.getHits());
    // Chinese units
    // Defending Chinese infantry still hit on a 2 (0 base)
    final List<Unit> infantryChina = infantry.create(1, chinese);
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    roll = DiceRoll.rollDice(infantryChina, true, chinese, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(1, roll.getHits());
    // Defending US infantry hit on a 1 (0 base)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0 }));
    roll = DiceRoll.rollDice(infantryUs, true, americans, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(1, roll.getHits());
    // Defending US marines hit on a 1 (0 base)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0 }));
    roll = DiceRoll.rollDice(marineUs, true, americans, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(1, roll.getHits());
    // Chinese units
    // Defending Chinese infantry still hit on a 2 (0 base)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    roll = DiceRoll.rollDice(infantryChina, true, chinese, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(1, roll.getHits());
}
Also used : TerritoryEffect(games.strategy.engine.data.TerritoryEffect) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Example 3 with TerritoryEffect

use of games.strategy.engine.data.TerritoryEffect in project triplea by triplea-game.

the class DiceRollTest method testSimple.

@Test
public void testSimple() {
    final Territory westRussia = gameData.getMap().getTerritory("West Russia");
    final MockBattle battle = new MockBattle(westRussia);
    final PlayerID russians = GameDataTestUtil.russians(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(russians);
    final UnitType infantryType = GameDataTestUtil.infantry(gameData);
    final List<Unit> infantry = infantryType.create(1, russians);
    final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(westRussia);
    // infantry defends and hits at 1 (0 based)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    final DiceRoll roll = DiceRoll.rollDice(infantry, true, russians, bridge, battle, "", territoryEffects, null);
    assertThat(roll.getHits(), is(1));
    // infantry does not hit at 2 (0 based)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 2 }));
    final DiceRoll roll2 = DiceRoll.rollDice(infantry, true, russians, bridge, battle, "", territoryEffects, null);
    assertThat(roll2.getHits(), is(0));
    // infantry attacks and hits at 0 (0 based)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0 }));
    final DiceRoll roll3 = DiceRoll.rollDice(infantry, false, russians, bridge, battle, "", territoryEffects, null);
    assertThat(roll3.getHits(), is(1));
    // infantry attack does not hit at 1 (0 based)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    final DiceRoll roll4 = DiceRoll.rollDice(infantry, false, russians, bridge, battle, "", territoryEffects, null);
    assertThat(roll4.getHits(), is(0));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) TerritoryEffect(games.strategy.engine.data.TerritoryEffect) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Test(org.junit.jupiter.api.Test)

Example 4 with TerritoryEffect

use of games.strategy.engine.data.TerritoryEffect in project triplea by triplea-game.

the class DiceRollTest method testDiceRollCount.

@Test
public void testDiceRollCount() {
    final PlayerID british = GameDataTestUtil.british(gameData);
    final Territory location = gameData.getMap().getTerritory("United Kingdom");
    final Unit bombers = gameData.getMap().getTerritory("United Kingdom").getUnits().getMatches(Matches.unitIsStrategicBomber()).get(0);
    final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(location);
    // default 1 roll
    assertThat(BattleCalculator.getRolls(bombers, british, false, true, territoryEffects), is(1));
    assertThat(BattleCalculator.getRolls(bombers, british, true, true, territoryEffects), is(1));
    // hb, for revised 2 on attack, 1 on defence
    final ITestDelegateBridge testDelegateBridge = getDelegateBridge(british);
    TechTracker.addAdvance(british, testDelegateBridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER, gameData, british));
    // lhtr hb, 2 for both
    gameData.getProperties().set(Constants.LHTR_HEAVY_BOMBERS, Boolean.TRUE);
    assertThat(BattleCalculator.getRolls(bombers, british, false, true, territoryEffects), is(2));
    assertThat(BattleCalculator.getRolls(bombers, british, true, true, territoryEffects), is(2));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) TerritoryEffect(games.strategy.engine.data.TerritoryEffect) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Test(org.junit.jupiter.api.Test)

Example 5 with TerritoryEffect

use of games.strategy.engine.data.TerritoryEffect in project triplea by triplea-game.

the class OddsCalculatorPanel method setWidgetActivation.

private void setWidgetActivation() {
    keepOneAttackingLandUnitCheckBox.setEnabled(landBattleCheckBox.isSelected());
    amphibiousCheckBox.setEnabled(landBattleCheckBox.isSelected());
    final boolean isLand = isLand();
    try {
        data.acquireReadLock();
        // do not include bombardment and aa guns in our "total" labels
        final List<Unit> attackers = CollectionUtils.getMatches(attackingUnitsPanel.getUnits(), Matches.unitCanBeInBattle(true, isLand, 1, false, true, true));
        final List<Unit> defenders = CollectionUtils.getMatches(defendingUnitsPanel.getUnits(), Matches.unitCanBeInBattle(false, isLand, 1, false, true, true));
        attackerUnitsTotalNumber.setText("Units: " + attackers.size());
        defenderUnitsTotalNumber.setText("Units: " + defenders.size());
        attackerUnitsTotalTuv.setText("TUV: " + TuvUtils.getTuv(attackers, getAttacker(), TuvUtils.getCostsForTuv(getAttacker(), data), data));
        defenderUnitsTotalTuv.setText("TUV: " + TuvUtils.getTuv(defenders, getDefender(), TuvUtils.getCostsForTuv(getDefender(), data), data));
        final int attackHitPoints = BattleCalculator.getTotalHitpointsLeft(attackers);
        final int defenseHitPoints = BattleCalculator.getTotalHitpointsLeft(defenders);
        attackerUnitsTotalHitpoints.setText("HP: " + attackHitPoints);
        defenderUnitsTotalHitpoints.setText("HP: " + defenseHitPoints);
        final boolean isAmphibiousBattle = isAmphibiousBattle();
        final Collection<TerritoryEffect> territoryEffects = getTerritoryEffects();
        final IntegerMap<UnitType> costs = TuvUtils.getCostsForTuv(getAttacker(), data);
        attackers.sort(new UnitBattleComparator(false, costs, territoryEffects, data, false, false));
        Collections.reverse(attackers);
        final int attackPower = DiceRoll.getTotalPower(DiceRoll.getUnitPowerAndRollsForNormalBattles(attackers, defenders, false, false, data, location, territoryEffects, isAmphibiousBattle, (isAmphibiousBattle ? attackers : new ArrayList<>())), data);
        // defender is never amphibious
        final int defensePower = DiceRoll.getTotalPower(DiceRoll.getUnitPowerAndRollsForNormalBattles(defenders, attackers, true, false, data, location, territoryEffects, isAmphibiousBattle, new ArrayList<>()), data);
        attackerUnitsTotalPower.setText("Power: " + attackPower);
        defenderUnitsTotalPower.setText("Power: " + defensePower);
    } finally {
        data.releaseReadLock();
    }
}
Also used : UnitBattleComparator(games.strategy.triplea.delegate.UnitBattleComparator) TerritoryEffect(games.strategy.engine.data.TerritoryEffect) UnitType(games.strategy.engine.data.UnitType) ArrayList(java.util.ArrayList) Unit(games.strategy.engine.data.Unit)

Aggregations

TerritoryEffect (games.strategy.engine.data.TerritoryEffect)11 Unit (games.strategy.engine.data.Unit)7 Test (org.junit.jupiter.api.Test)6 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)5 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)4 PlayerID (games.strategy.engine.data.PlayerID)4 Territory (games.strategy.engine.data.Territory)4 UnitType (games.strategy.engine.data.UnitType)4 TripleAUnit (games.strategy.triplea.TripleAUnit)4 ArrayList (java.util.ArrayList)2 CompositeChange (games.strategy.engine.data.CompositeChange)1 GameParseException (games.strategy.engine.data.GameParseException)1 UnitBattleComparator (games.strategy.triplea.delegate.UnitBattleComparator)1 CasualtyList (games.strategy.triplea.delegate.dataObjects.CasualtyList)1 TerritoryEffectDrawable (games.strategy.triplea.ui.screen.drawable.TerritoryEffectDrawable)1 Point (java.awt.Point)1 List (java.util.List)1