Stronghold Warlords - AI mechanics

The AI in Stronghold Warlords introduces dynamic decision-making, building on the Stronghold Crusader 2 variant.
Warlords AI characters have greatly simplified customization capabilities, as their behaviour is derived from one universal black box logic, meaning that every AI has the same economic, military and castle-building principles. This logic cannot be altered in its base, but internal .xml definitions are still available to shape the AI's personality to an extent.
==An AI player==
AI players have the following components:
*Core behaviour: Each AI follows the same principles regarding play, which is governed by the core game. AIs build at their own pace, develop their military in a somewhat reactive way. They also regularly reassign their troops and upgrade their building as they see fit.
*Castle templates: There are several castle templates bundled in the core game. The AI can reference one of them, which has a blueprint for unit spots, fortifications, and buildings.
*Media files: Bink videos are used for interacting with the player. These are included for each character and can be replaced as needed. The RAD Tools. Bink Video Converter can be used to produce a .bik video from the most popular formats.
Each AI player has a behaviour definition covering various gameplay aspects in an XML definition file. The following sub-sections cover all of them without precise technical info.
==Castles and building==
Each AI chooses one castle to build from a preset list of templates, which are defined by the core game.
===Castles===
The AI's fortifications are built gradually, much like in the previous games. These buildings however are not tied to any given behaviour, as the AI constantly evaluates its situation and adds the next step, if it sees fit. 
Significant spots, such as unit markers, are still present in any template, which can be populated by specific units. Castles also have predefined building regions, which govern the placement of different buildings: farms, weapons workshops, civilian buildings, etc.
It is possible to toggle which defenses and military buildings the AI can build. Stone fortifications and turrets have their places that vary with each template:
* Barracks / military academy
* Barricades
* Gunpowder stashes
* Hoardings
* Each engine platform: fire arrow platforms, mangonel platforms, ballista platforms
* Tiger cages
==Economy==
=== Building ===
The AI builds its economy based on hidden parameters. It always composes a priority list based on its needs and adds buildings accordingly. Naturally, the game prioritises wood production and farms early on, while quarries, mines and other producers are added gradually. As the game progresses, the AI also replaces some buildings in order to upgrade them (such as hovels) or introduce new ones (such as diplomacy buildings).
It can be controlled what type of food and luxury goods can be built by the AI, separately. Moreover, the number of free peasants to keep and Fear Factor buildings are also customizable.
===Production===
The AI normally operates buildings. It can temporarily halt production if it wants to free up population for other purposes, or when a building is attacked constantly. They will not repair buildings with the repair tool, however.
==Military==
The AI is designed to be very flexible in terms of unit compositions and strategies. 
===Group concept===
The AI takes the clan philosophy from Stronghold Crusader 2 and assembles them dynamically. While each unit had been assigned to a select group in previous games, the Warlords AI does have a preference for keeping units in defense, until it determines that an offensive clan is to be sent out. Units in offensive groups are never withdrawn.
===Group types===
The AI tries to build groups with increasing power and varying compositions. Depending on its available troops list, it composes a group of two or three unit types that well complement each other:
* light units with high speed and maneuverability;
* armored units that move slowly, but are harder to kill;
* pure cavalry units;
* swift units that combine cavalry and infantry.
Depending on its decision, the AI sends out such groups to take over a warlord, harass the enemy, retaliate against provocations, or to siege a player. Siege groups are generally larger groups that also feature siege weapons.
===Troops list===
Instead of concrete group definitions, a Warlords AI has a list of regular units and siege equipment it can use.
Each unit is assigned a percentage ratio, which governs the composition of army groups and how frequently a given troop is used. 100% is divided across regular troops and siege units, respectively.
The AI is also told how many attacks/harassment attempts it requires before a siege is attempted.
==Diplomacy==
The AI has limited interaction with the players. It periodically taunts the player, as well as it reacts to certain game events, such as taking control over a warlord, or losing one. 
Outside that, AI players cannot interact with each other, nor can they be interacted with. 
==Difficulty==
The AI has four difficulty levels: easy, normal, hard and extreme.
The four difficulties have difference in recruitment speed, as well as easier difficulties wait longer before starting recruitment. The "extreme" AI is also given free gold boosts every 30 seconds.