Devblog #39. Enemy AI – Part 1: One Brain for the Entire Group

devblog39 main

Hello everyone.

I’ve previously talked about combat in IRSEN. The core idea behind my combat system is that the player fights against groups of enemies. Each enemy fulfills a role familiar from classic RPGs: tank, healer, support, or damage dealer. However, simply having different roles doesn’t make a group a team. A role determines an enemy’s stats and abilities. Today, I’d like to explain the group AI system I introduced in the recently released version of the game.

Let’s consider a simple example.

Two enemies are fighting the player. One can apply Vulnerability, increasing the damage the target receives, while the other has a powerful attack. If the attacker acts first, it deals its normal damage. The second enemy then applies Vulnerability, which can no longer affect the attack that has already happened.

Both enemies performed useful actions, but in the wrong order. Simply reversing their turns would have produced a much better result. This is a basic example of why individual AI scripts aren’t enough for coordinated actions.

Individual Enemy AI Scripts

Some years ago, I was developing AI for mobs in the open world and dungeons of a private World of Warcraft server. Even back then, I became interested in how different types of mobs could interact with one another. I started with very simple scripts. Mobs could find allies within spellcasting range and cast basic buffs or healing spells on them. Each mob acted independently, but whenever it had an opportunity to cast something on an ally, it looked as though they were working together.

I liked how much stronger this pseudo-team could be compared to two completely independent mobs. Yet there wasn’t really a team at all. Each mob simply had its own script controlling its behavior.

I began thinking about creating a higher-level script that would coordinate the individual scripts of all the mobs. Such a system would know not only what each creature could do individually, but also the complete set of actions available to the entire group. This would take enemy behavior to another level and turn a collection of mobs into a real team.

devblog39 1

During the initial development of IRSEN’s core systems, I implemented a similar approach based on individual AI scripts. Each enemy made its decisions independently. It considered the battlefield and its own capabilities, but paid little attention to what its allies were doing. Individual decisions didn’t combine into a shared group strategy.

In recent updates, I reworked this part of the combat system and finally implemented the higher-level AI system I had once wanted to create for my WoW server. Enemies can now coordinate their actions across the entire group.

Why Individual AI Isn’t Enough

Previously, enemies already followed their own rules. Healers chose when and whom to heal, tanks tried to draw the player’s attention away from weaker targets, and damage dealers performed attacks according to predefined behavior scripts.

But what happens when the effectiveness of one enemy’s action depends on another enemy?

Let’s return to the example with Vulnerability and the powerful attack. If the attacker acts first, the opportunity for a useful combination is lost. The same applies to buffs, stacking effects, and conditional damage bonuses.

One possible solution would be to add rules such as “attack after your ally” or “wait until the target is weakened.” But with every new ability, the number of special-case rules and possible combinations would grow. Such rigid behavior would become increasingly difficult to maintain, especially when existing abilities are changed or rebalanced.

A higher-level group AI system solves this problem.

devblog39 2

How Coordination Works

Individual AI and group AI work together. On each turn, every enemy has a list of actions it can perform. Each action has its own properties, represented in a shared format.

For example, some abilities apply Vulnerability, increasing the damage a target receives. Others can stun, provide buffs, remove Fortify, apply debuffs, or inflict damage-over-time effects.

During ability processing, these different skills are converted into a standardized set of possible actions and their effects. Each enemy’s individual AI collects its available abilities, converts them into this shared format, and passes the information to the group AI. The information also includes expected raw damage or healing values, as well as ability cooldowns.

The group AI then compares the available options and selects the most useful action. The main difference from the old system is that the situation is reassessed after every enemy action. Instead of several independent enemies, the group becomes a single combat mechanism, with the group AI controlling how its different parts work together.

Enemies no longer follow a rigid sequence of actions planned for the entire round. The group AI also decides which enemy should act next and which of its abilities would provide the greatest benefit to the group. After that action, the next enemy and its action are selected based on the updated situation. If an ally dies or becomes endangered, priorities change accordingly.

One of the first noticeable results of this change is that enemies no longer take their turns in a fixed order. Previously, they acted one after another according to their positions. Now the group AI determines their priorities, so you can never be certain which enemy will act next.

In the next devblog, I’ll demonstrate with a concrete combat example how group AI changes enemy behavior. I’ll also explain why I deliberately limited the capabilities of this system.