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");
}
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());
}
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;
}
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;
}
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);
}
Aggregations