Search in sources :

Example 6 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class TriggerAttachment method triggerAvailableTechChange.

public static void triggerAvailableTechChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
    Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, techAvailableMatch());
    if (testWhen) {
        trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
    }
    if (testUses) {
        trigs = CollectionUtils.getMatches(trigs, availableUses);
    }
    for (final TriggerAttachment t : trigs) {
        if (testChance && !t.testChance(bridge)) {
            continue;
        }
        if (useUses) {
            t.use(bridge);
        }
        for (final PlayerID player : t.getPlayers()) {
            for (final String cat : t.getAvailableTech().keySet()) {
                final TechnologyFrontier tf = player.getTechnologyFrontierList().getTechnologyFrontier(cat);
                if (tf == null) {
                    throw new IllegalStateException("Triggers: tech category doesn't exist:" + cat + " for player:" + player);
                }
                for (final TechAdvance ta : t.getAvailableTech().get(cat).keySet()) {
                    if (t.getAvailableTech().get(cat).get(ta)) {
                        bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " gains access to " + ta);
                        final Change change = ChangeFactory.addAvailableTech(tf, ta, player);
                        bridge.addChange(change);
                    } else {
                        bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " loses access to " + ta);
                        final Change change = ChangeFactory.removeAvailableTech(tf, ta, player);
                        bridge.addChange(change);
                    }
                }
            }
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechAdvance(games.strategy.triplea.delegate.TechAdvance) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) CompositeChange(games.strategy.engine.data.CompositeChange) Change(games.strategy.engine.data.Change)

Example 7 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class TriggerAttachment method setTech.

private void setTech(final String techs) throws GameParseException {
    for (final String subString : techs.split(":")) {
        TechAdvance ta = getData().getTechnologyFrontier().getAdvanceByProperty(subString);
        if (ta == null) {
            ta = getData().getTechnologyFrontier().getAdvanceByName(subString);
        }
        if (ta == null) {
            throw new GameParseException("Technology not found :" + subString + thisErrorMsg());
        }
        m_tech.add(ta);
    }
}
Also used : TechAdvance(games.strategy.triplea.delegate.TechAdvance) GameParseException(games.strategy.engine.data.GameParseException)

Example 8 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class TriggerAttachment method triggerTechChange.

public static void triggerTechChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
    // final GameData data = aBridge.getData();
    Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, techMatch());
    if (testWhen) {
        trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
    }
    if (testUses) {
        trigs = CollectionUtils.getMatches(trigs, availableUses);
    }
    for (final TriggerAttachment t : trigs) {
        if (testChance && !t.testChance(bridge)) {
            continue;
        }
        if (useUses) {
            t.use(bridge);
        }
        for (final PlayerID player : t.getPlayers()) {
            for (final TechAdvance ta : t.getTech()) {
                if (ta.hasTech(TechAttachment.get(player))) {
                    continue;
                }
                bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " activates " + ta);
                TechTracker.addAdvance(player, bridge, ta);
            }
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechAdvance(games.strategy.triplea.delegate.TechAdvance)

Example 9 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance 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 10 with TechAdvance

use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.

the class TechAbilityAttachment method getAirborneTargettedByAa.

public static HashMap<String, HashSet<UnitType>> getAirborneTargettedByAa(final PlayerID player, final GameData data) {
    final HashMap<String, HashSet<UnitType>> airborneTargettedByAa = new HashMap<>();
    for (final TechAdvance ta : TechTracker.getCurrentTechAdvances(player, data)) {
        final TechAbilityAttachment taa = TechAbilityAttachment.get(ta);
        if (taa != null) {
            final Map<String, Set<UnitType>> mapAa = taa.getAirborneTargettedByAa();
            if (mapAa != null && !mapAa.isEmpty()) {
                for (final Entry<String, Set<UnitType>> entry : mapAa.entrySet()) {
                    final HashSet<UnitType> current = airborneTargettedByAa.getOrDefault(entry.getKey(), new HashSet<>());
                    current.addAll(entry.getValue());
                    airborneTargettedByAa.put(entry.getKey(), current);
                }
            }
        }
    }
    return airborneTargettedByAa;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) UnitType(games.strategy.engine.data.UnitType) GenericTechAdvance(games.strategy.triplea.delegate.GenericTechAdvance) TechAdvance(games.strategy.triplea.delegate.TechAdvance) HashSet(java.util.HashSet)

Aggregations

TechAdvance (games.strategy.triplea.delegate.TechAdvance)15 GenericTechAdvance (games.strategy.triplea.delegate.GenericTechAdvance)5 GameParseException (games.strategy.engine.data.GameParseException)3 PlayerID (games.strategy.engine.data.PlayerID)3 TechnologyFrontier (games.strategy.engine.data.TechnologyFrontier)3 UnitType (games.strategy.engine.data.UnitType)3 HashSet (java.util.HashSet)2 Element (org.w3c.dom.Element)2 Change (games.strategy.engine.data.Change)1 CompositeChange (games.strategy.engine.data.CompositeChange)1 Resource (games.strategy.engine.data.Resource)1 UnitTypeList (games.strategy.engine.data.UnitTypeList)1 InternalDoNotExport (games.strategy.engine.data.annotations.InternalDoNotExport)1 IStat (games.strategy.engine.stats.IStat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Set (java.util.Set)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1