Search in sources :

Example 6 with TerritoryEffect

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

the class TileManager method drawTerritoryEffects.

private static void drawTerritoryEffects(final Territory territory, final MapData mapData, final Set<IDrawable> drawing) {
    final Iterator<Point> effectPoints = mapData.getTerritoryEffectPoints(territory).iterator();
    Point drawingPoint = effectPoints.next();
    for (final TerritoryEffect te : TerritoryEffectHelper.getEffects(territory)) {
        drawing.add(new TerritoryEffectDrawable(te, drawingPoint));
        drawingPoint = effectPoints.hasNext() ? effectPoints.next() : drawingPoint;
    }
}
Also used : TerritoryEffect(games.strategy.engine.data.TerritoryEffect) TerritoryEffectDrawable(games.strategy.triplea.ui.screen.drawable.TerritoryEffectDrawable) Point(java.awt.Point)

Example 7 with TerritoryEffect

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

the class GameDataExporter method territoryEffectList.

private void territoryEffectList(final GameData data) {
    final Collection<TerritoryEffect> types = data.getTerritoryEffectList().values();
    if (types.isEmpty()) {
        return;
    }
    xmlfile.append("\n");
    xmlfile.append("    <territoryEffectList>\n");
    for (final TerritoryEffect current : types) {
        xmlfile.append("        <territoryEffect name=\"").append(current.getName()).append("\"/>\n");
    }
    xmlfile.append("    </territoryEffectList>\n");
}
Also used : TerritoryEffect(games.strategy.engine.data.TerritoryEffect)

Example 8 with TerritoryEffect

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

the class TriggerAttachment method triggerTerritoryEffectPropertyChange.

public static void triggerTerritoryEffectPropertyChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
    Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, territoryEffectPropertyMatch());
    if (testWhen) {
        trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
    }
    if (testUses) {
        trigs = CollectionUtils.getMatches(trigs, availableUses);
    }
    final CompositeChange change = new CompositeChange();
    for (final TriggerAttachment t : trigs) {
        if (testChance && !t.testChance(bridge)) {
            continue;
        }
        if (useUses) {
            t.use(bridge);
        }
        for (final Tuple<String, String> property : t.getTerritoryEffectProperty()) {
            for (final TerritoryEffect territoryEffect : t.getTerritoryEffects()) {
                String newValue = property.getSecond();
                boolean clearFirst = false;
                // test if we are resetting the variable first, and if so, remove the leading "-reset-" or "-clear-"
                if (newValue.length() > 0 && (newValue.startsWith(PREFIX_CLEAR) || newValue.startsWith(PREFIX_RESET))) {
                    newValue = newValue.replaceFirst(PREFIX_CLEAR, "").replaceFirst(PREFIX_RESET, "");
                    clearFirst = true;
                }
                // covers TerritoryEffectAttachment
                if (t.getTerritoryEffectAttachmentName().getFirst().equals("TerritoryEffectAttachment")) {
                    final TerritoryEffectAttachment attachment = TerritoryEffectAttachment.get(territoryEffect, t.getTerritoryEffectAttachmentName().getSecond());
                    if (newValue.equals(attachment.getRawPropertyString(property.getFirst()))) {
                        continue;
                    }
                    if (clearFirst && newValue.length() < 1) {
                        change.add(ChangeFactory.attachmentPropertyReset(attachment, property.getFirst()));
                    } else {
                        change.add(ChangeFactory.attachmentPropertyChange(attachment, newValue, property.getFirst(), clearFirst));
                    }
                    bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Setting " + property.getFirst() + (newValue.length() > 0 ? " to " + newValue : " cleared ") + " for " + t.getTerritoryEffectAttachmentName().getSecond() + " attached to " + territoryEffect.getName());
                }
            // TODO add other attachment changes here if they attach to a territory
            }
        }
    }
    if (!change.isEmpty()) {
        bridge.addChange(change);
    }
}
Also used : TerritoryEffect(games.strategy.engine.data.TerritoryEffect) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 9 with TerritoryEffect

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

the class PacificTest method testNonJapanAttack.

@Test
public void testNonJapanAttack() {
    // this will get us to round 2
    bridge.setStepName("japaneseEndTurn");
    bridge.setStepName("japaneseBattle");
    // Defending US infantry hit 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(1, roll.getHits());
    // Defending US marines hit 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(1, roll.getHits());
    // Chinese units
    // Defending Chinese infantry 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());
}
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 10 with TerritoryEffect

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

the class WW2V3Year41Test method testJetPower.

@Test
public void testJetPower() {
    // Set up tech
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final ITestDelegateBridge delegateBridge = getDelegateBridge(germans(gameData));
    TechTracker.addAdvance(germans, delegateBridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_JET_POWER, gameData, germans));
    // Set up the territories
    final Territory poland = territory("Poland", gameData);
    final Territory eastPoland = territory("East Poland", gameData);
    // Set up the unit types
    final UnitType fighterType = GameDataTestUtil.fighter(gameData);
    delegateBridge.setStepName("germanBattle");
    while (!gameData.getSequence().getStep().getName().equals("germanBattle")) {
        gameData.getSequence().next();
    }
    final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(eastPoland);
    // With JET_POWER attacking fighter hits on 4 (0 base)
    final List<Unit> germanFighter = (List<Unit>) poland.getUnits().getUnits(fighterType, 1);
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 3 }));
    final DiceRoll roll1 = DiceRoll.rollDice(germanFighter, false, germans, delegateBridge, new MockBattle(eastPoland), "", territoryEffects, null);
    assertEquals(1, roll1.getHits());
    // With JET_POWER defending fighter misses on 5 (0 base)
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 4 }));
    final DiceRoll roll2 = DiceRoll.rollDice(germanFighter, true, germans, delegateBridge, new MockBattle(eastPoland), "", territoryEffects, null);
    assertEquals(0, roll2.getHits());
}
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) List(java.util.List) ArrayList(java.util.ArrayList) CasualtyList(games.strategy.triplea.delegate.dataObjects.CasualtyList) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

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