Search in sources :

Example 51 with UnitAttachment

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));
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Test(org.junit.jupiter.api.Test)

Example 52 with UnitAttachment

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);
    }
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) HistoryNode(games.strategy.engine.history.HistoryNode) UnitType(games.strategy.engine.data.UnitType) IOException(java.io.IOException)

Example 53 with UnitAttachment

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;
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) Unit(games.strategy.engine.data.Unit)

Example 54 with UnitAttachment

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;
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment)

Example 55 with UnitAttachment

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;
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment)

Aggregations

UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)60 Unit (games.strategy.engine.data.Unit)45 ArrayList (java.util.ArrayList)25 TripleAUnit (games.strategy.triplea.TripleAUnit)23 UnitType (games.strategy.engine.data.UnitType)20 GameData (games.strategy.engine.data.GameData)19 Territory (games.strategy.engine.data.Territory)19 PlayerID (games.strategy.engine.data.PlayerID)12 CompositeChange (games.strategy.engine.data.CompositeChange)8 TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)7 IntegerMap (games.strategy.util.IntegerMap)6 Collection (java.util.Collection)6 Set (java.util.Set)6 Change (games.strategy.engine.data.Change)5 Resource (games.strategy.engine.data.Resource)5 Tuple (games.strategy.util.Tuple)5 HashSet (java.util.HashSet)5 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)4 Route (games.strategy.engine.data.Route)4 List (java.util.List)4