Search in sources :

Example 21 with ResourceCollection

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();
}
Also used : ResourceCollection(games.strategy.engine.data.ResourceCollection)

Example 22 with ResourceCollection

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);
    }
}
Also used : ProductionRule(games.strategy.engine.data.ProductionRule) ResourceCollection(games.strategy.engine.data.ResourceCollection)

Example 23 with ResourceCollection

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);
    }
}
Also used : RepairRule(games.strategy.engine.data.RepairRule) ResourceCollection(games.strategy.engine.data.ResourceCollection)

Aggregations

ResourceCollection (games.strategy.engine.data.ResourceCollection)23 Resource (games.strategy.engine.data.Resource)7 Test (org.junit.jupiter.api.Test)6 PlayerID (games.strategy.engine.data.PlayerID)4 ProductionRule (games.strategy.engine.data.ProductionRule)4 IntegerMap (games.strategy.util.IntegerMap)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Territory (games.strategy.engine.data.Territory)3 Unit (games.strategy.engine.data.Unit)3 UnitType (games.strategy.engine.data.UnitType)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Map (java.util.Map)3 GameData (games.strategy.engine.data.GameData)2 NamedAttachable (games.strategy.engine.data.NamedAttachable)2 ProductionFrontier (games.strategy.engine.data.ProductionFrontier)2 RepairRule (games.strategy.engine.data.RepairRule)2 TripleAUnit (games.strategy.triplea.TripleAUnit)2 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)2