use of games.strategy.triplea.attachments.UnitAttachment in project triplea by triplea-game.
the class DiceRollTest method testVariableArtillerySupport.
@Test
public void testVariableArtillerySupport() {
final Territory westRussia = gameData.getMap().getTerritory("West Russia");
final MockBattle battle = new MockBattle(westRussia);
final PlayerID russians = GameDataTestUtil.russians(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(russians);
// Add 1 artillery
final UnitType artillery = gameData.getUnitTypeList().getUnitType(Constants.UNIT_TYPE_ARTILLERY);
final List<Unit> units = artillery.create(1, russians);
// Set the supported unit count
for (final Unit unit : units) {
final UnitAttachment ua = UnitAttachment.get(unit.getType());
ua.setUnitSupportCount("2");
}
// Now add the infantry
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
units.addAll(infantryType.create(2, russians));
// artillery supported infantry and art attack at 1 (0 based)
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1, 1, 1 }));
final DiceRoll roll = DiceRoll.rollDice(units, false, russians, bridge, battle, "", TerritoryEffectHelper.getEffects(westRussia), null);
assertThat(roll.getHits(), is(3));
}
use of games.strategy.triplea.attachments.UnitAttachment in project triplea by triplea-game.
the class InitialSetup method run.
protected void run(final PrintGenerationData printData, final boolean useOriginalState) {
final GameData gameData = printData.getData();
if (useOriginalState) {
final HistoryNode root = (HistoryNode) gameData.getHistory().getRoot();
gameData.getHistory().gotoNode(root);
}
for (final UnitType currentType : gameData.getUnitTypeList()) {
final UnitAttachment currentTypeUnitAttachment = UnitAttachment.get(currentType);
unitInfoMap.put(currentType, currentTypeUnitAttachment);
}
new UnitInformation().saveToFile(printData, unitInfoMap);
for (final PlayerID currentPlayer : gameData.getPlayerList()) {
new CountryChart().saveToFile(currentPlayer, printData);
}
new PuInfo().saveToFile(printData);
try {
new PlayerOrder().saveToFile(printData);
new PuChart(printData).saveToFile();
} catch (final IOException e) {
ClientLogger.logQuietly("Failed to save print generation data", e);
}
}
use of games.strategy.triplea.attachments.UnitAttachment in project triplea by triplea-game.
the class ProTechAi method allAirStrength.
/**
* Determine the strength of a collection of airUnits
* Caller should guarantee units are all air.
*/
private static float allAirStrength(final Collection<Unit> units) {
float airstrength = 0.0F;
for (final Unit u : units) {
final UnitAttachment unitAttachment = UnitAttachment.get(u.getType());
airstrength += 1.00F;
airstrength += unitAttachment.getAttack(u.getOwner());
}
return airstrength;
}
use of games.strategy.triplea.attachments.UnitAttachment in project triplea by triplea-game.
the class TripleAUnit method getHowMuchCanUnitProduce.
public static int getHowMuchCanUnitProduce(final Unit u, final Territory producer, final PlayerID player, final GameData data, final boolean accountForDamage, final boolean mathMaxZero) {
if (u == null) {
return 0;
}
if (!Matches.unitCanProduceUnits().test(u)) {
return 0;
}
final UnitAttachment ua = UnitAttachment.get(u.getType());
final TripleAUnit taUnit = (TripleAUnit) u;
final TerritoryAttachment ta = TerritoryAttachment.get(producer);
int territoryProduction = 0;
int territoryUnitProduction = 0;
if (ta != null) {
territoryProduction = ta.getProduction();
territoryUnitProduction = ta.getUnitProduction();
}
int productionCapacity;
if (accountForDamage) {
if (Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(data)) {
if (ua.getCanProduceXUnits() < 0) {
// we could use territoryUnitProduction OR
// territoryProduction if we wanted to, however we should
// change damage to be based on whichever we choose.
productionCapacity = territoryUnitProduction - taUnit.getUnitDamage();
} else {
productionCapacity = ua.getCanProduceXUnits() - taUnit.getUnitDamage();
}
} else {
productionCapacity = territoryProduction;
if (productionCapacity < 1) {
productionCapacity = (Properties.getWW2V2(data) || Properties.getWW2V3(data)) ? 0 : 1;
}
}
} else {
if (ua.getCanProduceXUnits() < 0 && !Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(data)) {
productionCapacity = territoryProduction;
} else if (ua.getCanProduceXUnits() < 0 && Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(data)) {
productionCapacity = territoryUnitProduction;
} else {
productionCapacity = ua.getCanProduceXUnits();
}
if (productionCapacity < 1 && !Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(data)) {
productionCapacity = (Properties.getWW2V2(data) || Properties.getWW2V3(data)) ? 0 : 1;
}
}
// Increase production if have industrial technology
if (territoryProduction >= TechAbilityAttachment.getMinimumTerritoryValueForProductionBonus(player, data)) {
productionCapacity += TechAbilityAttachment.getProductionBonus(u.getType(), player, data);
}
return mathMaxZero ? Math.max(0, productionCapacity) : productionCapacity;
}
use of games.strategy.triplea.attachments.UnitAttachment in project triplea by triplea-game.
the class TripleAUnit method getHowMuchDamageCanThisUnitTakeTotal.
/**
* How much damage is the max this unit can take, accounting for territory, etc.
* Will return -1 if the unit is of the type that cannot be damaged
*/
public int getHowMuchDamageCanThisUnitTakeTotal(final Unit u, final Territory t) {
if (!Matches.unitCanBeDamaged().test(u)) {
return -1;
}
final UnitAttachment ua = UnitAttachment.get(u.getType());
final int territoryUnitProduction = TerritoryAttachment.getUnitProduction(t);
if (Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(u.getData())) {
if (ua.getMaxDamage() <= 0) {
// can use "production" or "unitProduction"
return territoryUnitProduction * 2;
}
if (Matches.unitCanProduceUnits().test(u)) {
// can use "production" or "unitProduction"
return (ua.getCanProduceXUnits() < 0) ? territoryUnitProduction * ua.getMaxDamage() : ua.getMaxDamage();
}
return ua.getMaxDamage();
}
return Integer.MAX_VALUE;
}
Aggregations