use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TriggerAttachment method setPurchase.
private void setPurchase(final String place) throws GameParseException {
if (place == null) {
m_purchase = null;
return;
}
final String[] s = place.split(":");
if (s.length < 1) {
throw new GameParseException("Empty purchase 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 purchase list" + thisErrorMsg());
}
if (m_purchase == null) {
m_purchase = new IntegerMap<>();
}
for (; i < s.length; i++) {
final UnitType type = getData().getUnitTypeList().getUnitType(s[i]);
if (type == null) {
throw new GameParseException("UnitType does not exist " + s[i] + thisErrorMsg());
}
m_purchase.add(type, count);
}
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setCreatesUnitsList.
private void setCreatesUnitsList(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length <= 0 || s.length > 2) {
throw new GameParseException("createsUnitsList 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("createsUnitsList: No unit called:" + unitTypeToProduce + thisErrorMsg());
}
final int n = getInt(s[0]);
if (n < 1) {
throw new GameParseException("createsUnitsList must have positive values" + thisErrorMsg());
}
m_createsUnitsList.put(ut, n);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setDestroyedWhenCapturedBy.
private void setDestroyedWhenCapturedBy(String value) throws GameParseException {
// We can prefix this value with "BY" or "FROM" to change the setting. If no setting, default to "BY" since this
// this is called by
// destroyedWhenCapturedBy
String byOrFrom = "BY";
if (value.startsWith("BY:") && getData().getPlayerList().getPlayerId("BY") == null) {
byOrFrom = "BY";
value = value.replaceFirst("BY:", "");
} else if (value.startsWith("FROM:") && getData().getPlayerList().getPlayerId("FROM") == null) {
byOrFrom = "FROM";
value = value.replaceFirst("FROM:", "");
}
final String[] temp = value.split(":");
for (final String name : temp) {
final PlayerID tempPlayer = getData().getPlayerList().getPlayerId(name);
if (tempPlayer != null) {
m_destroyedWhenCapturedBy.add(Tuple.of(byOrFrom, tempPlayer));
} else {
throw new GameParseException("No player named: " + name + thisErrorMsg());
}
}
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setCreatesResourcesList.
private void setCreatesResourcesList(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length <= 0 || s.length > 2) {
throw new GameParseException("createsResourcesList cannot be empty or have more than 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("createsResourcesList: No resource called:" + resourceToProduce + thisErrorMsg());
}
final int n = getInt(s[0]);
m_createsResourcesList.put(r, n);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class UnitAttachment method setTargetsAa.
private void setTargetsAa(final String value) throws GameParseException {
if (value == null) {
m_targetsAA = null;
return;
}
if (m_targetsAA == null) {
m_targetsAA = 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("AAtargets: no such unit type: " + u + thisErrorMsg());
}
m_targetsAA.add(ut);
}
}
Aggregations