Sly 2:Game state

The DAG (Directed Acyclic Graph) is a data structure used in Sly 2 and Sly 3 to control the current state of the game world. It was the subject of a 2005 GDC presentation by Bruce Oberg, the Principal Engineer at Sucker Punch.

Tasks
The DAG is a directed graph of nodes, where each node is called a "task". For instance, 't1_follow_dmitri_on_streets' is the task of tailing Dimitri in the "Follow Dimitri" job (the prefix t1 indicates that it is a task in Episode 1, and `follow` is the codename for the "Follow Dimitri" job).

Task States
Each task has a state, which is one of the following:


 * Unavailable
 * Available
 * Complete
 * Final

All tasks in the DAG start off as Unavailable. A task becomes Available once all of its predecessors are Complete. Tasks become Complete through conditions being met in the level scripts, and tasks become Final through missions.

At all times, every before an Available task must be Complete or Final. Additionally, every task after an Available task must be unavailable. It is possible to "force" a task to a particular state, which propagates throughout the DAG to ensure those conditions are always met.

Missions
Tasks in the node can be grouped into missions. These missions usually refer to particular jobs in the game's story. For instance, `m1_follow_dmitri` is the job "Follow Dmitri" (the prefix m1 indicates that it is a mission in Episode 1).

If a task belongs to a mission and the "exit" task in that mission is Completed, then all the tasks in that job become Final.

Checkpoints
A task is considered a checkpoint task if it has some checkpoint data associated with it, including a particular character a location in the game world. When a checkpoint task becomes Available, that checkpoint is set as the latest checkpoint.

When a rollback occurs, the game uses the latest checkpoint to set the current character and their location.

Rollbacks
A rollback is when the game rewinds the DAG to an earlier state (such as when the player dies). This is accomplished by:


 * Resetting the world
 * Placing the player at the last checkpoint
 * Forcing the checkpoint task to Available (which may result in the states of other tasks being changed)