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.
83 lines
3.2 KiB
Plaintext
83 lines
3.2 KiB
Plaintext
// Fresh static obstacles on top of the path: what the baked mesh cannot know. Two short physical
|
|
// rays from the front corners of the hull catch rubble and collapsed buildings and let the vehicle
|
|
// drive through what it can knock down (fences, light walls). Vehicles and wrecks are handled by
|
|
// wto_ai_traffic_common.
|
|
options indenting = 2
|
|
options no_global_heap = true
|
|
module wto_ai_avoid_common shared
|
|
|
|
require ecs
|
|
require math
|
|
require DagorMath
|
|
require Dacoll
|
|
require RendInst
|
|
require PhysMat
|
|
require %appGame.wtoai.wto_ai_config_common
|
|
require %appGame.wtoai.wto_ai_types_common
|
|
|
|
let private AVOID_STATIC_MASK = ETF_STRUCTURES | ETF_FRT
|
|
|
|
// Placed objects a tank cannot knock down. Matches the bake: riExtra objects up to
|
|
// navBake.crushableMaxRiExtraHp are crushable, destructible generated objects (fences, posts)
|
|
// fall over, indestructible ones block.
|
|
[never_inline]
|
|
def private wto_avoid_ri_blocks(desc : RendInstDesc const&) : bool
|
|
if desc.isValid && desc.isRiExtra && desc.riExtraHandle != RIEX_HANDLE_NULL
|
|
let handle = desc.riExtraHandle
|
|
let poolId = uint(handle_to_ri_type(handle))
|
|
if rendinst_isRIExtraGenPosInst(poolId)
|
|
return false
|
|
if riex_isImmortal(poolId) || riex_isInvincible(handle)
|
|
return true
|
|
return riex_getInitialHP(handle) > WTO_AI_NAVBAKE_CRUSH_MAX_HP
|
|
if !desc.isValid
|
|
return true
|
|
if rendinst_isRIGenPosInst(desc)
|
|
return false
|
|
return !rendinst_isRIGenDestr(desc)
|
|
|
|
// Clear distance along dir up to the first wall-like surface a tank cannot drive through.
|
|
[never_inline]
|
|
def private wto_avoid_drive_ray(startPos, dir : float3; maxRange : float) : float
|
|
var structDist = maxRange
|
|
var sTraveled = 0.0
|
|
for _hop in range(0, 4)
|
|
var hitD = maxRange - sTraveled
|
|
if hitD <= 0.0
|
|
break
|
|
var mat = PHYSMAT_INVALID
|
|
var norm = float3(0.0)
|
|
var desc = RendInstDesc()
|
|
let sOrigin = startPos + dir * sTraveled
|
|
if !traceray_normalized(sOrigin, dir, hitD, mat, norm, AVOID_STATIC_MASK, desc, PHYSMAT_INVALID)
|
|
break
|
|
if norm.y < 0.72
|
|
structDist = clamp(sTraveled + hitD, 0.0, maxRange)
|
|
break
|
|
sTraveled += max(0.0, hitD) + 0.5
|
|
var traveled = 0.0
|
|
for _hop in range(0, 4)
|
|
var hitDist = structDist - traveled
|
|
if hitDist <= 0.0
|
|
break
|
|
var riMat = PHYSMAT_INVALID
|
|
var riNorm = float3(0.0)
|
|
var riDesc = RendInstDesc()
|
|
let origin = startPos + dir * traveled
|
|
if !traceray_normalized(origin, dir, hitDist, riMat, riNorm, ETF_RI | ETF_RI_PHYS, riDesc, PHYSMAT_INVALID)
|
|
break
|
|
if riNorm.y < 0.72 && wto_avoid_ri_blocks(riDesc)
|
|
return clamp(traveled + hitDist, 0.0, structDist)
|
|
traveled += max(0.0, hitDist) + 0.35
|
|
return structDist
|
|
|
|
// Clear distance ahead along `dir` from both front corners of the hull (the shorter of the two).
|
|
[never_inline]
|
|
def public wto_avoid_bumper(myPos, dir : float3; spec : WtoVehicleSpec const&) : float
|
|
let left = float3(-dir.z, 0.0, dir.x)
|
|
let base = myPos + dir * max(0.5, spec.halfLen - 0.4) + float3(0.0, 1.0, 0.0)
|
|
let side = max(0.4, spec.halfWid - 0.25)
|
|
let clearL = wto_avoid_drive_ray(base + left * side, dir, WTO_AI_PF_BUMPER_RAY_M)
|
|
let clearR = wto_avoid_drive_ray(base - left * side, dir, WTO_AI_PF_BUMPER_RAY_M)
|
|
return min(clearL, clearR)
|