use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.
the class GameParser method parseTechs.
private void parseTechs(final List<Element> elements, final TechnologyFrontier allTechsFrontier) {
for (final Element current : elements) {
final String name = current.getAttribute("name");
final String tech = current.getAttribute("tech");
TechAdvance ta;
if (tech.length() > 0) {
ta = new GenericTechAdvance(name, TechAdvance.findDefinedAdvanceAndCreateAdvance(tech, data), data);
} else {
try {
ta = TechAdvance.findDefinedAdvanceAndCreateAdvance(name, data);
} catch (final IllegalArgumentException e) {
ta = new GenericTechAdvance(name, null, data);
}
}
allTechsFrontier.addAdvance(ta);
}
}
use of games.strategy.triplea.delegate.TechAdvance 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.triplea.delegate.TechAdvance in project triplea by triplea-game.
the class GameDataExporter method technologies.
private static String technologies(final GameData data) {
final StringBuilder returnValue = new StringBuilder();
if (data.getTechnologyFrontier().getTechs().size() > 0) {
returnValue.append(" <technologies>\n");
for (final TechAdvance tech : data.getTechnologyFrontier().getTechs()) {
String name = tech.getName();
final String cat = tech.getProperty();
// stored in java with the normal category and name, this causes an xml bug when exporting.
for (final String definedName : TechAdvance.ALL_PREDEFINED_TECHNOLOGY_NAMES) {
if (definedName.equals(name)) {
name = cat;
}
}
returnValue.append(" <techname name=\"").append(name).append("\"");
if (!name.equals(cat)) {
returnValue.append(" tech=\"").append(cat).append("\" ");
}
returnValue.append("/>\n");
}
returnValue.append(" </technologies>\n");
}
return returnValue.toString();
}
use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.
the class GameDataExporter method playertechs.
private static String playertechs(final GameData data) {
final StringBuilder returnValue = new StringBuilder();
for (final PlayerID player : data.getPlayerList()) {
if (player.getTechnologyFrontierList().getFrontiers().size() > 0) {
returnValue.append(" <playerTech player=\"").append(player.getName()).append("\">\n");
for (final TechnologyFrontier frontier : player.getTechnologyFrontierList().getFrontiers()) {
returnValue.append(" <category name=\"").append(frontier.getName()).append("\">\n");
for (final TechAdvance tech : frontier.getTechs()) {
String name = tech.getName();
final String cat = tech.getProperty();
for (final String definedName : TechAdvance.ALL_PREDEFINED_TECHNOLOGY_NAMES) {
if (definedName.equals(name)) {
name = cat;
}
}
returnValue.append(" <tech name=\"").append(name).append("\"/>\n");
}
returnValue.append(" </category>\n");
}
returnValue.append(" </playerTech>\n");
}
}
return returnValue.toString();
}
use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.
the class RulesAttachment method setTechs.
private void setTechs(final String newTechs) throws GameParseException {
if (newTechs == null) {
m_techs = null;
return;
}
final String[] s = newTechs.split(":");
if (s.length < 1) {
throw new GameParseException("Empty tech list" + thisErrorMsg());
}
int count = -1;
try {
count = getInt(s[0]);
m_techCount = count;
} catch (final Exception e) {
m_techCount = 0;
}
if (s.length < 1 || (s.length == 1 && count != -1)) {
throw new GameParseException("Empty tech list" + thisErrorMsg());
}
m_techs = new ArrayList<>();
for (int i = count == -1 ? 0 : 1; i < s.length; i++) {
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 :" + Arrays.toString(s) + thisErrorMsg());
}
m_techs.add(ta);
}
}
Aggregations