Search in sources :

Example 6 with GameParseException

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

the class TriggerAttachment method setTerritories.

private void setTerritories(final String names) throws GameParseException {
    final String[] s = names.split(":");
    for (final String element : s) {
        final Territory terr = getData().getMap().getTerritory(element);
        if (terr == null) {
            throw new GameParseException("Could not find territory. name:" + element + thisErrorMsg());
        }
        m_territories.add(terr);
    }
}
Also used : Territory(games.strategy.engine.data.Territory) GameParseException(games.strategy.engine.data.GameParseException)

Example 7 with GameParseException

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

the class TriggerAttachment method setFrontier.

private void setFrontier(final String s) throws GameParseException {
    if (s == null) {
        m_frontier = null;
        return;
    }
    final ProductionFrontier front = getData().getProductionFrontierList().getProductionFrontier(s);
    if (front == null) {
        throw new GameParseException("Could not find frontier. name:" + s + thisErrorMsg());
    }
    m_frontier = front;
}
Also used : GameParseException(games.strategy.engine.data.GameParseException) ProductionFrontier(games.strategy.engine.data.ProductionFrontier)

Example 8 with GameParseException

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

the class TriggerAttachment method setAvailableTech.

private void setAvailableTech(final String techs) throws GameParseException {
    if (techs == null) {
        m_availableTech = null;
        return;
    }
    final String[] s = techs.split(":");
    if (s.length < 2) {
        throw new GameParseException("Invalid tech availability: " + techs + " should be category:techs" + thisErrorMsg());
    }
    final String cat = s[0];
    final LinkedHashMap<TechAdvance, Boolean> tlist = new LinkedHashMap<>();
    for (int i = 1; i < s.length; i++) {
        boolean add = true;
        if (s[i].startsWith("-")) {
            add = false;
            s[i] = s[i].substring(1);
        }
        TechAdvance ta = getData().getTechnologyFrontier().getAdvanceByProperty(s[i]);
        if (ta == null) {
            ta = getData().getTechnologyFrontier().getAdvanceByName(s[i]);
        }
        if (ta == null) {
            throw new GameParseException("Technology not found :" + s[i] + thisErrorMsg());
        }
        tlist.put(ta, add);
    }
    if (m_availableTech == null) {
        m_availableTech = new HashMap<>();
    }
    if (m_availableTech.containsKey(cat)) {
        tlist.putAll(m_availableTech.get(cat));
    }
    m_availableTech.put(cat, tlist);
}
Also used : TechAdvance(games.strategy.triplea.delegate.TechAdvance) GameParseException(games.strategy.engine.data.GameParseException) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with GameParseException

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

the class TriggerAttachment method setActivateTrigger.

private void setActivateTrigger(final String value) throws GameParseException {
    // triggerName:numberOfTimes:useUses:testUses:testConditions:testChance
    final String[] s = value.split(":");
    if (s.length != 6) {
        throw new GameParseException("activateTrigger must have 6 parts: triggerName:numberOfTimes:useUses:testUses:testConditions:testChance" + thisErrorMsg());
    }
    TriggerAttachment trigger = null;
    for (final PlayerID player : getData().getPlayerList().getPlayers()) {
        for (final TriggerAttachment ta : getTriggers(player, null)) {
            if (ta.getName().equals(s[0])) {
                trigger = ta;
                break;
            }
        }
        if (trigger != null) {
            break;
        }
    }
    if (trigger == null) {
        throw new GameParseException("No TriggerAttachment named: " + s[0] + thisErrorMsg());
    }
    if (trigger == this) {
        throw new GameParseException("Cannot have a trigger activate itself!" + thisErrorMsg());
    }
    String options = value;
    options = options.replaceFirst((s[0] + ":"), "");
    final int numberOfTimes = getInt(s[1]);
    if (numberOfTimes < 0) {
        throw new GameParseException("activateTrigger must be positive for the number of times to fire: " + s[1] + thisErrorMsg());
    }
    getBool(s[2]);
    getBool(s[3]);
    getBool(s[4]);
    getBool(s[5]);
    m_activateTrigger.add(Tuple.of(s[0], options));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameParseException(games.strategy.engine.data.GameParseException)

Example 10 with GameParseException

use of games.strategy.engine.data.GameParseException 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)

Aggregations

GameParseException (games.strategy.engine.data.GameParseException)66 UnitType (games.strategy.engine.data.UnitType)29 PlayerID (games.strategy.engine.data.PlayerID)13 Territory (games.strategy.engine.data.Territory)7 Resource (games.strategy.engine.data.Resource)6 GameChooserEntry (games.strategy.engine.framework.ui.GameChooserEntry)3 TechAdvance (games.strategy.triplea.delegate.TechAdvance)3 IntegerMap (games.strategy.util.IntegerMap)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 EngineVersionException (games.strategy.engine.data.EngineVersionException)2 IOException (java.io.IOException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 GameMap (games.strategy.engine.data.GameMap)1 PlayerList (games.strategy.engine.data.PlayerList)1 ProductionFrontier (games.strategy.engine.data.ProductionFrontier)1 RelationshipType (games.strategy.engine.data.RelationshipType)1 ResourceCollection (games.strategy.engine.data.ResourceCollection)1 TerritoryEffect (games.strategy.engine.data.TerritoryEffect)1 InternalDoNotExport (games.strategy.engine.data.annotations.InternalDoNotExport)1