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);
}
}
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;
}
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);
}
}
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;
}
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());
}
Aggregations