Trigger - Intro

Translated by Wiesl
Basic Structure[ Copy codeblock ]
<Asset> <Template>Trigger</Template> <Values> <Standard /> <Trigger> <TriggerCondition> //a condition is expected at this place </TriggerCondition> <TriggerActions> <Item> //a condition is expected at this place </Item> </TriggerAction> </Trigger> <TriggerSetup /> </Values> </Asset>

A very simple but powerful concept, which exists since Anno 2205, are triggers.
Discovered by Fishboss in summer 2019, the unlock system is based on triggerable events, that are triggered as soon as their condition is met. Once triggered, they unlock everything they are supposed to unlock and stay triggered.
So a trigger implements the following concept: If the condition is met, it executes one or more actions.

There are a number of predefined conditions and actions in the templates.xml You are limited to these (there is also old code from Anno 2205) - but they can do a lot and are very versatile. These conditions and actions can be combined arbitrarily. For example, you can link the activation of the heavy AI in the AI shipyard to the construction of a building (e.g. an embassy) instead of a reached population. The actions of a trigger are triggered in their order.

Registering triggers

Translated by Wiesl

Imagine the following problem: I wrote a trigger to unlock the bank at 1 engineer and triggered it, unlocked the bank and made the residents happy. But in retrospect I realize that I also want to have the clubhouse from 1 engineer, so I add it to my trigger. If I would reload my savegame, I will notice that it is not activated at all, although I already have 1 engineer?
Why is that so?

Anno manages the triggers in an internal event list, in which a trigger must first be registered. When registering the trigger, the asset is parsed and an event is created for Anno based on it. In our case: 1 engineer reached -> unlock bank. This event gets the GUID of the trigger as ID. If Event 42 is already in the event list, no more changes are made to this event, no matter if we change the trigger. If Event 42 is triggered in the event list, the game remembers this. No matter what we change now on the asset with GUID = 42, the game will not re-register it by itself.

Normally, assets with the template trigger are automatically registered the first time they are used, unless we turn it off. (see below)
Then we have to re-register manually. For testing purposes, it is usually quite helpful to simply change the GUID of the asset, because Anno will then see the trigger as a new event and re-read it accordingly. For the manual registration we now have to do a few steps:

A few tricks using triggers

Translated by Wiesl

To register a trigger not automatically: under TriggerSetup you can disable the automatic registration of the trigger

Register a trigger with another trigger: Via the ActionRegisterTrigger - This works even if the trigger has already been triggered! After the new registration the trigger can be triggered again.


Let a trigger reset itself: Via the ActionResetTrigger

Register a trigger only when a certain condition is met: This is done by a SubTrigger in the SubTriggers container. This SubTrigger must be registered under Values/Trigger.

SubTrigger[ Copy codeblock ]
<SubTriggers> <Item> <SubTrigger> <Template>AutoCreateTrigger</Template> <Values> <Trigger> <TriggerCondition> //a condition is expected at this place </TriggerCondition> </Trigger> </Values> </SubTrigger> </Item> </SubTriggers> <SubTriggers> <Item> <SubTrigger> <Template>AutoCreateTrigger</Template> <Values> <Trigger> <TriggerCondition> //a condition is expected at this place </TriggerCondition> </Trigger> </Values> </SubTrigger> </Item> </SubTriggers> <SubTriggers> <Item> <SubTrigger> <Template>AutoCreateTrigger</Template> <Values> <Trigger> <TriggerCondition> //a condition is expected at this place </TriggerCondition> </Trigger> </Values> </SubTrigger> </Item> </SubTriggers> <SubTriggers> <Item> <SubTrigger> <Template>AutoCreateTrigger</Template> <Values> <Trigger> <TriggerCondition> //a condition is expected at this place </TriggerCondition> </Trigger> </Values> </SubTrigger> </Item> </SubTriggers>
Enlarge codebox

A SubTrigger can also have more SubTriggers added to it, if you feel like it you can have a look at the uPlay-Club challenge "Silocon Valley", where it has been pushed to an extreme.