use of games.strategy.engine.data.Resource in project triplea by triplea-game.
the class EditDelegate method changeTechTokens.
@Override
public String changeTechTokens(final PlayerID player, final int newTotal) {
final String result = checkEditMode();
if (result != null) {
return result;
}
final Resource techTokens = getData().getResourceList().getResource(Constants.TECH_TOKENS);
final int oldTotal = player.getResources().getQuantity(techTokens);
if (oldTotal == newTotal) {
return "New token total is unchanged";
}
if (newTotal < 0) {
return "New token total is invalid";
}
logEvent("Changing tech tokens for " + player.getName() + " from " + oldTotal + " to " + newTotal, null);
bridge.addChange(ChangeFactory.changeResourcesChange(player, techTokens, (newTotal - oldTotal)));
return null;
}
use of games.strategy.engine.data.Resource in project triplea by triplea-game.
the class ProPurchaseUtils method findMaxPurchaseDefenders.
public static List<Unit> findMaxPurchaseDefenders(final PlayerID player, final Territory t, final List<ProPurchaseOption> landPurchaseOptions) {
ProLogger.info("Find max purchase defenders for " + t.getName());
final GameData data = ProData.getData();
// Determine most cost efficient defender that can be produced in this territory
final Resource pus = data.getResourceList().getResource(Constants.PUS);
final int pusRemaining = player.getResources().getQuantity(pus);
final List<ProPurchaseOption> purchaseOptionsForTerritory = findPurchaseOptionsForTerritory(player, landPurchaseOptions, t, false);
ProPurchaseOption bestDefenseOption = null;
double maxDefenseEfficiency = 0;
for (final ProPurchaseOption ppo : purchaseOptionsForTerritory) {
if (ppo.getDefenseEfficiency() > maxDefenseEfficiency && ppo.getCost() <= pusRemaining) {
bestDefenseOption = ppo;
maxDefenseEfficiency = ppo.getDefenseEfficiency();
}
}
// Determine number of defenders I can purchase
final List<Unit> placeUnits = new ArrayList<>();
if (bestDefenseOption != null) {
ProLogger.debug("Best defense option: " + bestDefenseOption.getUnitType().getName());
int remainingUnitProduction = getUnitProduction(t, data, player);
int pusSpent = 0;
while (bestDefenseOption.getCost() <= (pusRemaining - pusSpent) && remainingUnitProduction >= bestDefenseOption.getQuantity()) {
// If out of PUs or production then break
// Create new temp defenders
pusSpent += bestDefenseOption.getCost();
remainingUnitProduction -= bestDefenseOption.getQuantity();
placeUnits.addAll(bestDefenseOption.getUnitType().create(bestDefenseOption.getQuantity(), player, true));
}
ProLogger.debug("Potential purchased defenders: " + placeUnits);
}
return placeUnits;
}
use of games.strategy.engine.data.Resource in project triplea by triplea-game.
the class AbstractEndTurnDelegateTest method testFindEstimatedIncome.
@Test
public void testFindEstimatedIncome() throws Exception {
final GameData global40Data = TestMapGameData.GLOBAL1940.getGameData();
final PlayerID germans = GameDataTestUtil.germans(global40Data);
final IntegerMap<Resource> results = AbstractEndTurnDelegate.findEstimatedIncome(germans, global40Data);
final int pus = results.getInt(new Resource(Constants.PUS, global40Data));
assertEquals(40, pus);
}
use of games.strategy.engine.data.Resource in project triplea by triplea-game.
the class MapRouteDrawer method findMovementLeftImageWidth.
private static int findMovementLeftImageWidth(final String curMovement, final String unitMovementLeft, final ResourceCollection movementFuelCost) {
// Create temp graphics to calculate necessary image width based on font sizes
final BufferedImage tempImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
final Graphics2D tempGraphics = tempImage.createGraphics();
tempGraphics.setFont(MESSAGE_FONT);
final FontMetrics fontMetrics = tempGraphics.getFontMetrics();
// Determine widths of each element to draw
int imageWidth = 2 * MESSAGE_PADDING;
imageWidth += fontMetrics.stringWidth(curMovement);
if (!unitMovementLeft.isEmpty()) {
imageWidth += fontMetrics.stringWidth(unitMovementLeft);
for (final Resource resource : movementFuelCost.getResourcesCopy().keySet()) {
imageWidth += MESSAGE_TEXT_SPACING;
imageWidth += fontMetrics.stringWidth("-" + movementFuelCost.getQuantity(resource));
imageWidth += ResourceImageFactory.IMAGE_SIZE;
}
}
tempGraphics.dispose();
return imageWidth;
}
use of games.strategy.engine.data.Resource in project triplea by triplea-game.
the class EconomyPanel method initLayout.
@Override
protected void initLayout() {
setLayout(new GridLayout(1, 1));
resourceModel = new ResourceTableModel();
final JTable table = new JTable(resourceModel);
table.getTableHeader().setReorderingAllowed(false);
final TableColumn column = table.getColumnModel().getColumn(0);
column.setPreferredWidth(175);
for (int i = 1; i < resourceModel.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setHeaderRenderer(new DefaultTableCellRenderer());
final JLabel label = (JLabel) table.getColumnModel().getColumn(i).getHeaderRenderer();
final Resource resource = resourceStats.get(i - 1).resource;
try {
label.setIcon(uiContext.getResourceImageFactory().getIcon(resource, false));
} catch (final IllegalStateException e) {
// ignore missing resource image
}
}
final JScrollPane scroll = new JScrollPane(table);
add(scroll);
}
Aggregations