use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.
the class ProductionPanel method getResources.
protected ResourceCollection getResources() {
if (bid) {
// TODO bid only allows you to add PU's to the bid... maybe upgrading Bids so multiple resources can be given?
final String propertyName = id.getName() + " bid";
final int bid = data.getProperties().get(propertyName, 0);
final ResourceCollection bidCollection = new ResourceCollection(data);
data.acquireReadLock();
try {
bidCollection.addResource(data.getResourceList().getResource(Constants.PUS), bid);
} finally {
data.releaseReadLock();
}
return bidCollection;
}
return (id == null || id.isNull()) ? new ResourceCollection(data) : id.getResources();
}
use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.
the class ProductionPanel method calculateLimits.
// This method can be overridden by subclasses
protected void calculateLimits() {
final ResourceCollection resources = getResources();
final ResourceCollection spent = new ResourceCollection(data);
int totalUnits = 0;
for (final Rule current : rules) {
spent.add(current.getCost(), current.getQuantity());
totalUnits += current.getQuantity() * current.getProductionRule().getResults().totalValues();
}
final ResourceCollection leftToSpend = resources.difference(spent);
setLeft(leftToSpend, totalUnits);
for (final Rule current : rules) {
int max = leftToSpend.fitsHowOften(current.getCost());
max += current.getQuantity();
current.setMax(max);
}
}
use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.
the class ProductionRepairPanel method calculateLimits.
protected void calculateLimits() {
// final IntegerMap<Resource> cost;
final ResourceCollection resources = getResources();
final ResourceCollection spent = new ResourceCollection(data);
for (final Rule current : rules) {
spent.add(current.getCost(), current.getQuantity());
}
final double discount = TechAbilityAttachment.getRepairDiscount(id, data);
if (discount != 1.0D) {
spent.discount(discount);
}
final ResourceCollection leftToSpend = resources.difference(spent);
setLeft(leftToSpend);
for (final Rule current : rules) {
int max = leftToSpend.fitsHowOften(current.getCost());
if (discount != 1.0F) {
max = (int) (max / discount);
}
max += current.getQuantity();
current.setMax(max);
}
}
Aggregations