I've made a few buildings which can produce fighting units but the AI will only build one type, making one cheaper, etc would only mean it'd just build that instead, really more control over the AI using xml would help.
Some form of AI flags would be a good idea, this way the AI has more of an idea on how to use each unit. <important value="true"/> would mean that the AI would have to build this at some point in a random order with other units or better still <importance value="#"/> the lowest number takes priority. <siegebuilding value="true"/> would let the AI they need them for attack or defence. Some AI flags in the faction XML would really be good stuff like <siegebuildings-toattack value="#"/> how many siege buildings should the AI have at least before it makes its first attack. Could sit here all day and list loads of useful flags. Could link storage buildings with resources so the AI opts to build them next to their suitable resource, etc too. I'll copy this over as a feature request.
Also looking into the Stronghold series, each AI has 8 pre built castle designs, would this can be repeatability this idea could be useful for giving the AI hints on placing buildings such as an order of what to build, this could be set for each difficulty. Walls or any unit could be placed using a cell map with a list of randomly layouts to choose from, if a map object obscures the layout the AI would just build up to it as it still keeps them safe, with walls a flag would be needed for cellmaps which only allow allied players to pass through them. Something like this:
In units xmls...
<building-importance type="important, siege or minor" order="#" position="resource_name, unit_name, closest or cellmap_reference" duplicate="true/false"/>
The lowest order has priority. Important buildings are built first then minor and siege are varied depending on whether the AI needs resources, defence or attack. Position helps with positioning the units, by a named resource, closest to the start, another building, if this building is not built the AI wont build this building until its position building is ready. Also a cell map reference, cell maps can't have the same name as a building or resource or closest therefore a convention such as cellmap01 or cellmap_walls should be used. Duplicate states whether the AI needs more than one, this works differently for each type. Important is more than one or just one, siege if false will build a siege building of each type before duplicate buildings, minor will work like important.
In faction xml or new ai.xml...
<important-units> these are built before anything else, resources are gathered if needed.
How many units of this type to build before the AI decides to consider building an amount of siege or minor buildings, always minor after its first 'session'.
<amount-before-attack value="#"/> How many to build before any attack.
<amount-for-powerattack value="#"/> How many to have for a full on attack.
<unit-combo unit1="unit_name" unit2="unit_name"/>
Combos for the AI to use when attack unit1 acts as a master unit so the Ai will try and make unit2 to fight alongside unit one. Linking more than one unit to unit1 would mean the AI would try and group a few types of unit2s with unit1, a snake effect could be created by linking unit2 to unit1 then a new unit2 to the old unit2 so for example:
<unit-combo unit1="ravager" unit2="reaper"/>
<unit-combo unit1="reaper" unit2="worg"/>
This would create an effect where there are many ravagers a load of reapers and a worgs, vs:
<unit-combo unit1="ravager" unit2="reaper"/>
<unit-combo unit1="ravager" unit2="worg"/>
Here there will be a more equal amount of reapers worgs alongside a load of ravagers. Basically look at it as a chain, the further down the chain, the rarer and less amount. Dependency loops could be made but this would just act as a separate chain, each chain is picked randomly. This way you can have strategies per AI difficulty, these would be random too. If buildings are set here they will be included this way units can be build for defence.
This will work the same as important only not as important.
<cellmaps width="#" height="#">
These are referenced by buildings using the position attribute. All cellmaps must have the same width and height. Cell maps are centred from the starting point using the top left centre cell of the cell map is even width/height (if it is odd an exact cell in the middle is used).
Different behaviour could be set for each map so:
behaviour="close" 1 = build here (randomly on it or as close as possible if obscured). 0 = Don't build here unless obscured or a non-cellmap building. Positions are chose randomly.
behaviour="exact" 1 = built from the top left of here. 0 Don't build here unless a unit is too large to fit completely in a 1 area. If obscured from a point completely then don't build at all.
behaviour="wall" Same as exact but once the first unit is placed the AI will attempt to build as close to that as possible.
<cellmap name="cellmap_01" behaviour="close"> Here is an example of placing some buildings, good for defence towers, etc.
<cellmap name="cellmap_01" behaviour="wall"> Here is an example of placing walls.
One more thing, AI will try to box it self in but not completely, it will keep on building until it is about to box itself in, here it could use a flag called <box-in value="#radius"/> so it will ensure that it can always get out of its domain with this radius considered. More thought could be put into Gatehouses with a flag set to tell the AI these are to be placed in box-in gaps with the radius considered still, these buildings must have a cell map. Alternatively you could have complete control setting the box-in to 0 and using exact and wall types to have complete control over where the AI builds.
A hell of a lot there, something like that would be nice or a smart AI that works it out itself. More realistically though a few flags for builds would be useful, especially ones to force the AI to build a buildings and not to (as randomly blocks of walls just look stupid at the minute so might as well disable them from the AI for now).