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