Difference between revisions of "Paths (GTA SA)"

From GTAMods Wiki
Jump to navigation Jump to search
(Structures)
(File format)
 
(35 intermediate revisions by 5 users not shown)
Line 1: Line 1:
The 64 <code>nodes*.dat</code> files in <code>gta3.img</code> (or any other [[archive]]) contain the vehicle and ped paths and related information for [[GTA SA]]. There's a file for every 750&times;750 [[unit]] square, starting at the south-west corner (-3000, -3000) in [[Wikipedia:row-major order|row-major order]].
+
[[File:SAPathNodes.png|thumb|450px|Colour-coded car path nodes for GTA: SA.]]
 +
The 64 <code>nodes*.dat</code> files in <code>gta3.img</code> (or any other [[archive]]) contain the vehicle and ped paths and related information for [[GTA SA]]. There's a file for every 750&times;750 [[unit]] square, starting at the south-west corner (-3000, -3000) in [[Wikipedia:Row- and column-major order|row-major order]].
  
However paths for planes and trains are not stored in the node-files. Nodes exist in any of the game's interiors and can only be influenced through SCM using the opcodes [[01EB|01EB]] and [[03DE|03DE]].
+
Paths for planes and trains are not stored in the node files. Trains use the four <code>tracks*.dat</code> files. There are also paths for several missions and concrete cars in <code>[[Carrec|carrec.img]]</code>.
Trains are using paths in the tracks(1-4).dat and there are also paths for several missions and concrete cars. These paths are <code>[[Carrec|carrec's]]</code>.
 
  
Usually cars and pedestriants are using nodes if they are not linked to an [[SCM]] or an carrec path in any way.
+
Nodes can be influenced through scripts using the opcodes [[01EB]] and [[03DE]].
 +
 
 +
Usually, cars and pedestrians use nodes if they are not linked to a script or <code>carrec.img</code> path in any way.
 +
 
 +
There is a [[Fastman92 Path Format|modified version]] of the path format that may be used with fastman92's Limit Adjuster, which removes or extends some of the limits that the native format imposes.
  
 
==Purpose==
 
==Purpose==
  
It is believed that these files were generated by some sort of path compiler during development of the game, and represent the processing-friendly binary data structures otherwise generated at runtime by previous versions of the game from files like <code>[[Item_Placement#PATH|paths.ipl]]</code> and related. These files are still present in SA, but unused.
+
It is believed that the node files were generated by some sort of path compiler during development of the game, and represent the processing-friendly binary data structures otherwise generated at runtime by previous versions of the game from files like <code>[[Item_Placement#PATH|paths.ipl]]</code> and related. Such files are still present in SA, but are unused.
  
Since the built-in path compiler has apparently been removed from the game code or at least made nonfunctional, custom tools and techniques are required to generate new paths for SA.
+
Since the built-in path compiler has apparently been removed from the game code or at least made non-functional, custom tools and techniques are required to generate new paths for SA.
  
 
Node files are streamed by the game &mdash; only the active area and those surrounding it are loaded at a time. Thus corrupt files only lead to a game crash when the player enters the specific area.
 
Node files are streamed by the game &mdash; only the active area and those surrounding it are loaded at a time. Thus corrupt files only lead to a game crash when the player enters the specific area.
Line 16: Line 20:
 
The separate <code>nodes*.dat</code> files in the <code>data\paths\</code> directory are ignored by the game.
 
The separate <code>nodes*.dat</code> files in the <code>data\paths\</code> directory are ignored by the game.
  
==File format of standard path file==
+
==File format==
  
 
Each file starts with a header, followed by 7 distinct sections.
 
Each file starts with a header, followed by 7 distinct sections.
Line 27: Line 31:
 
* '''INT32/UINT32''' - signed/unsigned 32 bit integer ''(4 byte)''
 
* '''INT32/UINT32''' - signed/unsigned 32 bit integer ''(4 byte)''
 
* '''FLOAT''' - single precision floating point number ''(4 byte)''
 
* '''FLOAT''' - single precision floating point number ''(4 byte)''
 +
 +
There are several main concepts that are important for understanding the way path files work:
 +
* A "node" is an individual point in space which is used as an anchor for a path.
 +
* Paths are routes between nodes. These are traced in-game by peds and vehicles, but are typically shown in editors as graphical lines.
 +
* Two nodes are connected by one referencing a "link" which points to the other.
 +
* Most nodes link to two other nodes, one for each direction along a path, but it is possible for there to be more (such as at a junction).
  
 
===Header===
 
===Header===
Line 41: Line 51:
  
 
===Section 1 - Path Nodes===
 
===Section 1 - Path Nodes===
 
 
The first section contains the node data for the paths. They are grouped by type: the list of vehicle nodes (cars, boats, race tracks) is followed by the ped nodes. Each node entry has a size of '''28 bytes'''.
 
The first section contains the node data for the paths. They are grouped by type: the list of vehicle nodes (cars, boats, race tracks) is followed by the ped nodes. Each node entry has a size of '''28 bytes'''.
  
Line 47: Line 56:
 
  4b - UINT32  - always zero, ''unused''
 
  4b - UINT32  - always zero, ''unused''
 
  6b - INT16[3] - Position (XYZ), see below
 
  6b - INT16[3] - Position (XYZ), see below
  2b - INT16    - unknown, always 0x7FFE, appears to have something to do with links
+
  2b - INT16    - heuristic cost, always 0x7FFE, used internally to calculate routes
 
  2b - UINT16  - Link ID
 
  2b - UINT16  - Link ID
 
  2b - UINT16  - Area ID (same as in filename)
 
  2b - UINT16  - Area ID (same as in filename)
 
  2b - UINT16  - Node ID (increments by 1)
 
  2b - UINT16  - Node ID (increments by 1)
 
  1b - UINT8    - Path Width
 
  1b - UINT8    - Path Width
  1b - UINT8    - Node Type
+
  1b - UINT8    - Flood Fill, used in route calculations
 
  4b - UINT32  - Flags
 
  4b - UINT32  - Flags
  
 
;Mem Address: These might have been pointers to path segment structures inside R*'s path compiler. Apparently they are ignored by the game and can be set to zero.
 
;Mem Address: These might have been pointers to path segment structures inside R*'s path compiler. Apparently they are ignored by the game and can be set to zero.
 
;Position: This is the position of the node in world coordinates. To convert the signed words to floating point values divide them by 8.
 
;Position: This is the position of the node in world coordinates. To convert the signed words to floating point values divide them by 8.
;Link ID: Index into sections 3, 5 and 6; used to find adjacent nodes.
+
;Link ID: The ID of the first node this node links to. The range of linked nodes is ''link ID ≤ x &lt; (link ID + link count)'', where the link count is given by the first four bits of the flags.
;Area ID and Node ID: Informational data, probably only used by the path generator. Area ID is always the same as the number in the filename, and Node ID is used to identify the node.
+
;Area ID and Node ID: Informational data, used to connect nodes via Links. Area ID is always the same as the number in the filename, and Node ID is used to identify the node.
;Path Width: This is used to modify the width of a path. The default value is 0 (zero). To convert the signed word to a floating point value divide it by 8 ''(unconfirmed)''.
+
;Path Width: This is used to modify the width of a path. The default value is 0 (zero). To convert the signed word to a floating point value divide it by 8.
;Node Type: Defines some kind of group for the nodes. For vehicle nodes a value of 1 is for cars, 2 is for boats and higher values are for race tracks and other mission applications. For ped nodes there seems to be a distinct ID per village/city/area.
+
;Flood Fill: Flood IDs for route calculation for NPCs. For normal NPC vehicle traffic a value of 1 is used, 2 is for boats and higher values are allocated to disconnected path area segment, e.g for race tracks and other mission applications.  
 
;Flags: The first 4 bits define the number of links to adjacent nodes. The other bits are used to characterize node behavior, for more information see the table below.
 
;Flags: The first 4 bits define the number of links to adjacent nodes. The other bits are used to characterize node behavior, for more information see the table below.
 
 
  
 
====Path Node Flags====
 
====Path Node Flags====
Line 121: Line 128:
 
===Section 2 - Navi Nodes===
 
===Section 2 - Navi Nodes===
  
The second section contains additional nodes, referred to as ''navigational nodes'' (navi nodes) in this article. Each record has a size of '''14 bytes'''.
+
The second section contains additional nodes. These nodes are ''navigational nodes'' (but are referred to in this article as "navi nodes" for brevity). Each record has a size of '''14 bytes'''.
  
 
Navi nodes are used to define additional information for vehicle path segments; they are not used by ped paths. They are usually positioned between two adjacent vehicle nodes on an interpolated curve.
 
Navi nodes are used to define additional information for vehicle path segments; they are not used by ped paths. They are usually positioned between two adjacent vehicle nodes on an interpolated curve.
  
There may be bugs if you don't connect navi nodes correctly. The order to connect them is to check first which of the 2 linked nodes is 'higher'. That means which one has the higher node ID or area ID. The direction of linking is allways from higher to lower node. So the target node of the navi nodes is allways the lower node. (Espacially on area boundaries!)
+
There may be bugs if you don't connect navi nodes correctly. Links always go from a node with a higher area/node ID to one with a lower ID, so the target is always the lower node.
  
 
  4b - INT16[2] - Position (XY), see below
 
  4b - INT16[2] - Position (XY), see below
Line 135: Line 142:
 
;Position: This is the position of the navi node in world coordinates. To convert the signed words to floating point values divide them by 8.
 
;Position: This is the position of the navi node in world coordinates. To convert the signed words to floating point values divide them by 8.
 
;Area ID and Node ID: These identify the target node a navi node is attached to.
 
;Area ID and Node ID: These identify the target node a navi node is attached to.
;Direction: This is a normalized vector pointing towards above mentioned target node, thus defining the general direction of the path segment. The vector components are represented by signed bytes with values within the interval <nowiki>[-100, 100]</nowiki>, which corresponds to floating point values <nowiki>[-1.0, 1.0]</nowiki>.
+
;Direction: This is a normalized vector pointing towards above mentioned target node, thus defining the general direction of the path segment. The vector components are represented by signed bytes with values within the interval <nowiki>[-100, 100]</nowiki>, which corresponds to the range of floating point values <nowiki>[-1.0, 1.0]</nowiki>.
 
====Navi Node Flags====
 
====Navi Node Flags====
 
These are used to characterize path segment behavior, for more information see the table below.
 
These are used to characterize path segment behavior, for more information see the table below.
Line 150: Line 157:
 
* Right (forward) and left (backward) lanes are relative to the direction vector.
 
* Right (forward) and left (backward) lanes are relative to the direction vector.
 
* Experience has shown that navi nodes with attachments across area borders don't work too well. A possible solution is to attach them to the last instead of the next node, reverse the direction and exchange the lane numbers (if different) and other direction dependent flags. However, this will never work if previous, navi and next node are located in different areas each. '''(*)'''
 
* Experience has shown that navi nodes with attachments across area borders don't work too well. A possible solution is to attach them to the last instead of the next node, reverse the direction and exchange the lane numbers (if different) and other direction dependent flags. However, this will never work if previous, navi and next node are located in different areas each. '''(*)'''
* ''Traffic light behavior'' can be a value from 0 to 2, where 1 and 2 are related to North-South and West-East cycles for traffic light synchronization.  
+
* ''Traffic light behavior'' can be a value from 0 to 2, where 0 means traffic lights is disabled, 1 and 2 are used for the traffic lights and are  North-South and West-East cycles for traffic light synchronization respectively.  
 
* The ''traffic light direction behavior'' is 1 if  the navi node has the same direction as the traffic light and 0 if the navi node points somewhere else.
 
* The ''traffic light direction behavior'' is 1 if  the navi node has the same direction as the traffic light and 0 if the navi node points somewhere else.
  
Line 164: Line 171:
 
===Section 4 - Filler===
 
===Section 4 - Filler===
  
This section hold data of constant size and content; its purpose is unknown. These '''768 bytes''' are filled with the repeating data pattern <code>0xFF,0xFF,0x00,0x00</code> (192x), but this can be filled with zeros as well.
+
This section holds data of constant size and content; its purpose is unknown. These '''768 bytes''' are filled with 192 repetitions of the pattern <code>0xFF 0xFF 0x00 0x00</code>, but this can be filled with zeros as well.
  
 
===Section 5 - Navi Links===
 
===Section 5 - Navi Links===
  
These are links to adjacent navi nodes, '''2 bytes''' per entry. For indices from ped nodes (in section 1b) these are zero (unused).
+
These are links to adjacent navi nodes, one for each link (in section 3), '''2 bytes''' per entry. For indices from ped nodes (in section 1b) these are zero (unused).
  
 
  2b - UINT16 - lower 10 bit are the Navi Node ID, upper 6 bit the corresponding Area ID
 
  2b - UINT16 - lower 10 bit are the Navi Node ID, upper 6 bit the corresponding Area ID
  
 
Please note that this limits the number of Navi Nodes (i.e. vehicle path segments) to '''1024''' per area file and the number of files/areas to '''64'''!
 
Please note that this limits the number of Navi Nodes (i.e. vehicle path segments) to '''1024''' per area file and the number of files/areas to '''64'''!
 +
Also, be aware that the Navi Node ID is not the Linked Node ID on Section 2, but rather, the order in which the Navi Node is on the file.
  
 
===Section 6 - Link Lengths===
 
===Section 6 - Link Lengths===
Line 190: Line 198:
 
The size of section is equal to count of node addresses.
 
The size of section is equal to count of node addresses.
 
The section is followed by 192 bytes of unknown data.
 
The section is followed by 192 bytes of unknown data.
 
==File format of fastman92 path file==
 
 
Each file starts with a header, followed by 7 distinct sections.
 
 
Paths are stored as double-linked (thus undirected) [[Wikipedia:graph theory|graphs]] in [[Wikipedia:adjacency list|adjacency list]] representation. There can be connections between separate areas.
 
 
The following data types and structures are used within this article:
 
* '''INT8/UINT8''' - signed/unsigned 8 bit integer ''(1 byte)''
 
* '''INT16/UINT16''' - signed/unsigned 16 bit integer ''(2 byte)''
 
* '''INT32/UINT32''' - signed/unsigned 32 bit integer ''(4 byte)''
 
* '''FLOAT''' - single precision floating point number ''(4 byte)''
 
 
===Structures===
 
Go here to see C++ structures used in new format of path file: http://pastebin.com/7hpLZmJJ
 
 
====Compressed vector====
 
Compressed vector is the way to save some memory in GTA games. It's a structure with __int16 values of x, y, z coordinates.
 
GTA uses accuracy of 8 parts per whole number.
 
To convert __int16 or __int32 value back into float value, you have to cast it into float value, then divide by 8.
 
 
#pragma pack(push, 1)
 
class CompressedVector
 
{
 
public:
 
    signed __int16 x;
 
    signed __int16 y;
 
    signed __int16 z;
 
};
 
#pragma pack(pop)
 
 
Extended version of CompressedVector is used in new format of path files. __int16 values were replaced into __int32 values.
 
__int16 was making a limit of (-2^15/8 = -4096) to ((2^15) - 1) / 8 = 4 095,875
 
 
#pragma pack(push, 1)
 
class CompressedVector_extended
 
{
 
public:
 
    signed __int32 x;
 
    signed __int32 y;
 
    signed __int32 z;
 
};
 
#pragma pack(pop)
 
 
====Node address====
 
#pragma pack(push, 1)
 
struct CNodeAddress
 
{
 
  unsigned __int16 areaId;
 
  unsigned __int16 nodeId;
 
};
 
#pragma pack(pop)
 
 
Node address structure hold area ID and node ID.
 
 
===Header===
 
 
The header contains information about the content of the various sections in the file. It has a size of '''20 bytes'''.
 
 
4b - UINT32 - is different format? Should have a value of 0xFFFFFFFF
 
4b - UINT32 - format, should have a value "FM92"
 
1b - UINT8 - n, size of nickname
 
char[n] - nickname, should have a value ( "\x00" "fastman92" "\x00" )
 
4b - UINT32 - format version, should have a value "VER2"
 
4b - UINT32 - number of nodes (section 1)
 
4b - UINT32 - number of vehicle nodes (section 1a)
 
4b - UINT32 - number of ped nodes (section 1b)
 
4b - UINT32 - number of navi nodes (section 2)
 
4b - UINT32 - number of links (section 3/5/6)
 
 
'''Note:''' Sections related to links (3/5/6) have the same number of entries. These entries belong together and can be treated as one record by editors.
 
 
===Section 1 - Path Nodes===
 
 
The first section contains the node data for the paths. They are grouped by type: the list of vehicle nodes (cars, boats, race tracks) is followed by the ped nodes. Size of CPathNode_extended equals to '''40 bytes'''.
 
 
#pragma pack(push, 1)
 
struct CPathNode
 
{
 
  CPathNode *m_pPrev;
 
  CPathNode **m_ppNext;
 
  CompressedVector m_posn;
 
  __int16 m_wSearchList;
 
  __int16 m_wConnectedNodesStartId;
 
  __int16 m_wAreaId;
 
  __int16 m_wNodeId;
 
  char m_nPathWidth;
 
  char m_nNodeType;
 
  char m_dwFlags[4];
 
};
 
#pragma pack(pop)
 
 
 
struct CPathNode_extended : public CPathNode
 
{
 
  CompressedVector_extended m_extended_posn;
 
};
 
 
 
====Path Node Flags====
 
 
 
 
===Section 2 - Navi Nodes===
 
 
The second section contains additional nodes, referred to as ''navigational nodes'' (navi nodes) in this article. Size of CCarPathLink_extended equals to '''22 bytes'''.
 
 
Navi nodes are used to define additional information for vehicle path segments; they are not used by ped paths. They are usually positioned between two adjacent vehicle nodes on an interpolated curve.
 
 
There may be bugs if you don't connect navi nodes correctly. The order to connect them is to check first which of the 2 linked nodes is 'higher'. That means which one has the higher node ID or area ID. The direction of linking is allways from higher to lower node. So the target node of the navi nodes is allways the lower node. (Especially on area boundaries!)
 
 
#pragma pack(push, 1)
 
struct CCarPathLink
 
{
 
  __int16 posX;  // deprecated field
 
  __int16 posY;  // deprecated field
 
  CNodeAddress info;
 
  char dirX;
 
  char dirY;
 
  char m_nPathNodeWidth;
 
  char m_nFlags[2];
 
  char field_D;
 
};
 
#pragma pack(pop)
 
 
#pragma pack(push, 1)
 
struct CCarPathLink_extended : public CCarPathLink
 
{
 
  signed __int32 extended_posX;
 
  signed __int32 extended_posY;
 
};
 
#pragma pack(pop)
 
 
;Area ID and Node ID: These identify the target node a navi node is attached to.
 
;Direction: This is a normalized vector pointing towards above mentioned target node, thus defining the general direction of the path segment. The vector components are represented by signed bytes with values within the interval <nowiki>[-100, 100]</nowiki>, which corresponds to floating point values <nowiki>[-1.0, 1.0]</nowiki>.
 
;Extended position: This is the position of the navi node in world coordinates. To convert the signed dwords to floating point values divide them by 8.
 
 
====Navi Node Flags====
 
These are used to characterize path segment behavior, for more information see the table below.
 
 
  0- 7 - path node width, usually a copy of the linked node's path width (byte)
 
  8-10 - number of left lanes
 
11-13 - number of right lanes
 
    14 - traffic light direction behavior
 
    15 - zero/unused
 
16,17 - traffic light behavior
 
    18 - train crossing
 
19-31 - zero/unused
 
 
* Right (forward) and left (backward) lanes are relative to the direction vector.
 
* Experience has shown that navi nodes with attachments across area borders don't work too well. A possible solution is to attach them to the last instead of the next node, reverse the direction and exchange the lane numbers (if different) and other direction dependent flags. However, this will never work if previous, navi and next node are located in different areas each. '''(*)'''
 
* ''Traffic light behavior'' can be a value from 0 to 2, where 1 and 2 are related to North-South and West-East cycles for traffic light synchronization.
 
* The ''traffic light direction behavior'' is 1 if  the navi node has the same direction as the traffic light and 0 if the navi node points somewhere else.
 
 
( ''(*)'' Gots clear after knowing how Navis are linked exactly. So you may use this but it is not obligation.)
 
 
===Section 3 - Links===
 
 
These are links to adjacent nodes, '''4 bytes''' per entry.
 
 
2b - UINT16 - Area ID
 
2b - UINT16 - Node ID
 
 
===Section 4 - Filler===
 
 
This section hold data of constant size and content; its purpose is unknown. These '''768 bytes''' are filled with the repeating data pattern <code>0xFF,0xFF,0x00,0x00</code> (192x), but this can be filled with zeros as well.
 
 
===Section 5 - Navi Links===
 
 
These are links to adjacent navi nodes, '''4 bytes''' per entry. For indices from ped nodes (in section 1b) these are zero (unused).
 
 
4b - UINT16 - lower 16 bit are the Navi Node ID, upper 16 bit the corresponding Area ID
 
 
===Section 6 - Link Lengths===
 
 
These are the distances between linked nodes in full [[unit]]s, '''1 byte''' per entry. They are essential for path finding algorithms.
 
 
1b - UINT8 - Length
 
 
===Section 7 - Path Intersection Flags===
 
This section consists of intersection flag values for each node address (i.e. node link).
 
class CPathIntersectionInfo
 
{
 
public:
 
    unsigned char m_bRoadCross : 1;
 
    unsigned char m_bPedTrafficLight : 1;
 
};
 
The size of section is equal to count of node addresses.
 
The section is followed by 192 bytes of unknown data.
 
 
===EOF===
 
Path file should be terminated by a DWORD value "EOF". Otherwise, it's considered invalid.
 
 
4b - UINT32 - Last value of path file - "EOF"
 
  
 
==Tools &amp; Scripts==
 
==Tools &amp; Scripts==
 
+
* [[Fastman92 Path Format]]
 
* {{GTAG|1093|SA Path Editor (WIP)}} by {{U|JGuntherS@NL}} &ndash; Only useful for editing existing path data.
 
* {{GTAG|1093|SA Path Editor (WIP)}} by {{U|JGuntherS@NL}} &ndash; Only useful for editing existing path data.
 
* {{GTAF|post|214901|3841297|Path Compiler (WIP)}} by {{U|ocram88}} &ndash; Allows to create linear ped paths by generating waypoints from inside the game.
 
* {{GTAF|post|214901|3841297|Path Compiler (WIP)}} by {{U|ocram88}} &ndash; Allows to create linear ped paths by generating waypoints from inside the game.
Line 392: Line 207:
 
* {{GTAF|283684|Path Script}} &ndash; a script by {{U|Deniska}} for 3DSMax that creates path files directly.
 
* {{GTAF|283684|Path Script}} &ndash; a script by {{U|Deniska}} for 3DSMax that creates path files directly.
 
* {{GTAF|392955|PathViewer}} &ndash; a tool by {{U|Aschratt}} which allows to view paths and highlight nodes with special flags in 3D.
 
* {{GTAF|392955|PathViewer}} &ndash; a tool by {{U|Aschratt}} which allows to view paths and highlight nodes with special flags in 3D.
 +
* {{GTAF|733982|fastman92 limit adjuster}} &ndash; Limit adjuster by {{U|fastman92}} which allows to increase the path limits.
  
 
==See Also==
 
==See Also==

Latest revision as of 17:52, 5 June 2021

Colour-coded car path nodes for GTA: SA.

The 64 nodes*.dat files in gta3.img (or any other archive) contain the vehicle and ped paths and related information for GTA SA. There's a file for every 750×750 unit square, starting at the south-west corner (-3000, -3000) in row-major order.

Paths for planes and trains are not stored in the node files. Trains use the four tracks*.dat files. There are also paths for several missions and concrete cars in carrec.img.

Nodes can be influenced through scripts using the opcodes 01EB and 03DE.

Usually, cars and pedestrians use nodes if they are not linked to a script or carrec.img path in any way.

There is a modified version of the path format that may be used with fastman92's Limit Adjuster, which removes or extends some of the limits that the native format imposes.

Purpose

It is believed that the node files were generated by some sort of path compiler during development of the game, and represent the processing-friendly binary data structures otherwise generated at runtime by previous versions of the game from files like paths.ipl and related. Such files are still present in SA, but are unused.

Since the built-in path compiler has apparently been removed from the game code or at least made non-functional, custom tools and techniques are required to generate new paths for SA.

Node files are streamed by the game — only the active area and those surrounding it are loaded at a time. Thus corrupt files only lead to a game crash when the player enters the specific area.

The separate nodes*.dat files in the data\paths\ directory are ignored by the game.

File format

Each file starts with a header, followed by 7 distinct sections.

Paths are stored as double-linked (thus undirected) graphs in adjacency list representation. There can be connections between separate areas.

The following data types and structures are used within this article:

  • INT8/UINT8 - signed/unsigned 8 bit integer (1 byte)
  • INT16/UINT16 - signed/unsigned 16 bit integer (2 byte)
  • INT32/UINT32 - signed/unsigned 32 bit integer (4 byte)
  • FLOAT - single precision floating point number (4 byte)

There are several main concepts that are important for understanding the way path files work:

  • A "node" is an individual point in space which is used as an anchor for a path.
  • Paths are routes between nodes. These are traced in-game by peds and vehicles, but are typically shown in editors as graphical lines.
  • Two nodes are connected by one referencing a "link" which points to the other.
  • Most nodes link to two other nodes, one for each direction along a path, but it is possible for there to be more (such as at a junction).

Header

The header contains information about the content of the various sections in the file. It has a size of 20 bytes.

4b - UINT32 - number of nodes (section 1)
4b - UINT32 - number of vehicle nodes (section 1a)
4b - UINT32 - number of ped nodes (section 1b)
4b - UINT32 - number of navi nodes (section 2)
4b - UINT32 - number of links (section 3/5/6)

Note: Sections related to links (3/5/6) have the same number of entries. These entries belong together and can be treated as one record by editors.

Section 1 - Path Nodes

The first section contains the node data for the paths. They are grouped by type: the list of vehicle nodes (cars, boats, race tracks) is followed by the ped nodes. Each node entry has a size of 28 bytes.

4b - UINT32   - Mem Address, unused
4b - UINT32   - always zero, unused
6b - INT16[3] - Position (XYZ), see below
2b - INT16    - heuristic cost, always 0x7FFE, used internally to calculate routes
2b - UINT16   - Link ID
2b - UINT16   - Area ID (same as in filename)
2b - UINT16   - Node ID (increments by 1)
1b - UINT8    - Path Width
1b - UINT8    - Flood Fill, used in route calculations
4b - UINT32   - Flags
Mem Address
These might have been pointers to path segment structures inside R*'s path compiler. Apparently they are ignored by the game and can be set to zero.
Position
This is the position of the node in world coordinates. To convert the signed words to floating point values divide them by 8.
Link ID
The ID of the first node this node links to. The range of linked nodes is link ID ≤ x < (link ID + link count), where the link count is given by the first four bits of the flags.
Area ID and Node ID
Informational data, used to connect nodes via Links. Area ID is always the same as the number in the filename, and Node ID is used to identify the node.
Path Width
This is used to modify the width of a path. The default value is 0 (zero). To convert the signed word to a floating point value divide it by 8.
Flood Fill
Flood IDs for route calculation for NPCs. For normal NPC vehicle traffic a value of 1 is used, 2 is for boats and higher values are allocated to disconnected path area segment, e.g for race tracks and other mission applications.
Flags
The first 4 bits define the number of links to adjacent nodes. The other bits are used to characterize node behavior, for more information see the table below.

Path Node Flags

Node flag bits, from low to high:

0-3   - Link Count
4-5   - TrafficLevel

The LinkCount defines the number of enties incrementing from the LinkID. The TrafficLevel uses 4 steps: 0 = full 1 = high 2 = medium 3 = low

A    06    - Road-Blocks
B    07    - Boats
C    08    - Emergency Vehicles only
D    09    - zero/unused
E    10    - unknown, grove house entrance paths ?
F    11    - zero/unused
G    12    - Is not Highway
H    13    - Is Highway (ignored for PED-Nodes and never 11 or 00 for Cars!)
I    14    - zero
J    15    - zero
K-M  16-19 - spawn probability (0x00 to 0x0F)[1]
O    20    - RoadBlock?
P    21    - Parking
Q    22    - zero
R    23    - RoadBlock?

 24-31 - zero (unused)

The following statistics on flag usage, grouped by path type, might be useful for further research:

   | Peds           | Cars           | #
#  | 37650          | 30587          | --
A  | 0              | 391 (1.28%)    | 391
B  | 0              | 1596 (5.22%)   | 1596
C  | 6019 (15.99%)  | 7669 (25.08%)  | 13688
D  | 0              | 0              | 0
E  | 17 (0.05%)     | 0              | 17
F  | 0              | 0              | 0
G  | 0              | 27936 (91.33%) | 27936
H  | 0              | 2539 (8.3%)    | 2539
I  | 0              | 0              | 0
J  | 0              | 0              | 0
K  | 37646 (99.98%) | 30582 (99.98%) | 68228
L  | 36676 (97.41%) | 30141 (98.54%) | 66817
M  | 36676 (97.41%) | 30136 (98.52%) | 66812
N  | 36607 (97.22%) | 30046 (98.23%) | 66653
O  | 0              | 8 (0.03%)      | 8
P  | 0              | 215 (0.7%)     | 215
Q  | 0              | 0              | 0
R  | 0              | 16 (0.05%)     | 16

Section 2 - Navi Nodes

The second section contains additional nodes. These nodes are navigational nodes (but are referred to in this article as "navi nodes" for brevity). Each record has a size of 14 bytes.

Navi nodes are used to define additional information for vehicle path segments; they are not used by ped paths. They are usually positioned between two adjacent vehicle nodes on an interpolated curve.

There may be bugs if you don't connect navi nodes correctly. Links always go from a node with a higher area/node ID to one with a lower ID, so the target is always the lower node.

4b - INT16[2] - Position (XY), see below
2b - UINT16   - Area ID
2b - UINT16   - Node ID
2b - INT8[2]  - Direction (XY), see below
4b - UINT32   - Flags
Position
This is the position of the navi node in world coordinates. To convert the signed words to floating point values divide them by 8.
Area ID and Node ID
These identify the target node a navi node is attached to.
Direction
This is a normalized vector pointing towards above mentioned target node, thus defining the general direction of the path segment. The vector components are represented by signed bytes with values within the interval [-100, 100], which corresponds to the range of floating point values [-1.0, 1.0].

Navi Node Flags

These are used to characterize path segment behavior, for more information see the table below.

 0- 7 - path node width, usually a copy of the linked node's path width (byte)
 8-10 - number of left lanes
11-13 - number of right lanes
   14 - traffic light direction behavior
   15 - zero/unused
16,17 - traffic light behavior
   18 - train crossing
19-31 - zero/unused
  • Right (forward) and left (backward) lanes are relative to the direction vector.
  • Experience has shown that navi nodes with attachments across area borders don't work too well. A possible solution is to attach them to the last instead of the next node, reverse the direction and exchange the lane numbers (if different) and other direction dependent flags. However, this will never work if previous, navi and next node are located in different areas each. (*)
  • Traffic light behavior can be a value from 0 to 2, where 0 means traffic lights is disabled, 1 and 2 are used for the traffic lights and are North-South and West-East cycles for traffic light synchronization respectively.
  • The traffic light direction behavior is 1 if the navi node has the same direction as the traffic light and 0 if the navi node points somewhere else.

( (*) Gots clear after knowing how Navis are linked exactly. So you may use this but it is not obligation.)

Section 3 - Links

These are links to adjacent nodes, 4 bytes per entry.

2b - UINT16 - Area ID
2b - UINT16 - Node ID

Section 4 - Filler

This section holds data of constant size and content; its purpose is unknown. These 768 bytes are filled with 192 repetitions of the pattern 0xFF 0xFF 0x00 0x00, but this can be filled with zeros as well.

Section 5 - Navi Links

These are links to adjacent navi nodes, one for each link (in section 3), 2 bytes per entry. For indices from ped nodes (in section 1b) these are zero (unused).

2b - UINT16 - lower 10 bit are the Navi Node ID, upper 6 bit the corresponding Area ID

Please note that this limits the number of Navi Nodes (i.e. vehicle path segments) to 1024 per area file and the number of files/areas to 64! Also, be aware that the Navi Node ID is not the Linked Node ID on Section 2, but rather, the order in which the Navi Node is on the file.

Section 6 - Link Lengths

These are the distances between linked nodes in full units, 1 byte per entry. They are essential for path finding algorithms.

1b - UINT8 - Length

Section 7 - Path Intersection Flags

This section consists of intersection flag values for each node address (i.e. node link).

class CPathIntersectionInfo
{
public:
    unsigned char m_bRoadCross : 1;
    unsigned char m_bPedTrafficLight : 1;
};

The size of section is equal to count of node addresses. The section is followed by 192 bytes of unknown data.

Tools & Scripts

See Also