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));
}
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);
}
}
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);
}
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;
}
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());
}
}
}
Aggregations