Heart of Darkness | Behind the AI and Storytelling of Spec Ops: The Line
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.
Artificial intelligence is heavily employed in video games for the purposes of non-player characters that can either assist or oppose the player in a number of ways. Combat-driven video games such as first or third-person shooters provide an ample backdrop for innovation in both technology and design. So what happens when you come to make a shooting game aiming at defying modern conventions? Not just deviating from expectation, but making us question the very games we play and the choices we make as players. In this instance I'm going to look at a game that did just that, Yager Development's critically acclaimed 2012 third-person shooter: Spec Ops: The Line.
On the surface, Spec Ops is but another cover shooter in the mould of Microsoft's Gears of War or the Ghost Recon series by Ubisoft, but this presentation hides a much darker tale told against the backdrop of war-torn Dubai. The AI non-player characters are instrumental in telling that tale and I'll be taking a look at the design of the AI systems, the significant changes made during Spec Ops long and troubled development cycle and how both ally and enemy alike are designed to support the narrative.
EXPECT SPOILERS FOR 'SPEC OPS: THE LINE' THROUGHOUT THIS PIECE
About Spec Ops: The Line
In the wake of the worst sandstorm in recorded history, the city of Dubai is cut off from the rest of the world. Players assume the role of Martin Walker, a delta force operative who alongside his squad mates Adams and Lugo, are responding to a SOS signal sent by Colonel John Conrad: leader of the 33rd infantry battalion of the United States army who had entered the city against orders in a failed attempt to evacuate civilians. It's been six months since the storms hit and Dubai has officially been declared a No Man's Land. The world knows nothing of the fate of the 33rd - now publicly disavowed by the American government for treason - or the local population who were trapped in the city.
Spec Ops is highly story driven; establishing a rhythm whereby Walker and his squad explore the atrocities taking place within Dubai in between major combat set pieces. The tragedy that befell the city is everywhere to be seen and as players explore it further, you learn more about not just what has transpired but the damage your presence is having upon the remaining survivors.
In time as players persevere in combat and adapt to this harsh and unwieldy environment, we come to learn of the consequences of our actions. As a result, the protagonist Walker becomes increasingly mentally unstable; unravelling as he is unwilling to come to terms with what he - and by extension you - has done in an effort to bring peace to Dubai. This core conceit of the game is for players to not only question what's happening in front of them, but ultimately whether they're doing the right thing in a game that provides no other recourse but to gun down those that oppose you.
As detailed in his book 'Significant Zero', Walt Williams worked as narrative designer, lead writer and publisher liaison for 2K games during the project and realised it would require a difficult balancing act of player agency and the clever execution of the game's intended design in order to reinforce that narrative:
"If this was going to work, Walker couldn't start off unstable. That would be cheating. When a player starts a game, they become their character. At that moment, they need to understand the character's state of mind...
...To earn Walker's insanity, we needed to break him emotionally and psychologically. There had to be a moment when Walker, under the player's control, committed an act so terrible it could conceivably shatter his mind...
If Walker's mental breakdown was caused by a moment outside of the player's control, then they would no longer be in sync and the twist would not work."
(Significant Zero, pages 241 & 242)
This required the game to be able to communicate and maintain the constraints of the story during play. As such, the AI behind both the enemy NPCs as well as the supporting characters had to be given not just theatrical direction, but allow for improvisation as each players own unique telling of the story takes place. Through a clever usage of AI tools and design integration, Spec Ops successfully delivers on this experience. But in truth, the AI systems built and how they were adopted went through significant changes during the games development.
The AI Architecture
As mentioned earlier, the project went through numerous iterations before maturing into what we now consider to be Spec Ops: The Line. During this time the AI systems went through several iterations, completely rewriting many of the core systems in a period of 3 years. The project began development in 2007 under the title of 'Stealth Ranger', during which the AI used a STRIPS-style planning system - much like that seen in First Encounter Assault Recon, the subject of my first ever AI and Games video. Players could use this to give explicit commands to AI buddies in a manner akin to classic Rainbow Six games: players could assign locations for characters to take cover, to commit specific tactics, flank enemy opponents and more.
But this approach didn't sit well with the level designers: not because of the flexibility afforded to players, but rather that the AI was difficult to work with. The problem with the STRIPS-style non-player characters was that they were great at coming up with immediate and interesting strategies, but in the context of a cover shooter, it meant that the enemies frequently realised the best choice of action was to stay in cover. At this point a smart AI, did not make for a fun AI and as such a change was needed.
In 2008 the game migrated from 'Stealth Ranger' to 'Spec Ops' and again into 'Spec Ops: The Line' in 2010, with the overall design and the story of the game beginning to shift away from what these AI systems could provide. As such, the AI team rebuilt the entire system to use behaviour trees. Behaviour trees are a popular methodology in modern AAA games that I covered back in my pieces on Halo 2 and Alien Isolation. Behaviour Trees gave designers the opportunity to craft sequences of behaviours together that suited a specific purpose. However, as noted in a minute, the AI team made some small yet significant changes to the Behaviour Tree approach in order to make them more pragmatic for designers as well as maintain performance.
During this time all of the original behaviours built in STRIPS were translated over to the new system to be used. But as the game's design moved away from giving the player complete control of AI characters, these behaviours still found use in the hands of designers. In the final game players can only instruct allies to attack specific targets, heal each other when downed or commit a flash grenade when under heavy fire. However, most of the AI behaviours originally intended for the player's squad commands were retained in the final game, as designers reworked them in a number of ways throughout the campaign. This includes the likes of pushing up to cover, shooting from behind cover and blind firing. Interestingly, one squad behaviour originally intended for Adam's was the ability to deploy a portable mortar during the campaign. While this was ultimately scrapped, it is still used in the horrifying white phosphorous attack in order to achieve that desired sequence.
As mentioned earlier, Yager made one small change to the typical behaviour tree design that has a big effect on subsequent execution. Typically, behaviour trees on every frame or every couple of frames of execution will re-evaluate where within the tree it should be executing from; providing a more reactive behaviour based on what's transpiring in the world. However, with up to 8 active behaviour-tree-driven AI running at any point in time - two of which being Adam's and Lugo - this was becoming a big performance overhead, particularly on consoles. To address this, in Spec Ops all behaviour trees are entirely event driven - meaning AI characters will continue to execute a specific behaviour until an event occurs that causes them to shift to a different one. To achieve this, a sensory system was developed that processed everything happening in the game at a given point in time and distilled this data into useful facts that could be fed to the NPCs to react to.
With this system in place, the design and AI teams could work together to craft specific sequences and gameplay moments, but also leave some wriggle room for the NPCs to improvise during combat and provide a more cinematic experience. As such, major story moments such as the execution scene, the lynching of Lugo and Walker's subsequent hallucination of his ally after his death are all entirely scripted by designers.
Enemy AI Design
As we venture through the streets and buildings of Dubai, players come into contact with three different factions: the looters - armed civilians who are trapped in Dubai and fighting for survival, the damned 33rd itself and Zulu squad - Colonel Conrads' elite guard who are more aggressive and immoral than their compatriots. Each faction carries the same three enemy AI archetypes: close range, assault and long range, with each having their own distinct set of abilities and weapons. Outside of these are two special enemies used by the 33rd faction: the Commando and the Heavy Trooper. Both of which are designed to force the player out of cover, with the Commando charging the player while the Heavy is armoured, carries a big gun and proves to be a real challenge. Each archetype is designed to react differently if at all to a variety of events, such as the player pushing forward, grenades being thrown, the player reloading and many others. However, there are also a variety of dumb AI available known as 'cheapshooters' that are often used in the background to simply shoot guns and have basic reactions in larger sequences. A major design concern throughout development was to avoid dehumanising the enemies as much as possible, given they are in fact survivors of the disaster, but also feel a sense of familiarity when faced off against the likes of the 33rd, with a battle chatter system akin to Call of Duty where enemies frequently yell commands and express themselves - a point that will prove useful interesting later in this video.
Many of these archetypes have specific tweaks at design level that are aimed at building the overall experience as well as minimising performance overheads. So instead of working harder to simulate their intelligence they just outright fake it. For example, all AI characters know the location of every other AI in the game. This is largely to prevent them attempting to take cover, failing as someone else gets to it before them and then running back or to another location, which would look rather stupid. While the standard AI archetypes have to find you in the level before they can start attacking, specalists such as the Commando and Heavy always know your location: a deliberate choice to force players out of cover. In addition, not only do AI have unlimited ammo, but all their grenade throws are faked. Each of these is done for dramatic effect and to minimise issues that will occur in game. Enemies are forced to reload periodically to provide a break in the onslaught, but they also are not allowed to reload if it will break from the experience at a given point in time, such as flanking the player. Meanwhile, grenades are handled by a separate system that simply drops them somewhere near the players feet. The system assesses how long the player has been in cover, then selects a NPC within the players line of sight to throw the grenade: it will commit the animation and then whoops, a grenade lands a few feet away.
But don't worry, the systems at play also support players too! First up, NPCs will deliberately stand up when players attempt to mount cover they're hiding behind to allow you to kick them. In addition, NPCs will only target the player with grenades or flanking manoeuvres so as not to down ally NPCs too frequently and force you to go back and heal them - which is just so generous of them. Conversely, enemies will react to you throwing a grenade, but often slow enough that some of them will still be caught in the blast radius. In fact, throwing a sticky grenade at a regular enemy will force a behaviour where they run towards allies if they are in proximity.
Friendly AI Design
But while getting the enemy AI to work, your allies were a lot more taxing. Lugo and Adam's went through a lot of work to be tweaked and balanced in such a way that they are useful to player in combat and don't steal your thunder, but also behave as expected during more story driven sequences as well as at critical moments of the game.
First up, is how do the designers ensure that your allies continue to move around the world with you as expected? This is achieved through what Yager refer to as Squad Triggers: invisible volumes in the world that are placed by designers that when either the player or an ally walk into them, it tells them exactly what behaviours to start executing and often where in the world they need to go. Hence they can follow you through buildings, move across zip lines and the like with zero hassle. In addition, these triggers often influence movement delays - such that they typically don't overtake you lest you permit them, but also triggers specific voice lines to occur that allow for the story to play out.
Once combat kicks in, squad triggers allow for allies to know where they should be in the map. Each level has a set of preferred as well as permitted positions for each battle, with preferred locations often providing a more cinematic experience for the player. Ultimately these prevent the allies from getting caught in awkward positions and ensure they behave as intended. However once combat begins, each ally is given free reign to move around between permitted locations, but will willingly sacrifice cover positions if the player seeks to take them. Ultimately the squad trigger setup allowed for designers to ensure Lugo and Adams adhere to the story and does as is expected, but still gives them enough freedom such that it isn't entirely scripted.
To help you out during combat, your allies can carry out two main supporting behaviours: take-down and flash attacks. These are two of the many squad actions originally conceived back in the days of 'Stealth Ranger'. With both of them aimed at helping the player when pinned down behind cover. First up the take-down attack is useful for prioritising targets during heated combat, such as a heavy or turret. But in addition, it's a useful tool for exposing enemy players that are hiding behind cover. Distant targets had flags set in-engine to dictate that Lugo should snipe them, with all other targets taken down by Adams by default. But the problem is, the system needs to ensure players ultimately see their allies take down opponents, which is kinda difficult when they're hiding behind cover. So enemies will deliberately pop out of cover in order for the companion to take the shot and bring them down. Meanwhile, the flash attack only arises when players are stuck in game: given they might be suppressed or at low health and have stayed in cover for a period of time. Once again this is intended to push enemies out of cover and leave them open to attack, but is only available if designers permit it, with it potentially being disabled in specific sequences and difficulties.
Now one of the most interesting parts of the allies functionality is their participation in the battle chatter system. As mentioned earlier, the enemy NPCs are able to shout and react to the players behaviour. However, Adams and Lugo in-turn can react to the enemies as well: pointing out when certain types of enemies are spawned in, whether they're attempting to flank the player or that they're pushing up to more tactical locations. Once again Spec Ops avoids a more realistic and complex system for these callouts and instead crafts a very simple solution akin to the co-operative behaviours in F.E.A.R. When an enemy AI makes a tactical decision, they tell your assisting AI what they're going to do. Then your allies communicate this to you so you are aware of it taking place. Simple! In addition, as players progress further into the campaign, the relationship between Walker and his teammates becomes increasingly more fragile as disagreements break out and tensions flare. However, this turmoil does not cause the AI to behave any differently, instead the battle chatter system swaps out the active voice pack for each character. Hence while for example Adams will respect the chain of authority throughout, the voice work implies that his willingness and tolerance for Walker's behaviour begins to erode as time passes.
Horrors of War
While the AI systems carry many interesting quirks, be it the information being shared between friend and foe or the designer-placed squad triggers, these are all present to reinforce the story of Spec Ops: The Line. To immerse players in the harsh reality that Walker and his unit succumb to. What makes this game so important - and the underlying game design so powerful - is that while it seeks to build a stage upon which this story can be told, your experiences still carry their own unique aspects. That the story will not play out the same way twice. But despite this, the focus is first and foremost on ensuring the player feels the dramatic weight of the story the game tells: to ensure players understand the horrors of what transpires and remind us that the journeys of our protagonist whilst fictional, are far from fantasy.
By the end of our journey, Martin Walker suffers from an acute case of dissociative disorder and the effects of it prove devastating to everyone around him, be it the Dubai natives, the 33rd, Lugo, Adams and even himself. These horrors of war are safely experienced from the confines of our own home, in a game designed to present this experience in safety, but for many escaping this reality is not as straight forward as ejecting a disc or turning off a console. This is a warning to ourselves in the real world and a call to arms to support those who have experienced post-traumatic stress disorder in many avenues of life.
- Special Thanks to ex-Yager programmer Jörg Reisig for his assistance and insight in preparing this article.
- Images of AI Archetypes, Behaviour Trees and Squad Triggers lifted from the Game/AI 2012 presentation listed in the bibliography.
"Design-Driven AI in Spec Ops: The Line", Daniel Kollman and Jörg Reisig, Game AI Conference 2012.
"Significant Zero", Walt Williams, Simon & Schuster, 2017