Przejdź do głównej zawartości

Path Nodes

Source Attribution

This documentation was originally sourced from GTAMods Wiki - Paths (GTA SA) and has been preserved here for archival purposes. The content remains unchanged, with only formatting improvements to enhance readability in the open.mp documentation.

Overview

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.

Data Types

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

TypeDescriptionSize
INT8/UINT8signed/unsigned 8 bit integer1 byte
INT16/UINT16signed/unsigned 16 bit integer2 bytes
INT32/UINT32signed/unsigned 32 bit integer4 bytes
FLOATsingle precision floating point number4 bytes

Key Concepts

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)

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

SizeTypeDescription
4bUINT32number of nodes (section 1)
4bUINT32number of vehicle nodes (section 1a)
4bUINT32number of ped nodes (section 1b)
4bUINT32number of navi nodes (section 2)
4bUINT32number of links (section 3/5/6)
notatka

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.

SizeTypeDescription
4bUINT32Mem Address, unused
4bUINT32always zero, unused
6bINT16[3]Position (XYZ), see below
2bINT16heuristic cost, always 0x7FFE, used internally to calculate routes
2bUINT16Link ID
2bUINT16Area ID (same as in filename)
2bUINT16Node ID (increments by 1)
1bUINT8Path Width
1bUINT8Flood Fill, used in route calculations
4bUINT32Flags

Field Descriptions

  • 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:

BitsDescription
0-3Link Count
4-5TrafficLevel

The LinkCount defines the number of entries incrementing from the LinkID. The TrafficLevel uses 4 steps:

  • 0 = full
  • 1 = high
  • 2 = medium
  • 3 = low
FlagBitDescription
A06Road-Blocks
B07Boats
C08Emergency Vehicles only
D09zero/unused
E10unknown, grove house entrance paths ?
F11zero/unused
G12Is not Highway
H13Is Highway (ignored for PED-Nodes and never 11 or 00 for Cars!)
I14zero
J15zero
K-M16-19spawn probability (0x00 to 0x0F)
O20RoadBlock?
P21Parking
Q22zero
R23RoadBlock?
24-31zero (unused)

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

FlagPedsCarsTotal
Total37,65030,58768,237
A0391 (1.28%)391
B01,596 (5.22%)1,596
C6,019 (15.99%)7,669 (25.08%)13,688
D000
E17 (0.05%)017
F000
G027,936 (91.33%)27,936
H02,539 (8.3%)2,539
I000
J000
K37,646 (99.98%)30,582 (99.98%)68,228
L36,676 (97.41%)30,141 (98.54%)66,817
M36,676 (97.41%)30,136 (98.52%)66,812
N36,607 (97.22%)30,046 (98.23%)66,653
O08 (0.03%)8
P0215 (0.7%)215
Q000
R016 (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.

SizeTypeDescription
4bINT16[2]Position (XY), see below
2bUINT16Area ID
2bUINT16Node ID
2bINT8[2]Direction (XY), see below
4bUINT32Flags
  • 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].

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

BitsDescription
0-7path node width, usually a copy of the linked node's path width (byte)
8-10number of left lanes
11-13number of right lanes
14traffic light direction behavior
15zero/unused
16,17traffic light behavior
18train crossing
19-31zero/unused

Important Notes

  • 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.
notatka

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

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

SizeTypeDescription
2bUINT16Area ID
2bUINT16Node 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.

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).

SizeTypeDescription
2bUINT16lower 10 bit are the Navi Node ID, upper 6 bit the corresponding Area ID
Important Limitations

Navi Node Limits:

  • Maximum 1024 Navi Nodes per area file
  • Maximum 64 files/areas total

Navi Node ID Note:

  • The Navi Node ID is not the Linked Node ID from Section 2, but rather the sequential order in which the Navi Node appears in the file.

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

SizeTypeDescription
1bUINT8Length

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

  • Fastman92 Path Format
  • SA Path Editor (WIP) by JGuntherS@NL - Only useful for editing existing path data
  • Path Compiler (WIP) by ocram88 - Allows to create linear ped paths by generating waypoints from inside the game
  • Path Tool (WIP) by steve-m - Comes bundled with a MaxScript to export ped and vehicle paths from Max (by using spline shapes)
  • APE v1.1 by Aschratt - Based on a memhack and including a decompiler it is possible to add path to the existing or to create completely new from ingame!
  • Path Script - a script by Deniska for 3DSMax that creates path files directly
  • PathViewer - a tool by Aschratt which allows to view paths and highlight nodes with special flags in 3D
  • fastman92 limit adjuster - Limit adjuster by fastman92 which allows to increase the path limits

See Also