Search in sources :

Example 1 with InternalDoNotExport

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

the class TerritoryEffectAttachment method setCombatEffect.

@InternalDoNotExport
private void setCombatEffect(final String combatEffect, final boolean defending) throws GameParseException {
    final String[] s = combatEffect.split(":");
    if (s.length < 2) {
        throw new GameParseException("combatDefenseEffect and combatOffenseEffect must have a count and at least one unitType" + thisErrorMsg());
    }
    final Iterator<String> iter = Arrays.asList(s).iterator();
    final int effect = getInt(iter.next());
    while (iter.hasNext()) {
        final String unitTypeToProduce = iter.next();
        final UnitType ut = getData().getUnitTypeList().getUnitType(unitTypeToProduce);
        if (ut == null) {
            throw new GameParseException("No unit called:" + unitTypeToProduce + thisErrorMsg());
        }
        if (defending) {
            m_combatDefenseEffect.put(ut, effect);
        } else {
            m_combatOffenseEffect.put(ut, effect);
        }
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GameParseException(games.strategy.engine.data.GameParseException) InternalDoNotExport(games.strategy.engine.data.annotations.InternalDoNotExport)

Example 2 with InternalDoNotExport

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

the class TechAbilityAttachment method setDefaultTechnologyAttachments.

/**
 * Must be done only in GameParser, and only after we have already parsed ALL technologies, attachments, and game
 * options/properties.
 */
@InternalDoNotExport
public static void setDefaultTechnologyAttachments(final GameData data) throws GameParseException {
    // non-default tech are ignored.
    for (final TechAdvance techAdvance : TechAdvance.getTechAdvances(data)) {
        final TechAdvance ta;
        if (techAdvance instanceof GenericTechAdvance) {
            final TechAdvance adv = ((GenericTechAdvance) techAdvance).getAdvance();
            if (adv != null) {
                ta = adv;
            } else {
                continue;
            }
        } else {
            ta = techAdvance;
        }
        final String propertyString = ta.getProperty();
        TechAbilityAttachment taa = TechAbilityAttachment.get(ta);
        if (taa == null) {
            // perhaps just the easy ones, of air, land, and sea?
            if (propertyString.equals(TechAdvance.TECH_PROPERTY_LONG_RANGE_AIRCRAFT)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                final List<UnitType> allAir = CollectionUtils.getMatches(data.getUnitTypeList().getAllUnitTypes(), Matches.unitTypeIsAir());
                for (final UnitType air : allAir) {
                    taa.setMovementBonus("2:" + air.getName());
                }
            } else if (propertyString.equals(TechAdvance.TECH_PROPERTY_AA_RADAR)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                final List<UnitType> allAa = CollectionUtils.getMatches(data.getUnitTypeList().getAllUnitTypes(), Matches.unitTypeIsAaForAnything());
                for (final UnitType aa : allAa) {
                    taa.setRadarBonus("1:" + aa.getName());
                }
            } else if (propertyString.equals(TechAdvance.TECH_PROPERTY_SUPER_SUBS)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                final List<UnitType> allSubs = CollectionUtils.getMatches(data.getUnitTypeList().getAllUnitTypes(), Matches.unitTypeIsSub());
                for (final UnitType sub : allSubs) {
                    taa.setAttackBonus("1:" + sub.getName());
                }
            } else if (propertyString.equals(TechAdvance.TECH_PROPERTY_JET_POWER)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                final List<UnitType> allJets = CollectionUtils.getMatches(data.getUnitTypeList().getAllUnitTypes(), Matches.unitTypeIsAir().and(Matches.unitTypeIsStrategicBomber().negate()));
                final boolean ww2v3TechModel = Properties.getWW2V3TechModel(data);
                for (final UnitType jet : allJets) {
                    if (ww2v3TechModel) {
                        taa.setAttackBonus("1:" + jet.getName());
                        taa.setAirAttackBonus("1:" + jet.getName());
                    } else {
                        taa.setDefenseBonus("1:" + jet.getName());
                        taa.setAirDefenseBonus("1:" + jet.getName());
                    }
                }
            } else if (propertyString.equals(TechAdvance.TECH_PROPERTY_INCREASED_FACTORY_PRODUCTION)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                final List<UnitType> allFactories = CollectionUtils.getMatches(data.getUnitTypeList().getAllUnitTypes(), Matches.unitTypeCanProduceUnits());
                for (final UnitType factory : allFactories) {
                    taa.setProductionBonus("2:" + factory.getName());
                    taa.setMinimumTerritoryValueForProductionBonus("3");
                    // means a 50% discount, which is half price
                    taa.setRepairDiscount("50");
                }
            } else if (propertyString.equals(TechAdvance.TECH_PROPERTY_WAR_BONDS)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                taa.setWarBondDiceSides(Integer.toString(data.getDiceSides()));
                taa.setWarBondDiceNumber("1");
            } else if (propertyString.equals(TechAdvance.TECH_PROPERTY_ROCKETS)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                final List<UnitType> allRockets = CollectionUtils.getMatches(data.getUnitTypeList().getAllUnitTypes(), Matches.unitTypeIsRocket());
                for (final UnitType rocket : allRockets) {
                    taa.setRocketDiceNumber("1:" + rocket.getName());
                }
                taa.setRocketDistance("3");
                taa.setRocketNumberPerTerritory("1");
            } else if (propertyString.equals(TechAdvance.TECH_PROPERTY_DESTROYER_BOMBARD)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                final List<UnitType> allDestroyers = CollectionUtils.getMatches(data.getUnitTypeList().getAllUnitTypes(), Matches.unitTypeIsDestroyer());
                for (final UnitType destroyer : allDestroyers) {
                    taa.setUnitAbilitiesGained(destroyer.getName() + ":" + ABILITY_CAN_BOMBARD);
                }
            } else if (propertyString.equals(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER)) {
                taa = new TechAbilityAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, ta, data);
                ta.addAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME, taa);
                final List<UnitType> allBombers = CollectionUtils.getMatches(data.getUnitTypeList().getAllUnitTypes(), Matches.unitTypeIsStrategicBomber());
                final int heavyBomberDiceRollsTotal = Properties.getHeavyBomberDiceRolls(data);
                final boolean heavyBombersLhtr = Properties.getLhtrHeavyBombers(data);
                for (final UnitType bomber : allBombers) {
                    // TODO: The bomber dice rolls get set when the xml is parsed.
                    // we subtract the base rolls to get the bonus
                    final int heavyBomberDiceRollsBonus = heavyBomberDiceRollsTotal - UnitAttachment.get(bomber).getAttackRolls(PlayerID.NULL_PLAYERID);
                    taa.setAttackRollsBonus(heavyBomberDiceRollsBonus + ":" + bomber.getName());
                    if (heavyBombersLhtr) {
                        // TODO: this all happens WHEN the xml is parsed. Which means if the user changes the game options, this
                        // does not get changed.
                        // (meaning, turning on LHTR bombers will not result in this bonus damage, etc. It would have to start on,
                        // in the xml.)
                        taa.setDefenseRollsBonus(heavyBomberDiceRollsBonus + ":" + bomber.getName());
                        // LHTR adds 1 to base roll
                        taa.setBombingBonus("1:" + bomber.getName());
                    }
                }
            }
        // The following technologies should NOT have ability attachments for them:
        // shipyards and industrialTechnology = because it is better to use a Trigger to change player's production
        // improvedArtillerySupport = because it is already completely atomized and controlled through support
        // attachments
        // paratroopers = because it is already completely atomized and controlled through unit attachments + game
        // options
        // mechanizedInfantry = because it is already completely atomized and controlled through unit attachments
        // IF one of the above named techs changes what it does in a future version of a&a, and the change is large
        // enough or different
        // enough that it cannot be done easily with a new game option,
        // then it is better to create a new tech rather than change the old one, and give the new one a new name, like
        // paratroopers2 or
        // paratroopersAttack or Airborne_Forces, or some crap.
        }
    }
}
Also used : UnitType(games.strategy.engine.data.UnitType) GenericTechAdvance(games.strategy.triplea.delegate.GenericTechAdvance) TechAdvance(games.strategy.triplea.delegate.TechAdvance) List(java.util.List) GenericTechAdvance(games.strategy.triplea.delegate.GenericTechAdvance) InternalDoNotExport(games.strategy.engine.data.annotations.InternalDoNotExport)

Example 3 with InternalDoNotExport

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

the class UnitSupportAttachment method getTargets.

@InternalDoNotExport
private static Set<UnitType> getTargets(final GameData data) {
    Set<UnitType> types = null;
    for (final UnitSupportAttachment rule : get(data)) {
        if (rule.getBonusType().equals(Constants.OLD_ART_RULE_NAME)) {
            types = rule.getUnitType();
            if (rule.getName().startsWith(Constants.SUPPORT_RULE_NAME_OLD_TEMP_FIRST)) {
                // remove it because it is a "first", which is just a temporary one made to hold target info. what a hack.
                final UnitType attachedTo = (UnitType) rule.getAttachedTo();
                attachedTo.removeAttachment(rule.getName());
                rule.setAttachedTo(null);
            }
        }
    }
    return types;
}
Also used : UnitType(games.strategy.engine.data.UnitType) InternalDoNotExport(games.strategy.engine.data.annotations.InternalDoNotExport)

Aggregations

UnitType (games.strategy.engine.data.UnitType)3 InternalDoNotExport (games.strategy.engine.data.annotations.InternalDoNotExport)3 GameParseException (games.strategy.engine.data.GameParseException)1 GenericTechAdvance (games.strategy.triplea.delegate.GenericTechAdvance)1 TechAdvance (games.strategy.triplea.delegate.TechAdvance)1 List (java.util.List)1