Archid
Warlord
I'll knock up some documentation on the new trait tags. Its very different, much more flexible that the old mechanism. It works a bit like the event system in that you have the definition of the Trait in one file with another file (TraitTriggerInfos) defining when the trait counter is changed, and by how much. The events (Hooks) that can cause the counter to be changed are stored as enum values so are defined in /Assets/XML/GlobalTypes.xml .... this is going to make you go until you get your head round it, but it's a better system once you understand how the pieces fit together
Process in short is:
1 - Game runs along until it reaches a hook (e.g. one unit killing another) from the GlobalTypes.xml in the dll code
2 - All the TraitTriggersInfos that are associated with that hook are then processed
3 - Traits get their counters changed based on the info in the TraitTriggerInfo
I have only added the places where GreyFox had hooks to change the counters for now, so I need to expand it a bit to add some new ones in such as Improvements being built, etc. The way it is coded makes it very simple to add new hooks so those can be added almost at will.
I have moved the existing trait changes over to the new system where there are hook's in place for them so you have some examples. The easiest way is to look at the examples in the TraitTriggerInfos and work your way backwards from there.
Walking through a couple of simple examples:
a - When the player constructs any building increase the Industrious trait counter by +5
b - When the player constructs a religious shrine increase Spritual by 10%, but the change must be at least +5 and capped at +25 additionally increase Organised by +2
The process is the same for both:
1 - Identify the hook and any available options you need from GlobalTtpe.xml file. In this case it is the TRAITHOOK_CONSTRUCT_BUILDING and we have the shrine option. The options will all have a corresponding prereq tag in the TraitTrigger file
2 - Identify the traits from the Trait file: TRAIT_INDUSTRIOUS, TRAIT_SPIRITUAL & TRAIT_ORGANIZED
3 - Create the trait triggers that links these together.
Each trigger has 2 main parts: The trait change section and the prereq section. You can combine multiple trait changes into a single trigger IF the prereqs match. In our case we have 2 different sets of prereqs: 'all buildings' and 'shrine only' so we need 2 triggers.
All Buildings
======================
Firstly we need to define a unique name for the trigger:
The trait change section is all contained in a single tag <CounterChanges> to increment Industrious by 5 we would use:
You then need to define under what conditions these changes are made.
You always need to define the hook, and optionally any prereqs. For the all buildings there are no addtional prereqs so we just need the hook:
Now we can put the complete all buildings TraitTrigger together:
Building a Shrine
============================
The second scenario is for when a shrine is built. Firstly define its unique name
There are 2 traits that get modified in this scenario so we need 2 entries in the <CounterChanges> element. The first to say that Spiritual gets a 10% increase in the trait counter, but will get at least +5 and no more that 25; the second to give Organised a flat +2 to the counter
We now need to define the hook, which is the same as before
In this scenario we also have a prereq condition (Shrine) so look for the assocated tag in the Trigger:
Putting it all together we get:
When the game runs and any player constructs a building both these triggers will be processed for the player completing the building. The first trigger will always fire (make the defined trait counter changes) as it has no additional prereqs, but the second will only fire if the building is a shrine.
Process in short is:
1 - Game runs along until it reaches a hook (e.g. one unit killing another) from the GlobalTypes.xml in the dll code
2 - All the TraitTriggersInfos that are associated with that hook are then processed
3 - Traits get their counters changed based on the info in the TraitTriggerInfo
I have only added the places where GreyFox had hooks to change the counters for now, so I need to expand it a bit to add some new ones in such as Improvements being built, etc. The way it is coded makes it very simple to add new hooks so those can be added almost at will.
I have moved the existing trait changes over to the new system where there are hook's in place for them so you have some examples. The easiest way is to look at the examples in the TraitTriggerInfos and work your way backwards from there.
Walking through a couple of simple examples:
a - When the player constructs any building increase the Industrious trait counter by +5
b - When the player constructs a religious shrine increase Spritual by 10%, but the change must be at least +5 and capped at +25 additionally increase Organised by +2
Spoiler :
The process is the same for both:
1 - Identify the hook and any available options you need from GlobalTtpe.xml file. In this case it is the TRAITHOOK_CONSTRUCT_BUILDING and we have the shrine option. The options will all have a corresponding prereq tag in the TraitTrigger file
2 - Identify the traits from the Trait file: TRAIT_INDUSTRIOUS, TRAIT_SPIRITUAL & TRAIT_ORGANIZED
3 - Create the trait triggers that links these together.
Each trigger has 2 main parts: The trait change section and the prereq section. You can combine multiple trait changes into a single trigger IF the prereqs match. In our case we have 2 different sets of prereqs: 'all buildings' and 'shrine only' so we need 2 triggers.
All Buildings
======================
Firstly we need to define a unique name for the trigger:
Code:
<Type>TRAITTRIGGER_ALL_BUILDINGS</Type>
The trait change section is all contained in a single tag <CounterChanges> to increment Industrious by 5 we would use:
Code:
<CounterChanges>
<CounterChange>
<TraitType>TRAIT_INDUSTRIOUS</TraitType>
<iModifier>5</iModifier>
</CounterChange>
</CounterChanges>
You always need to define the hook, and optionally any prereqs. For the all buildings there are no addtional prereqs so we just need the hook:
Code:
<TraitHookType>TRAITHOOK_CONSTRUCT_BUILDING</TraitHookType>
Now we can put the complete all buildings TraitTrigger together:
Code:
<TraitTriggerInfo>
<Type>TRAITTRIGGER_ALL_BUILDINGS</Type>
<CounterChanges>
<CounterChange>
<TraitType>TRAIT_INDUSTRIOUS</TraitType>
<iModifier>5</iModifier>
</CounterChange>
</CounterChanges>
<TraitHookTypes>
<TraitHookType>TRAITHOOK_CONSTRUCT_BUILDING</TraitHookType>
</TraitHookTypes>
</TraitTriggerInfo>
Building a Shrine
============================
The second scenario is for when a shrine is built. Firstly define its unique name
Code:
<Type>TRAITTRIGGER_BUILDING_SHRINE</Type>
There are 2 traits that get modified in this scenario so we need 2 entries in the <CounterChanges> element. The first to say that Spiritual gets a 10% increase in the trait counter, but will get at least +5 and no more that 25; the second to give Organised a flat +2 to the counter
Code:
<CounterChanges>
<CounterChange>
<TraitType>TRAIT_SPIRITUAL</TraitType>
<iPercentChange>10</iPercentChange>
<iPercentChangeMin>5</iPercentChangeMin>
<iPercentChangeMax>25</iPercentChangeMax>
</CounterChange>
<CounterChange>
<TraitType>TRAIT_ORGANIZED</TraitType>
<iModifier>2</iModifier>
</CounterChange>
</CounterChanges>
We now need to define the hook, which is the same as before
Code:
<TraitHookType>TRAITHOOK_CONSTRUCT_BUILDING</TraitHookType>
In this scenario we also have a prereq condition (Shrine) so look for the assocated tag in the Trigger:
Code:
<bPrereqShrine>1</bPrereqShrine>
Putting it all together we get:
Code:
<TraitTriggerInfo>
<Type>TRAITTRIGGER_BUILDING_SHRINE</Type>
<CounterChanges>
<CounterChange>
<TraitType>TRAIT_SPIRITUAL</TraitType>
<iPercentChange>10</iPercentChange>
<iPercentChangeMin>5</iPercentChangeMin>
<iPercentChangeMax>25</iPercentChangeMax>
</CounterChange>
<CounterChange>
<TraitType>TRAIT_ORGANIZED</TraitType>
<iModifier>2</iModifier>
</CounterChange>
</CounterChanges>
<TraitHookTypes>
<TraitHookType>TRAITHOOK_CONSTRUCT_BUILDING</TraitHookType>
</TraitHookTypes>
<bPrereqShrine>1</bPrereqShrine>
</TraitTriggerInfo>
When the game runs and any player constructs a building both these triggers will be processed for the player completing the building. The first trigger will always fire (make the defined trait counter changes) as it has no additional prereqs, but the second will only fire if the building is a shrine.