Where do I begin?
With the Unofficial Crusader Patch, the entrails of the AI’s have been made accessible to you.
Changing these values will change the AI’s behavior to a certain degree.
You can change the army composition for the AI.
It is also possible to change how the AI manages its stockpile, how it gets use out of different production chains and how fast it sets up, balancing army and economy.
If you want to change any of these behavioral aspects in your modded AI’s, this patcher is for you.
If you want to go beyond the core mechanics of how AI’s work in Stronghold Crusader and script your own AI for the game you love,
you are very much welcome to join our awesome community and contribute to the Patcher, making more and more mechanics available for modding.
Keep Management
It is possible to impact the recruitment speed of the AI by regulating his popularity.
Three different Popularity values are available for changing.
The usual state for any AI should be between LowestPopularity and HighestPopularity.
The AI will periodically go up and down between these two, with the critical popularity being reserved for an emergency case, forcing the AI to sell most of its stocks to regain popularity.
Taxes are set by the ingame tax tiers, ranging in impact from +7 popularity to -24 popularity.
Economy
Regarding the economy of the AI, you can set up which farms it can build by populating the fields Farm1 to Farm8.
These are only for proportional measures though, as the actual maximum numbers of any resource buildings the AI will build are setup later with the Max[ResourceBuildingType] values.
With farms it is a bit tricky, as Hop Farms currently don’t count towards the maximum farm buildings and still have to be set up on the Farm spots.
In cases of question, the AI will work its way down the list from the top, skipping farms it might not be able to build at the time.
Therefore setting up Hop Farms in the first spot might result in the AI spamming Hop Farms wherever space is available, while not building any other farms, and never reaching its maximum farm limit.
For each resource building type, besides its maximum amount, you can set up how fast the AI will place buildings relative to its other production facilities.
You can achieve this by setting the PopulationPer[ResourceBuildingName] values, indicating how many workers have to be available for each of the said buildings.
Only setting these values to 0 or a higher number than the population amount available to the AI will result in the AI not placing buildings of the specified type.
How fast the AI rebuilds resource buildings after destruction can be set by the ResourceRebuildDelay.
The BuildInterval plays a very important role.
The lower it is set, the faster the AI will build it’s castle, where 1 will result in the fastest speed.
But note that an AI with 5k gold or more will set this value automatically to 1 until it’s gold level falls below 5k.
The BuildInterval only affects the buildsteps set up in the aiv, not those that are required to build resource buildings.
As the AI will change its recruitment behavior to the one set in the aic values only after its village has been completed, this will mainly impact how fast the AI will access troops offensively.
Setting the maximum values of different resources and weapons is useful for dealing with the limited stockpile, granary and armoury space your AI has.
It will sell any excess resources when its amount surpasses its maximum value plus the MaxResourceVariance.
The AI might store an extra amount of stone up to the stone requirement of its most expensive stone costing building.
Food
To manage your AI’s food management, you want to set MaxFood (the maximum of each food type to be stored at once) and define a minimum for each of the food types your AI wants to keep in stock at all times.
It will prioritize buying these before anything else. Wheat will also count towards MaxFood and TradeAmountFood.
Hops will also be bought in margins of TradeAmountFood as well as the other ‘Food’ resources, but for maximum stocks that the AI would keep before selling, that will be handled alongside iron, flour and pitch by the MaxResourceOther field.
Income
The AI will periodically buy goods which it needs, if it has enough gold to afford them.
It’s budget to buy goods will be shared with the budget to recruit troops.
The procedure will be initiated every time that the AI surpasses the RecruitGoldThreshold.
So far we know, the AI prioritizes buying food over everything else.
After food it prioritizes buying weapons and recruiting troops, then buying resources to build up its missing aiv-defined buildings.
Finally, it will eventually buy wood and iron for its weapon production buildings.
Note that Sortie units, defensive siege engines and resource buildings are excluded from this procedure, leading to the AI always buying those even if it doesn’t hit its RecruitGoldThreshold.
With this note that even though the AI will cheat pitch and walls, it still needs one of each resource or more than RecruitGoldThreshold gold to do so.
A fast way for the AI to sell any resources it doesn’t use in its production chains, thereby freeing up space, is to set up these resources in the SellResource[Number] spots.
These resources will be instantly sold when they come in stock, which means any resources the AI needs to build stuff or needs to produce other goods should not be defined here.
If they were, the AI would constantly buy and sell these resources, losing gold and possible trade ticks in the process.