Obviously, building units that are needed instead of yet another archer is a good thing for the ai, but how does it know it should build a new unit when one becomes available? Particularly, when such a unit doesn't obsolete a previous unit, but is something new (like cavalry when you didn't have any, or airplanes or ships...)?
I define for the ai use a set of unit abilities:
Right now, I picked:
Attack, defense, breach, cost, support, movement.
This defines a set of abilities which the ai will want.
For instance, you may say you want:
60% legion, 30% archers, 10% siege engines.
But you may also state it thus:
60% attack, 30% support, 10% breach.
These are not categories, however. I don't like categories a lot, because if you label an army as 'defender', ai's like civ2 use it as defender when they would sometimes make excellent attackers.
Additionnally, I put movement and cost in because you may want a mix of these. For instance, I may want a set of fast cheap units to use as scouts, a few strong attack units, even if they are slow and expensive, and a lot of relatively cheap attack units which can move a bit.
So I have categories, with weights in each category:
For example I could represent scouts/strong attackers/cheap fast attackers this way:
Scouts: Movement 10. Cost 1.
Strong attackers: Attack 1.
Cheap fast attckers: Attack 10. Movement 3. Cost 1.
The ai would then scan the available units, classify each available unit in each category, and decide which unit is best to build. If the system works well, humans could also use it (for instance, I will use it because I have to tune the ai).
Mapping of units to abilities would vary a bit:
Breaching is a yes/no ability, so it is not hard to find out when you want siege weapons. There are more extreme cases, like being an airplane or a ship, where you don't even have the breach strength value available.
Attack, defense... are numbers, so there will be a number crunching equation I haven't devised yet to find out how much a unit fits a certain role.
So this approach is to define a set of categories that the ai can use, categories which can be defined on the fly if needed (like I realize I need breachers to get through the wall of city XXX). What do you think of the approach for the ai? Should the player be able to use it too? Would you use such an interface as a player?