Search in sources :

Example 41 with GameParseException

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

the class UnitAttachment method setMovementLimit.

private void setMovementLimit(final String value) throws GameParseException {
    if (value == null) {
        m_movementLimit = 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("movementLimit must have 2 fields, value and count" + 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 value must owned, allied, or total" + thisErrorMsg());
    }
    m_movementLimit = Tuple.of(max, s[1]);
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 42 with GameParseException

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

the class UnitAttachment method setBombingTargets.

private void setBombingTargets(final String value) throws GameParseException {
    if (value == null) {
        m_bombingTargets = null;
        return;
    }
    if (m_bombingTargets == null) {
        m_bombingTargets = new HashSet<>();
    }
    final String[] s = value.split(":");
    for (final String u : s) {
        final UnitType ut = getData().getUnitTypeList().getUnitType(u);
        if (ut == null) {
            throw new GameParseException("bombingTargets: no such unit type: " + u + thisErrorMsg());
        }
        m_bombingTargets.add(ut);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 43 with GameParseException

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

the class UnitAttachment method setGivesMovement.

private void setGivesMovement(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length <= 0 || s.length > 2) {
        throw new GameParseException("givesMovement cannot be empty or have more than two fields" + thisErrorMsg());
    }
    final String 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());
    }
    // we should allow positive and negative numbers, since you can give bonuses to units or take away a unit's movement
    final int n = getInt(s[0]);
    m_givesMovement.put(ut, n);
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 44 with GameParseException

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

the class UnitAttachment method setWhenCapturedChangesInto.

@VisibleForTesting
void setWhenCapturedChangesInto(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length < 5 || s.length % 2 == 0) {
        throw new GameParseException("whenCapturedChangesInto must have 5 or more values, " + "playerFrom:playerTo:keepAttributes:unitType:howMany " + "(you may have additional unitType:howMany:unitType:howMany, etc" + thisErrorMsg());
    }
    final PlayerID pfrom = getData().getPlayerList().getPlayerId(s[0]);
    if (pfrom == null && !s[0].equals("any")) {
        throw new GameParseException("whenCapturedChangesInto: No player named: " + s[0] + thisErrorMsg());
    }
    final PlayerID pto = getData().getPlayerList().getPlayerId(s[1]);
    if (pto == null && !s[1].equals("any")) {
        throw new GameParseException("whenCapturedChangesInto: No player named: " + s[1] + thisErrorMsg());
    }
    getBool(s[2]);
    final IntegerMap<UnitType> unitsToMake = new IntegerMap<>();
    for (int i = 3; i < s.length; i += 2) {
        final UnitType ut = getData().getUnitTypeList().getUnitType(s[i]);
        if (ut == null) {
            throw new GameParseException("whenCapturedChangesInto: No unit named: " + s[i] + thisErrorMsg());
        }
        unitsToMake.put(ut, getInt(s[i + 1]));
    }
    m_whenCapturedChangesInto.put(s[0] + ":" + s[1], Tuple.of(s[2], unitsToMake));
}
Also used : IntegerMap(games.strategy.util.IntegerMap) PlayerID(games.strategy.engine.data.PlayerID) UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 45 with GameParseException

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

the class UnitAttachment method setRequiresUnitsToMove.

private void setRequiresUnitsToMove(final String value) throws GameParseException {
    final String[] array = value.split(":");
    if (array.length == 0) {
        throw new GameParseException("requiresUnitsToMove must have at least 1 unit type" + thisErrorMsg());
    }
    for (final String s : array) {
        final UnitType ut = getData().getUnitTypeList().getUnitType(s);
        if (ut == null) {
            throw new GameParseException("No unit called:" + s + thisErrorMsg());
        }
    }
    m_requiresUnitsToMove.add(array);
}
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