Search in sources :

Example 11 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class TechAbilityAttachmentTest method setup.

@BeforeEach
public void setup() {
    when(attachment.toString()).thenReturn(customToString);
    when(data.getUnitTypeList()).thenReturn(list);
    when(list.getUnitType(testUnitType)).thenReturn(dummyUnitType);
    final TechnologyFrontier fron = mock(TechnologyFrontier.class);
    when(data.getTechnologyFrontier()).thenReturn(fron);
    final TechAdvance advance = mock(TechAdvance.class);
    when(fron.getTechs()).thenReturn(Arrays.asList(advance, advance, advance, advance));
    when(advance.hasTech(any())).thenReturn(Boolean.TRUE);
    when(advance.getAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME)).thenReturn(attachment, null, attachment, attachment);
}
Also used : TechAdvance(games.strategy.triplea.delegate.TechAdvance) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class ExtendedStats method fillExtendedStats.

private void fillExtendedStats(final GameData data) {
    // add other resources, other than PUs and tech tokens
    final List<Resource> resources = data.getResourceList().getResources();
    for (final Resource r : resources) {
        if (r.getName().equals(Constants.PUS) || r.getName().equals(Constants.TECH_TOKENS)) {
            continue;
        }
        final GenericResourceStat resourceStat = new GenericResourceStat();
        resourceStat.init(r.getName());
        final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
        statsExtended.add(resourceStat);
        this.statsExtended = statsExtended.toArray(new IStat[0]);
    }
    // add tech related stuff
    if (Properties.getTechDevelopment(data)) {
        // add tech tokens
        if (data.getResourceList().getResource(Constants.TECH_TOKENS) != null) {
            final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
            statsExtended.add(new TechTokenStat());
            this.statsExtended = statsExtended.toArray(new IStat[0]);
        }
        // add number of techs
        final List<IStat> techStatsExtended = new ArrayList<>(Arrays.asList(statsExtended));
        techStatsExtended.add(new TechCountStat());
        statsExtended = techStatsExtended.toArray(new IStat[0]);
        // add individual techs
        for (final TechAdvance ta : TechAdvance.getTechAdvances(gameData)) {
            final GenericTechNameStat techNameStat = new GenericTechNameStat();
            techNameStat.init(ta);
            final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
            statsExtended.add(techNameStat);
            this.statsExtended = statsExtended.toArray(new IStat[0]);
        }
    }
    // now add actual number of each unit type (holy gumdrops batman, this is going to be long!)
    final UnitTypeList allUnitTypes = data.getUnitTypeList();
    for (final UnitType ut : allUnitTypes) {
        final GenericUnitNameStat unitNameStat = new GenericUnitNameStat();
        unitNameStat.init(ut);
        final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
        statsExtended.add(unitNameStat);
        this.statsExtended = statsExtended.toArray(new IStat[0]);
    }
}
Also used : Resource(games.strategy.engine.data.Resource) ArrayList(java.util.ArrayList) IStat(games.strategy.engine.stats.IStat) UnitTypeList(games.strategy.engine.data.UnitTypeList) UnitType(games.strategy.engine.data.UnitType) TechAdvance(games.strategy.triplea.delegate.TechAdvance)

Example 13 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class GameParser method getTechnology.

private TechAdvance getTechnology(final String name) {
    final TechnologyFrontier frontier = data.getTechnologyFrontier();
    TechAdvance type = frontier.getAdvanceByName(name);
    if (type == null) {
        type = frontier.getAdvanceByProperty(name);
    }
    return type;
}
Also used : GenericTechAdvance(games.strategy.triplea.delegate.GenericTechAdvance) TechAdvance(games.strategy.triplea.delegate.TechAdvance)

Example 14 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class GameParser method parseCategoryTechs.

private void parseCategoryTechs(final List<Element> elements, final TechnologyFrontier frontier) throws GameParseException {
    for (final Element current : elements) {
        TechAdvance ta = data.getTechnologyFrontier().getAdvanceByProperty(current.getAttribute("name"));
        if (ta == null) {
            ta = data.getTechnologyFrontier().getAdvanceByName(current.getAttribute("name"));
        }
        if (ta == null) {
            throw newGameParseException("Technology not found :" + current.getAttribute("name"));
        }
        frontier.addAdvance(ta);
    }
}
Also used : Element(org.w3c.dom.Element) GenericTechAdvance(games.strategy.triplea.delegate.GenericTechAdvance) TechAdvance(games.strategy.triplea.delegate.TechAdvance)

Example 15 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class TechPanel method getTechListToolTipText.

private static String getTechListToolTipText(final TechnologyFrontier techCategory) {
    final List<TechAdvance> techList = techCategory.getTechs();
    if (techList.size() <= 1) {
        return null;
    }
    final Collection<TechAdvance> listedAlready = new HashSet<>();
    final StringBuilder strTechCategory = new StringBuilder("Available Techs:  ");
    final Iterator<TechAdvance> iterTechList = techList.iterator();
    while (iterTechList.hasNext()) {
        final TechAdvance advance = iterTechList.next();
        if (listedAlready.contains(advance)) {
            continue;
        }
        listedAlready.add(advance);
        final int freq = Collections.frequency(techList, advance);
        strTechCategory.append(advance.getName()).append(freq > 1 ? " (" + freq + "/" + techList.size() + ")" : "");
        if (iterTechList.hasNext()) {
            strTechCategory.append(", ");
        }
    }
    return strTechCategory.toString();
}
Also used : TechAdvance(games.strategy.triplea.delegate.TechAdvance) HashSet(java.util.HashSet)

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