Search in sources :

Example 21 with GameParseException

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

the class PlayerAttachment method setPlacementLimit.

private void setPlacementLimit(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length < 3) {
        throw new GameParseException("placementLimit must have 3 parts: count, type, unit list" + 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 type must be: owned, allied, or total" + thisErrorMsg());
    }
    final HashSet<UnitType> types = new HashSet<>();
    if (s[2].equalsIgnoreCase("all")) {
        types.addAll(getData().getUnitTypeList().getAllUnitTypes());
    } else {
        for (int i = 2; i < s.length; i++) {
            final UnitType ut = getData().getUnitTypeList().getUnitType(s[i]);
            if (ut == null) {
                throw new GameParseException("No unit called: " + s[i] + thisErrorMsg());
            }
            types.add(ut);
        }
    }
    m_placementLimit.add(Triple.of(max, s[1], types));
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException) HashSet(java.util.HashSet)

Example 22 with GameParseException

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

the class PlayerAttachment method setMovementLimit.

private void setMovementLimit(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length < 3) {
        throw new GameParseException("movementLimit must have 3 parts: count, type, unit list" + thisErrorMsg());
    }
    final int max = getInt(s[0]);
    if (max < 0) {
        throw new GameParseException("movementLimit count must have a positive number" + thisErrorMsg());
    }
    if (!(s[1].equals("owned") || s[1].equals("allied") || s[1].equals("total"))) {
        throw new GameParseException("movementLimit type must be: owned, allied, or total" + thisErrorMsg());
    }
    final HashSet<UnitType> types = new HashSet<>();
    if (s[2].equalsIgnoreCase("all")) {
        types.addAll(getData().getUnitTypeList().getAllUnitTypes());
    } else {
        for (int i = 2; i < s.length; i++) {
            final UnitType ut = getData().getUnitTypeList().getUnitType(s[i]);
            if (ut == null) {
                throw new GameParseException("No unit called: " + s[i] + thisErrorMsg());
            }
            types.add(ut);
        }
    }
    m_movementLimit.add(Triple.of(max, s[1], types));
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException) HashSet(java.util.HashSet)

Example 23 with GameParseException

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

the class PlayerAttachment method setSuicideAttackResources.

private void setSuicideAttackResources(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length != 2) {
        throw new GameParseException("suicideAttackResources must have exactly 2 fields" + thisErrorMsg());
    }
    final int attackValue = getInt(s[0]);
    if (attackValue < 0) {
        throw new GameParseException("suicideAttackResources attack value must be positive" + thisErrorMsg());
    }
    final Resource r = getData().getResourceList().getResource(s[1]);
    if (r == null) {
        throw new GameParseException("no such resource: " + s[1] + thisErrorMsg());
    }
    m_suicideAttackResources.put(r, attackValue);
}
Also used : Resource(games.strategy.engine.data.Resource) GameParseException(games.strategy.engine.data.GameParseException)

Example 24 with GameParseException

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

the class RelationshipTypeAttachment method setUpkeepCost.

private void setUpkeepCost(final String integerCost) throws GameParseException {
    if (integerCost.equals(PROPERTY_DEFAULT)) {
        m_upkeepCost = PROPERTY_DEFAULT;
    } else {
        final String[] s = integerCost.split(":");
        if (s.length < 1 || s.length > 2) {
            throw new GameParseException("upkeepCost must have either 1 or 2 fields" + thisErrorMsg());
        }
        final int cost = getInt(s[0]);
        if (s.length == 2) {
            if (s[1].equals(UPKEEP_FLAT)) {
            // do nothing
            } else if (s[1].equals(UPKEEP_PERCENTAGE)) {
                if (cost > 100) {
                    throw new GameParseException("upkeepCost may not have a percentage greater than 100" + thisErrorMsg());
                }
            } else {
                throw new GameParseException("upkeepCost must have either: " + UPKEEP_FLAT + " or " + UPKEEP_PERCENTAGE + thisErrorMsg());
            }
        }
        m_upkeepCost = integerCost;
    }
}
Also used : GameParseException(games.strategy.engine.data.GameParseException)

Example 25 with GameParseException

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

the class RulesAttachment method setAtWarPlayers.

private void setAtWarPlayers(final String players) throws GameParseException {
    if (players == null) {
        m_atWarPlayers = null;
        return;
    }
    final String[] s = players.split(":");
    if (s.length < 1) {
        throw new GameParseException("Empty enemy list" + thisErrorMsg());
    }
    int count = -1;
    try {
        count = getInt(s[0]);
        m_atWarCount = count;
    } catch (final Exception e) {
        m_atWarCount = 0;
    }
    if (s.length < 1 || (s.length == 1 && count != -1)) {
        throw new GameParseException("Empty enemy list" + thisErrorMsg());
    }
    m_atWarPlayers = new HashSet<>();
    for (int i = count == -1 ? 0 : 1; i < s.length; i++) {
        final PlayerID player = getData().getPlayerList().getPlayerId(s[i]);
        if (player == null) {
            throw new GameParseException("Could not find player. name:" + s[i] + thisErrorMsg());
        }
        m_atWarPlayers.add(player);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameParseException(games.strategy.engine.data.GameParseException) 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