Game Career Guide is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Get the latest Education e-news
 
  • The AI Of DOOM (1993)

    [06.21.22]
    - Tommy Thompson

  • Infighting

    One of the most memorable aspects of DOOM is that the monsters have a habit of infighting. They'll tear chunks out of each other if the mood strikes them. How on earth does that work? Well, it's actually quite simple: there's logic in the code that states in the event an NPC is attacked and hurt by another character, then it might assign that character as their new target. Even if it's not the player. Naturally, this means that the demons don't attack one another without cause. So you need to lure one enemy into the line of fire of another, and hope it accidentally causes some friendly fire.

    There are some exceptions to this, given Barons and Hell Knights can't hurt each other with their attacks. Pain elementals technically can't get caught in infighting because they hurt other characters by spewing Lost Souls (which will then get targeted instead). And there's a specific edge case coded into the game to stop Arch-Vile's being attacked by other NPCs. This means you need to go and smash his skull in yourself... typical.

    Designing Encounters

    So we've explained the core logic, how individual state actions are defined and the optimisations for pathfinding, visibility and sound checks. But that isn't enough to make DOOM behave the way it works. The game is full of traps, of dead ends and much more that help create these rich and interesting encounters. The trick to this is two critical parts of the game's design.

    First of all, the game has a variety of different custom actions that can be synced up with the map. If you've ever cracked open a DOOM map you'll have noticed a lot of lines that hide inside the map. Some of this is the actual geometry, while others are essentially trigger volumes. Meaning the game can detect when the player crosses into that volume (it's a very common practice in modern game engines). One trick DOOM heavily employs is the level editor allows for code snippets to be executed upon entering a volume, and it can also add a tag that references what parts of the map should be affected. Hence you can have a hidden door somewhere around, stick some enemies in there, all of whom are in the SPAWN state and can't hear any noise you make because the secret door prevents the audio propagation and you're good to go.

    However, each trigger can only have one function pointing to one object. So what if you need to have two things happen at once? A great example of this is the blue key trap in the Toxin Refinery (that's E1M3 btw). The trap involves walking in to grab the key, only for the lights to dim and a secret door with imps inside to open. Well, the solution is you just place two triggers right next to each other targeting different objects.

    There are over 130 of these functions in the game, ranging from opening and closing doors, raising or lowering the floor, locking a door, changing the light levels, teleporting the player and more. Using this you can simply set up an environment, and once the walls move and the enemies can see the player, or hear a gunshot nearby, then we're good to go! But sometimes, it leads to some even more creative choices.

    A really good example of this is in the Military Base, the secret level in the first episode of DOOM. In which the player can trigger a trap by grabbing the rocket launcher sitting atop the pentagram on the ground. When the player crosses over the pentagram, it doesn't change the room the player is in, but rather, it removes a small wall that has been protecting a teleporter in a small room locked off at the side.

    SoundPipe-edited.png

    The enemies in the room are already active and moving around but they need to wander into the teleporter in order for them to appear on the pentagram in front of the player. The trick is that there is a small and largely imperceptible corridor of level that connects the main room with the pentagram to this tiny room on the side. This is used so that any noises that occurs in that room will propagate through to the hidden room and encourage the monsters to head towards the noise, ultimately walking into the teleporter. This 'sound pipe' is actually a fairly common tactic and crops up on other occasions throughout the WAD files of both DOOM and DOOM II.

    But that isn't the only trick that helps make it all come together. The second trick, is a little special customisation that happens on a per-demon basis when the levels in DOOM are designed. There is a special Ambush flag that can be set on a given monster. MF_AMBUSH sets an additional logic to the previously mentioned SEE state. As mentioned previously, if a demon can see the player or hears the gunshot, then they treat that location as a target and move towards it. MF_AMBUSH changes this logic so that even if a demon hears a noise that alerts it, it doesn't act on this knowledge until it receives visual confirmation. So the demon is awake and active, but it stays rooted to the spot.

    This means that during an encounter, some demons will still be able to catch the player off guard and - as their name implies - create an ambush. It's a simple yet highly effective trick that combined with the level tags and sound pipes, can lead to all sorts of interesting combinations!

    A great example of this is Containment Area: the second mission of The Shores of Hell. While getting into gunfights often results in kiting the odd zombieman or imp toward you, many of the imps in that level are using the Ambush flag, meaning that even when you kill someone right next to them, they still wait until they achieve a line of sight before they trip to rip your face off.

    Closing

    It's crazy to think that DOOM is now approaching 30 years old. But it's a game that continues to influence and impact the industry in a myriad of ways. And it keeps getting ported to pretty much every device imaginable.

    One of the big reasons that DOOM is able to appear on everything from PCs to consoles, mobile phones, smartwatches and even ATMs is because the source code of DOOM has been public knowledge for now for over 20 years. As we've discussed, the game is highly optimised C code, and id Software put the code online in 1997. If you're keen to learn more, check out the links to the source alongside Fabien Sanglard's Game Engine Black Book on the subject and the DOOM wiki.

Comments

comments powered by Disqus