Search in sources :

Example 56 with GameParseException

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

the class PlayerAttachment method setAttackingLimit.

private void setAttackingLimit(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length < 3) {
        throw new GameParseException("attackingLimit must have 3 parts: count, type, unit list" + 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 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_attackingLimit.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 57 with GameParseException

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

the class PlayerAttachment method setSuicideAttackTargets.

private void setSuicideAttackTargets(final String value) throws GameParseException {
    if (value == null) {
        m_suicideAttackTargets = null;
        return;
    }
    if (m_suicideAttackTargets == null) {
        m_suicideAttackTargets = 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("suicideAttackTargets: no such unit called " + u + thisErrorMsg());
        }
        m_suicideAttackTargets.add(ut);
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 58 with GameParseException

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

the class TechAbilityAttachment method setUnitAbilitiesGained.

private void setUnitAbilitiesGained(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length < 2) {
        throw new GameParseException("unitAbilitiesGained must list the unit type, then all abilities gained" + thisErrorMsg());
    }
    final String unitType = s[0];
    // validate that this unit exists in the xml
    final UnitType ut = getUnitType(unitType);
    final Set<String> abilities = m_unitAbilitiesGained.getOrDefault(ut, new HashSet<>());
    // start at 1
    for (int i = 1; i < s.length; i++) {
        final String ability = s[i];
        if (!(ability.equals(ABILITY_CAN_BLITZ) || ability.equals(ABILITY_CAN_BOMBARD))) {
            throw new GameParseException("unitAbilitiesGained so far only supports: " + ABILITY_CAN_BLITZ + " and " + ABILITY_CAN_BOMBARD + thisErrorMsg());
        }
        abilities.add(ability);
    }
    m_unitAbilitiesGained.put(ut, abilities);
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException)

Example 59 with GameParseException

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

the class UnitSupportAttachment method setDice.

private void setDice(final String dice) throws GameParseException {
    if (dice == null) {
        resetDice();
        return;
    }
    m_roll = false;
    m_strength = false;
    for (final String element : dice.split(":")) {
        if (element.equalsIgnoreCase("roll")) {
            m_roll = true;
        } else if (element.equalsIgnoreCase("strength")) {
            m_strength = true;
        } else {
            throw new GameParseException(dice + " dice must be roll or strength" + thisErrorMsg());
        }
    }
    m_dice = dice;
}
Also used : GameParseException(games.strategy.engine.data.GameParseException)

Example 60 with GameParseException

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

the class UnitSupportAttachment method setFaction.

private void setFaction(final String faction) throws GameParseException {
    m_faction = faction;
    if (faction == null) {
        resetFaction();
        return;
    }
    m_allied = false;
    m_enemy = false;
    for (final String element : faction.split(":")) {
        if (element.equalsIgnoreCase("allied")) {
            m_allied = true;
        } else if (element.equalsIgnoreCase("enemy")) {
            m_enemy = true;
        } else {
            throw new GameParseException(faction + " faction must be allied, or enemy" + thisErrorMsg());
        }
    }
}
Also used : 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