use of games.strategy.triplea.delegate.GenericTechAdvance in project triplea by triplea-game.
the class GameParser method parseTechs.
private void parseTechs(final List<Element> elements, final TechnologyFrontier allTechsFrontier) {
for (final Element current : elements) {
final String name = current.getAttribute("name");
final String tech = current.getAttribute("tech");
TechAdvance ta;
if (tech.length() > 0) {
ta = new GenericTechAdvance(name, TechAdvance.findDefinedAdvanceAndCreateAdvance(tech, data), data);
} else {
try {
ta = TechAdvance.findDefinedAdvanceAndCreateAdvance(name, data);
} catch (final IllegalArgumentException e) {
ta = new GenericTechAdvance(name, null, data);
}
}
allTechsFrontier.addAdvance(ta);
}
}
use of games.strategy.triplea.delegate.GenericTechAdvance 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.
}
}
}
Aggregations