Search in sources :

Example 1 with UnitTypeList

use of games.strategy.engine.data.UnitTypeList in project triplea by triplea-game.

the class ParserTest method testUnitTypesAdded.

@Test
public void testUnitTypesAdded() {
    final UnitTypeList units = gameData.getUnitTypeList();
    assertEquals(1, units.size());
}
Also used : UnitTypeList(games.strategy.engine.data.UnitTypeList) Test(org.junit.jupiter.api.Test)

Example 2 with UnitTypeList

use of games.strategy.engine.data.UnitTypeList in project triplea by triplea-game.

the class OrderOfLossesInputPanel method isValidOrderOfLoss.

/**
 * Validates if a given string can be parsed for order of losses.
 */
public static boolean isValidOrderOfLoss(final String orderOfLoss, final GameData data) {
    if (orderOfLoss == null || orderOfLoss.trim().length() == 0) {
        return true;
    }
    try {
        final String[] sections;
        if (orderOfLoss.contains(OOL_SEPARATOR)) {
            sections = orderOfLoss.trim().split(OOL_SEPARATOR_REGEX);
        } else {
            sections = new String[1];
            sections[0] = orderOfLoss.trim();
        }
        final UnitTypeList unitTypes;
        try {
            data.acquireReadLock();
            unitTypes = data.getUnitTypeList();
        } finally {
            data.releaseReadLock();
        }
        for (final String section : sections) {
            if (section.length() == 0) {
                continue;
            }
            final String[] amountThenType = section.split(OOL_AMOUNT_DESCRIPTOR_REGEX);
            if (amountThenType.length != 2) {
                return false;
            }
            if (!amountThenType[0].equals(OOL_ALL)) {
                final int amount = Integer.parseInt(amountThenType[0]);
                if (amount <= 0) {
                    return false;
                }
            }
            final UnitType type = unitTypes.getUnitType(amountThenType[1]);
            if (type == null) {
                return false;
            }
        }
    } catch (final Exception e) {
        return false;
    }
    return true;
}
Also used : UnitTypeList(games.strategy.engine.data.UnitTypeList) UnitType(games.strategy.engine.data.UnitType)

Example 3 with UnitTypeList

use of games.strategy.engine.data.UnitTypeList 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)

Aggregations

UnitTypeList (games.strategy.engine.data.UnitTypeList)3 UnitType (games.strategy.engine.data.UnitType)2 Resource (games.strategy.engine.data.Resource)1 IStat (games.strategy.engine.stats.IStat)1 TechAdvance (games.strategy.triplea.delegate.TechAdvance)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1