Files
WT-Offline/native/wto-nav/wto_nav_internal.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

96 lines
3.4 KiB
C++

/*
* State shared by the navigation engine's translation units (wto_nav_runtime.cpp: packs and
* loading; wto_nav_paths.cpp: queued sliced path searches; wto_nav_queries.cpp: point queries and
* dynamic costs). Everything below is guarded by g_lock unless noted.
*/
#pragma once
#include "wto_nav_runtime.h"
#include "wto_nav_format.h"
#include "DetourCommon.h"
#include "DetourNavMesh.h"
#include "DetourNavMeshQuery.h"
#include <windows.h>
#include <vector>
#ifndef DT_VIRTUAL_QUERYFILTER
#error "Detour must be built with DT_VIRTUAL_QUERYFILTER for the chokepoint and dynamic cost filter"
#endif
namespace wtonav {
constexpr int kPathSearchNodes = 32768; /* Node pool of the sliced path search, per tier */
constexpr int kPointSearchNodes = 2048; /* Node pool of point queries (wall distance) */
constexpr int kMaxPathPolys = 4096;
/* A circle that multiplies the cost of every edge whose midpoint lies inside it. */
struct DynamicCost {
float pos[3];
float radius;
float mul;
float until;
};
extern DynamicCost g_dynamic[WTO_NAV_RT_MAX_DYNAMIC];
extern uint32_t g_dynamic_count;
/* Area costs per WtoPolyArea, times the chokepoint multiplier, live dynamic costs and the
* traffic of the searching path's group. */
class QueryFilter : public dtQueryFilter {
public:
float chokepointMul = 1.0f;
float getCost(const float *pa, const float *pb,
const dtPolyRef, const dtMeshTile *, const dtPoly *,
const dtPolyRef curRef, const dtMeshTile *, const dtPoly *curPoly,
const dtPolyRef, const dtMeshTile *, const dtPoly *) const override;
};
struct Pack {
float heightSpan = 0.0f; /* Vertical extent of the mesh bounds */
dtNavMesh *meshes[WTO_NAV_TIER_COUNT] = {};
dtNavMeshQuery *pathQueries[WTO_NAV_TIER_COUNT] = {}; /* Owned by the sliced path search */
dtNavMeshQuery *pointQueries[WTO_NAV_TIER_COUNT] = {}; /* Snapping, raycasts, wall distance */
std::vector<WtoCoverPoint> covers;
std::vector<WtoTacticalCell> tactical;
/* First flat polygon index of every tile slot, and per traffic group how many counted paths
* cross each polygon (indexed by tileBase[tile] + polygon). */
std::vector<uint32_t> tileBase[WTO_NAV_TIER_COUNT];
std::vector<uint16_t> traffic[WTO_NAV_TIER_COUNT][WTO_NAV_RT_TRAFFIC_GROUPS];
};
extern SRWLOCK g_lock;
extern Pack *g_pack;
extern QueryFilter g_filters[WTO_NAV_RT_FILTER_COUNT];
extern WtoNavStats g_stats;
extern WtoNavTuning g_tuning;
/* Tier and traffic group (0-based, -1 none) of the search being advanced; read by getCost. */
extern int g_cost_tier;
extern int g_cost_group;
double now_micros();
/* Flat polygon index for Pack::traffic, or -1. */
int poly_index(const Pack &pack, uint32_t tier, dtPolyRef ref);
/*
* Nearest polygon within `snap` metres; mission points (spawn and capture zone centres) carry
* heights that are not on the ground, so a miss is retried over the mesh's whole height range,
* still within `snap` horizontally.
*/
bool snap_to_mesh(const dtNavMeshQuery *query, const dtQueryFilter &filter, float snap, float height_span,
const float point[3], dtPolyRef *ref, float nearest[3]);
/* Called with g_lock held whenever the loaded pack changes. */
void paths_reset_locked();
void dynamic_reset_locked();
void dynamic_expire_locked(float now);
uint32_t paths_pending_locked();
uint32_t traffic_paths_locked();
} // namespace wtonav