Search in sources :

Example 1 with ObjectiveDummyDelegateBridge

use of games.strategy.triplea.ui.ObjectiveDummyDelegateBridge in project triplea by triplea-game.

the class EndTurnDelegate method findNationalObjectiveAndTriggerResources.

/**
 * Find the resources generated by national objectives and triggers that are currently met.
 */
public static IntegerMap<Resource> findNationalObjectiveAndTriggerResources(final PlayerID player, final GameData data) {
    final IDelegateBridge bridge = new ObjectiveDummyDelegateBridge(data);
    // Find and test all the conditions for triggers and national objectives
    final Set<TriggerAttachment> triggers = new HashSet<>();
    final List<RulesAttachment> objectives = new ArrayList<>();
    final HashMap<ICondition, Boolean> testedConditions = testNationalObjectivesAndTriggers(player, data, bridge, triggers, objectives);
    // Find triggers value
    final IntegerMap<Resource> resources;
    final boolean useTriggers = Properties.getTriggers(data);
    if (useTriggers && !triggers.isEmpty()) {
        final Set<TriggerAttachment> toFireTestedAndSatisfied = new HashSet<>(CollectionUtils.getMatches(triggers, AbstractTriggerAttachment.isSatisfiedMatch(testedConditions)));
        resources = TriggerAttachment.findResourceIncome(toFireTestedAndSatisfied, bridge);
    } else {
        resources = new IntegerMap<>();
    }
    // Find national objectives value
    int pus = 0;
    for (final RulesAttachment rule : objectives) {
        final int uses = rule.getUses();
        if (uses == 0 || !rule.isSatisfied(testedConditions)) {
            continue;
        }
        pus += (rule.getObjectiveValue() * rule.getEachMultiple() * Properties.getPuMultiplier(data));
    }
    resources.add(data.getResourceList().getResource(Constants.PUS), pus);
    return resources;
}
Also used : TriggerAttachment(games.strategy.triplea.attachments.TriggerAttachment) AbstractTriggerAttachment(games.strategy.triplea.attachments.AbstractTriggerAttachment) ArrayList(java.util.ArrayList) Resource(games.strategy.engine.data.Resource) ObjectiveDummyDelegateBridge(games.strategy.triplea.ui.ObjectiveDummyDelegateBridge) RulesAttachment(games.strategy.triplea.attachments.RulesAttachment) ICondition(games.strategy.triplea.attachments.ICondition) IDelegateBridge(games.strategy.engine.delegate.IDelegateBridge) HashSet(java.util.HashSet)

Aggregations

Resource (games.strategy.engine.data.Resource)1 IDelegateBridge (games.strategy.engine.delegate.IDelegateBridge)1 AbstractTriggerAttachment (games.strategy.triplea.attachments.AbstractTriggerAttachment)1 ICondition (games.strategy.triplea.attachments.ICondition)1 RulesAttachment (games.strategy.triplea.attachments.RulesAttachment)1 TriggerAttachment (games.strategy.triplea.attachments.TriggerAttachment)1 ObjectiveDummyDelegateBridge (games.strategy.triplea.ui.ObjectiveDummyDelegateBridge)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1