• Add Review
  • Subscribe
  • Nominate
  • Submit Media
  • RSS

Enemy AI

One of the benefits of doing an entirely custom combat system is that you can control what actions enemies will take in combat. RM2K3's built-in enemy behavior system is pretty limited, providing only a few controls for deciding to take one action over another. If you were determined enough, you could probably build a system in RM2K3 scripting which runs in between each battle action and sets switches to control the upcoming enemy action, but it would be very messy. In Forgotten Gates, the built-in behavior of the enemies is always "Do nothing", and I use scripting to decide what the enemy's action should be and then simulate the effects (show a battle animation, deal damage, etc.).

In the currently available demo of FG, there is a limited amount of actual intelligence to the enemies' action choices. There's a script event which calculates a tactical value for each possible action, then chooses one randomly with the more valuable ones being more likely. It takes into account things like how much damage would be dealt, what status conditions might be inflicted and whether the target already has them, the probability of missing, etc. As it currently stands, this leads to enemies that largely fight to win, albeit in a short-sighted way. If you've played the demo and run into a group of lizalfos, for example, you might have noticed that their opening move is almost always to spend most of their mana on a Fire Breath attack, because dealing damage to your entire party is a high-value tactical choice. Whether that makes the game more fun than simple random action choices is a matter which depends on both the preferences of the individual player and on the other balance choices of the game as a whole. I would argue that at the very least, this predictability that the enemies will likely choose the most difficult action for the player to deal with allows the designer to balance the game around that scenario, while simple randomness can cause the occasional total party kill in a game balanced around enemies' long-term average choices being easier for the player.

At any rate, the tactical greedy algorithm with weighted randomness has always been intended as just the core of my enemy AI, which I plan to build upon. The enemy behavior shouldn't just be to always try for a win as if they were controlled by a human opponent, they should behave in interesting and flavorful ways. I want to have enemies take into consideration things like what they and their comrades have done recently, what has happened to them (an enemy panicking and making a bad choice is certainly an option), and possibly even having special interactions between certain kinds of enemies. On top of that, the current narrator should have some influence on enemy behavior, with one narrator liking enemies to go for status debuffs, another preferring high-damage magic, etc. This will all be significantly easier now that I'm redoing the combat plugin in a DynRPG plugin; I'll have unlimited variable space to work with and the ability to work in an object-oriented fashion. A while ago I read a Gamasutra article (which I can't seem to find now, oh well) which mentioned graph editing programs like yEd can be used to create behavior trees and export them to a text-based file that can be easily read by other programs. Considering the success I've had using data exported from Excel for my combat plugin, that may be a useful avenue to explore for my enemy AI.

Of course, in all this I have to be careful that I don't wind up creating some intricate masterpiece of AI that's no fun to play against. X) Or almost as bad, no more fun than a simple random AI, which would mean I just wasted my time making it. A Gamasutra article about why designers should learn animation gave me this quote from Emily Short:

"It’s pointless to simulate anything in AI that you don’t also have a plan for communicating to the player - otherwise they don't see how clever you're being or (worse) what is actually sophisticated behaviour winds up looking like a bug."

In my case, I'm hoping to communicate to the player through literal tells: enemies will occasionally say things or the narrator will describe them doing things that hint at their next combat action. But, that's a topic for a separate blog post. ;)