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);
}
}
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());
}
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));
}
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));
}
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();
}
}
Aggregations