Files
WT-Offline/native/wto-nav/wto_nav_runtime.h
T
N0VAN0M4LY 413bd55c54 fix(ground-ai): spread team routes, pass vehicles and keep off deep water
First in-game run of the path follower on Berlin and Poland showed whole
teams queueing on one road, bots ramming stopped teammates and wrecks,
bots clipping building corners, bots sliding into the Poland river and
the same bot getting stuck at the same spot dozens of times.

Native engine (native/wto-nav):
- Team traffic: a bot's finished path counts for its team for
  trafficHoldSec; the team's later searches pay trafficCostPerPath more
  per counted path through a polygon (up to trafficCostMaxMul), so
  teammates spread over parallel routes. A slot's previous path stops
  counting when it asks for a new one.
- Path corners are moved up to cornerOffsetM away from the edge they
  turn around, when the mesh allows both legs; off-mesh link endpoints
  stay put.
- path_request takes the team; load_map takes the new settings;
  get_stats reports live traffic paths and moved corners.

Bake (tools/navgen):
- Water deeper than navBake.maxFordDepthM (0.9 m, was a fixed 0.6 m)
  is a wall before erosion, so walkable ground keeps the tier radius
  from it, plus deepWaterMarginM on banks lower than
  deepWaterBankHeightM above the water line. Quays and ramps above it
  keep only the radius. The preview marks deep water from the terrain.

Ground AI scripts:
- The lookahead point is pulled back along the path until the mesh
  allows the straight line to it, so corners are no longer cut through
  buildings.
- New traffic module replaces the fixed sideways step: hull length and
  width along the heading; stopped vehicles, wrecks and parked players
  are passed on the side with room, or the bot stops short and after
  blockWaitSec marks the spot and plans again; moving traffic ahead is
  followed; oncoming traffic is passed in the open and in narrow
  passages the bigger vehicle goes first. Wrecks carry their heading.
- A hull pressed against a vehicle or wreck backs off after
  contactReverseSec instead of the full stuck window.
- Jams and confirmed obstacles cost far more, and a given-up place is
  all but closed (giveUpRadiusM, giveUpCostMul), so replanning leaves
  instead of returning to it.

Tuning: navEngine trafficCostPerPath, trafficCostMaxMul, trafficHoldSec,
cornerOffsetM; pathFollow stationarySpeedMps, passMarginM, passSpeedMps,
blockWaitSec, blockTtlSec, contactGapM, contactReverseSec, giveUpRadiusM,
giveUpCostMul; avoidShiftM removed; jamCostMul 4 -> 12, rubbleCostMul
8 -> 25; navBake maxFordDepthM, deepWaterMarginM, deepWaterBankHeightM
(bake only). Launcher fields and en/zh-CN labels updated (978/978 keys).

Checked: root and launcher typecheck, MSVC build with no warnings in
project code, check-patches for 2.61.0.58 and 2.61.0.60, rebake of
avg_berlin, avg_poland and avg_hurtgen (all spawn-to-zone pairs still
connected on every tier), offline run on the new avg_poland pack (eight
same-team paths spread over different roads, traffic released after
the hold time, corners moved, pump within budget), isolated game copy
build. daScript compilation and in-battle behaviour still need the
in-game run.
2026-12-05 21:39:07 +08:00

180 lines
8.8 KiB
C

/*
* In-game navigation engine: one baked `.wtonav` pack (tools/navgen) held for the battle in
* progress, queried through upstream Detour. The C side (wto-net local_mp_nav.c) owns the
* daScript request protocol; this interface only knows packs, levels, paths and mesh queries.
*
* Every function is safe to call from any thread; queries are serialized internally.
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define WTO_NAV_RT_AREA_COUNT 12 /* WtoPolyArea values 0..11 */
#define WTO_NAV_RT_FILTER_COUNT 2 /* 0 tracked, 1 wheeled */
#define WTO_NAV_RT_PATH_SLOTS 160 /* Independent path searches the script may keep in flight */
#define WTO_NAV_RT_MAX_CORNERS 96 /* Straight-path corners returned per path */
#define WTO_NAV_RT_MAX_DYNAMIC 64 /* Live dynamic cost circles (wrecks, jams, rubble) */
#define WTO_NAV_RT_TRAFFIC_GROUPS 2 /* Teams whose planned paths count as traffic for each other */
/* Battle-wide search behaviour, set before the pack loads. */
typedef struct WtoNavTuning {
float trafficCostPerPath; /* Cost added per path of the same group through a polygon; 0 = off */
float trafficCostMaxMul; /* Highest traffic multiplier */
float trafficHoldSec; /* A finished path counts as traffic this long (script seconds) */
float cornerOffsetM; /* Path corners are moved this far away from the edge they turn around */
} WtoNavTuning;
/* Detour traversal costs for one vehicle class, indexed by WtoPolyArea. */
typedef struct WtoNavCosts {
float area[WTO_NAV_RT_AREA_COUNT];
float chokepointMul; /* Multiplies the area cost on WTO_FLAG_CHOKEPOINT polygons */
} WtoNavCosts;
typedef enum WtoNavLoadResult {
WTO_NAV_LOAD_OK = 0,
WTO_NAV_LOAD_MISSING, /* No pack file for the level */
WTO_NAV_LOAD_UNREADABLE, /* The file exists but cannot be read */
WTO_NAV_LOAD_CORRUPT, /* Bad header, offsets or Detour tile data */
} WtoNavLoadResult;
typedef struct WtoNavLoadInfo {
WtoNavLoadResult result;
int fingerprintKnown; /* 1 when the level file's eVER SHA-1 was read */
int fingerprintMatch; /* 1 when it equals the pack's; meaningful only when known */
int prefetched; /* 1 when the pack was read in the background beforehand */
uint8_t packSha1[20];
uint8_t levelSha1[20];
uint32_t tiers;
uint32_t covers;
uint32_t polys[3];
double readMs; /* Time spent reading and parsing, wherever it happened */
double waitMs; /* Time the caller of wto_nav_load was held up */
char detail[96]; /* Why loading failed, for the log */
} WtoNavLoadInfo;
typedef enum WtoNavPathStatus {
WTO_NAV_PATH_FULL = 0,
WTO_NAV_PATH_PARTIAL, /* Ends at the reachable polygon closest to the goal */
WTO_NAV_PATH_NO_START, /* Start not within the snap radius of the mesh */
WTO_NAV_PATH_NO_GOAL, /* Goal not within the goal snap radius of the mesh */
WTO_NAV_PATH_FAILED, /* No pack loaded, bad tier or Detour failure */
WTO_NAV_PATH_PENDING, /* Queued or being searched; ask again after the next pump */
WTO_NAV_PATH_STALE, /* The slot holds another (newer) request, or none */
} WtoNavPathStatus;
typedef struct WtoNavPathRequest {
uint32_t tier; /* 0 narrow, 1 standard, 2 wide */
uint32_t filter; /* 0 tracked, 1 wheeled */
float snapM; /* Start (and first goal) snap radius */
float goalSnapM; /* Wider horizontal goal snap when the goal misses snapM */
uint32_t group; /* 1..WTO_NAV_RT_TRAFFIC_GROUPS: avoids and adds to that group's traffic; 0 none */
float start[3];
float goal[3];
} WtoNavPathRequest;
typedef struct WtoNavPathResult {
WtoNavPathStatus status;
int count; /* Corners written, the first being the snapped start */
int truncated; /* 1 when the path has more corners than were returned */
int goalMoved; /* 1 when the goal was snapped with goalSnapM */
float lengthM; /* Length of the returned corners */
} WtoNavPathResult;
/* What the mesh says about one point of the tier's mesh. */
typedef struct WtoNavProbe {
int onMesh; /* 1 when a polygon lies within the snap radius */
float nearest[3]; /* Closest point on that polygon */
float offsetM; /* Horizontal distance from the asked point to `nearest` */
float wallDistM; /* Distance to the mesh edge, capped at the search radius */
uint32_t area; /* WtoPolyArea of the polygon */
uint32_t flags; /* WtoPolyFlag bits of the polygon */
} WtoNavProbe;
typedef struct WtoNavStats {
int loaded;
uint32_t queries; /* Finished path searches */
uint32_t failures; /* Of which not FULL */
double totalMicros; /* Search time of finished paths, summed over their frames */
double maxMicros; /* Longest search time of a single path */
uint32_t maxFrames; /* Most pump frames a single path took */
double pumpMaxMicros; /* Longest single pump */
uint32_t pending; /* Paths waiting or being searched now */
uint32_t dynamic; /* Live dynamic cost circles */
uint32_t meshQueries; /* Probe, raycast and nearest calls */
uint32_t trafficPaths; /* Finished paths counting as traffic now */
uint32_t cornersMoved; /* Path corners moved away from the edge they turn around */
} WtoNavStats;
/* Reads the eVER SHA-1 of a Dagor level file (levels/<name>.bin) without loading the level. */
int wto_nav_read_level_fingerprint(const wchar_t *level_path, uint8_t sha1[20]);
/*
* Starts reading `pack_path` (and the fingerprint of `level_path`) on a background thread so a
* later wto_nav_load of the same pack only takes the result. Nothing happens when that pack is
* already being read or waiting; a different one replaces it.
*/
void wto_nav_prefetch(const wchar_t *pack_path, const wchar_t *level_path);
/*
* Makes `pack_path` the loaded pack, replacing any other: from the background read when it is
* the same file (waiting for it to finish), otherwise read here. A fingerprint mismatch is
* reported but never refuses the pack. Clears paths in flight and dynamic costs.
*/
void wto_nav_load(const wchar_t *pack_path, const wchar_t *level_path, WtoNavLoadInfo *info);
void wto_nav_unload(void);
int wto_nav_is_loaded(void);
/* Replaces the traversal costs of one filter (0 tracked, 1 wheeled). */
void wto_nav_set_costs(uint32_t filter, const WtoNavCosts *costs);
/* Replaces the traffic and corner settings; applies to searches started afterwards. */
void wto_nav_set_tuning(const WtoNavTuning *tuning);
/*
* Queues a path search in `slot`, replacing whatever the slot held. Start and goal are snapped
* at once; a miss is final and reported through the ticket's result. Returns the ticket that
* wto_nav_path_result must quote (0 when the slot or request is invalid).
*
* With a traffic group the search pays more for polygons that other paths of the group (finished
* within trafficHoldSec) pass through, and its own result counts for the next ones. The slot's
* previous path stops counting as soon as the new request arrives.
*/
uint32_t wto_nav_path_request(uint32_t slot, const WtoNavPathRequest *request);
/* Result of `ticket` in `slot`; `points` receives up to `max_points` xyz triples. */
void wto_nav_path_result(uint32_t slot, uint32_t ticket, float *points, int max_points, WtoNavPathResult *result);
/*
* Advances queued searches for at most `budget_us` microseconds (one call per game frame) and
* expires dynamic costs whose end time is before `now` (script time, seconds).
*/
void wto_nav_pump(double budget_us, float now);
int wto_nav_probe(uint32_t tier, uint32_t filter, const float pos[3], float snap_m, float wall_radius_m, WtoNavProbe *probe);
/*
* Walks the mesh surface from `start` toward `goal`. Returns 1 when nothing blocks the way,
* 0 when a mesh edge does (`hit_frac` and `hit` tell where), -1 when `start` is off the mesh.
*/
int wto_nav_raycast(uint32_t tier, uint32_t filter, float snap_m, const float start[3], const float goal[3],
float *hit_frac, float hit[3]);
/* Closest point of the tier's mesh within `radius_m` (horizontally, any height); 1 if found. */
int wto_nav_nearest(uint32_t tier, uint32_t filter, float radius_m, const float pos[3], float out[3]);
/*
* Adds a circle that multiplies path costs by `cost_mul` until script time `until`; a circle
* close to an existing one updates it. Returns the number of live circles.
*/
uint32_t wto_nav_add_dynamic(const float pos[3], float radius_m, float cost_mul, float until);
void wto_nav_get_stats(WtoNavStats *stats);
#ifdef __cplusplus
}
#endif