use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setFuelCost.
private void setFuelCost(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length != 2) {
throw new GameParseException("fuelCost must have two fields" + thisErrorMsg());
}
final String resourceToProduce = s[1];
// validate that this resource exists in the xml
final Resource r = getData().getResourceList().getResource(resourceToProduce);
if (r == null) {
throw new GameParseException("fuelCost: No resource called:" + resourceToProduce + thisErrorMsg());
}
final int n = getInt(s[0]);
if (n < 0) {
throw new GameParseException("fuelCost must have positive values" + thisErrorMsg());
}
m_fuelCost.put(r, n);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setRepairsUnits.
private void setRepairsUnits(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length <= 0) {
throw new GameParseException("repairsUnits cannot be empty" + thisErrorMsg());
}
int i = 0;
int amount;
try {
amount = Integer.parseInt(s[0]);
i++;
} catch (final NumberFormatException nfe) {
amount = 1;
}
for (; i < s.length; i++) {
final UnitType ut = getData().getUnitTypeList().getUnitType(s[i]);
if (ut == null) {
throw new GameParseException("No unit called:" + s[i] + thisErrorMsg());
}
m_repairsUnits.put(ut, amount);
}
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setPlacementLimit.
private void setPlacementLimit(final String value) throws GameParseException {
if (value == null) {
m_placementLimit = 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("placementLimit must have 2 fields, value and count" + thisErrorMsg());
}
final int max = getInt(s[0]);
if (max < 0) {
throw new GameParseException("placementLimit count must have a positive number" + thisErrorMsg());
}
if (!(s[1].equals("owned") || s[1].equals("allied") || s[1].equals("total"))) {
throw new GameParseException("placementLimit value must owned, allied, or total" + thisErrorMsg());
}
m_placementLimit = Tuple.of(max, s[1]);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class AbstractRulesAttachment method setRounds.
private void setRounds(final String rounds) throws GameParseException {
if (rounds == null) {
m_turns = null;
return;
}
m_turns = new HashMap<>();
final String[] s = rounds.split(":");
if (s.length < 1) {
throw new GameParseException("Empty turn list" + thisErrorMsg());
}
for (final String subString : s) {
int start;
int end;
try {
start = getInt(subString);
end = start;
} catch (final Exception e) {
final String[] s2 = subString.split("-");
if (s2.length != 2) {
throw new GameParseException("Invalid syntax for turn range, must be 'int-int'" + thisErrorMsg());
}
start = getInt(s2[0]);
if (s2[1].equals("+")) {
end = Integer.MAX_VALUE;
} else {
end = getInt(s2[1]);
}
}
m_turns.put(start, end);
}
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class AbstractRulesAttachment method setPlayers.
private void setPlayers(final String names) throws GameParseException {
final PlayerList pl = getData().getPlayerList();
for (final String p : names.split(":")) {
final PlayerID player = pl.getPlayerId(p);
if (player == null) {
throw new GameParseException("Could not find player. name:" + p + thisErrorMsg());
}
m_players.add(player);
}
}
Aggregations