use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TerritoryAttachment method setResources.
private void setResources(final String value) throws GameParseException {
if (value == null) {
m_resources = null;
return;
}
if (m_resources == null) {
m_resources = new ResourceCollection(getData());
}
final String[] s = value.split(":");
final int amount = getInt(s[0]);
if (s[1].equals(Constants.PUS)) {
throw new GameParseException("Please set PUs using production, not resource" + thisErrorMsg());
}
final Resource resource = getData().getResourceList().getResource(s[1]);
if (resource == null) {
throw new GameParseException("No resource named: " + s[1] + thisErrorMsg());
}
m_resources.putResource(resource, amount);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TerritoryAttachment method setWhenCapturedByGoesTo.
private void setWhenCapturedByGoesTo(final String value) throws GameParseException {
final String[] s = value.split(":");
if (s.length != 2) {
throw new GameParseException("whenCapturedByGoesTo must have 2 player names separated by a colon" + thisErrorMsg());
}
for (final String name : s) {
final PlayerID player = getData().getPlayerList().getPlayerId(name);
if (player == null) {
throw new GameParseException("No player named: " + name + thisErrorMsg());
}
}
m_whenCapturedByGoesTo.add(value);
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TerritoryAttachment method setConvoyAttached.
private void setConvoyAttached(final String value) throws GameParseException {
if (value.length() <= 0) {
return;
}
for (final String subString : value.split(":")) {
final Territory territory = getData().getMap().getTerritory(subString);
if (territory == null) {
throw new GameParseException("No territory called:" + subString + thisErrorMsg());
}
m_convoyAttached.add(territory);
}
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TriggerAttachment method setRelationshipTypes.
private void setRelationshipTypes(final String names) throws GameParseException {
final String[] s = names.split(":");
for (final String element : s) {
final RelationshipType relation = getData().getRelationshipTypeList().getRelationshipType(element);
if (relation == null) {
throw new GameParseException("Could not find relationshipType. name:" + element + thisErrorMsg());
}
m_relationshipTypes.add(relation);
}
}
use of games.strategy.engine.data.GameParseException in project triplea by triplea-game.
the class TriggerAttachment method setPlacement.
/**
* Fudging this, it really represents adding placements.
*/
private void setPlacement(final String place) throws GameParseException {
if (place == null) {
m_placement = null;
return;
}
final String[] s = place.split(":");
if (s.length < 1) {
throw new GameParseException("Empty placement 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 placement list" + thisErrorMsg());
}
final Territory territory = getData().getMap().getTerritory(s[i]);
if (territory == null) {
throw new GameParseException("Territory does not exist " + s[i] + thisErrorMsg());
}
i++;
final IntegerMap<UnitType> map = 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());
}
map.add(type, count);
}
if (m_placement == null) {
m_placement = new HashMap<>();
}
if (m_placement.containsKey(territory)) {
map.add(m_placement.get(territory));
}
m_placement.put(territory, map);
}
Aggregations