use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setFuelFlatCost.
private void setFuelFlatCost(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length != 2) {
throw new GameParseException("fuelFlatCost 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("fuelFlatCost: No resource called:" + resourceToProduce + thisErrorMsg());
}
final int n = getInt(s[0]);
if (n < 0) {
throw new GameParseException("fuelFlatCost must have positive values" + thisErrorMsg());
}
m_fuelFlatCost.put(r, n);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setAttackingLimit.
private void setAttackingLimit(final String value) throws GameParseException {
if (value == null) {
m_attackingLimit = 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("attackingLimit must have 2 fields, value and count" + 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 value must owned, allied, or total" + thisErrorMsg());
}
m_attackingLimit = Tuple.of(max, s[1]);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UserActionAttachment method setActivateTrigger.
private void setActivateTrigger(final String value) throws GameParseException {
// triggerName:numberOfTimes:useUses:testUses:testConditions:testChance
final String[] s = value.split(":");
if (s.length != 6) {
throw new GameParseException("activateTrigger must have 6 parts: triggerName:numberOfTimes:useUses:testUses:testConditions:testChance" + thisErrorMsg());
}
TriggerAttachment trigger = null;
for (final PlayerID player : getData().getPlayerList().getPlayers()) {
for (final TriggerAttachment ta : TriggerAttachment.getTriggers(player, null)) {
if (ta.getName().equals(s[0])) {
trigger = ta;
break;
}
}
if (trigger != null) {
break;
}
}
if (trigger == null) {
throw new GameParseException("No TriggerAttachment named: " + s[0] + thisErrorMsg());
}
String options = value;
options = options.replaceFirst((s[0] + ":"), "");
final int numberOfTimes = getInt(s[1]);
if (numberOfTimes < 0) {
throw new GameParseException("activateTrigger must be positive for the number of times to fire: " + s[1] + thisErrorMsg());
}
getBool(s[2]);
getBool(s[3]);
getBool(s[4]);
getBool(s[5]);
m_activateTrigger.add(Tuple.of(s[0], options));
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class AbstractConditionsAttachment method setChance.
protected void setChance(final String chance) throws GameParseException {
final String[] s = chance.split(":");
try {
final int i = getInt(s[0]);
final int j = getInt(s[1]);
if (i > j || i < 0 || j < 0 || i > 120 || j > 120) {
throw new GameParseException("chance should have a format of \"x:y\" where x is <= y and both x and y are >=0 and <=120" + thisErrorMsg());
}
} catch (final IllegalArgumentException iae) {
throw new GameParseException("Invalid chance declaration: " + chance + " format: \"1:10\" for 10% chance" + thisErrorMsg());
}
m_chance = chance;
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class AbstractPlayerRulesAttachment method setProductionPerXTerritories.
private void setProductionPerXTerritories(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length <= 0 || s.length > 2) {
throw new GameParseException("productionPerXTerritories cannot be empty or have more than two fields" + thisErrorMsg());
}
final String unitTypeToProduce;
if (s.length == 1) {
unitTypeToProduce = Constants.UNIT_TYPE_INFANTRY;
} else {
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());
}
final int n = getInt(s[0]);
if (n <= 0) {
throw new GameParseException("productionPerXTerritories must be a positive integer" + thisErrorMsg());
}
m_productionPerXTerritories.put(ut, n);
}
Aggregations