Posted on February 26, 2014
When we started building Kyn one thing I felt strongly about is that the game is only as tough as its enemies. I didn’t want the player to just pick a powerful skill and rush through the entire game without a challenge. I also didn’t want it to just be a matter of the one with the strongest equipment or highest level wins. The enemy’s AI and abilities are pivotal in providing a more interesting challenge.
There are different ways to provide challenge that are often used in rpg and rts games. You can take the baldur’s gate route and make it slow/turn based and focus on countering the opponent’s abilities. I like this approach, but it can become repetitive and it is also too slow for Kyn. I think Baldur’s gate is more like chess, while Kyn should feel like fast chess. Another approach is to make it about positional awareness. I think Company of Heroes and Dawn of War do this quite well, but the enemies often have rather limited abilities (think shoot, throw grenade).
In Kyn positioning is important, so is prioritizing targets and selecting the right abilities for the situation. The enemy AI plays a big role in challenging your efforts. For example, some carry shields that nullify all incoming damage from the front, soaking up the damage for their more squishy friends. Some enemies work together to use their abilities efficiently. One will pin you down by throwing a net. Another uses a spell that you could dodge earlier, but it isn’t as easy now that you are pinned down.
This type of behavior requires the enemy to organize its efforts. Squad formation and communication is one of the key elements that determine how organized an enemy will be.
Our AI uses blackboards to store world information. The blackboard stores various things:
- Enemies: At what location was an enemy spotted and how long ago.
- Friends: Where are my friends located, are they healthy, do they need my help?
- Location Information: Where are good cover positions, is there high ground nearby, are there ambush positions, regroup points, etc.
- Communication: Are there any messages for me, does someone need my help or my abilities, did they spot something. etc.
Squads use a shared blackboard. When an agent (common term for AI entity) is assigned to a squad it will use both its personal blackboard and a squad blackboard. This shared blackboard is very useful, because all information on spotted enemies and interesting locations will be shared with the entire group immediately. Besides the blackboard the AI can also send messages to specific squad members or broadcast information in the area.
We use two approaches to squad behavior, directed behavior and autonomous behavior. The directed approach has one leader that directs the entire squad. This boss might be a pack leader that you can kill, or it is a virtual brain that gives orders. With the autonomous approach the agent determines for itself how to be useful to the squad. Both approaches have their strengths and weaknesses. In Kyn the directed approach results in more rigid but powerful formations. The autonomous approach results in more dynamic and situational aware AI.
The best way to show the difference is by looking at the squad positioning. In Kyn each squad member has a distinct role:
- FrontLiner: This agent tries to get in the midst of combat and stays near the enemy.
- Melee Flanker: This agent is not looking for the direct confrontation, instead it will try to flank, do hit and runs, and attack weakened targets.
- Ranged Flanker: The ranged flanker is a very mobile agent that keeps it ranges while harassing the player from different angles.
- Ranged Core: This agent is often at the centre of a squad. Usually mages that deal a lot of damage but want to stick behind front liners to avoid direct damage.
- Support: This agent is often in the back of a squad. Usually a support that casts healing spells.
Individual approach – the support
The support is an agent that is there to support his squad instead of directly fight the player. A typical example of a support is a healing agent. The ideal position for a support is behind his stronger comrades, out of range of the player. In the individual approach the support determines its own ideal position. This is done by following a very simple rule:
Stay in range of my allies while keeping my allies between me and the enemy.
When combined with front liners the emerging behavior is the frontliners attacking the player at close range while the support stays behind them throwing healing spells. If the player moves towards the support, the support will reposition trying to find a good position behind the frontliners again.
The directed approach is quite different from the individual approach. In the directed approach the AI uses formations similar to medieval and modern army formations. The directing AI changes formation depending on the enemy approach and its own composition. This results in more rigid but coordinated formations.
- V Formation: The V formation is used when the director wants maximum attack potential at a specific location. This formation is especially useful when the AI heavily outnumbers its opponent.
- Line Formation: The line formation is a balanced formation that is ideal when a squad has about equal frontliners and support and ranged mid cores. This formation is weak to flanking though.
- Wedge Formation: The wedge formation is a formation that has good protection from flanking while maintaining some frontal firepower.
- File Formation: The file formation provides good mobility, cover from flanking and stealth, but lacks frontal firepower. It is usually reserved for when on the move.
- Circle formation: The circle formation is used when surrounded. All available units form a circle around the supports and ranged cores. Since they are often the most valuable and vulnerable targets for the enemy. The circle formation is rather inefficient and often a last resort. It is very vulnerable to Area of Effect attacks because the squad is tightly packed.
AI Formation decision making
The director gets its information from the squad blackboard and assigns positions to the squad members based on number of factors:
- Squad composition
- Squad member count
- Enemy count
- Enemy position
Each enemy is checked for distance and angle relative to the squad. Based on this information the squad determines the best direction to face. Then this information is combined with the squads compositions to determine what formation is best to counter the enemy.
Combat is most fun when the two types of AI are combined by having different agents on the battlefield. For example a rigid directed group of enemies moving down a path while there is a guerilla squad trying to stay on your flank and in ambush positions. This will require you to prioritize, do I chase the highly mobile guerillas while the squads core is throwing high damage spells at me? Or do I try to break through the rather weak front line of the squad and take out the damage dealers first? Maybe split up and keep the guerillas busy while flanking the squad?
Next week I will talk a bit about the latest progress on Kyn.