Modding Tutorial No. 5: Skills and Skill Trees

Welcome to the fourth entry of our modding blog where we post a new mod every week and explain how we did it. We've mentioned before that four things use attribute definitions; stances, factions, upgrades and faction skills. We've spent the last three weeks going over the first three of those, so now it's time to finish that list off and cover skills.

There are two main things that need to be modified in a skill; the skill itself needs to be defined, and a skill tree needs to be edited to have it. For our mod, we'll be creating a naval construction skill, one that makes every city act like it has a shipyard, thus enabling you to build ships in any port. It will go into the Naval tree, right after Advanced Taxation.

So let's look at an existing skill.

```
<entity class="factionskill" type="income2">
       <name>FactionSkills::Income2</name>
       <icon atlas="skills" sprite="production_trade"/>
       <attribute attrtype="taxoutput" op="mult">0.05</attribute>
</entity>

```

Skills are fairly small and easy entities, without much to them.
"name", which points to a string (you will need to create the ::NAME substring for these, so for the income2 skill, the actual string name is FactionSkills::Income2::NAME)
"icon", an atlas ref to the image that appears for this skill in the tree view. As usual, we'll want to change atlas to "FILE:" and sprite to the image's filename.
"attribute" is the list of attribute changes this skill uses, formatted that same way as in stances, factions and upgrades. You can have as many as you want, or even none if you want a skill that's purely a prerequisite.

So for our skill, we'll change the type to "buildshipsanywhere", the name to "FactionSkills::BuildShipsAnywhere", and point the icon to a new image. The attribute type will be switched to a boolean construction attribute; sometimes a brigade or upgrade will require a certain attribute to be true, like Cavalry Training (found via stables upgrade) or Military Reforms (found by the skill of the same name) allowing Hastati. Usually these attributes are activated by setting the op to bool and the value to 1; we'll do that with buildships, the attrtype normally only reachable through the shipyard upgrade. Our final skill looks like this:

```
<entity class="factionskill" type="buildshipsanywhere">
       <name>FactionSkills::BuildShipsAnywhere</name>
       <icon atlas="FILE:" sprite="Resources/BuildShipsAnywhere.png"/>
       <attribute attrtype="buildships" op="bool">1</attribute>
</entity>

```

So we have our skill defined, but right now it's not possible to get. It will needed to be added to a skill tree. Each faction group (like the gauls, or the greeks) has a list of valid skill trees defined; the default ones refer to tree\_common\_economy, tree\_common\_navy, and a special military tree that varies from group to group (this is why the Romans have the Military Reforms and Manipular Tactics skills, but other factions have other ones). We'll want to add our skill to tree\_common\_navy; let's have a look at what tree\_common\_navy looks like by default.

```
<entity class="skilltree" type="tree_common_navy">
       <name>FactionSkills::Trees::Navy</name>

       <skill class="factionskill" type="shipspeed">
               <pos>2 0</pos>
       </skill>

       <skill class="factionskill" type="shipimpact">
               <pos>1 1</pos>
               <prereq class="factionskill" type="shipspeed"/>
       </skill>

       <skill class="factionskill" type="shipmelee">
               <pos>2 1</pos>
               <prereq class="factionskill" type="shipspeed"/>
       </skill>

       <skill class="factionskill" type="shipranged">
               <pos>3 1</pos>
               <prereq class="factionskill" type="shipspeed"/>
       </skill>

       <skill class="factionskill" type="shiprepair">
               <pos>2 2</pos>
               <prereq class="factionskill" type="shipimpact"/>
               <prereq class="factionskill" type="shipmelee"/>
               <prereq class="factionskill" type="shipranged"/>
       </skill>

       <skill class="factionskill" type="shipwinter">
               <pos>2 3</pos>
               <prereq class="factionskill" type="shiprepair"/>
       </skill>

</entity>

```

So it has the class and type defined, name pointing to a string (this time no substring, it just points straight to FactionSkills::Trees::Navy), and a list of skill tags. Each of those skill tags points to a defined skill, has a pos, and a list of prereqs. The two numbers in pos say where it shows up when you look at the tree through the skill window; the first number is which column, from 0 at the left to 4 at the right, and the second is which row it shows up in with 0 at the top. The prereq tags, if any, point to skills; the skill will not be activatable until tge faction has at least one of the prereq skills active. If there aren't any, the skill can be activated any time.

So how do we add the skill to the tree? We'll have to create another entity file. This time we'll apply modtechnique="merge" to tell the game we want to add this information to an existing entity rather than define a new one, then declare its class and type as the one we want to merge with ("skilltree" and "tree\_common\_navy"). Then we just have to add the new skill block; the rest of the data in tree\_common\_navy will still be pulled from the default game.

So for our new skill block, we have to decide on a position and prereqs. Since this is a fairly powerful skill, I decided to put it at the same level as shiprepair; for its position, I put it one column to the right and the same row, and copied the list of prereqs from shiprepair; just like shiprepair, it will only be activatable once the faction picks shipimpact, shipmelee or shipranged. The final skill looks like

```
<entity class="skilltree" type="tree_common_navy" modtechnique="merge">
       <skill class="factionskill" type="buildshipsanywhere">
               <pos>3 2</pos>
               <prereq class="factionskill" type="shipimpact"/>
               <prereq class="factionskill" type="shipmelee"/>
               <prereq class="factionskill" type="shipranged"/>
       </skill>
</entity>

```

And that's our skill added to the naval tree, and this week's mod is complete!