Targets not preserved in saved games

From DoomWiki.org

Revision as of 15:26, 7 September 2007 by Ilovefoxes (talk | contribs)


In any Doom game, when the game is saved, monster targets are not kept in the savegame, so any monsters which were active at the time of saving become dormant upon loading of the saved game. However, their location and angle when the game was saved is preserved.

Demonstrating the effect

Here is one way to see the anomalous behavior:

  1. Start a new game of Doom II (MAP01) on I'm too young to die.
  2. When the program loads, you will be looking at two troopers with their backs to you. Ignore them for now; instead, walk west along the short corridor until you reach the balcony.
  3. Fire a bullet. Two grunting sounds will now indicate that you have attracted the troopers' attention.
  4. Save the game.
  5. Load the game you just saved.
  6. (Optional) Stand still for a minute or two and listen. One would expect to hear the breathing noise made by zombies as they walk around, but all is quiet.
  7. Carefully move back along the corridor to the starting point, keeping your eye on the opening to the north. As you move into each trooper's line of sight, one of two things will happen:
    • If he is facing you, he will become active and start moving again.
    • If he is not facing you, you will see him standing still.

So, even though the troopers woke up in step 3, they "fell asleep" during step 5.

Technical

The cause of this effect can be found in the Doom source code in p_saveg.c, in the functions P_ArchiveThinkers and P_UnarchiveThinkers.

In the Doom source code, the mobj_t structure is used to represent game objects such as monsters. Monster targets are stored in these structures as a field named target, which is a pointer to another mobj_t that the monster is currently targeting.

Doom saves games by directly writing the raw structures used in memory to disk. When reloading saved games, pointers such as the target field are no longer valid (as the layout of structures within memory is different). When loading a game, the P_UnarchiveThinkers function deliberately sets target on all map objects to NULL in order to avoid crashes due to accessing invalid areas of memory. A null target indicates that a monster has no current target, causing active monsters to return to sleep.

Affecting gameplay

Near the beginning of Doom II MAP20, Gotcha!, the player is required to lure a Spider Mastermind and a Cyberdemon into fighting each other via monster infighting. Wich mean that you almost will lost your progress on that part when loading a game.