use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TriggerAttachment method setTerritories.
private void setTerritories(final String names) throws GameParseException {
final String[] s = names.split(":");
for (final String element : s) {
final Territory terr = getData().getMap().getTerritory(element);
if (terr == null) {
throw new GameParseException("Could not find territory. name:" + element + thisErrorMsg());
}
m_territories.add(terr);
}
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TriggerAttachment method setFrontier.
private void setFrontier(final String s) throws GameParseException {
if (s == null) {
m_frontier = null;
return;
}
final ProductionFrontier front = getData().getProductionFrontierList().getProductionFrontier(s);
if (front == null) {
throw new GameParseException("Could not find frontier. name:" + s + thisErrorMsg());
}
m_frontier = front;
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TriggerAttachment method setAvailableTech.
private void setAvailableTech(final String techs) throws GameParseException {
if (techs == null) {
m_availableTech = null;
return;
}
final String[] s = techs.split(":");
if (s.length < 2) {
throw new GameParseException("Invalid tech availability: " + techs + " should be category:techs" + thisErrorMsg());
}
final String cat = s[0];
final LinkedHashMap<TechAdvance, Boolean> tlist = new LinkedHashMap<>();
for (int i = 1; i < s.length; i++) {
boolean add = true;
if (s[i].startsWith("-")) {
add = false;
s[i] = s[i].substring(1);
}
TechAdvance ta = getData().getTechnologyFrontier().getAdvanceByProperty(s[i]);
if (ta == null) {
ta = getData().getTechnologyFrontier().getAdvanceByName(s[i]);
}
if (ta == null) {
throw new GameParseException("Technology not found :" + s[i] + thisErrorMsg());
}
tlist.put(ta, add);
}
if (m_availableTech == null) {
m_availableTech = new HashMap<>();
}
if (m_availableTech.containsKey(cat)) {
tlist.putAll(m_availableTech.get(cat));
}
m_availableTech.put(cat, tlist);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TriggerAttachment 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 : 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());
}
if (trigger == this) {
throw new GameParseException("Cannot have a trigger activate itself!" + 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 TriggerAttachment method setTerritoryEffects.
private void setTerritoryEffects(final String names) throws GameParseException {
final String[] s = names.split(":");
for (final String element : s) {
final TerritoryEffect effect = getData().getTerritoryEffectList().get(element);
if (effect == null) {
throw new GameParseException("Could not find territoryEffect. name:" + element + thisErrorMsg());
}
m_territoryEffects.add(effect);
}
}
Aggregations