use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.
the class ChangeResourceChange method perform.
@Override
protected void perform(final GameData data) {
final Resource resource = data.getResourceList().getResource(m_resource);
final ResourceCollection resources = data.getPlayerList().getPlayerId(m_player).getResources();
if (m_quantity > 0) {
resources.addResource(resource, m_quantity);
} else if (m_quantity < 0) {
resources.removeResource(resource, -m_quantity);
}
}
use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.
the class EndTurnDelegate method getResourceProduction.
/**
* Since territory resource may contain any resource except PUs (PUs use "getProduction" instead),
* we will now figure out the total production of non-PUs resources.
*/
public static IntegerMap<Resource> getResourceProduction(final Collection<Territory> territories, final GameData data) {
final IntegerMap<Resource> resources = new IntegerMap<>();
for (final Territory current : territories) {
final TerritoryAttachment attachment = TerritoryAttachment.get(current);
if (attachment == null) {
throw new IllegalStateException("No attachment for owned territory:" + current.getName());
}
final ResourceCollection toAdd = attachment.getResources();
if (toAdd == null) {
continue;
}
// Match will check if territory is originally owned convoy center, or if contested
if (Matches.territoryCanCollectIncomeFrom(current.getOwner(), data).test(current)) {
resources.add(toAdd.getResourcesCopy());
}
}
return resources;
}
use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.
the class ResourceCollectionUtils method exclude.
/**
* Returns a copy of the specified resource collection filtered to exclude the blacklisted resources.
*
* @param unfiltered The resource collection to filter; must not be {@code null}.
* @param resources The blacklisted resources to exclude; must not be {@code null}.
*
* @return The filtered resource collection; never {@code null}.
*
* @throws IllegalArgumentException If {@code resources} contains a {@code null} element.
*/
public static ResourceCollection exclude(final ResourceCollection unfiltered, final Resource... resources) {
checkNotNull(unfiltered);
checkNotNull(resources);
checkArgument(Arrays.stream(resources).noneMatch(Objects::isNull), "resources must not contain null");
final ResourceCollection filtered = new ResourceCollection(unfiltered);
Arrays.stream(resources).forEach(filtered::removeAllOfResource);
return filtered;
}
use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.
the class DoesNothingAi method endTurn.
@Override
protected void endTurn(final IAbstractForumPosterDelegate endTurnForumPosterDelegate, final GameData data, final PlayerID player) {
// destroy whatever we have
final ResourceCollection resourceCollection = player.getResources();
final Change removeChange = ChangeFactory.removeResourceCollection(player, resourceCollection);
// shameless cheating... (do NOT do this, normally you are never supposed to access the IDelegateBridge from outside
// of a delegate)
final IDelegateBridge bridge = endTurnForumPosterDelegate.getBridge();
// resourceCollection is not yet a valid renderingObject
bridge.getHistoryWriter().startEvent(player.getName() + " removes resources: " + resourceCollection, null);
bridge.addChange(removeChange);
}
use of games.strategy.engine.data.ResourceCollection in project triplea by triplea-game.
the class ResourceCollectionUtilsTest method testExcludeByNames_ShouldExcludeSpecifiedResources.
@Test
public void testExcludeByNames_ShouldExcludeSpecifiedResources() {
givenGameResources(pus, techTokens, vps);
final ResourceCollection unfiltered = createResourceCollection(pus, techTokens, vps);
final ResourceCollection filtered = ResourceCollectionUtils.exclude(unfiltered, pus.getName(), vps.getName());
assertThat(filtered.getQuantity(pus), is(0));
assertThat(filtered.getQuantity(techTokens), is(unfiltered.getQuantity(techTokens)));
assertThat(filtered.getQuantity(vps), is(0));
}
Aggregations