Search in sources :

Example 16 with GameParseException

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

the class UnitAttachment method setFuelFlatCost.

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

Example 17 with GameParseException

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

the class UnitAttachment method setAttackingLimit.

private void setAttackingLimit(final String value) throws GameParseException {
    if (value == null) {
        m_attackingLimit = 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("attackingLimit must have 2 fields, value and count" + thisErrorMsg());
    }
    final int max = getInt(s[0]);
    if (max < 0) {
        throw new GameParseException("attackingLimit count must have a positive number" + thisErrorMsg());
    }
    if (!(s[1].equals("owned") || s[1].equals("allied") || s[1].equals("total"))) {
        throw new GameParseException("attackingLimit value must owned, allied, or total" + thisErrorMsg());
    }
    m_attackingLimit = Tuple.of(max, s[1]);
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 18 with GameParseException

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

the class UserActionAttachment 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 : TriggerAttachment.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());
    }
    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 19 with GameParseException

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

the class AbstractConditionsAttachment method setChance.

protected void setChance(final String chance) throws GameParseException {
    final String[] s = chance.split(":");
    try {
        final int i = getInt(s[0]);
        final int j = getInt(s[1]);
        if (i > j || i < 0 || j < 0 || i > 120 || j > 120) {
            throw new GameParseException("chance should have a format of \"x:y\" where x is <= y and both x and y are >=0 and <=120" + thisErrorMsg());
        }
    } catch (final IllegalArgumentException iae) {
        throw new GameParseException("Invalid chance declaration: " + chance + " format: \"1:10\" for 10% chance" + thisErrorMsg());
    }
    m_chance = chance;
}
Also used : GameParseException(games.strategy.engine.data.GameParseException)

Example 20 with GameParseException

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

the class AbstractPlayerRulesAttachment method setProductionPerXTerritories.

private void setProductionPerXTerritories(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length <= 0 || s.length > 2) {
        throw new GameParseException("productionPerXTerritories cannot be empty or have more than two fields" + thisErrorMsg());
    }
    final String unitTypeToProduce;
    if (s.length == 1) {
        unitTypeToProduce = Constants.UNIT_TYPE_INFANTRY;
    } else {
        unitTypeToProduce = s[1];
    }
    // validate that this unit exists in the xml
    final UnitType ut = getData().getUnitTypeList().getUnitType(unitTypeToProduce);
    if (ut == null) {
        throw new GameParseException("No unit called: " + unitTypeToProduce + thisErrorMsg());
    }
    final int n = getInt(s[0]);
    if (n <= 0) {
        throw new GameParseException("productionPerXTerritories must be a positive integer" + thisErrorMsg());
    }
    m_productionPerXTerritories.put(ut, n);
}
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