Scott Martin (bio) was kind enough to give us a demonstration of Deus Ex's advanced AI at this year's E3, and even nine months ago it was looking very solid. Take a look as we interrogate him on how he got the AI to that point, and what he's been doing since then.
[Stormtroopers] First of all, why AI? Why not tools, or rendering, or new model formats or something?
[Scott] When it comes to programming, I don't think of myself as an "AI Guy." I'm more of a generalist. I haven't even spent all my time on Deus Ex doing AI -- I also built Deus Ex's user interface library at the beginning of the project (whose implementation is now in the capable hands of Albert Yarusso).
I became the AI programmer on this project for two main reasons: I wanted to try something new, and nobody else wanted the job. :)
My goal for myself, for as long as I'm in the game industry, is to do everything at least once. So far, I've written AI, user interfaces, top-down 2D maps, databases, sound libraries, and socket code. If I feel like I'm getting into a rut doing AI, I'll probably move on to 3D graphics programming (something I've wanted to do forever), but I'm sure that won't happen for a while. For now, AI is keeping me very busy.
[Stormtroopers] Way back in the day when you began working on Deus Ex AI, did you sit down in front of your dev kit and start coding immediately? Or were there any paper steps for planning and specifying.
[Scott] Before I started doing any serious AI coding, I spent a lot of time thinking about how I wanted the AI to act during the game. Then I wrote up some design docs for Warren and Chris to review.
I wanted NPCs to react to the world in roughly the same way that real people do. The key to this was to make the AI recognize things based on sight and sound. The Unreal engine has a decent pathfinding system built into it (written by Epic's Steve Polge), so thankfully I didn't have to build one from scratch. But because the original Unreal was a single-player shooter, its A/V event handling didn't consist of much more than "I see the player, so I attack" and "I hear the player, so I attack." I built an audio/visual event manager into the Unreal engine so NPCs could detect things like footsteps, gunshots, smashed windows, objects hitting the ground, drawn weapons, screams, distress, etc. -- and more importantly, it could distingish between them. I also wrote behaviors for the NPCs so they could react appropriately to these events.
Of course, nothing ever works out the way you expect when you're writing design docs. Since this was my first time coding AI, I fell into the trap of thinking that realistically modelled AI is inherently fun, and it isn't. Would *you* want to shoot it out with 50 guards who've come running from all corners of the level, just because you made the mistake of blowing up a door with a crate full of very loud explosives? I didn't think so. :)
So, while the AI isn't slavishly devoted to reality, it is still *believable* without presenting you with a totally impossible challenge. It's a balancing act that I'm still getting used to.
[Stormtroopers] How about a description of what the general step-by-step process is for creating a specific character's AI.
[Scott] I'm not sure you could call this a "process," but here's how I write AI:
1) Figure out how a particular NPC class should act -- how the NPC moves, what other NPC classes he's afraid of, how he reacts to noise and motion, that sort of thing.
2) Program the NPC class.
3) Spend the next six months tweaking the living hell out of it. :)
[Stormtroopers] Which do you prefer, creating the AI for a human with all the traits and reactions that gamers are going to expect from a human character, or coding the AI for some new creature for which there are no previous expectations or references for how it should act?
[Scott] They're both fun! But I think I'd have to give the edge to creating AI for humans and real-life animals. That kind of AI is harder to write and more limiting, because the player already has expectations about how humans and animals will act -- but when it works, it helps the immersiveness of the game *and* gives us a powerful gameplay dynamic.
Say you're crouched in the shadows, and a guard is stationed near a doorway. You need to get past the guard, but you're not carrying anything that can take him out. All you've got is a bottle of liquor. What would you expect that guard to do, if you threw the bottle over his shoulder and it shattered on the ground behind him? He'd turn around, trying to find out where the noise came from, and you could use that time to sneak around him and slip through the door. In a case like that, you can use real-life experience to help you play the game. If I've done my job right, Deus Ex will have plenty of little moments like that. :)
I'd guess about 80% of the NPCs in Deus Ex are real-world animals and humans (or augmented humans). The rest are either various types of robots, or certain gen--
Oops, the G-man in the black suit is pointing a pistol at my head. I'd better shut up now.
[Stormtroopers] Are there any specific AI buzzwords or concepts that programmers looking to learn about game AI would want to know?
[Scott] The only advice I can give is: observe real-life behaviors and try to model them in your game, but also be willing to sacrifice some realism upon the altar of gameplay...
Pretty vague, huh?
[Stormtroopers] Do you ever get comments back like "Not dumb enough", "Not smart enough, "Doesn't get stuck in doorways or backflip into lava enough"?
[Scott] I don't get that last comment very often. I sometimes get the first two in the same sentence. :)
[Stormtroopers] What tools do you use? Are they standard programming tools, or do you just use UnrealEd's class editor?
[Scott] I jump back and forth between C++ and UnrealScript a lot, so I generally avoid the class editor in UnrealEd and stick with Visual Studio for all my programming needs.
[Stormtroopers] At E3 last year, the character AI was already in very impressive shape (you may recall me saying "@#$&in' whoa!" an awful lot)... Has the bulk of your work since then been composed of just adding in new characters? Or have you been continually refining what was already working so well during the show...
[Scott] I've done both, but most of my recent work has been adding AI behaviors -- telling NPCs how to activate alarms, react to loud noises, crouch during combat... there's more, but I'd rather leave some surprises for the player.
[Stormtroopers] Did you find that the incremental codebase releases from Epic over the life of the project has required you to revamp or rethink the AI at any point?
[Scott] Thankfully, no. Most of the changes to Unreal's baseline AI code have been small improvements and bug fixes.
[Stormtroopers] From what we've heard, it appears that you and the team are heading into the serious QA phase. What's it like trying to hunt down AI bugs? Will the testers try and set up every different possible kind of situation and check for inappropriate responses? Or will they just play away and see if anything weird happens?
[Scott] Well, for my part, I'm spending a lot of time playing the game and creating test scenarios to make sure the AI doesn't break as I change stuff. I try to avoid influencing the QA team in any way -- I just let them do their thing, and if they run up against AI behavior that thwarts their expectations or breaks the game, they report it to me and I try to fix it. They've been pretty thorough so far.
[Stormtroopers] Where do you think gaming AI is heading for the next 5 years?
[Scott] Personally, I'm hoping that in five years, computers will be powerful enough to handle *dozens* of NPCs on the screen at once in a fully-modelled 3D world -- walking around, interacting with each other, avoiding obstacles, performing routine tasks, responding to the things you do. I'd love to play in an interactive virtual world whose denizens are all computer-controlled, yet behave like real humans.
In theory, we can do this now, provided that the game takes place in a large square room with one texture and all the NPCs are sprites. Otherwise the framerate grinds to a halt. Advanced AI and eye-popping 3D graphics are both computationally expensive, and improving one of these usually comes at the expense of the other. I'm looking forward to the day when we can have them both. :)