OpenXcom Forum

Contributions => Programming => Topic started by: Phezzan on July 08, 2013, 12:40:49 am

Title: How to code the AI
Post by: Phezzan on July 08, 2013, 12:40:49 am
I'm interested in tweaking, or perhaps overhauling the AI to make X-Com scare me as much as it did back when I was 13.

So far, I've managed only to tweak the formula that attempts to find and retrieve weapons.  (hooray - stun damage is no longer instant win)

While banging my head against that - I noticed the game seems to have 'AI states' and that these operate for a while, and then it maybe decides to pick a new state - perhaps on the same turn as it picked the last one...  Additionally there doesn't seem to be any alien group consciousness.

The melee AI will target flying or otherwise unreachable targets. (like the rear tile of a tank despite the fact that it's within a blocked entrance)
The AI does attempt to hit units from the rear (less armor), but it doesn't choose targets based on armor.
(a Chryssalid will wail on a Tank it can't hurt rather than take two steps and hit a soldier in personal armor.)

Aliens do not react as a group - ie: they will not stop patrolling and come help defend the UFO, but they will retreat from visual range until they are pressed against the edge of the map.
Even Sectopods will retreat despite being nearly invincible on their front armor.

Aliens act individually, they do not come in 'teams' or squads -
If Aliens prepare ambushes, I haven't seen that yet - and I bet they wouldn't wait long before attempting a patrol anyway.

Somehow I want to fix some or all of these things

I imagine that 'threat to tile' can be tweaked to keep a 'max power' estimate so that heavily armored units can ignore the 'threat' of 20 troops with LasPistols.
The 'find cover' logic perhaps could be tweaked to allow units to hide behind large units.
The 'choose target' logic might weigh armor, hit probability, and cover (with a double penalty for cover from our own units).

But maybe I'm wrong and this stuff is implemented (or implemented and turned off)?

Phez
Title: Re: How to code the AI
Post by: kkmic on July 08, 2013, 09:52:21 am
The AI is in "playable" condition right now (with some extra highlights compared to the original one), and it is open for improvements.

You up for it? :)
Title: Re: How to code the AI
Post by: Phezzan on July 08, 2013, 04:19:11 pm
We'll see.    I'm certainly no expert - I had exactly two college courses in AI, and that was a long long time ago.

At the very least I'd like to improve target selection.
Title: Re: How to code the AI
Post by: Warboy1982 on July 10, 2013, 03:28:24 pm
i WILL answer all this... i just need to find an opportunity to sit down and write it all out.
Title: Re: How to code the AI
Post by: Warboy1982 on July 14, 2013, 02:59:46 pm
I'm interested in tweaking, or perhaps overhauling the AI to make X-Com scare me as much as it did back when I was 13.

So far, I've managed only to tweak the formula that attempts to find and retrieve weapons.  (hooray - stun damage is no longer instant win)

all you needed to do to acheive that was add some attraction values of like... 8 or so to plasma weapons, blaster launchers, small launchers and their ammunitions.

The melee AI will target flying or otherwise unreachable targets. (like the rear tile of a tank despite the fact that it's within a blocked entrance)

The AI does attempt to hit units from the rear (less armor), but it doesn't choose targets based on armor.
(a Chryssalid will wail on a Tank it can't hurt rather than take two steps and hit a soldier in personal armor.)

it shouldn't, it should only be targetting units it can pathfind to.
it doesn't prioritize rear armour, it prioritizes attacking whatever's closest. and for the record, a chryssalid should have no problem reducing a tank to a pile of rubble.

Aliens do not react as a group - ie: they will not stop patrolling and come help defend the UFO, but they will retreat from visual range until they are pressed against the edge of the map.
Even Sectopods will retreat despite being nearly invincible on their front armor.

Aliens act individually, they do not come in 'teams' or squads -
If Aliens prepare ambushes, I haven't seen that yet - and I bet they wouldn't wait long before attempting a patrol anyway.

they do to some extent, aliens will use squad sight for targetting far away units with blaster launchers, and once the aliens spot a player unit, they keep "psychic" track of him for a few turns, leaving him vulnerable to mind control/panic. they don't use squad sight for regular shooting YET, but i have some thoughts on this.


I imagine that 'threat to tile' can be tweaked to keep a 'max power' estimate so that heavily armored units can ignore the 'threat' of 20 troops with LasPistols.
The 'find cover' logic perhaps could be tweaked to allow units to hide behind large units.
The 'choose target' logic might weigh armor, hit probability, and cover (with a double penalty for cover from our own units).
the "threat to tile" is based on the number of units that can see the tile. taking into account what those units are holding is a bit... iffy, i mean, they might be holding motion scanners and medikits, but have a blaster launcher in their backpack.

The 'find cover' logic was deliberately tweaked to STOP units using each other as cover, as hilarious as it was, they often decided that directly behind/beside your men was a pretty good place to keep out of sight. even more hilariously, it often worked.

the "choose target" logic, generally speaking, prioritizes whoever's closest, because naturally, there's a better chance of hitting them, and in the case of melee, it means more TUs left over when you reach them to use on chewing and swallowing.


about the AI states: the ai functions in two basic modes, "patrol", where he just wanders from map node to map node, looking for something to kill/eat/experiment on, and "aggro", when he has found somebody he doesn't like.

in the patrol state, he reserves a % of TUs as he wanders about, in case some hapless soldier wanders into his field of vision.

in the aggro state, he stalks his prey, and when he spots it, he makes a quick (very slow and cpu intensive) assessment of the cover around him, chooses a spot to move to, and reserves enough TUs to get there, spending the rest on shooting at his opponent.

unless he's psionic or has a blaster launcher, in which case he tries to use those instead.
Title: Re: How to code the AI
Post by: Phezzan on July 15, 2013, 12:42:50 am
all you needed to do to acheive that was add some attraction values of like... 8 or so to plasma weapons, blaster launchers, small launchers and their ammunitions.

I'm using that option, and most of the original code, but I streamlined it a bit -
The old code picked only weapons it really liked and was really close to, then filtered it out based on some extra criteria.
Once it filtered it didn't go for a second choice it just gave up.
The result was that almost never finds a weapon because it's scared of being seen, or some other reason.

I combined the extra criteria into the finding function.  Aliens never fail to find a weapon now - anything with an attraction above 0 will do.

it shouldn't, it should only be targetting units it can pathfind to.
it doesn't prioritize rear armour, it prioritizes attacking whatever's closest. and for the record, a chryssalid should have no problem reducing a tank to a pile of rubble.

I haven't modified pathfinding and the chryssalid paces away all his TU in the two sqaures on the ground in front of my flying armor/hovertank.

I've seen melee units walk past the front and around the back before attacking - perhaps because it was out of sight ?
Yes in the unmodified game, a Chryssalid kills almost anything in one round and most things in one hit...
In the unmodified source code, any hit kills literally any woundable unit at the end of turn regardless of armor or damage - it doesn't even have to deal damage to kill.
Some people may like it that way, but I didn't, so I fixed it. 
My chryssalids actually have to inflict 1 damage to infect you and infection is a degenerative state instead of instakill. ... etc.

they do to some extent, aliens will use squad sight for targetting far away units with blaster launchers, and once the aliens spot a player unit, they keep "psychic" track of him for a few turns, leaving him vulnerable to mind control/panic. they don't use squad sight for regular shooting YET, but i have some thoughts on this.

I did see that - sometimes aliens just kind of ignore me and just keep pacing back and forth.
I ran into some Mutons in a barn - I surrounded the entrance with guys w/Laser pistols (veteran difficulty)
The Mutons would generally attempt to leave the barn, then realize I was shooting at them and re-enter the barn.  They rarely fired back.
I spent a lot of turns playing fish in a barrel.

The other aliens didn't try to flank me - they stayed in the UFO.
Eventually I knocked out the back wall and they ran -  had to chase them. 
Admittedly I had 8+ guys covering the door with LasPistols... so the 'threat' was pretty huge and it probably decided to run, but had only one place to go and it had no exit.

the "threat to tile" is based on the number of units that can see the tile. taking into account what those units are holding is a bit... iffy, i mean, they might be holding motion scanners and medikits, but have a blaster launcher in their backpack.

The 'find cover' logic was deliberately tweaked to STOP units using each other as cover, as hilarious as it was, they often decided that directly behind/beside your men was a pretty good place to keep out of sight. even more hilariously, it often worked.

Ah yes the old giant weapon hiding in backpack trick...
I really wouldn't mind that problem - I mean if the aliens were really calculating and I wanted to draw them into a trap it's what I'd do.
And OTOH if I were the alien commander it's not something I'd really worry about - alien forces are infinite - They can lose every battle and win the war.

Ex: Sectopods usually take me 10-15 shots to take down due to their armor.  But they rarely fire back.  Instead they run and hide. I simply must fix this.

the "choose target" logic, generally speaking, prioritizes whoever's closest, because naturally, there's a better chance of hitting them, and in the case of melee, it means more TUs left over when you reach them to use on chewing and swallowing.

And that works great your units can likely damage anything (or aren't supposed to be smart enough to worry about it)
I admit I don't know how to keep my reapers dangerous by the end if they aren't overpowering in the early game.  I'm thinking about balancing it with an armor piercing damage property - it would reduce the effectiveness of armor for purposes of determining damage, but wouldn't become damage after successful armor penetration.

about the AI states: the ai functions in two basic modes, "patrol", where he just wanders from map node to map node, looking for something to kill/eat/experiment on, and "aggro", when he has found somebody he doesn't like.

in the patrol state, he reserves a % of TUs as he wanders about, in case some hapless soldier wanders into his field of vision.

in the aggro state, he stalks his prey, and when he spots it, he makes a quick (very slow and cpu intensive) assessment of the cover around him, chooses a spot to move to, and reserves enough TUs to get there, spending the rest on shooting at his opponent.

unless he's psionic or has a blaster launcher, in which case he tries to use those instead.

So if I were to 'aggro' all 'patrolling' alien units at the beginning of any alien turn in which an xcom unit is spotted, the result would be the battle of Normandy !?

Phez
Title: Re: How to code the AI
Post by: Warboy1982 on July 16, 2013, 04:37:13 pm
i've made a bunch of adjustments to the AI routines, you should see many of these issues fixed.
Title: Re: How to code the AI
Post by: Phezzan on July 17, 2013, 06:30:21 am
I'll be chewing on that  merge for a bit. :)

I see you touched unconscious item loss - you should know that:

1 - convertUnitToCorpse() is called for unconscious units
2 - line 225 removes the Chryssalid's weapon.

therefore stunning a chryssalid will disarm it.

The easiest way to fix this is to condition line 225 on the unit actually being dead - as the fixed weapon already refused to drop in the preceding loop.
Well I don't know what your change (setting owner to 0) will do to an item that refused to drop.  Perhaps nothing.

I imagine that clearing the inventory vector would be dangerous if we had actually added a fixed weapon to the _game's _items.

Title: Re: How to code the AI
Post by: Warboy1982 on July 17, 2013, 07:20:21 am
nice catch, thanks.
Title: Re: How to code the AI
Post by: Phezzan on July 20, 2013, 07:27:26 am
So I'm playing with changes to fire mode selection, target selection, grenade determination, aggression (cover determination) and psiAttack estimation.
I've been reloading saves a lot more.  It's really powerful to allow the PsiAttack AI to pick-up weapons - it tends to panic a unit, then mind-control it.  Of course that unit now needs a weapon, and they might decide the harmless pistol they dropped is less appealing than the heavy plasma next to that dead alien. This really messes with my simple solution of giving all the weak minded people weak weapons.

Probably the biggest difference is my fire mode selection calculation tends to prefer auto-fire... I take into account the probability of hitting once in three shots compared to the probability of hitting with snap or aimed.  The game only considers distance - not the accuracy of the fire mode or number of shots.
formula: (100 - Accuracy) ^ 3 / (100 ^ 3)   * 100
More shots in the air means more lucky hits to penetrate armor, and more 'misses' that hit a different target.

Another change - I factored armor into the target choice.  I simply take the front armor of the target, double it and subtract my weapon power. This is added to the distanceSq() value and I choose the minimum result. I need to introduce some randomness and a tweak for facing.  This makes the aliens much less likely to harmlessly shoot your tank unless you actually hide behind it for cover or send it out well ahead of your troops.

Warboy's recent change makes the value moot but  SECTOPODs only had an aggression of '1' (the middle value in the cover calculation).  Considering they're tougher than almost anything on the battlefield and large there's not much effective cover for them anyway.

I tried to make grenades / explosiveEvaluation consider target armor when tallying effectiveness but I think my formula is too conservative and predictable, I want to have a shortage of loot due to all the explosions.

I haven't figured out what to do with melee units.

Between WarBoy's improvements and my own I admit I now have great difficulty with Ethereals - basically I can't send a rookie team, and I have to give all my weak minded guys weak weapons which are useless against Sectopods.

Mutons give me some trouble because they tend to live through several turns and can get lucky with auto fire plasma.

I want to give Chryssalids a 'sneaky' AI and Reapers a 'charge' AI which at higher difficulties hunt in packs and synchronize attacks.  Perhaps this would be a 'NinjaBAIState' and 'PackBAIState'.  Neither would 'Patrol'
Ninja would prefer small spaces and would avoid 'seen' tiles like the 'sneaky' AI.  Additionally they would prefer targets that are not visible to other targets.
Pack would always attempt to be 8-12 distance from the group's center, and would avoid any path less than 4 spaces wide unless it isn't visible to the enemy.  The 'group' would move by pathfinding this center to a new area and then allowing the individual units to find paths that place them within a 12 square radius.

Sectoids should use a 'hidden team' AI - basically a ranged version of 'Pack' but the whole group picks a target and then decides who shoots first, second, etc.  Everyone in the team 'sees' the target regardless of distance, cover, etc and each member offers up a guess on how much damage they can do to the target.  The best estimate is allowed to take their shot until the target is out - At which  point a new target is chosen.  The members who have no line of sight will either:
calculate a nearby tile to move to that has LOS, or
Force ignore LOS and autofire if the cover is weak (hedge) and more than 2 spaces from the AI unit, or
Grenade - either the target or one of the 8 squares surrounding the target if no direct arc is found.
They don't need to consider walls likely damage or secondary enemy targets - the idea is to destroy the cover.

If I get any of this to work (and still have hair) I'll post about the terrible terrible changes I made to the game.
Currently I'm thinking that there's a single 'GroupBAIState' and all 'squadmates' add themselves to it as _members.
Then since every member uses the same instance of 'GroupBAIState' it will do all the thinking for each _member the first time any member->think() is called. Future calls to its think() will simply return until a new turn is processed.
Title: Re: How to code the AI
Post by: wsmithjr on July 20, 2013, 05:35:00 pm
Very interested to see this and looking forward to the results.  Was watching a Let's Play and while I didn't think the guy played particularly well, he muddled through because the aliens just seemed to wander about and never go after him.  (Not sure what version it was.)  Thanks for the efforts.
Title: Re: How to code the AI
Post by: 54x on July 23, 2013, 02:02:10 pm
Just remember that if you're introducing randomness to the AI it should seed in a way that's reproducable in battlescape saves, so we can reproduce bugs still. :)
Title: Re: How to code the AI
Post by: pmprog on July 23, 2013, 02:11:31 pm
Maybe a Quake-style console should be added to battlescape, then you can call something like "Seed {n}", and "GetSeed" :)
Title: Re: How to code the AI
Post by: SupSuper on July 23, 2013, 05:36:43 pm
Saves already store the seed, if he uses the same RNG it should still be reproducible.
Title: Re: How to code the AI
Post by: mercy on August 05, 2013, 11:27:05 am
Respected coders here might wanna take a look at the best AI ever seen in UFO DEFENSE:

Version 1.31.2
https://www.strategycore.co.uk/forums/topic/10341-ufo-extender/

On Superhuman that AI feels real, visceral. I feel like a victim in the movies Predator 1 & 2. Exactly what is needed! It is a real thrill to win a bloody battle there. The entire gaming experience is narrowed down to tight spaces, where XCOM soldiers are screaming and begging for their lifes and the hungry aliens are hunting them down like prey.

OpenXCom has the best UI in the world, awesome MODs, still it lacks a good frightening AI (beyond Warboys awesome surround Skyranger-feature, which should remain!!), which aliens are all about.

OpenXCom does a good job at making aliens surround the Skyranger and shoot, but later the aliens should move, use surprising tactics and must be deadly as hell.  Check out above link!
Title: Re: How to code the AI
Post by: Amunak on August 06, 2013, 02:13:18 pm
You know... Some of us still like the fact that it plays like the original. It's nice to have deadly aliens, but I guess for most people it's not really fun when you play one mission for  four hours only because you have to repeat it over and over again ;)
Title: Re: How to code the AI
Post by: 54x on August 06, 2013, 10:13:22 pm
You know... Some of us still like the fact that it plays like the original. It's nice to have deadly aliens, but I guess for most people it's not really fun when you play one mission for  four hours only because you have to repeat it over and over again ;)

It doesn't play like the original. ;) If saves were portable you could see for yourself, but iirc, the AI is entirely new code?
Title: Re: How to code the AI
Post by: Warboy1982 on August 07, 2013, 07:20:47 am
the AI is similar but different, i'm currently working on making it MORE similar, by sifting through the decompiled original and taking notes where appropriate.
i have to say, for the most part what we're doing is very similar to what i'm seeing in the original, except we cheat LESS. in the original the aliens had eyes in the back of their heads, for example, and they know where you are even if they can't see you (not just for psi targetting).
and the cover assessment was MUCH more simple in the original, except they had 2 types of cover, full and partial. i've even found some unused code for melee attacking without a weapon (code that was probably actually put to use in TFTD) which gives me a nice insight into the melee damage calculations regarding melee accuracy and strength.

the AI was much more... squad based in the original. aliens would stop patrolling to seek out enemies they "know of" but can't see when in range, for example. i'll be working on this today ;)
Title: Re: How to code the AI
Post by: 54x on August 07, 2013, 11:13:45 am
the AI is similar but different, i'm currently working on making it MORE similar, by sifting through the decompiled original and taking notes where appropriate.
i have to say, for the most part what we're doing is very similar to what i'm seeing in the original, except we cheat LESS. in the original the aliens had eyes in the back of their heads, for example, and they know where you are even if they can't see you (not just for psi targetting).
and the cover assessment was MUCH more simple in the original, except they had 2 types of cover, full and partial. i've even found some unused code for melee attacking without a weapon (code that was probably actually put to use in TFTD) which gives me a nice insight into the melee damage calculations regarding melee accuracy and strength.

the AI was much more... squad based in the original. aliens would stop patrolling to seek out enemies they "know of" but can't see when in range, for example. i'll be working on this today ;)

Cheers for that clarification, I was aware we were making it more similar in a lot of individual ways and that it was currently original code, but this clarifies that a lot... :D
Title: Re: How to code the AI
Post by: mercy on August 07, 2013, 11:22:02 am
Just make it fun:
- which meant aliens cheat a lot
-  they have eyes in their back - they are clairvoyant / telepathic / superintelligent - that would mean aliens "smell" and sense the miasma of human thoughts so they most of the time know where soldiers are.   

Unless 20-30% of the time the soldiers mind is able to contain fear so his/hear thoughts doesn't "smell" as strong.
Title: Re: How to code the AI
Post by: Mr. Quiet on August 07, 2013, 11:45:34 am
Hahahaha mercy but I want the aliens to use real and badass squad tactics to strategically take you down once they spot you. I want to be shocked at what they can pull off. I'm waiting for Xenonauts to fulfill that promise hehehehe  8) they promised hardcore alien A.I. without boosting stats.
Title: Re: How to code the AI
Post by: kevL on August 07, 2013, 03:47:41 pm
sounds like there's two (strongly) divergent camps..

Personally I don't want oXc to become a purebred tactical shooter sim. i want it like the original.

Take chyrssalids... remember how they would stagger and strut back and forth in front of your front line soldiers? I haven't met any yet in the new AI, but in the old I'd freak out whenever they started pacing toward my dudes, then sigh of relief when they turn away, then freak out as they turn back and come a few paces closer....

i Mean, if we really want it hardcore: they turn a corner, see your guys, make a beeline and that's that.


+1 for original, "alien" AI here
Title: Re: How to code the AI
Post by: mercy on August 12, 2013, 02:25:17 pm
Regarding fun gameplay the only serious feature OpenXCOM needs now is a better AI than XCOMUTIL+UFO Extender.
Title: Re: How to code the AI
Post by: Surrealistik on August 13, 2013, 12:05:04 am
I want smart, tactical AI, not the retardation of the original.
Title: Re: How to code the AI
Post by: kevL on August 13, 2013, 12:54:36 am
well, the thing is there's 4 battlemodes in the original: patrol, attack, ambush, flee...

if those get implemented tightly I'd be hap.
Title: Re: How to code the AI
Post by: Warboy1982 on August 13, 2013, 02:02:12 am
i'm working on it, but i need help, i can't handle this on my own.
i'm pretty sure i have the decision making figured out, but some of the functions are a little obscure.
mostly it's to do with the nodes.
the original stored info on node links, specifically, what movement type was valid between one node and another.
it also did a lot of target calculation based on these nodes. i can assume that the nodes were used as a way of cutting down on calculations, as they could be placed by hand in logical positions, rather than forcing the AI to evaluate every single tile.
i've managed to identify what triggers each type of behaviour, and how it flows, but the devil is in the details, as they say. there's a LOT of alteration required.

if anyone is interested in helping me out, i'm almost always available on IRC.
Title: Re: How to code the AI
Post by: Mr. Quiet on August 13, 2013, 07:06:32 am
I like original aliens too. I just want them to do more than the usual. This will be fun for Warboy :)
Each time I get into the battlescape, I want the aliens to be ready for me and they'll always have different setups. Some will be ambushes waiting for you to come to them if they're weak and low in numbers. Others will be immediate assaults on your Skyranger if you don't move out quick enough. Scattered aliens is fine, I just want them to regroup or plan well when they see you showing up. They'll always know oyur position unless it's a Crash Site mission, where they might be injured and dizzy ::)

In midgame, when the aliens are reaching full strength with Mutons and large ships, they'll work in small squads of 2 to 4, each with a different strategy and some working together like an assault team that will attempt flanking maneuvers while your operatives are busy in a firefight, taking plasma shots from a short distance away. Others will wait patiently for your appearance so they can snipe you from the high ground. Another team will attempt to go the long way, away from the battles and toward your Skyranger if you're not careful enough. If you left Ops inside your trans, they'll probably throw a grenade inside before going in. I'd say it's smart to run into the nearest two to three story and set up shop.

Good luck Warboy, we appreciate all your work. We just want the best and the most evil alien A.I.
Title: Re: How to code the AI
Post by: kevL on August 13, 2013, 11:46:17 am
dammit i'm just trying to get them to do a death pirouette, Jim!

/ McCoy


[edit] woohoo!
good luck, Wb. I hope someone else w/ chops dives in...
Title: Re: How to code the AI
Post by: Warboy1982 on August 13, 2013, 07:39:13 pm
starting to make some real progress, though nothing compilable yet.
Title: Re: How to code the AI
Post by: mercy on August 14, 2013, 10:11:04 am
i'm working on it, but i need help, i can't handle this on my own.
[..]

You mean you need help in looking at the vanilla code in the debugger and figure out how their ASM works regarding AI?  What functions go where do what?
Title: Re: How to code the AI
Post by: darkestaxe on September 15, 2013, 08:43:54 pm
Here's a thought, suppose we have a three option setting: Original, Realistic, and RealSmart. When Warboy or whoever finds a part of the code like the examples he gave then that part can be coded up to three ways. RealSmart would fall through to Realistic when a RealSmart version isn't present. The idea is to have a consistent system for distinguishing between the three attitudes toward AI when the AI programmer wants to without having to code/update/maintain 3 separate AIs for everything.

Original: Mimic original behavior as accurately as possible, down to wandering chrysilids and omniscient aliens.

Realistic: Original-like non cheating choices in which aliens make decisions that make sense and are based on what they can know.

RealSmart: Ignore the original and make the AI as smart, deadly, and unpredictable as possible without cheating or otherwise being unrealistic.

Example with chrissalid:
Code: [Select]
IF (AI=STR_ORIG) {
   https://wander aimlessly
}
ELSE {
   https://approach visible soldiers directly without thinking
}

https://with smart AI code added
IF (AI=STR_ORIG) {
   https://wander aimlessly
}
IF (AI=STR_SMART) {
    https://plan optimal number of zombies without taking too much reaction fire and still
    https://being able to retreat to cover, or hide and wait for better opportunity.
}
ELSE {
   https://approach visible soldiers directly without thinking
}
Title: Re: How to code the AI
Post by: djemon_lda on October 13, 2013, 04:54:01 pm
you are going to suffer deadly in all those "if-else/switches" just begging for someone to show you mercy and kill you.
make the core AI actions polimorphic and be produced by an abstract factory configured by your options with concreete factories for example:
Code: [Select]
IAIFactory
{
virtual IAIBehaviour* Make(UnitCreationData creationData) = 0;
};
or
Code: [Select]
IAIFactory
{
virtual IAIBehaviour* MakeSectiod() = 0;
.
.
.
virtual IAIBehaviour* MakeCivilian() = 0;
};
whatever suits you best, but I personally would chose the first version, and then make an implementation for each of the AI type like:

Code: [Select]
class VanillaAIFactory : public IAIFactory{ ... };
class RealisticAIFactory : public IAIFactory { ... };
class RealSmartAIFactory : public IAIFactory { ... };

That way you can write a lot of code, that won't have to be changed when you add new AI modes, or will wish to do stuff like sharing some AI behaviour, or distinguishing. You will be able to, at any point, say "hey, I want all sectoids to do ABC, but their commanders are going to act absolutely different, but only for Smart AI!", and the only thing you need to change in that scenario is:
a) make an SectoidCommanderSmartBehaviour class describing it's behaviour
b) change the RealSmartIAFactory to support the new guy - here is why I prefered the first factory, because giving it the creation data makes it THAT much more stabile code, and the interface would basically never change