Skip to main content

Module trade_routes

Module trade_routes 

Source
Expand description

Trade routes file format support (campaign_maps/<map>/trade_routes.ptd).

These files contain the precomputed trade network of a campaign map: the spline curves trade routes follow, and the routes between regions and between ports. The game copies them into the trade manager of the campaign startpos.

§File Format

All values are little endian:

  • Signature \x89PTD\r\n\x1a\n, u32 version (1 in Attila).
  • u32 region count, then each region key as u32 length + bytes.
  • u32 spline count, then per spline: 4 flag bytes, u32 segment count, and per segment the start point (u16, u16), the first control point as an i16 offset from the start, the second control point as an i16 offset from the end, and the end point (u16, u16). Points are in raw map units; offsets are at 100 times the raw scale.
  • Region routes, then port routes: u32 count, then per route u32 from, u32 to, u32 edge count and the edges. from/to index the region table. A pair can appear more than once (alternative paths).
  • A trailing u32 (checksum?).

Structs§

TradeRoute
A route between two regions or ports: the spline edges to follow, in order.
TradeRouteEdge
A spline traversal in a route: spline index * 2 + direction, where an odd value means the spline is traversed from end to start.
TradeRoutes
Decoded trade routes (.ptd) file.
TradeSpline
A spline of the trade network: a chain of cubic Bezier segments.
TradeSplineSegment
A cubic Bezier segment, in raw map units.

Constants§

EXTENSION
File extension of trade routes files.
SIGNATURE
Signature of trade routes files.