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