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