Search in sources :

Example 31 with GameParseException

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

the class TerritoryAttachment method setResources.

private void setResources(final String value) throws GameParseException {
    if (value == null) {
        m_resources = null;
        return;
    }
    if (m_resources == null) {
        m_resources = new ResourceCollection(getData());
    }
    final String[] s = value.split(":");
    final int amount = getInt(s[0]);
    if (s[1].equals(Constants.PUS)) {
        throw new GameParseException("Please set PUs using production, not resource" + thisErrorMsg());
    }
    final Resource resource = getData().getResourceList().getResource(s[1]);
    if (resource == null) {
        throw new GameParseException("No resource named: " + s[1] + thisErrorMsg());
    }
    m_resources.putResource(resource, amount);
}
Also used : Resource(games.strategy.engine.data.Resource) GameParseException(games.strategy.engine.data.GameParseException) ResourceCollection(games.strategy.engine.data.ResourceCollection)

Example 32 with GameParseException

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

the class TerritoryAttachment method setWhenCapturedByGoesTo.

private void setWhenCapturedByGoesTo(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length != 2) {
        throw new GameParseException("whenCapturedByGoesTo must have 2 player names separated by a colon" + thisErrorMsg());
    }
    for (final String name : s) {
        final PlayerID player = getData().getPlayerList().getPlayerId(name);
        if (player == null) {
            throw new GameParseException("No player named: " + name + thisErrorMsg());
        }
    }
    m_whenCapturedByGoesTo.add(value);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameParseException(games.strategy.engine.data.GameParseException)

Example 33 with GameParseException

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

the class TerritoryAttachment method setConvoyAttached.

private void setConvoyAttached(final String value) throws GameParseException {
    if (value.length() <= 0) {
        return;
    }
    for (final String subString : value.split(":")) {
        final Territory territory = getData().getMap().getTerritory(subString);
        if (territory == null) {
            throw new GameParseException("No territory called:" + subString + thisErrorMsg());
        }
        m_convoyAttached.add(territory);
    }
}
Also used : Territory(games.strategy.engine.data.Territory) GameParseException(games.strategy.engine.data.GameParseException)

Example 34 with GameParseException

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

the class TriggerAttachment method setRelationshipTypes.

private void setRelationshipTypes(final String names) throws GameParseException {
    final String[] s = names.split(":");
    for (final String element : s) {
        final RelationshipType relation = getData().getRelationshipTypeList().getRelationshipType(element);
        if (relation == null) {
            throw new GameParseException("Could not find relationshipType. name:" + element + thisErrorMsg());
        }
        m_relationshipTypes.add(relation);
    }
}
Also used : RelationshipType(games.strategy.engine.data.RelationshipType) GameParseException(games.strategy.engine.data.GameParseException)

Example 35 with GameParseException

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

the class TriggerAttachment method setPlacement.

/**
 * Fudging this, it really represents adding placements.
 */
private void setPlacement(final String place) throws GameParseException {
    if (place == null) {
        m_placement = null;
        return;
    }
    final String[] s = place.split(":");
    if (s.length < 1) {
        throw new GameParseException("Empty placement 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 placement list" + thisErrorMsg());
    }
    final Territory territory = getData().getMap().getTerritory(s[i]);
    if (territory == null) {
        throw new GameParseException("Territory does not exist " + s[i] + thisErrorMsg());
    }
    i++;
    final IntegerMap<UnitType> map = 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());
        }
        map.add(type, count);
    }
    if (m_placement == null) {
        m_placement = new HashMap<>();
    }
    if (m_placement.containsKey(territory)) {
        map.add(m_placement.get(territory));
    }
    m_placement.put(territory, map);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) 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