As some of you know, I’ve never written tactical battle AI before. Galactic Civilizations and Stardock’s other games didn’t have tactical battles. War of Magic had tactical battles but I wasn’t involved in that portion of the game.
This series of journals will take you through the journey of how to write AI for tactical battles. In my experience, games have tended to have pretty crummy AI when it comes to tactical battles (War of Magic no exception).
So for starters, I’ve got help. Seasoned developer Charles Lentz, who has been at Stardock for some years now, is assisting me on this project. The first thing I asked him to do is make it easy for me to do mock battles. When I was working on War of Magic v1.4, which was the first build I even got to look at how tactical battles were done, I noticed that there was no way for me to conduct mock battles. I’d have to “get lucky” and find an AI player who could cast spells to see if it even worked which was time consuming.
So for Fallen Enchantress, I asked Charles to set up a cheat key that would create opposing armies and that it would read from an XML file that I could mod to decide what powers those units would have. That way, I could test out all kinds of combinations.
Since I come from the modding world, I prefer to have my games let me, the player, mod as much as possible. My AIs have not been very moddable in the past because, frankly, the coding necessary was far outside my area of expertise (i.e. making it read variables and data from external XML files rather than just hard coding it in C++). But with Fallen Enchantress, Charles is going to take care of that for me.
So one of the things I intend to do is stuff as much data as I can in XML files. I want to be able to have the AI gather as much data as it can about who it opposes and then look at the XML data to help it decide what to do.
That means I want to make it so that every spell, ability, weapon, etc. in the game has in its XML AI data that I (or others) can mod with good things to go against it.
Does the enemy side have a spell that rains down a fire storm on me? Then I want that spell to include in its XML what spells are good counters to it. Then, the player comes in with his fire mage and the enemy casts a frost shield on her first turn.
Moreover, this gives me the excuse to request the UI team to let both sides see what spells/abilities each other have easily because a good tactical battle, in my opinion, should be a real battle of wits making use of terrain, spells, counter-spells, and maneuver. And the more data the player gets to see, the more data I can let the AI see without “cheating”.
Man, if I can come away from a FE tactical combat feeling like I just played a Magic: The Gathering duel I'll be one happy camper.
I just finished playing Tactics Ogre on my PSP, just a couple of days ago. Maybe most games don't have good tactical AI, but Tactics Ogre is one that is reasonably okay, or at least has withstood the test of time as being enjoyed by many and still played today which isn't bad for a game that first came out in 1995 (kind of like Master of Magic now that I think about it). Final Fantasy Tactics isn't too shabby either and gets a little 3D action, kind of. Not that I'm saying Stardock isn't on top of this, but I hope people on the team are at least familiar with these staple games of tactical strategy role playing, and aren't just looking at the games that don't have particularly good tactical AI.
I like what I've read here, but just want to throw this out. Fearzone mentioned Tactics ogre (amazing game). I mention final fantasy tactics and disgaea. If you had a fantasy game with tactical combat that matched the depth and polish of disgaea and the city building and storyline you've been working on, I'd think this would be a game I'd play the crap out of and love. I personally care more for tactical combat than most aspects (FF Tactics is one of my fav games). IMO, one of the best games of all time (kinda off topic, kinda not) is Actraiser. This was one of the first of its types. An action game that was also a city builder hybrid. But the main thing was that it did both things well and was entertaining. I'd love playing the action part and I'd love working on my city. Never really got old. It just ended before I'd have liked it to.
I guess I just don't want things to just be OK in FE. I want it to be great. Personally, I'd have one team (4-6 folks) working on tactical battles and another team (4-6) working on everything else. I'd think a huge amount of the ground work was already covered for the main game (non tactical), so perhaps less there. I'm not looking for "improved elemental." I'm looking for a brand new game that not only refines concepts, but innovates as well (eg I don't want madden 2000 compared to madden 2001).
Thanks for the post and sharing where things are. If you haven't played a game like disgaea, Brad, do it. Sell .1% of the electricity on your solar array, pick up a ps3, and play disgaea 4 for an hour. What do you think of tactical battle then and what enhancements could you come up with? Always good to look at successful turn based tactical battles (step MORE outside the box of the civ4/5 venue). They are one type - FF tactics and disgaea are a whole other beast.
If you somehow captured the uniqueness that characters have in disgaea in your turn based combat, that would be huge.
Anyway, my 2 cents.
Sounds very promising.
Really looking forward to the Beta.
to be fair, disgaea's tactical AI is not very good Pacov
Plus the first hour is all the tutorials zzzzzzzz. But Disgaea does have a great flavor, and 3 is one of my favs.
My concern:
I could see this AI being gamed a bit, though I think it's impossible to avoid gaming an AI unless the AI has a bit of randomness, or pre-knowledge that a player likes to play games.
I really think AI should adjust to the player's tendencies from game to game, how hard would that be to implement? I remember VF4 on the PS2 having that in its AI code- where if you kept doing certain things, the game would counter it and force you to mix it up.
i like iarienna's post... i think puts out alot of good ideas. im also feeling a ogrebattle like concept of giving units orders and that unit pretty much does its own thing according to the strategy given. i mean im not saying that on the world map you dont move around your pieces but when in tactical combat you dont directly control each action your armies just set the strategy for their behavior. the only thing that should be player controlled should be the soverign as how the game always advertised that you take took role as a soverign bit. i think that would give a unique flavor as the only unit in strategic combat you can directly control is the soverign ( yourself) and the rest of your armies do things according to the strategy do select for them.
any case i think the idea should be explored to some extent in the game as it would remove micromagement in the tactical battles... as i would find it rather boring to press a button 3 times in a row to make my line of pikemen attack. i would find it alot faster and funner to select a strategy that i see the pike men go at it for a round then themselves dig into a defensive position.
anycase + karma to iarienna's post
A note:
What's equally or even more important than the tactical AI is making sure that the AI controlled side arrives in battle with a mix of units capable of doing what's being discussed.
In most games the strategic AI sends armies to engage the enemy only to have the tactical AI withdraw.
Allow me to advise slightly against this. Instead I'd suggest allowing spells to be tagged, e.g. "Warming Aura" might be tagged with [defensive], [fire], [aoe]. The XML for "Deadly Blizzard" would specify tags as counters, for example [fire], [immunity], [resistance], [defensive]. The counter-AI would try to pick a spell with multiple appropriate counter-tags.
This way there's a lot of room for AI optimization by manipulating spell-tags; and makes it MUCH MUCH easier to add new spells without having to manually update 2mb of XML counter-data.
Basically the AI shouldn't work with spell-names, but spell-function-identifiers.
I disagree, general tags like that never reach the depth necessary. And the game won't consist of 10 spells doing the same thing slightly differently. It'll be one AOE fire spell, one AOE ice spell and so on. Each type would need a different tag anyway, such as CounterAoeFire and CounterAoeIce. You might as well link straight to suggested spells instead. You wouldn't have to update "2 mb" of xml data. You'd update one or two lines.
As with every piece of software, the possibility to create a test-case exactly how you want, and to rerun it ad infinitum is incredibly valuable. I am very, very surprised this was not present in War of Magic, but it does explain why the battles are so flat - there simply wasn't a huge investment in time there, at least not as much as should have been. Such is the life of the developer.
Thanks for the update Frogboy! I've grown enthousiastic about the WoM-line again, because of the FE-stuff... Hopefully, more for you than for me, it will pay off in the end. Of course, you already have my money, so no worries there
No, each type gets multiple tags. Instead of [CounterAOEFire] you'd have [AOE] and [Fire]. "Deadly Blizzard" would indicate that [Fire], [Defensive], [Resistance], [Immunity] are valid counter tags. [Fire] would fall under the category of Damage-Type tags, while [Defensive] and the rest are under category Protective tags. The AI's job is picking a spell that ideally matches at least 1 tag from every of the categories specified. So its not a matter of a single super-tag [CounterAOEFire], but having a list of viable tags and finding spells that match a suitable subset.
"Heart of the Sun" [self], [fire], [resistance], [permanent]"Aspect of the Immortal" [self], [all-damage], [immunity], [temporary]"Warm Aura" [aoe], [fire], [defense], [permanent]"Mass Elemental Shield" [aoe], [all-elements], [resistance], [temporary]
Would all qualify for countering "Deadly Blizzard". Note that [fire] is a child of tag [all-elements] which is a child of tag [all-damage]. So parent-child relations are accounted for in the counter-process.
This makes a massive difference when there's a substantial number of spells. Also it will make modding vastly simpler.
I can already see this bug happening: Fireblast is countered by Iceshield. But on release the AI doesn't use Iceshield because in its XML the counter spell specified is "Fireball" - but marketing decided that "Fireblast" sounds much better, so the name got changed but not updated into all its outlying fields.
HenriHakl has the right of it I believe. If you want people to be able to mod in a few extra spells without having to also modify EVERY existing spell in the game to update counter spells etc then you need it to be done through applying multiple generic tags to each spell.
Having said that I think there is a benefit in also allowing a spell to specify that it is a counter to a specific spell by name for a few special cases there there are very powerful or special spells which have odd effects and need to be linked. But the vast majority of spells should be understandable and useable by the AI with generic tags.
Yes. Mistwraithe has it right - there should be facility to specify specific spells as well. Sometimes it is just necessary because of complex spell-interactions that cannot be readily modeled in tags.
Yes. Mistwraithe and HenriHakl have it right, I believe. Not that I know anything about game AI, but this would make things a lot easier on modders.
HenriHaki, so you want to have spell tags AND unique spell counter information in the XML, in order to simplify it from having only unique spell counter information?
I'm with Heavenfall on this. Doing it by tags makes it a lot harder to make AI do the right choices. You need to balance the tags perfectly for it to know which spell is the best counter. There's also a big risk that the AI would cast a spell that is in fact not a proper counter at all. Simple example: Spell "poison immunity" has tags [immunity] and [poison]. You cast a spell "spread disease" which says that spells that have tags [immunity], [resistance] and [disease] are a valid counter. Now, in order to not make the AI use poison immunity which wouldn't work, you would have to have the XML say that the counter MUST have the tag [disease] in it. So you need to have logic operations in the XML now, instead of just listing the counterspells directly. With a little bit of imagination, it's not hard to vision examples that make the tag system even more complicated.
Direct counter information is a better system.
EDIT:To make modding spells as easy as possible, I would consider making the AI to go through both the spell the opponent has cast for COUNTER tags and spells he can cast himself for EFFECTIVE tags (for spells this spell is effective *against*). This way whenever you mod in a new spell you would only need to add the COUNTER and EFFECTIVE tags to the new spells to keep the whole database updated. It doesn't matter that there is duplicate data.
OR, I would just write a simple script that updates the spell XML counters whenever you make a new spell. Either case, I don't think adding new spells comes so often that updating the counter information is that big of a chore.
I like the initiative concept and the delay idea between choosing an action and it occurringvs the opponents' defensive/counter action. This should make magic more valuable in combat and perhaps more relevant to keep your units protected or toast the opponent. I look forward to seeing how it works in practice. Two thumbs up. I am curious how the interaction between defense, offense, range weapons and spells will work out and what variety results.
How about:
- Combat rules programmable via xml (in addition to data on spells)- Two levels of AI, Commander and Unit specific
The unit AI comes into play if the commander chooses not to do anything with it or decides to let the unit make a decision.This might help with the 'dumb unit behaviour' .
The Commander AI has the option to direct the priorities of the unit. (over-ride).
This creates a programmable combat engine.
Example Unit AI rule snippet
// Basic Sword Unit[Melee DPS] Basic Sword Unit
[Priority Target List] Attack directed, Attack Nearest, Attack Ranged, Combined Attack, Attack Magic unit. // Highest to lowest priority[Priority Defensive List] Defend directed, Defend self, defend closest, defend closest magical, defend closest NPC // Highest to lowest priority.[Orders Priority List] Attack, defend, fallback, avoid //initial priority list, highest to lowest.
[Decisions][Health<50%] Bump Defend up priority List[Health<75%] Bump fallback up priority list[Hit with AOE]Bump Avoid to top of priority list
Will it still be turn based? ie. will any game time elapse while you're choosing what a certain troop will do?
Best regards,Steven.
StevenAus, game time will not elapse while you think, no. It's turn based but it doesn't have game 'rounds', upon which all units act once.
I have a question about AI knowledge (which also applies to the strategic level as well). How does the AI know that the opponent has a fire storm spell unless they have faced the opponent before and it was used on them?
I also think that a player shouldn't be able to "know" everything about an enemy or, in particular, its cities unless it has somehow gained that knowledge.
The main way I see of obtaining this info is through spies. It may be too late to work this into the framework of the game, but it would be a neat touch and lend more logic to how players gain knowledge of the opponents.
Great news, looking forward to your further posts on this subjects.
I wonder if a modder will be able to create different tactical AI's for different fractions to reflect an AI sovereign's tactical bent - i.e. some might be cautious, others might be methodical and some might just charge in while some AIs might be sneaky and others forthright.
Mmm, perhaps link the AI used to the Sovereign's Intelligence (and/or level; battle experience)? A higher intelligence (and/or level) Sovereign/Hero accessing a more nuanced AI routine.
Perhaps: If an opponent is going to cast a spell you can recognize the caster's actions if you have that spell book OR you make an intelligence check (5% x Intel Level).
Are the AI players going to be attacked by wandering nasties? That was a big break in immersion in WoM - undefended pioneers having all sorts of monsters just walk past them, while the monsters head for the human player. In the more dangerous world of FE, it would be even more immersion-breaking to have AI players left alone by neutral nasties, purely because they are AI players, while the human player gets attacked without fail.
to the AI comment by XIA:
I disagree, I think this is a good way to start. If the AI knows that it has a counter it should use it, sort of reminds me of yugio when I was reading it and it sounded fun. The battle system has never been very good in elemental it was more about overwelhm the enemy with numbers or if you had a spell caster just bomb away on them before they reach you - fun but not truly tacticle.
The spell types and such in the game make it so that it should play more like a tacticalRPG in battle - which it sounds like they are trying to make it do now. So please have at it.
To the Comment above me:
Good point, monsters should be a problem for every one
There is a performance hit that has to be considered also, disc read and writes are intrinsically slower than any other type of access. If this becomes too complicated. That being said, create the XML files dynamically is a good idea and it pretty easy in c# (not sure what language you guys are using). This should be done one game load with the battle system querying the xml data for counters and attacks, returning the data should be ordered by effectiveness. Decent AI will select the most effective counter 50 percent of the time, Good 75% Great 100%. For this to be effective they need to also have an initiative roll to determine who gets the 1st attack.
There are many great features available to you once you register, including:
Sign in or Create Account