Search in sources :

Example 1 with IAttachment

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

the class AttachmentPropertyReset method perform.

@Override
public void perform(final GameData data) {
    final IAttachment attachment = m_attachedTo.getAttachment(m_attachmentName);
    attachment.getPropertyOrThrow(m_property).resetValue();
}
Also used : IAttachment(games.strategy.engine.data.IAttachment)

Example 2 with IAttachment

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

the class GameDataExporter method printAttachments.

private void printAttachments(final Tuple<IAttachment, ArrayList<Tuple<String, String>>> attachmentPlusValues) {
    final IAttachment attachment = attachmentPlusValues.getFirst();
    try {
        // TODO: none of the attachment exporter classes have been updated since TripleA version 1.3.2.2
        final String attachmentOptions;
        attachmentOptions = printAttachmentOptionsBasedOnOriginalXml(attachmentPlusValues.getSecond(), attachment);
        final NamedAttachable attachTo = (NamedAttachable) attachment.getAttachedTo();
        // TODO: keep this list updated
        String type = "";
        if (attachTo.getClass().equals(PlayerID.class)) {
            type = "player";
        }
        if (attachTo.getClass().equals(UnitType.class)) {
            type = "unitType";
        }
        if (attachTo.getClass().equals(Territory.class)) {
            type = "territory";
        }
        if (attachTo.getClass().equals(TerritoryEffect.class)) {
            type = "territoryEffect";
        }
        if (attachTo.getClass().equals(Resource.class)) {
            type = "resource";
        }
        if (attachTo.getClass().equals(RelationshipType.class)) {
            type = "relationship";
        }
        if (TechAdvance.class.isAssignableFrom(attachTo.getClass())) {
            type = "technology";
        }
        if (type.isEmpty()) {
            throw new AttachmentExportException("no attachmentType known for " + attachTo.getClass().getCanonicalName());
        }
        if (attachmentOptions.length() > 0) {
            xmlfile.append("        <attachment name=\"").append(attachment.getName()).append("\" attachTo=\"").append(attachTo.getName()).append("\" javaClass=\"").append(attachment.getClass().getCanonicalName()).append("\" type=\"").append(type).append("\">\n");
            xmlfile.append(attachmentOptions);
            xmlfile.append("        </attachment>\n");
        }
    } catch (final Exception e) {
        ClientLogger.logError("An Error occured whilst trying to print the Attachment \"" + attachment.getName() + "\"", e);
    }
}
Also used : NamedAttachable(games.strategy.engine.data.NamedAttachable) IAttachment(games.strategy.engine.data.IAttachment)

Example 3 with IAttachment

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

the class RulesAttachment method getNationalObjectives.

/**
 * Convenience method, for use returning any RulesAttachment that begins with "objectiveAttachment"
 * National Objectives are just conditions that also give money to a player during the end turn delegate. They can be
 * used for testing by
 * triggers as well.
 * Conditions that do not give money are not prefixed with "objectiveAttachment",
 * and the trigger attachment that uses these kinds of conditions gets them a different way because they are
 * specifically named inside
 * that trigger.
 */
public static Set<RulesAttachment> getNationalObjectives(final PlayerID player) {
    final Set<RulesAttachment> natObjs = new HashSet<>();
    final Map<String, IAttachment> map = player.getAttachments();
    for (final Map.Entry<String, IAttachment> entry : map.entrySet()) {
        final IAttachment attachment = entry.getValue();
        if (attachment instanceof RulesAttachment) {
            if (attachment.getName().startsWith(Constants.RULES_OBJECTIVE_PREFIX)) {
                natObjs.add((RulesAttachment) attachment);
            }
        }
    }
    return natObjs;
}
Also used : IAttachment(games.strategy.engine.data.IAttachment) GameMap(games.strategy.engine.data.GameMap) Map(java.util.Map) IntegerMap(games.strategy.util.IntegerMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashSet(java.util.HashSet)

Aggregations

IAttachment (games.strategy.engine.data.IAttachment)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 GameMap (games.strategy.engine.data.GameMap)1 NamedAttachable (games.strategy.engine.data.NamedAttachable)1 IntegerMap (games.strategy.util.IntegerMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1