Search in sources :

Example 1 with TechAdvance

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);
    }
}
Also used : Element(org.w3c.dom.Element) GenericTechAdvance(games.strategy.triplea.delegate.GenericTechAdvance) TechAdvance(games.strategy.triplea.delegate.TechAdvance) GenericTechAdvance(games.strategy.triplea.delegate.GenericTechAdvance)

Example 2 with TechAdvance

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);
}
Also used : TechAdvance(games.strategy.triplea.delegate.TechAdvance) GameParseException(games.strategy.engine.data.GameParseException) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with TechAdvance

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();
}
Also used : TechAdvance(games.strategy.triplea.delegate.TechAdvance)

Example 4 with TechAdvance

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();
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechAdvance(games.strategy.triplea.delegate.TechAdvance) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier)

Example 5 with TechAdvance

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);
    }
}
Also used : TechAdvance(games.strategy.triplea.delegate.TechAdvance) GameParseException(games.strategy.engine.data.GameParseException) GameParseException(games.strategy.engine.data.GameParseException)

Aggregations

TechAdvance (games.strategy.triplea.delegate.TechAdvance)15 GenericTechAdvance (games.strategy.triplea.delegate.GenericTechAdvance)5 GameParseException (games.strategy.engine.data.GameParseException)3 PlayerID (games.strategy.engine.data.PlayerID)3 TechnologyFrontier (games.strategy.engine.data.TechnologyFrontier)3 UnitType (games.strategy.engine.data.UnitType)3 HashSet (java.util.HashSet)2 Element (org.w3c.dom.Element)2 Change (games.strategy.engine.data.Change)1 CompositeChange (games.strategy.engine.data.CompositeChange)1 Resource (games.strategy.engine.data.Resource)1 UnitTypeList (games.strategy.engine.data.UnitTypeList)1 InternalDoNotExport (games.strategy.engine.data.annotations.InternalDoNotExport)1 IStat (games.strategy.engine.stats.IStat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Set (java.util.Set)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1