Search in sources :

Example 31 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class TechnologyDelegate method chargeForTechRolls.

private void chargeForTechRolls(final int rolls, final IntegerMap<PlayerID> whoPaysHowMuch) {
    final Resource pus = getData().getResourceList().getResource(Constants.PUS);
    int cost = rolls * getTechCost();
    if (whoPaysHowMuch == null || whoPaysHowMuch.isEmpty()) {
        final String transcriptText = bridge.getPlayerId().getName() + " spend " + cost + " on tech rolls";
        bridge.getHistoryWriter().startEvent(transcriptText);
        final Change charge = ChangeFactory.changeResourcesChange(bridge.getPlayerId(), pus, -cost);
        bridge.addChange(charge);
    } else {
        for (final Entry<PlayerID, Integer> entry : whoPaysHowMuch.entrySet()) {
            final PlayerID p = entry.getKey();
            final int pays = Math.min(cost, entry.getValue());
            if (pays <= 0) {
                continue;
            }
            cost -= pays;
            final String transcriptText = p.getName() + " spend " + pays + " on tech rolls";
            bridge.getHistoryWriter().startEvent(transcriptText);
            final Change charge = ChangeFactory.changeResourcesChange(p, pus, -pays);
            bridge.addChange(charge);
        }
    }
    if (isWW2V3TechModel()) {
        final Resource tokens = getData().getResourceList().getResource(Constants.TECH_TOKENS);
        final Change newTokens = ChangeFactory.changeResourcesChange(bridge.getPlayerId(), tokens, rolls);
        bridge.addChange(newTokens);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Resource(games.strategy.engine.data.Resource) Change(games.strategy.engine.data.Change)

Example 32 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class TechnologyDelegate method delegateCurrentlyRequiresUserInput.

@Override
public boolean delegateCurrentlyRequiresUserInput() {
    if (!Properties.getTechDevelopment(getData())) {
        return false;
    }
    if (!TerritoryAttachment.doWeHaveEnoughCapitalsToProduce(player, getData())) {
        return false;
    }
    if (Properties.getWW2V3TechModel(getData())) {
        final Resource techtokens = getData().getResourceList().getResource(Constants.TECH_TOKENS);
        if (techtokens != null) {
            final int techTokens = player.getResources().getQuantity(techtokens);
            if (techTokens > 0) {
                return true;
            }
        }
    }
    final int techCost = TechTracker.getTechCost(player);
    int money = player.getResources().getQuantity(Constants.PUS);
    if (money < techCost) {
        final PlayerAttachment pa = PlayerAttachment.get(player);
        if (pa == null) {
            return false;
        }
        final Collection<PlayerID> helpPay = pa.getHelpPayTechCost();
        if (helpPay == null || helpPay.isEmpty()) {
            return false;
        }
        for (final PlayerID p : helpPay) {
            money += p.getResources().getQuantity(Constants.PUS);
        }
        return money >= techCost;
    }
    return true;
}
Also used : PlayerAttachment(games.strategy.triplea.attachments.PlayerAttachment) PlayerID(games.strategy.engine.data.PlayerID) Resource(games.strategy.engine.data.Resource)

Example 33 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class UserActionDelegate method chargeForAction.

/**
 * Subtract money from the players wallet
 *
 * @param uaa
 *        the UserActionAttachment this the money is charged for.
 */
private void chargeForAction(final UserActionAttachment uaa) {
    final Resource pus = getData().getResourceList().getResource(Constants.PUS);
    final int cost = uaa.getCostPu();
    if (cost > 0) {
        // don't notify user of spending money anymore
        // notifyMoney(uaa, true);
        final String transcriptText = bridge.getPlayerId().getName() + " spend " + cost + " PU on User Action: " + MyFormatter.attachmentNameToText(uaa.getName());
        bridge.getHistoryWriter().startEvent(transcriptText);
        final Change charge = ChangeFactory.changeResourcesChange(bridge.getPlayerId(), pus, -cost);
        bridge.addChange(charge);
    } else {
        final String transcriptText = bridge.getPlayerId().getName() + " takes action: " + MyFormatter.attachmentNameToText(uaa.getName());
        // we must start an event anyway
        bridge.getHistoryWriter().startEvent(transcriptText);
    }
}
Also used : Resource(games.strategy.engine.data.Resource) Change(games.strategy.engine.data.Change)

Example 34 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class UserActionDelegate method checkEnoughMoney.

/**
 * @param uaa
 *        The UserActionAttachment the player should be charged for.
 * @return false if the player can't afford the action
 */
private boolean checkEnoughMoney(final UserActionAttachment uaa) {
    final Resource pus = getData().getResourceList().getResource(Constants.PUS);
    final int cost = uaa.getCostPu();
    final int has = bridge.getPlayerId().getResources().getQuantity(pus);
    return has >= cost;
}
Also used : Resource(games.strategy.engine.data.Resource)

Example 35 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class HistoryLog method printProductionSummary.

public void printProductionSummary(final GameData data) {
    final PrintWriter logWriter = printWriter;
    Collection<PlayerID> players;
    Resource pus;
    data.acquireReadLock();
    try {
        pus = data.getResourceList().getResource(Constants.PUS);
        players = data.getPlayerList().getPlayers();
    } finally {
        data.releaseReadLock();
    }
    if (pus == null) {
        return;
    }
    logWriter.println("Production/PUs Summary :\n");
    for (final PlayerID player : players) {
        final int pusQuantity = player.getResources().getQuantity(pus);
        final int production = getProduction(player, data);
        logWriter.println("    " + player.getName() + " : " + production + " / " + pusQuantity);
    }
    logWriter.println();
    logWriter.println();
    textArea.setText(stringWriter.toString());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Resource(games.strategy.engine.data.Resource) PrintWriter(java.io.PrintWriter)

Aggregations

Resource (games.strategy.engine.data.Resource)71 PlayerID (games.strategy.engine.data.PlayerID)22 IntegerMap (games.strategy.util.IntegerMap)16 GameData (games.strategy.engine.data.GameData)15 Unit (games.strategy.engine.data.Unit)15 ArrayList (java.util.ArrayList)15 Territory (games.strategy.engine.data.Territory)14 UnitType (games.strategy.engine.data.UnitType)13 Change (games.strategy.engine.data.Change)11 CompositeChange (games.strategy.engine.data.CompositeChange)11 ProductionRule (games.strategy.engine.data.ProductionRule)10 TripleAUnit (games.strategy.triplea.TripleAUnit)10 NamedAttachable (games.strategy.engine.data.NamedAttachable)9 ResourceCollection (games.strategy.engine.data.ResourceCollection)8 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)7 GameParseException (games.strategy.engine.data.GameParseException)6 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Test (org.junit.jupiter.api.Test)5