Search in sources :

Example 1 with GameParseException

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

the class TerritoryAttachment method setOriginalOwner.

private void setOriginalOwner(final String player) throws GameParseException {
    if (player == null) {
        m_originalOwner = null;
    }
    final PlayerID tempPlayer = getData().getPlayerList().getPlayerId(player);
    if (tempPlayer == null) {
        throw new GameParseException("No player named: " + player + thisErrorMsg());
    }
    m_originalOwner = tempPlayer;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameParseException(games.strategy.engine.data.GameParseException)

Example 2 with GameParseException

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

the class TerritoryEffectAttachment method setUnitsNotAllowed.

private void setUnitsNotAllowed(final String unitsNotAllowedUnitTypes) throws GameParseException {
    final String[] s = unitsNotAllowedUnitTypes.split(":");
    if (s.length < 1) {
        throw new GameParseException("unitsNotAllowed must have at least one unitType" + thisErrorMsg());
    }
    for (final String unitTypeName : s) {
        final UnitType ut = getData().getUnitTypeList().getUnitType(unitTypeName);
        if (ut == null) {
            throw new GameParseException("No unit called:" + unitTypeName + thisErrorMsg());
        }
        m_unitsNotAllowed.add(ut);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 3 with GameParseException

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

the class TerritoryEffectAttachment method setCombatEffect.

@InternalDoNotExport
private void setCombatEffect(final String combatEffect, final boolean defending) throws GameParseException {
    final String[] s = combatEffect.split(":");
    if (s.length < 2) {
        throw new GameParseException("combatDefenseEffect and combatOffenseEffect must have a count and at least one unitType" + thisErrorMsg());
    }
    final Iterator<String> iter = Arrays.asList(s).iterator();
    final int effect = getInt(iter.next());
    while (iter.hasNext()) {
        final String unitTypeToProduce = iter.next();
        final UnitType ut = getData().getUnitTypeList().getUnitType(unitTypeToProduce);
        if (ut == null) {
            throw new GameParseException("No unit called:" + unitTypeToProduce + thisErrorMsg());
        }
        if (defending) {
            m_combatDefenseEffect.put(ut, effect);
        } else {
            m_combatOffenseEffect.put(ut, effect);
        }
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException) InternalDoNotExport(games.strategy.engine.data.annotations.InternalDoNotExport)

Example 4 with GameParseException

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

the class TerritoryEffectAttachment method setNoBlitz.

private void setNoBlitz(final String noBlitzUnitTypes) throws GameParseException {
    final String[] s = noBlitzUnitTypes.split(":");
    if (s.length < 1) {
        throw new GameParseException("noBlitz must have at least one unitType" + thisErrorMsg());
    }
    for (final String unitTypeName : s) {
        final UnitType ut = getData().getUnitTypeList().getUnitType(unitTypeName);
        if (ut == null) {
            throw new GameParseException("No unit called:" + unitTypeName + thisErrorMsg());
        }
        m_noBlitz.add(ut);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 5 with GameParseException

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

the class TriggerAttachment method setRemoveUnits.

private void setRemoveUnits(final String value) throws GameParseException {
    if (value == null) {
        m_removeUnits = null;
        return;
    }
    if (m_removeUnits == null) {
        m_removeUnits = new HashMap<>();
    }
    final String[] s = value.split(":");
    if (s.length < 1) {
        throw new GameParseException("Empty removeUnits 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 removeUnits list" + thisErrorMsg());
    }
    final Collection<Territory> territories = new ArrayList<>();
    final Territory terr = getData().getMap().getTerritory(s[i]);
    if (terr == null) {
        if (s[i].equalsIgnoreCase("all")) {
            territories.addAll(getData().getMap().getTerritories());
        } else {
            throw new GameParseException("Territory does not exist " + s[i] + thisErrorMsg());
        }
    } else {
        territories.add(terr);
    }
    i++;
    final IntegerMap<UnitType> map = new IntegerMap<>();
    for (; i < s.length; i++) {
        final Collection<UnitType> types = new ArrayList<>();
        final UnitType tp = getData().getUnitTypeList().getUnitType(s[i]);
        if (tp == null) {
            if (s[i].equalsIgnoreCase("all")) {
                types.addAll(getData().getUnitTypeList().getAllUnitTypes());
            } else {
                throw new GameParseException("UnitType does not exist " + s[i] + thisErrorMsg());
            }
        } else {
            types.add(tp);
        }
        for (final UnitType type : types) {
            map.add(type, count);
        }
    }
    for (final Territory t : territories) {
        if (m_removeUnits.containsKey(t)) {
            map.add(m_removeUnits.get(t));
        }
        m_removeUnits.put(t, map);
    }
}
Also used : IntegerMap(games.strategy.util.IntegerMap) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) GameParseException(games.strategy.engine.data.GameParseException) GameParseException(games.strategy.engine.data.GameParseException) UnitType(games.strategy.engine.data.UnitType)

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