Search in sources :

Example 6 with ProductionFrontier

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

the class GameDataExporter method productionFrontiers.

private void productionFrontiers(final GameData data) {
    for (final String frontierName : data.getProductionFrontierList().getProductionFrontierNames()) {
        final ProductionFrontier frontier = data.getProductionFrontierList().getProductionFrontier(frontierName);
        xmlfile.append("\n");
        xmlfile.append("        <productionFrontier name=\"").append(frontier.getName()).append("\">\n");
        for (final ProductionRule rule : frontier.getRules()) {
            xmlfile.append("            <frontierRules name=\"").append(rule.getName()).append("\"/>\n");
        }
        xmlfile.append("        </productionFrontier>\n");
    }
    xmlfile.append("\n");
}
Also used : ProductionRule(games.strategy.engine.data.ProductionRule) ProductionFrontier(games.strategy.engine.data.ProductionFrontier)

Example 7 with ProductionFrontier

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

the class ParserTest method testPlayerProduction.

@Test
public void testPlayerProduction() {
    final ProductionFrontier cf = gameData.getProductionFrontierList().getProductionFrontier("canProd");
    final PlayerID can = gameData.getPlayerList().getPlayerId("chretian");
    assertEquals(cf, can.getProductionFrontier());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) ProductionFrontier(games.strategy.engine.data.ProductionFrontier) Test(org.junit.jupiter.api.Test)

Example 8 with ProductionFrontier

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

the class TuvUtils method getResourceCostsForTuv.

/**
 * Return map where keys are unit types and values are resource costs of that unit type, based on a player.
 * Any production rule that produces multiple units
 * (like artillery in NWO, costs 7 but makes 2 artillery, meaning effective price is 3.5 each)
 * will have their costs rounded up on a per unit basis.
 * Therefore, this map should NOT be used for Purchasing information!
 */
public static Map<PlayerID, Map<UnitType, ResourceCollection>> getResourceCostsForTuv(final GameData data, final boolean includeAverageForMissingUnits) {
    final HashMap<PlayerID, Map<UnitType, ResourceCollection>> result = new LinkedHashMap<>();
    final Map<UnitType, ResourceCollection> average = includeAverageForMissingUnits ? TuvUtils.getResourceCostsForTuvForAllPlayersMergedAndAveraged(data) : new HashMap<>();
    final List<PlayerID> players = data.getPlayerList().getPlayers();
    players.add(PlayerID.NULL_PLAYERID);
    for (final PlayerID p : players) {
        final ProductionFrontier frontier = p.getProductionFrontier();
        // any one will do then
        if (frontier == null) {
            result.put(p, average);
            continue;
        }
        final Map<UnitType, ResourceCollection> current = result.computeIfAbsent(p, k -> new LinkedHashMap<>());
        for (final ProductionRule rule : frontier.getRules()) {
            if (rule == null || rule.getResults() == null || rule.getResults().isEmpty() || rule.getCosts() == null || rule.getCosts().isEmpty()) {
                continue;
            }
            final IntegerMap<NamedAttachable> unitMap = rule.getResults();
            final ResourceCollection costPerGroup = new ResourceCollection(data, rule.getCosts());
            final Set<UnitType> units = new HashSet<>();
            for (final NamedAttachable resourceOrUnit : unitMap.keySet()) {
                if (!(resourceOrUnit instanceof UnitType)) {
                    continue;
                }
                units.add((UnitType) resourceOrUnit);
            }
            if (units.isEmpty()) {
                continue;
            }
            final int totalProduced = unitMap.totalValues();
            if (totalProduced == 1) {
                current.put(units.iterator().next(), costPerGroup);
            } else if (totalProduced > 1) {
                costPerGroup.discount((double) 1 / (double) totalProduced);
                for (final UnitType ut : units) {
                    current.put(ut, costPerGroup);
                }
            }
        }
        // we will add any unit types not in our list, based on the list for everyone
        for (final UnitType ut : average.keySet()) {
            if (!current.keySet().contains(ut)) {
                current.put(ut, average.get(ut));
            }
        }
    }
    result.put(null, average);
    return result;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) NamedAttachable(games.strategy.engine.data.NamedAttachable) ProductionFrontier(games.strategy.engine.data.ProductionFrontier) LinkedHashMap(java.util.LinkedHashMap) ProductionRule(games.strategy.engine.data.ProductionRule) UnitType(games.strategy.engine.data.UnitType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IntegerMap(games.strategy.util.IntegerMap) ResourceCollection(games.strategy.engine.data.ResourceCollection) HashSet(java.util.HashSet)

Example 9 with ProductionFrontier

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

the class PlayerUnitsPanel method getUnitTypes.

/**
 * Return all the unit types available for the given player. A unit type is
 * available if the unit can be purchased or if a player has one on the map.
 */
private Collection<UnitType> getUnitTypes(final PlayerID player) {
    Collection<UnitType> unitTypes = new LinkedHashSet<>();
    final ProductionFrontier frontier = player.getProductionFrontier();
    if (frontier != null) {
        for (final ProductionRule rule : frontier) {
            for (final NamedAttachable type : rule.getResults().keySet()) {
                if (type instanceof UnitType) {
                    unitTypes.add((UnitType) type);
                }
            }
        }
    }
    for (final Territory t : data.getMap()) {
        for (final Unit u : t.getUnits()) {
            if (u.getOwner().equals(player)) {
                unitTypes.add(u.getType());
            }
        }
    }
    // Filter out anything like factories, or units that have no combat ability AND cannot be taken casualty
    unitTypes = CollectionUtils.getMatches(unitTypes, Matches.unitTypeCanBeInBattle(!defender, isLand, player, 1, false, false, false));
    return unitTypes;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Territory(games.strategy.engine.data.Territory) ProductionRule(games.strategy.engine.data.ProductionRule) NamedAttachable(games.strategy.engine.data.NamedAttachable) UnitType(games.strategy.engine.data.UnitType) Unit(games.strategy.engine.data.Unit) ProductionFrontier(games.strategy.engine.data.ProductionFrontier)

Example 10 with ProductionFrontier

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

the class IndustrialTechnologyAdvance method perform.

@Override
public void perform(final PlayerID id, final IDelegateBridge bridge) {
    final ProductionFrontier current = id.getProductionFrontier();
    // they already have it
    if (current.getName().endsWith("IndustrialTechnology")) {
        return;
    }
    final String industrialTechName = current.getName() + "IndustrialTechnology";
    final ProductionFrontier advancedTech = bridge.getData().getProductionFrontierList().getProductionFrontier(industrialTechName);
    // it doesnt exist, dont crash
    if (advancedTech == null) {
        Logger.getLogger(TechAdvance.class.getName()).log(Level.WARNING, "No tech named:" + industrialTechName + " not adding tech");
        return;
    }
    final Change prodChange = ChangeFactory.changeProductionFrontier(id, advancedTech);
    bridge.addChange(prodChange);
}
Also used : Change(games.strategy.engine.data.Change) ProductionFrontier(games.strategy.engine.data.ProductionFrontier)

Aggregations

ProductionFrontier (games.strategy.engine.data.ProductionFrontier)12 ProductionRule (games.strategy.engine.data.ProductionRule)7 UnitType (games.strategy.engine.data.UnitType)5 GameData (games.strategy.engine.data.GameData)4 NamedAttachable (games.strategy.engine.data.NamedAttachable)4 PlayerID (games.strategy.engine.data.PlayerID)4 Change (games.strategy.engine.data.Change)3 CompositeChange (games.strategy.engine.data.CompositeChange)3 IntegerMap (games.strategy.util.IntegerMap)3 HashSet (java.util.HashSet)3 GameParseException (games.strategy.engine.data.GameParseException)2 Resource (games.strategy.engine.data.Resource)2 Territory (games.strategy.engine.data.Territory)2 Unit (games.strategy.engine.data.Unit)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ClientLogger (games.strategy.debug.ClientLogger)1 Attachable (games.strategy.engine.data.Attachable)1 IAttachment (games.strategy.engine.data.IAttachment)1 MutableProperty (games.strategy.engine.data.MutableProperty)1 RelationshipType (games.strategy.engine.data.RelationshipType)1