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.  FactionSkills::Income2  0.05 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:  FactionSkills::BuildShipsAnywhere  1

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.  FactionSkills::Trees::Navy  2 0         1 1                  2 1                  3 1                  2 2                 <prereq class="factionskill" type="shipmelee"/> <prereq class="factionskill" type="shipranged"/> <skill class="factionskill" type="shipwinter"> 2 3                <prereq class="factionskill" type="shiprepair"/> 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"> 3 2                <prereq class="factionskill" type="shipimpact"/> <prereq class="factionskill" type="shipmelee"/> <prereq class="factionskill" type="shipranged"/>

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