|
|
|
|
last update: October 19, 2004
|
|
|
This page lists implementation details about the game AI used in several tactical shooter games. All games discussed make public a significant part of their AI implementation public either as part of the game's distribution or as a separately available SDK.
Disclaimer: The description of the game AI in the games listed below is based on playing the game, studying that part of the source code that is public, and experience in creating tactical FPS AI. It represents William's best guess as to how the game AI was designed and implemented, and is likely to contain errors.
For an overview, I recommend the following paper that provides more insight in the AI techniques and tooling used in the game industry (from a academic/defense simulations background).
Behavior Modeling in Commercial Games, David E. Diller, William Ferguson, Alice M. Leung, Brett Benyo, Dennis Foley, BBN Technologies, in Proceedings of the 2004 Conference on Behavior Representation in Modeling and Simulation (BRIMS), 2004
| |
|
|
|
|
|
|
|
"Although their movements are utterly scripted, i.e. dependent on the removal of key enemies, it's hard not to be impressed by the dynamic way each soldier seeks cover, finding a suitable place to return fire while simultaneously shouting exclamations and instructions. Their path finding, too, is generally excellent, and unlike so many games you won't find them running like headless chicken into walls or stubbornly getting in your way. In fact, it's a joy to at last witness a game that has enemy and buddy AI capable of doing the basic things with ease.
Obstacles and low walls are no problem and they mount them with ease. Enter a room with an abandoned gun emplacement and one of them will use it (and they'll also leave it if you want a go). What's more, they'll peep around cracks and return fire, helping you to take out a whole posse of enemies in the process - in general they just look like they know what they're doing, and do so without ever becoming a hindrance. Expressing that with ageing Quake III Arena tech at the game's core is a feat worthy of serious applause."
[citation from Eurogamer review].
files and AI code organization
The majority of the AI is implemented in a proprietary script language, in text files with extension "gsc". The script language uses micro-threads to run multiple eligible unit behaviors in parallel.
The script files are easily viewed by renaming or copying all .pk3 files the "Call of Duty" folder to .zip files, and browsing these archives, and in particular the following three folders in these archives:
aitype folder, contains ~37 files (~4KLOC) of unit configurations
animscripts folder, contains ~113 files (~10KLOC) of unit (state) behaviors
maps folder, contains ~90 files (~58KLOC) of mission scripts and mission specific unit behaviors
The following parts of the AI seem to be implemented in C++ (and absent from the *.gsc files): perception (and the corresponding CPU intensive raycasting), pathfinding, low level movement and collision avoidance, nearest waypoint lookup, hit detection and damage processing.
individual AI
Call of Duty frequently accompanies the player with a friendly squad of believable and expressive characters, displaying dramatic and believable action against hostile troops firing from cover.
The individual AI (mainly hostile soldiers and friendly soldiers) is parametrized with health, accuracy, and bravery. Bravery serves to tweak the tendency to pursue goals set by the script.
The soldier AI has several states, each reflecting a short term goal: combat (exposed, melee, ranged combat, grenade attack), concealment, cover, death, grenade response, run, stop, and wounded.
Additionally, a couple of 'mood states' are tracked to select the appropriate audio sound bites: death, run, oneoff, tense, nottense, pain. For variation in the friendly AI characters, there are five different personalities, each with a matching set of sound bites: trained, cheerleader, educated, fearless, friendly, and smartass.
Goals for the individual AI are set by the script, typically as a combination of goal waypoint and radius and optionally a goal entity. A script thread can block itself until a goal has been accomplished.
Note that the AI has no 'fear' and will not pullback autonomously; pulling back is only done when ordered by the script, and the AI will solely run away from the current location when a grenade lands nearby.
squad AI
The game creates a powerful illusion of being surrounded by a friendly squad employing sound squad tactics. However, most of this behavior is directed by the script and level triggers.
The squad AI itself is limited, and used only in a handful of missions for hostile forces. There appears to be no squad entity or squad state, and the squad does not issue orders to squad members (instead, the script issues the orders to each squad member).
Squads use one generic maneuver to advance and attack a dedicated area; paths for the squad members are selected a priori based on entry nodes, end (capture) nodes and intermediate (contact) nodes (which also signal from where the AI is supposed to engage threats. Although the squad members convincingly call "flank right", "flank left" or "cover me", this is done at random.
terrain representation
The game is full of AI showing effective use of the terrain. Most of the fighting is done from behind cover, and the AI is capable of scaling walls in military style.
Most of the special movements and terrain specific behaviors are encoded in the terrain as waypoint (node) hints or triggers. The game uses the following terrain hints:
This works well given the linear nature of the game: combat occurs typically once at each location and in a predictable direction, so static 'cover' hints work fine.
To prevent units from moving along paths in a very predictable way, 'branching' hints are used.
mission scripts
The mission scripts make up the bulk of the "AI" scripts and control much of the unit spawning, mission objectives, game logic, in-game cut scenes and AI (notably the friendly squad).
player orientation and cheats
While most of the game AI in Call of Duty plays by the "simulation" rules, occasionally it pulls of some tricks, typically to create a more heroic or dramatic experience for the player. Here are some examples:
When the player is in a shellshock state (as a result of a nearby explosion), the AI attempts not to target the player. Heavy machine guns (MG42's) do not target the player when the player is prone or crouching behind cows. Friendly AI characters consistently duck between shots or burst, but enemy characters sometimes stay up to give the player a better chance to take them out. When friendly casualties are required, the game attempts to select an expendable AI character closest to the player, so the player is more likely to notice this drama.
All (friendly) AI generate audio cues when applicable, which then are filtered (with time-outs) per individual and team. This way, the player will not be confronted with
simultaneous (thus hard to understand) shouting nor repeated statements (breaking the immersion).
The friendly AI has a cool ability to notice when a player might want to occupy their position and will give up that position. For example, when the AI is firing from one of the few holes in the wall of a building, or when the AI is manning a fixed machine gun, the player can walk up to the AI, and the AI will move out of the way.
Occasionally, the AI cheats and sends soldiers to the player's position, whether AI could have known the player's position or not.
miscellaneous
Call of Duty features moving vehicles in a number of missions. The move along fixed 'rails' with the occasional branch for variety.
| |
|
|
|
|
|
|
|
The much-vaunted AI is something that might cause a few arguments, though. It's true that if one person sees or hears you, they will call for back up, and enemies from various points on the map do all get hauled into action. It appears that every map has its stock of grunts pre-placed in set positions, so they don't just spawn when you appear, like most FPS enemies would. They chat among themselves in little clusters, with mobile speedboat, chopper-based and various land-based vehicles often roaming around looking for action. It doesn't quite feel like a living breathing world yet, but it's definitely a big improvement to know that these enemies aren't just being created on the fly. Kill them all and they don't come back (actually vanishing after a while, annoyingly), so if that's what you feel like doing, then you're guaranteed a good fight in each of the 20 levels.
[citation from Eurogamer review].
The Far Cry AI is largely scripted using Lua. The level editor manual provides some info on the AI behaviors and configuration available, and suggests to which extent the AI depends on annotations in the terrain itself. You'll find the AI in the game's subdirectory Scripts\AI\ in *.lua scripts (text files).
| |
|
|
|
|
|
|
|
How many times have you shot at a monster only to have it either grimace at you blankly, perhaps firing off a few tepid shots, or slouch and drool while you pick off his comrades? Well, not here. The teams of soldiers you'll fight in Half-Life have to be the toughest, most convincing enemies yet seen in an action game. Where other opponents grunt incomprehensibly, these guys actually yell stuff relevant to the combat, such as "Fire in the Hole!" or "Look out!" as the grenades go flying. Then they actually try to get away from your grenades. And what's more, they also throw grenades at you.
[...] But that's just part of the appeal of Half-Life's enemies; unlike other games, they also cooperate. Teamwork, for monsters in other games, is if they all happen to be in the same room shooting in the same direction. Here, the infantry squads will split up, trying to hit you from several sides while one guy keeps you pinned or lobs grenades. It's surprising how entertaining well-implemented artificial intelligence can be, and it's probably worth it to play Half-Life just to fight its infantry. There could be a whole game based on nothing but fighting Half-Life's infantry.
[citation from IGN review].
The Half-Life AI is implemented in C++. You'll find the AI in the SDK's subdirectory SDK\Source\dlls.
| |
|