Search in sources :

Example 11 with GameParseException

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

the class TriggerAttachment method setPurchase.

private void setPurchase(final String place) throws GameParseException {
    if (place == null) {
        m_purchase = null;
        return;
    }
    final String[] s = place.split(":");
    if (s.length < 1) {
        throw new GameParseException("Empty purchase list" + thisErrorMsg());
    }
    int count;
    int i = 0;
    try {
        count = getInt(s[0]);
        i++;
    } catch (final Exception e) {
        count = 1;
    }
    if (s.length < 1 || (s.length == 1 && count != -1)) {
        throw new GameParseException("Empty purchase list" + thisErrorMsg());
    }
    if (m_purchase == null) {
        m_purchase = new IntegerMap<>();
    }
    for (; i < s.length; i++) {
        final UnitType type = getData().getUnitTypeList().getUnitType(s[i]);
        if (type == null) {
            throw new GameParseException("UnitType does not exist " + s[i] + thisErrorMsg());
        }
        m_purchase.add(type, count);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException) GameParseException(games.strategy.engine.data.GameParseException)

Example 12 with GameParseException

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

the class UnitAttachment method setCreatesUnitsList.

private void setCreatesUnitsList(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length <= 0 || s.length > 2) {
        throw new GameParseException("createsUnitsList cannot be empty or have more than two fields" + thisErrorMsg());
    }
    final String unitTypeToProduce = s[1];
    // validate that this unit exists in the xml
    final UnitType ut = getData().getUnitTypeList().getUnitType(unitTypeToProduce);
    if (ut == null) {
        throw new GameParseException("createsUnitsList: No unit called:" + unitTypeToProduce + thisErrorMsg());
    }
    final int n = getInt(s[0]);
    if (n < 1) {
        throw new GameParseException("createsUnitsList must have positive values" + thisErrorMsg());
    }
    m_createsUnitsList.put(ut, n);
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 13 with GameParseException

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

the class UnitAttachment method setDestroyedWhenCapturedBy.

private void setDestroyedWhenCapturedBy(String value) throws GameParseException {
    // We can prefix this value with "BY" or "FROM" to change the setting. If no setting, default to "BY" since this
    // this is called by
    // destroyedWhenCapturedBy
    String byOrFrom = "BY";
    if (value.startsWith("BY:") && getData().getPlayerList().getPlayerId("BY") == null) {
        byOrFrom = "BY";
        value = value.replaceFirst("BY:", "");
    } else if (value.startsWith("FROM:") && getData().getPlayerList().getPlayerId("FROM") == null) {
        byOrFrom = "FROM";
        value = value.replaceFirst("FROM:", "");
    }
    final String[] temp = value.split(":");
    for (final String name : temp) {
        final PlayerID tempPlayer = getData().getPlayerList().getPlayerId(name);
        if (tempPlayer != null) {
            m_destroyedWhenCapturedBy.add(Tuple.of(byOrFrom, tempPlayer));
        } else {
            throw new GameParseException("No player named: " + name + thisErrorMsg());
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameParseException(games.strategy.engine.data.GameParseException)

Example 14 with GameParseException

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

the class UnitAttachment method setCreatesResourcesList.

private void setCreatesResourcesList(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length <= 0 || s.length > 2) {
        throw new GameParseException("createsResourcesList cannot be empty or have more than two fields" + thisErrorMsg());
    }
    final String resourceToProduce = s[1];
    // validate that this resource exists in the xml
    final Resource r = getData().getResourceList().getResource(resourceToProduce);
    if (r == null) {
        throw new GameParseException("createsResourcesList: No resource called:" + resourceToProduce + thisErrorMsg());
    }
    final int n = getInt(s[0]);
    m_createsResourcesList.put(r, n);
}
Also used : Resource(games.strategy.engine.data.Resource) GameParseException(games.strategy.engine.data.GameParseException)

Example 15 with GameParseException

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

the class UnitAttachment method setTargetsAa.

private void setTargetsAa(final String value) throws GameParseException {
    if (value == null) {
        m_targetsAA = null;
        return;
    }
    if (m_targetsAA == null) {
        m_targetsAA = new HashSet<>();
    }
    final String[] s = value.split(":");
    for (final String u : s) {
        final UnitType ut = getData().getUnitTypeList().getUnitType(u);
        if (ut == null) {
            throw new GameParseException("AAtargets: no such unit type: " + u + thisErrorMsg());
        }
        m_targetsAA.add(ut);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) 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