Suppose for your custom civilization you want to replace Knights with Cobra Cars, and you want the default AI to be able to train Cobra Cars. To do that, you’ll need to a) use the Advance Genie Editor and b) edit unitlines.json.
Part 1: Advance Genie Editor
To make the Cobra Car trainable at the Stables with AGE:
- Go to the Units tab and navigate to the entry for Cobra Car (unit ID 748)
- Change Train Location to Stables (101) and Train Button to 2.
The Unit entry should now look something like this:
Now you need to create an effect that will trick the AI into treating the Cobra Car as a Knight-line unit:
- Create a new effect and add Disable tech effect commands for Cavaliers and Paladins (Techs 209 and 265 respectively).
- Add effect commands to upgrade Knights (38), Cavaliers (283) and Paladins (569) to Cobra Cars (748)
- Under the Techs tab, create a new tech. Set Repeatable to 1, Effect to the effect number of the new effect and Civilization to whatever civilization modifying. In my own testing, I set the civilization to Teutons, because that civ really likes to train Knights.
Your new Effect entry should look like this:
Your new Tech entry look something like this:
The default AI will now recruit Cobra Cars as if it was a Knight-line unit. However, the AI will not include Cobra Cars in its count of Knight-line unit. This probably isn’t an issue for the default AI, in that I think it uses the military-population parameter to control its army size. However, say that you’re using a custom AI and that custom AI has the following block of code:
(defrule
(unit-type-count-total knight-line < 10)
(can-train knight-line)
=>
(train knight-line)
)
Because the AI does not include Cobra Cars in its count of Knight-line units, the AI will train way more than 10 Cobra Cars, because as far the AI is concerned, the Knight-line count is still 0. To get the AI to include Cobra Cars in its Knight-line count, you will need to edit unitlines.json.
Part 2: unitlines.json
Unitlines.json defines which unit belongs to which Line ID and is located inside AoE2DE\resources_common\dat. The only way to edit LIneIDs is by editing the original unitlines.json file; mod folders do not work. Therefore, you should backup unitlines.json before editing it.
Inside unitlines.json, search for the entry for “Knight Line.” It should look like this:
{
"Name": "Knight Line",
"LineID": -287,
"IDChain": [
38,
283,
569
]
},
As you may recall, 38 refers to Knights, 283 refers to Cavaliers and 569 refers to Paladins. To add Cobra Cars to this entry, add a comma after 569. Then create a new line and add 748, without a comma. The entry will now look like this:
{
"Name": "Knight Line",
"LineID": -287,
"IDChain": [
38,
283,
569,
748
]
},
If we run that block of AI code again, the AI will recruit the correct number of Cobra Cars.
Special thanks to LeifEricson on the AI Scripting Discord for informing me of the existence of unitlines.json.
And here’s a video of the default AI training Cobra Cars: