use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class PlayerAttachment method setPlacementLimit.
private void setPlacementLimit(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length < 3) {
throw new GameParseException("placementLimit must have 3 parts: count, type, unit list" + 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 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_placementLimit.add(Triple.of(max, s[1], types));
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class PlayerAttachment method setMovementLimit.
private void setMovementLimit(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length < 3) {
throw new GameParseException("movementLimit must have 3 parts: count, type, unit list" + 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 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_movementLimit.add(Triple.of(max, s[1], types));
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class PlayerAttachment method setSuicideAttackResources.
private void setSuicideAttackResources(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length != 2) {
throw new GameParseException("suicideAttackResources must have exactly 2 fields" + thisErrorMsg());
}
final int attackValue = getInt(s[0]);
if (attackValue < 0) {
throw new GameParseException("suicideAttackResources attack value must be positive" + thisErrorMsg());
}
final Resource r = getData().getResourceList().getResource(s[1]);
if (r == null) {
throw new GameParseException("no such resource: " + s[1] + thisErrorMsg());
}
m_suicideAttackResources.put(r, attackValue);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class RelationshipTypeAttachment method setUpkeepCost.
private void setUpkeepCost(final String integerCost) throws GameParseException {
if (integerCost.equals(PROPERTY_DEFAULT)) {
m_upkeepCost = PROPERTY_DEFAULT;
} else {
final String[] s = integerCost.split(":");
if (s.length < 1 || s.length > 2) {
throw new GameParseException("upkeepCost must have either 1 or 2 fields" + thisErrorMsg());
}
final int cost = getInt(s[0]);
if (s.length == 2) {
if (s[1].equals(UPKEEP_FLAT)) {
// do nothing
} else if (s[1].equals(UPKEEP_PERCENTAGE)) {
if (cost > 100) {
throw new GameParseException("upkeepCost may not have a percentage greater than 100" + thisErrorMsg());
}
} else {
throw new GameParseException("upkeepCost must have either: " + UPKEEP_FLAT + " or " + UPKEEP_PERCENTAGE + thisErrorMsg());
}
}
m_upkeepCost = integerCost;
}
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class RulesAttachment method setAtWarPlayers.
private void setAtWarPlayers(final String players) throws GameParseException {
if (players == null) {
m_atWarPlayers = null;
return;
}
final String[] s = players.split(":");
if (s.length < 1) {
throw new GameParseException("Empty enemy list" + thisErrorMsg());
}
int count = -1;
try {
count = getInt(s[0]);
m_atWarCount = count;
} catch (final Exception e) {
m_atWarCount = 0;
}
if (s.length < 1 || (s.length == 1 && count != -1)) {
throw new GameParseException("Empty enemy list" + thisErrorMsg());
}
m_atWarPlayers = new HashSet<>();
for (int i = count == -1 ? 0 : 1; i < s.length; i++) {
final PlayerID player = getData().getPlayerList().getPlayerId(s[i]);
if (player == null) {
throw new GameParseException("Could not find player. name:" + s[i] + thisErrorMsg());
}
m_atWarPlayers.add(player);
}
}
Aggregations