Search in sources :

Example 51 with GameParseException

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

the class UnitAttachment method setFuelCost.

private void setFuelCost(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length != 2) {
        throw new GameParseException("fuelCost must have 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("fuelCost: No resource called:" + resourceToProduce + thisErrorMsg());
    }
    final int n = getInt(s[0]);
    if (n < 0) {
        throw new GameParseException("fuelCost must have positive values" + thisErrorMsg());
    }
    m_fuelCost.put(r, n);
}
Also used : Resource(games.strategy.engine.data.Resource) GameParseException(games.strategy.engine.data.GameParseException)

Example 52 with GameParseException

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

the class UnitAttachment method setRepairsUnits.

private void setRepairsUnits(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length <= 0) {
        throw new GameParseException("repairsUnits cannot be empty" + thisErrorMsg());
    }
    int i = 0;
    int amount;
    try {
        amount = Integer.parseInt(s[0]);
        i++;
    } catch (final NumberFormatException nfe) {
        amount = 1;
    }
    for (; i < s.length; i++) {
        final UnitType ut = getData().getUnitTypeList().getUnitType(s[i]);
        if (ut == null) {
            throw new GameParseException("No unit called:" + s[i] + thisErrorMsg());
        }
        m_repairsUnits.put(ut, amount);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 53 with GameParseException

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

the class UnitAttachment method setPlacementLimit.

private void setPlacementLimit(final String value) throws GameParseException {
    if (value == null) {
        m_placementLimit = null;
        return;
    }
    final UnitType ut = (UnitType) this.getAttachedTo();
    if (ut == null) {
        throw new GameParseException("getAttachedTo returned null" + thisErrorMsg());
    }
    final String[] s = value.split(":");
    if (s.length != 2) {
        throw new GameParseException("placementLimit must have 2 fields, value and count" + thisErrorMsg());
    }
    final int max = getInt(s[0]);
    if (max < 0) {
        throw new GameParseException("placementLimit count must have a positive number" + thisErrorMsg());
    }
    if (!(s[1].equals("owned") || s[1].equals("allied") || s[1].equals("total"))) {
        throw new GameParseException("placementLimit value must owned, allied, or total" + thisErrorMsg());
    }
    m_placementLimit = Tuple.of(max, s[1]);
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 54 with GameParseException

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

the class AbstractRulesAttachment method setRounds.

private void setRounds(final String rounds) throws GameParseException {
    if (rounds == null) {
        m_turns = null;
        return;
    }
    m_turns = new HashMap<>();
    final String[] s = rounds.split(":");
    if (s.length < 1) {
        throw new GameParseException("Empty turn list" + thisErrorMsg());
    }
    for (final String subString : s) {
        int start;
        int end;
        try {
            start = getInt(subString);
            end = start;
        } catch (final Exception e) {
            final String[] s2 = subString.split("-");
            if (s2.length != 2) {
                throw new GameParseException("Invalid syntax for turn range, must be 'int-int'" + thisErrorMsg());
            }
            start = getInt(s2[0]);
            if (s2[1].equals("+")) {
                end = Integer.MAX_VALUE;
            } else {
                end = getInt(s2[1]);
            }
        }
        m_turns.put(start, end);
    }
}
Also used : GameParseException(games.strategy.engine.data.GameParseException) GameParseException(games.strategy.engine.data.GameParseException)

Example 55 with GameParseException

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

the class AbstractRulesAttachment method setPlayers.

private void setPlayers(final String names) throws GameParseException {
    final PlayerList pl = getData().getPlayerList();
    for (final String p : names.split(":")) {
        final PlayerID player = pl.getPlayerId(p);
        if (player == null) {
            throw new GameParseException("Could not find player. name:" + p + thisErrorMsg());
        }
        m_players.add(player);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) PlayerList(games.strategy.engine.data.PlayerList) 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