WC3 Pathfinding And Harvest Reachability
Contract
WC3 movement keeps target selection, static routing, and interaction behavior separate:
games/warcraft-3/game/skills/s_move.c owns per-tick steering and local block-and-slide. server/sv_routing.c owns static pathmap line tests, connectivity queries, and cached flow fields. Harvest target selection remains in skills/s_harvest_lumber.c; the router never changes a tree target by itself.
Research inspiration
The following commits were inspired by WC3 pathfinding research by lofcz in lofcz/open-realm. They adapt that research to OpenRealm's routing APIs, WC3 movement lifecycle, and save/load contracts.
| Commit | Commit message |
|---|---|
a87b32429272 |
routing: expose bounded multi-waypoint path results |
8b54d29ed248 |
wc3: retain multi-turn routes across movement ticks |
d60bfb626b62 |
wc3: preserve order goals and distinguish navigation completion |
b9aeeeaf2427 |
wc3: publish static footprint changes to routing |
fbb120791af6 |
wc3: recover movement around stationary unit blockers |
1b555fd80eac |
wc3: preserve group move slots and refresh formation speed |
b58d5d96bb9c |
wc3: stabilize route steering and movement save recovery |
415d478a4613 |
wc3: preserve patrol and combat move order continuity |
baa006e6340c |
server: skip unchanged spatial relinks and expose profiling counters |
9b787bf058de |
wc3: defer admitted gold-mine orders until worker exit |
6a4fe065ea8b |
wc3: prioritize queued worker orders at resource handoffs |
f33e9b0b2307 |
wc3: make resource return one-shot and guard harvest resume state |
2784007a2eb0 |
wc3: restore construction-aware move arrival check |
58aa338d045e |
wc3: align movement regressions with retained routes |
29b6da539b04 |
tests: align movement assertions with routed destinations |
86ff458e3842 |
tests: reset waypoint ring with synthetic edicts |
48a4a1763cf9 |
docs(wc3): credit pathfinding research inspiration |
Ground Move, Patrol, Attack-move location orders, and Attack chases use collision-size-aware static routing through direct-line checks, waypoint acceleration, and flow generation. Attack still owns its interaction range independently: reaching a collision-safe route endpoint does not complete the attack. Harvest has an explicit collision split: Gold Mine approach and all resource-return legs use collision-sized static-only routing (live units ignored), while tree approach keeps live-unit collision and uses collision-sized resource-worker local avoidance.
Normal movement uses the live unitinfo.PropWindow, initialized from UnitData.propWin / object field uprw and mutable through SetUnitPropWindow. The authored value is a propulsion window in degrees: steering may continue turning toward the avoidance-resolved heading every simulation tick, but unit_moveindirection() does not translate until the remaining facing error is strictly inside that window. This is shared movement behavior, so Attack chase, Follow, Patrol, Harvest, Repair, Way Gate approach, and ordinary Move inherit the same turn-before-propulsion rule rather than implementing Attack-specific steering. A zero runtime value prevents translation until facing exactly matches the resolved heading, so it can be used to hold movement while retaining turning.
Bounded local multi-waypoint search (foundation)
server/sv_routing.c exposes CM_FindBoundedPath() as an additive generic
routing query. The caller supplies pathAccelParams_t, a fixed-capacity array
of vec2_t waypoints, and receives a cmRoutePath_t result. Routing still uses
static pathmap.original, a radius-expanded footprint and the existing
blocked-channel mask; it does not bake moving units into the pathmap.
The result's status is CM_ROUTE_COMPLETE only when local A* reached the
legal navigation endpoint. CM_ROUTE_PARTIAL means either search stopped at
its 2,048-expansion budget / explored only a disconnected component, or the
output buffer is too short to carry the complete smoothed path. A partial
route supplies safe forward progress not unit/task arrival. CM_ROUTE_NONE
means the local search cannot supply any valid forward segment; the existing
resumable shared field may still find a route. A target outside the 48-cell
local envelope is deliberately deferred to that field.
The result separates navigation_goal (which may be the closest legal cell)
from the caller's authored destination, and includes the returned segment's
endpoint, count, truncated, goal_adjusted, and map_revision. Waypoints
are in start-to-end order; every emitted segment is checked by
CM_LineIsPathableForRadiusFlags(), including its diagonal corner rule. A
fixed 16-cell lookahead bounds smoothing work; a limited output array returns
an explicitly partial prefix rather than silently dropping remaining turns.
CM_GetPathRevision() changes on static-pathmap setup/bake and explicit
cache invalidation, not for transient unit occupancy. The revision is exposed
by WC3's retained-route invalidation. The generic CM_AccelerateRoute()
remains unchanged for other games, while WC3's movement now uses the bounded
multi-waypoint result. CM_FindPathWaypoint() deliberately keeps its
completed-search-only behavior for existing generic callers.
Local stationary-body detours (Patch 5)
A stalled WC3 mover may request an additional bounded A* search with a
caller-owned, temporary stationary-unit obstruction snapshot. The generic
CM_FindBoundedPathWithBlockers() API accepts an optional predicate that
vetoes occupied cell centres, diagonal corner neighbours, and simplified
segments without inserting live occupancy into pathmap.original, changing
CM_GetPathRevision(), or invalidating shared flow fields. The unfiltered
CM_FindBoundedPath() interface retains its earlier static-only behavior.
Only eligible idle solid units in the same movement collision domain are included. Moving units remain handled by move-time slide/avoidance; workers using resource queueing or static-only resource return do not use this additional detour query. A short local route is installed after the existing 24-frame displacement-stall threshold and at most once per 500 ms retry window. Routes stop at a bounded staging leg if the original goal is distant; they never claim that a partial search has completed the gameplay order.
The original goal and target incarnation remain authoritative. A valid stationary-body detour is retained while occupied; if the obstacle departs and a direct static/dynamic segment becomes clear, ordinary routing resumes. A temporary near-goal body blocker does not force a permanent Hold, so a previously blocked movement order can recover without a second click. The detour and retry throttle are transient movement state, cleared on order reset and save/load; the pool layout change bumps save format to 125.
WC3 mover-owned retained routes (Patch 2)
movement_t.local_route retains up to 16 collision-validated turns produced by
CM_FindBoundedPath() while the current travel order remains active. The unit
advances its cursor only on reaching a turn; a newly ready shared flow field
must not abruptly discard a still-safe local segment. A direct traversable
line may replace the retained route. The router's PARTIAL output supplies
progress but never signals gameplay arrival. An unfinished prefix can
hand off to the shared field when exhausted.
The route is invalidated on goal-entity incarnation change, movement of its
requested destination by half a path cell, mover radius/pathing-mask change,
static pathmap revision, failed segment legality, or move_reset_progress().
The existing movement_t.path mirrors only the currently active retained
turn for compatible movement checks. Local route arrays are runtime-only in
g_save.c: after a load they are reconstructed from the authoritative order
and position; no A* parent/search data or flow generation is saved.
The new state is Warcraft III-specific: CM_AccelerateRoute() remains
available unchanged to StarCraft II. Dynamic stationary blocker detours,
original-goal vs navigation-goal completion and group-route policy are later
patches, not part of this mover-state change.
Static interaction rectangles
G_ClosestStaticPathablePointInRectForRadiusFlags() is a WC3-owned query for interactions whose legal destination is a world-space rectangle rather than one point or an entity footprint. It searches every pathmap cell intersecting the rectangle, applies the caller's collision radius and blocked-pathing mask to pathmap.original, and returns the closest point inside a legal intersecting cell. It does not stamp live units into the query. Temporary occupancy remains a move-time collision/local-avoidance concern, preventing a crowded interaction area from becoming unavailable at order submission. Way Gates use it for authored Wrp1/Wrp2 entry rectangles; the shared router retains only generic pathing primitives.
Tests cover sub-cell rectangles, blocked intersecting cells, and live occupancy being ignored by the static query.
Escaping a baked footprint
A mover can legally stand inside blocked static pathing: the Human primary builder stays on the construction site it started (see Building Construction), and scripts can place units inside a structure. Static routing has no legal node there, so every route field reports the mover's own cell as unreachable and local slide alone cannot escape.
move_steer_egress() therefore runs before any route request. While CM_PointIsPathableForRadiusFlags() rejects the mover's own origin, it caches the nearest pathable point from CM_ClosestPathablePointForRadiusFlags(), sets the heading straight at it, and marks the escape on movement_t (egress_target/egress_valid). move_is_valid_policy() accepts steps while egressing only when they do not move away from that point, so the escape stays local instead of slipping through unrelated walls. unit_commit_step() clears the egress as soon as the new origin is pathable, and ordinary direct-line/flow/bounded-A* routing resumes. Live units still constrain every egress step; only static pathing is bypassed, and only for the escape corridor.
Egress applies to ordinary Move/Attack/Patrol/Follow steering and to the interaction walks that use unit_changeangle_for_radius*. It is deliberately not used by the resource-return point helpers, which keep their own wisp_egress tree corridor or ignore-live-units contracts. The construction-start relocation teleport is gone: the builder works from its site, and an order that takes it elsewhere walks it out to the nearest legal point.
Crowd contact and no-marching
Two behaviours keep packed movers from locking up or standing still while playing the walk cycle:
- Contact grazing. A unit resting exactly on another unit's collision boundary has no 15° slide candidate that clears the circle — every chord cuts inside it.
move_is_valid_policy()therefore accepts a step whose swept path never comes closer thanrr - MOVE_CONTACT_GRAZEwhen the mover already sits withinrr + MOVE_CONTACT_GRAZE. The step can shave at most the sub-unit tolerance and lets packed units slide along each other instead of freezing. It can never deepen penetration beyond the tolerance. - Blocked movers stand, they do not march.
unit_moveindirection_policy()asks for Walk only once the heading is inside the propulsion window, and when both the facing-lagged and the resolved-heading steps are rejected it switches the presentation back to Stand for that tick. Every move behaviour (Move, Attack, Harvest, Repair, Patrol, resource legs) inherits this: a unit that cannot advance stops the walk clip instead of restarting it in place forever.
wc3_lumber_crowd.group_ordered_to_one_tree_reaches_chop_range and wc3_lumber_crowd.crowded_tree_large_footprint_waits_without_marching assert the no-marching result for a packed worker group; the contact-graze rule is exercised by the existing collision and crowd suites.
Interaction slots
Several units ordered to one structure must surround it rather than queue on a single approach point. repair_find_interaction_slot() starts from the nearest footprint point, and when another worker assigned to the same building already stands on it or is walking to it, rotates around the footprint in 30° steps until it finds a legal, unclaimed point. Peak-build and repair groups therefore spread around the building and all contribute without stacking. Workers targeting one tree use the equivalent near-side scan (each worker's own bearing) described in Resource Worker Crowd Routing.
Movement-class static pathing
WC3 derives static routing policy from authored movetp rather than reducing every non-flyer to ground movement:
| WC3 movement | Shared routing policy | Static cell is blocked when |
|---|---|---|
foot, horse, hover |
CM_PATHING_UNWALKABLE |
nowalk |
fly |
CM_PATHING_UNFLYABLE |
nofly |
float |
CM_PATHING_UNSWIMMABLE |
nowater |
amph |
CM_PATHING_REQUIRE_ALL \| CM_PATHING_UNWALKABLE \| CM_PATHING_UNSWIMMABLE |
both nowalk and nowater |
M_UnitStaticPathingFlags() owns that WC3 mapping. The resulting policy is carried through destination correction, direct/swept line tests, bounded A*, closest-reachable fallback, resumable flow fields, trained-unit exit placement, formation slots, Way Gate/ability movement helpers, and pathing-aware scripted repositioning. The generic CM_*Walkable* entry points intentionally remain UNWALKABLE wrappers so SC2 and existing ground callers do not change semantics; games that need another movement class use the mask-aware CM_*Pathable*Flags forms. Flow-cache identity includes the full pathing policy as well as adjusted target cell and collision radius, so fields for ground, air, sea, and amphibious movers cannot be reused across incompatible policies.
The shared router exposes generic pathing channels and a generic CM_PATHING_REQUIRE_ALL query modifier; it does not define a Warcraft amphibious unit type. WC3 uses the modifier to express the Warsmash rule that an amphibious unit may traverse a cell when either walking or swimming is legal.
Static entity footprints preserve the relevant Warcraft pathing channels when they are baked. A blocked/red pathing-texture pixel contributes both UNWALKABLE and UNSWIMMABLE, while the green channel contributes UNFLYABLE. LoadTGA stores source BGRA bytes in COLOR32, so the authored red/green channels are read through the loader's existing component layout. A walkable bridge deck clears the land-pathing block over its crossing lane without clearing the underlying water-pathing channel, so ground/amphibious movers can use the deck without turning it into a naval surface. A tall model does not automatically block flight; only authored UNFLYABLE pathing does.
Dynamic command-time obstacles use requester-aware WC3 collision domains rather than the static amph predicate directly. Ground movers overlap ground blockers, float overlaps sea blockers, fly overlaps air blockers, and amph overlaps both ground and sea blockers. For an amphibious request, a blocker in either overlapping domain stamps both selected static channels into the temporary query map, so CM_PATHING_REQUIRE_ALL rejects that occupied space. Precise move-time validation uses the same ground/sea/air domain contract. See Naval Movement And Water Pathing for the naval-specific contract.
Harvest Worker Routing
Harvest/resource movement now follows the Warsmash-style collision contract directly: Gold Mine approach and all resource-return movement ignore live units while still respecting static pathing; tree approach keeps ordinary live-unit collision but applies the deterministic resource-worker queue/pass policy when another worker blocks the local approach. Building interaction routes use the worker's real collision radius, mover-owned bounded A* detours while shared fields rebuild, and footprint-aware near-side endpoints for Town Halls/Lumber Mills.
Wisp auto-harvest also routes with the Wisp's collision radius. A NightElf07 trace showed a Wisp oscillating 118-134 units from its assigned tree, outside Awha's 116-unit harvest range, after the route switched from its nearby waypoint to a completed zero-radius flow field. The mover's step validation still used its 16-unit collision radius, so that field could direct it toward cells its body could not occupy. ai_wisp_walktree() now uses unit_changeangle_for_radius_worker() before unit_moveindirection(), keeping the shared flow field, local worker avoidance, and step validation on the same collision contract.
The NightElf07 regression starts at the logged stalled position with the tree-centered collision-sized field already available and includes the four nearby ATtr footprints from the pathing-grid dump. Starting the test at the original order position was insufficient: its early waypoint could reach harvest range and end the test before the problematic completed-field route was exercised. The regression therefore checks the state where the runtime trace actually stopped, and fails if Wisp lumber movement returns to the generic zero-radius route.
The movement validator is split accordingly: ordinary movement calls the full static + swept-unit check, while Harvest building legs exit after the static point/line checks. SetUnitPathing(false) remains the stronger existing override and still bypasses all collision. The Harvest policy does not mutate the shared pathmap, does not make buildings walkable, and does not alter Harvest/Return resource accounting.
Mine/drop-off interaction legs route with the worker's collision radius even though live-unit collision is disabled. This matters when static pathing changes after an order starts: a newly constructed Farm invalidates the shared field, the bounded mover-owned A* immediately seeks a collision-sized detour while the replacement field is built, and the resulting field cannot choose point-only gaps that the Peasant's physical step validator will reject. Return-resource legs do not use the blocked drop-off centre as their normal endpoint: they choose the innermost collision-safe ring around the authored footprint and select the point on that ring nearest the worker's current side. The bounded mover path can detour around a Farm to that point without making a worker coming from the left circle around to the right side of a Town Hall or Lumber Mill. Because the collision-sized path grid is cell-centred, that innermost legal route endpoint can still sit slightly outside the continuous footprint+one-step deposit threshold. Reaching that exact near-side endpoint is therefore an explicit Return Resources handoff, matching the existing flow_goal_reached rasterization escape rather than making the worker bounce across the same staging cell forever.
Flow-generation handles remain monotonic across cache invalidation. Route entities can retain an old generation after CM_BakeStaticObstacles(); recycling generation 1 after every rebuild could otherwise let that stale handle activate an unrelated newly built field.
The implementation reuses OpenRealm's direct-line, bounded-waypoint, and shared resumable flow routing rather than replacing the entire worker pathfinder. Warsmash itself keeps a longer per-unit waypoint path in CBehaviorMove; a full mover-owned path remains a later option if runtime cases still expose shared-field limitations.
Walkable Bridges And Water
The WPM remains authoritative for horizontal movement: water cells with the no-walk bit are impassable, while the passable cells authored through a bridge form the only legal crossing lane. Bridge elevation is a separate game-side contract. M_CheckGround() starts with W3E terrain height, then checks the level's sparse registry of live DestructableData.walkable entities. Ordinary walkable destructables use their authored Z; DTrx/DTrf elevators add their mutable occluder_height, with the elevator's support footprint extended by the unit collision size. Dead, hidden/non-solid, and pathing-texture-less destructables do not supply ground. See Warcraft III elevators for the animation and height lifecycle.
Human01's river bridge confirms the split. Map object LT05 (WoodBridgeLarge45) is walkable=1, onWater=1, has a 32x32 pathing texture, and is placed at (1216, -960, -114). W3E terrain at its centre is -170.8, so terrain-only ground snapping puts a unit 56.8 world units below the deck even though WPM routing correctly accepts the crossing. Walkable surfaces are registered at map/runtime destructable spawn and unregistered on edict free; ground checks iterate bridges rather than every map entity.
Attack range against a building is measured from the attacker's collision edge to the building's authored no-walk footprint when pathtex is available. skills/s_attack.c therefore uses CM_DistanceToPathingFootprint() for building targets instead of requiring the attacker to enter weapon range of the blocked building centre. This is especially important for explicit force-fire on owned/friendly large buildings: centre-distance range checks make a melee unit orbit the footprint forever even though it is already beside a valid attack surface. Non-building targets retain the existing centre-distance attack check.
Lumber's unreachable-interior-tree detection is the narrower exception: unit_changeangle_for_radius() uses the Peasant's collision radius so Harvest can identify when the best legal approach to a blocked tree has genuinely been exhausted outside HARVEST_RANGE. Do not use that route-end signal for building interactions unless the route request also carries the behavior's interaction range.
Plain right-click movement is different from an interaction order: move_selectlocation() already assigns a collision-safe final waypoint, so ai_move_walk() may safely route that order with the mover's real collision radius. A distant temporary block does not cancel a plain move order. The unit keeps the order and retries local movement while the static route remains reachable; the existing near-goal settle rule is retained for an occupied final slot. If a completed collision-sized flow field reports the mover's component unreachable, the move may stop.
Steering, live speed and mid-route recovery (PF-06)
The selected route heading is distinct from the unit's physical facing. Each
translation tick first checks the live PropWindow turn gate, then samples the
current effective move speed (including status reductions and group caps).
Waiting for a route or having zero available movement speed selects Stand rather
than keeping the Walk pose while the origin is unchanged. The facing candidate
and avoidance-resolved heading candidate still pass through the same swept
collision policy before committing a position. Point Move's final near-goal snap and its
corrected-endpoint snap also respect PropWindow: an in-range destination is not
permission to translate while facing outside the movement window. A shared
field handle alone does not authorize a stale-heading step when the current
cell has no usable direction.
For a retained local waypoint, displacement target, Wisp egress or corrected point-Move approach, the accepted step length is capped at the distance to that intermediate endpoint. This prevents a fast unit from stepping beyond a turn and immediately steering backward on the next tick. Waypoint progression still occurs only after the committed position reaches the current turn; route endpoints never replace an ability's own completion/range checks.
The save format (version 127) stores the authoritative Move order,
waypoint entity incarnation, committed position and group-leg identity. Local
A* waypoints, transient fallback endpoints, flow handles and resume headings
remain runtime scratch (F_IGNORE) and are cleared on read; routing resumes
from the saved position after the restored static map is rebuilt. No serialized
gameplay field changes are needed, but the added runtime-only group-speed
sample changes the movement pool layout, so PF-06 increments version 126 to 127. A focused mid-route round-trip regression exercises this contract.
Authored Goals And Navigation Endpoints (PF-03)
A point Move owns an original waypoint/order goal, which must not be moved by
unreachable-path correction. The closest legal point from the static router is
stored only as movement_t.flow_fallback_approach, guarded by goal incarnation
and static path-map revision. The mover follows a collision-sized direct or
bounded local route toward that approach. A corrected endpoint can complete
only the owning plain Move through its normal ability-arrival/Shift-queue edge.
An adjusted flow-cell endpoint may likewise complete that plain point Move;
being near the goal in Euclidean distance alone is never sufficient to snap
through static pathing.
Follow, Attack, Harvest, Build and Repair retain their entity/range-specific
completion rules. flow_goal_reached, partial A* results and pending fields
are navigation observations, not ability success. The active Follow target
is guarded by follow_target_spawn_time, and an active point/transport Move
checks active_move_goal_generation against the waypoint ring serial or the
entity spawn time. Navigation resets preserve that identity. If a slot is
recycled, the old order ends through unit_stand() and lets the next queued
order begin.
Navigation state (MOVE_NAV_*) is movement-owned; the original point and
behavior target remain with the order. Patrol and Attack Move retain their
leg while blocked and translate once a legal heading is available. A Move
staging at a temporary construction detour waits for the path revision
before it can complete or start a Shift successor.
Authoritative Static Footprints (PF-05)
CM_BakeStaticObstacles() reconstructs pathing from immutable WPM terrain:
walkable surfaces are applied first, then ordinary solid building and
non-monster destructable footprints. This keeps path-texture channels and
underlying terrain intact when overlapping blockers disappear. The router
advances CM_GetPathRevision() and discards old flow fields, queued field
requests and retained mover routes through the existing revision checks.
The Warcraft III game publishes static changes at the authoritative lifecycle
boundary: map-spawn completion, runtime structure creation, construction
start/finish, destructable creation/death/restore/remove, Ancient root/unroot,
structure morph, scripted structure positioning and ShowUnit visibility
transitions. RemoveUnit publishes when the edict is hidden for deferred
removal; direct G_FreeEdict publishes after removing a visible static edict.
This deliberately does not rebake for moving actors, even when they obstruct a
local route: their temporary occupancy belongs to WC3 steering/recovery.
SetUnitPathing(false) still controls the unit's own collision admission,
not terrain or other units' baked footprints.
Flow-Field Lifecycle
Game routing no longer uses the old lifetime quota of two synchronous whole-map flow-field bakes. That quota avoided repeated handheld stalls, but after it was spent a later uncached move order received generation 0 forever and generic steering fell back toward the raw target. A reachable order behind trees/buildings could therefore stop even though the static router could have found a route.
CM_RequestHeatmapForRadius() is the game-facing shared-cache miss path. A cache hit returns its generation immediately; a miss takes a place in a FIFO of distinct target/radius/pathing-mask requests and returns 0 until its job completes. G_RunFrame() advances the active resumable reverse shortest-path job after entity simulation through CM_ProcessPathJobs(). On completion, the next queued request is promoted before later entity thinks can claim the slot. Repeated requests for the same field share one queue entry, and a moving goal updates its queued destination without losing its place. This prevents early entities from repeatedly taking the slot after each completion and starving later movers. Static-pathing invalidation clears both the active job and pending requests.
The default relaxation budget is 65,536 queue pops per frame and is runtime-tunable with:
The value is clamped to 256-65,536. The doubled Warcraft III default is a trial aimed at shortening the route-wait frames seen when new and moving units add distinct destinations to the shared FIFO. It keeps SPFA relaxation bounded while allowing each queued destination to make more progress per frame. Only one miss is built at a time; later destinations wait in FIFO order. Route-wait diagnostics can report active flood progress and queued destination fields.
For temporary per-mover wait diagnostics, enable wc3_route_wait_debug 1. The log emits one WC3_ROUTE_WAIT begin and matching end line per route-field wait, with mover and goal identities, wait duration, position delta, active job target, and FIFO depth. Set it back to 0 after capturing the behavior.
Nearby detours do not wait for that whole field. CM_FindPathWaypoint() runs a bounded point-to-point A* accelerator for endpoints within 48 pathing cells, expands at most 2,048 nodes, and returns the farthest recovered path point with a collision-sized clear line from the mover. The mover retains that waypoint until it reaches it, the target changes, or static pathing invalidates the segment. A failed or out-of-envelope acceleration request falls back to the shared incremental field, so long routes remain frame-budgeted.
While a resumable request is pending, unit_changeangle*() leaves both movement->flow_generation == 0 and movement->flow_direct == false. unit_moveindirection() treats that pair as "no heading resolved this tick" and does not commit a step. This shared guard is important: a caller must never turn a pending route into movement along the unit's stale facing.
Plain Move also keeps the stand presentation while that pair is clear. The order switches to walk only after direct steering or a completed flow field supplies a heading; starting the walk pose at order submission made the old facing look like an incorrect first turn during a long route build.
Wisps placed at a harvested tree's origin may start inside its baked UNWALKABLE footprint. When a Move order starts from such a blocked position, the Wisp steers toward its destination until it reaches pathable ground, then resumes ordinary collision-sized routing. The wisp_harvest_move_order_leaves_tree movement regression covers this departure.
The stepper rejects a collision-free candidate along a turn-lagged facing when it points more than 90 degrees away from the resolved route heading or increases distance to the active goal. The old stepper accepted the facing candidate first, so a short scripted cinematic move could advance in the wrong direction while the unit was still rotating; Human02Interlude then left Jaina on Antonidas's later ride-off path. Construction displacement uses its temporary exit point as the active progress goal until it is reached, after which the unit resumes its original order. unit_commit_step() and the arrival snap keep the network/render origin synchronized with authoritative origin2 for the same reason.
The route-job fairness regression is wc3_movement.attack_chase_waits_through_competing_route_jobs_then_resumes; it keeps distinct route requests arriving while asserting the attacker gets its earlier queued field and resumes before those later requests drain. wc3_movement.turn_lag_does_not_step_away_from_route_heading covers turn-lag steering. Both live in games/warcraft-3/game/tests/t_movement.c. Run both game variants with:
CM_BuildHeatmapForRadius() remains the synchronous API for tests/tools that explicitly require a completed field. Production movement goes through M_RefreshHeatmap() -> CM_RequestHeatmapForRadius().
Production services the shared incremental build with 32,768 queue pops per 10 Hz server frame. A 256x256 open field therefore completes in at most two frames instead of the previous sixteen-frame (1.6 second) delay. Override wc3_path_work_budget for slower targets. Complete destination-rooted publication remains the long-route fallback; the bounded accelerator is what removes that publication delay from nearby obstacle detours.
CM_BuildHeatmapForRadius() and the resumable request path key cached fields by adjusted target cell and mover collision radius; movement-class-aware requests additionally key by the blocked pathing mask. The flood and flow query use the same radius-expanded static pathability predicate as move-time terrain checks. The zero-radius CM_BuildHeatmap() wrapper remains for callers that intentionally route a point.
Flow vectors only descend to a strictly lower heatmap price for both collision-sized and radius-zero point fields. The adjusted goal cell therefore has a zero vector instead of pointing back out to a higher-cost neighbour. This matters for shared interaction routes such as Gold Mines and resource drop-offs: an outward point-flow at the adjusted cell makes every worker sharing that field orbit the same wrong location. Cached prices retain INT_MAX for cells that the completed field cannot reach. CM_FlowReachedGoal(generation, x, y) identifies the adjusted goal cell, while CM_FlowCanReach(generation, x, y) distinguishes a disconnected cell from a zero produced by interpolation near the goal.
Harvest interactions still own their final range/contact semantics. Gold Mine approach requests a collision-sized static route toward the Mine, ignores live units at steering/move time, and continues toward the real Mine after the adjusted route goal until the Mine footprint/contact check admits the worker. Because construction rebakes static pathing and invalidates cached fields, a Farm built across the lane causes a collision-sized rebuild; while the shared field is pending, the mover-owned bounded A* waypoint provides the local detour.
Return Resources uses a stronger endpoint contract. CM_FindInnerApproachPointToFootprintForRadius() marks pathmap cells near the authored footprint, chooses the innermost collision-safe ring, then uses distance from the worker only to select the near side of that ring. Gold and lumber return route to that point with static-only collision. If grid/radius quantization leaves the innermost legal cell a few world units outside the continuous footprint+step threshold, reaching the exact endpoint is accepted as the deposit handoff instead of bouncing toward the blocked building and back. Longer detours fall back to the shared collision-sized field. CM_PathCellWorldSize() supplies routing-grid scale only; it is not a gameplay range constant.
The approach mask stores a small footprint-proximity rank so the inner ring can be selected without rescanning every authored footprint pixel for every candidate. Do not replace it with a simple footprint bounding box: sparse and irregular pathing textures require distance to the actual blocked pixels.
Retail Move Destination Behavior
Two defects explained the Human01 fence report and units getting stuck behind trees or towers:
CM_LineIsWalkableForRadius()used ordinary Bresenham stepping. A 45-degree step from one cell to the next checked only those two cells, so the direct shortcut accepted anox/xoarrangement even though both cardinal side cells were blocked. The shortcut now requires both side cells to be legal, matching heatmap expansion andcompute_flow_at().- Location steering requested a point-sized route while
move_is_valid()rejected positions using the unit collision radius. The field could therefore direct a unit through a gap that its body could not occupy. Move, Patrol, and Attack-move now useself->collisionfor the direct line and field; interaction behaviors retain radius zero.
When a clicked destination is in another static connected component, the destination-rooted field reports the mover cell unreachable. CM_ClosestReachablePointForRadius(from, target, radius) floods the mover component with the same radius and diagonal rules, then chooses its legal cell nearest the click. The location order retargets its private waypoint once and follows a normal field to that point. This avoids both failure modes of the old behavior: freezing at the order origin and sliding forever along the blocking wall.
While any structure is under construction, move_has_active_construction() keeps a private location waypoint authoritative instead of consuming the order, because a new construction site can temporarily split the route (a scripted Peasant may still be travelling to a broad trigger region). In that state unit_changeangle() installs the closest-reachable staging point. ai_move_walk() then snaps onto that point when it is within one movement step and waits there in the stand pose until static pathing changes. Two details matter: the mover must not re-steer at the raw unreachable click on the following tick, and it must not simply keep stepping toward the staging point. Either mistake produces a two-tick cycle: the unit steps one movement distance past the point, the heading flips, it steps back, and it looks like the unit is walking in place (or swaying left and right) forever. The order stays active and resumes when the site completes or is cancelled; once no construction is active the waypoint retarget above resolves it normally. wc3_collision.location_order_cut_by_construction_waits_without_swaying covers the wait window, the preserved waypoint, the snap, and the final resolution.
Ordinary destination fields remain incremental and frame-budgeted. The mover-component flood is synchronous only after a completed destination field proves the click unreachable, so this exceptional recovery does not add input-time work to reachable orders.
The current router is now deliberately hybrid. Direct collision-sized lines handle open ground, bounded per-mover A* handles nearby static detours, destination-cached integration fields amortize long routes shared by groups, and local avoidance handles live units. This is closer to retail's split between mover-owned route state and a global pathing system without claiming its unrecovered accelerator implementation.
Route-wait diagnostics
Route-wait begin/end records are compiled only with WC3_DEBUG_ROUTING=1. In
that build, set wc3_route_wait_debug 1 to write WC3_ROUTE_WAIT records to
stderr; leave it at 0 to keep the diagnostics quiet.
Retail Game.dll path audit
The ROC demo data/Warcraft3demo/Game.dll (build 4486, SHA-256 286823c37a1083e91f07d040e46a9df7af4c4952e01fcbba460589bd4e297654) retains RTTI for CAbilityMove, NIpse::CLrPathingSys, and NIpse::CLrPathingAcc. CAbilityMove installs its vtable at Game.dll+0x102898. The path constructor at +0x458040 initializes a roughly 0xb0-byte persistent object, including two 32-byte containers at +0x2c and +0x4c, coordinate/state fields, and a pathing-system pointer. Mover setup at +0x466aa0 allocates and stores one such object. Submission at +0x458670 resets route state and copies the requested coordinate into both current and destination fields.
The update at +0x458930 checks flags at +0x80, can return a pending state from a countdown at +0x8c, invokes progression routines at +0x457da0 and +0x457f20, and exposes multiple result states to the movement caller at +0x4661d0. +0x457da0 appends 8-byte coordinate pairs to the object's route container. +0x457f20 consults one of two global indexed arrays through a signed selector and a -2 sentinel before advancing the route. Together with the separate CLrPathingAcc and CLrPathingSys types, this establishes persistent per-mover progress backed by global accelerated pathing data. It does not establish whether the accelerator is A*, hierarchical sectors, a portal graph, or another Blizzard-specific structure.
Group movement at +0x46a130 and +0x46a330 derives per-mover coordinates and path flags before updating each path object. Retail routing is therefore not a point-only line test followed by movement that independently rejects the unit footprint, nor is there evidence that every order waits for a complete destination-rooted map flood.
This supports the direction of commit 4bad783d: using the mover's collision size consistently and resolving an
unreachable click to a legal endpoint are closer to retail's per-mover, adjusted-endpoint architecture than routing a
point toward an impossible destination. The binary does not establish that OpenRealm's bounded A*, nearest-cell flood,
SPFA integration field, four-slot cache policy, or exact ox/xo diagonal test matches Blizzard's algorithm. Treat the
accelerator as a behaviorally supported approximation: it reproduces immediate nearby route output and mover-owned
progress while retaining OpenRealm's group-friendly cache for long routes.
Retail and OpenRealm algorithm outline
| Stage | Retail evidence | OpenRealm |
|---|---|---|
| Open ground | Route setup can retain or reset mover path state by destination and mode | Collision-sized Bresenham line; no search |
| Nearby detour | Persistent mover path object emits coordinate pairs; global accelerator is consulted | Bounded octile A* emits one smoothed, persistent waypoint |
| Long/shared route | Global CLrPathingSys and CLrPathingAcc; exact sharing policy unrecovered |
Four LRU destination/radius integration fields, built backward with SPFA |
| Dynamic units | Per-mover path flags and updates | Swept-circle movement plus deterministic local avoidance; not baked into static routes |
| Scheduling | Countdown/pending and multiple result states prove resumable progress | A* is capped at 2,048 expansions; complete fields get a configurable per-frame queue budget |
The speed difference was primarily work selection. Before the accelerator, one nearby cache miss cleared every route
node, relaxed the complete reachable component, then copied one integer per map cell before movement could start. A
256x256 diagnostic trace printed cells=65536 at both build start and publication. The accelerator touches only nodes
reached by the bounded A* and uses generation stamps instead of clearing its scratch array. Its contiguous node/heap
arrays usually leave a nearby search with a small L1/L2 working set, but no retail evidence identifies an explicit
"L2 cache" technique.
The same corner rule is applied to direct routing and movement steps: a diagonal
segment is rejected when either cardinal side of the crossed cell corner is
blocked. CM_LineIsWalkableForRadius() and M_MoveIsValid() therefore agree
with the flow flood instead of allowing a direct order or a long simulation step
to squeeze through a diagonal wall corner. With no loaded path map, line tests
remain permissive, matching the existing no-map movement behavior.
Retail Lumber Fallback
Retail Warcraft III continues lumber gathering when the explicitly clicked tree is alive but buried inside an unreachable group of trees.
OpenRealm keeps the clicked tree authoritative while routing can still approach it. If the worker reaches the collision-sized flow field's adjusted goal but remains outside HARVEST_RANGE, or the active field has no route from the worker's component, Harvest treats that approach as failed and selects a replacement tree. The replacement search excludes the failed tree and prefers the nearest live tree with a directly reachable legal harvest approach; a tree already within HARVEST_RANGE is immediately eligible.
This fallback is gameplay behavior in s_harvest_lumber.c, not a pathfinder rule. Normal movement, attack, patrol, item pickup, and spells do not acquire a different target when routing fails.
Multiple Peasants may legally harvest the same tree. Harvest now keeps the closest direct legal chop point instead of pre-assigning angular lanes. Dynamic separation is handled by the resource-worker local avoidance policy: a worker blocked by same-direction resource traffic queues briefly, while crossing or persistently pinned traffic uses deterministic right-first bounded passing. Static flow fields remain shared and occupancy-free, and the final tree approach no longer scans all edicts to allocate or reserve lanes. See worker-crowd-routing.md for the Human02 simulation and policy contract.
Confirmed August 2026 Regression
A Human02 handheld trace for a Peasant ordered to an interior tree showed the worker reaching the forest edge and oscillating indefinitely at roughly 352-358 world units from the target. Every tick reported blocked_frames=0 and, after instrumentation was extended, flow=0 flow_goal=0.
Two routing defects originally combined to prevent Harvest from ever receiving a usable failure/exhaustion state:
- The lumber direct-line gate used
CM_LineIsWalkable()as a zero-radius point test while the actual movement step usedCM_PointIsPathableForRadius(..., self->collision). A line could therefore be declared clear even when the Peasant could not physically fit along it. The fix remains scoped to behavior contracts that can safely use a collision-sized route; gold-mine/building interactions complete at their own contact/range boundary rather than at a flow field's adjusted goal. - The legacy generic heatmap build cap could permanently deny later route fields. The current implementation removes that lifetime quota entirely and uses resumable game routing instead, so lumber and ordinary movement do not depend on which route misses happened earlier in the match.
A third defect made a reached flow goal unstable: compute_flow_at() blended reachable neighbours including equal/higher-cost cells, so an adjusted goal beside asymmetric blocked geometry could point outward. All fields now follow only lower prices; radius-zero interaction routing then hands the final approach back to the behavior at the adjusted route end.
Do not reintroduce a distance-only timeout around Harvest to hide these routing failures. Fix and expose the routing state first, then let Harvest decide whether to retarget.
JASS repositioning: SetUnitPosition vs raw X/Y
SetUnitPosition and SetUnitPositionLoc are pathing-aware repositioning natives. Warsmash implements both through
CUnit.setPointAndCheckUnstuck(): it tests the requested point, then checks a deterministic 64-world-unit square spiral for up to
300 candidates against unit collision and movement pathing. If no candidate is legal, the requested point remains the fallback.
OpenRealm mirrors that contract in G_FindUnitUnstuckPosition() (g_spawn.c). The requested point is checked against
the mover's M_UnitStaticPathingFlags() policy (ground, air, sea, or amphibious) and live blockers in the mover's overlapping collision domain(s) before the spiral advances. Authored building/destructable
pathing is already baked into the static pathmap, so a script that requests a point inside a structure is displaced to the first
legal nearby candidate instead of being left occluded inside the structure. SetUnitX and SetUnitY intentionally remain raw
coordinate setters; do not route them through the unstuck search.
This distinction matters for campaign scripts. The Prologue01 Thrall investigation showed Othr alive and renderer-visible at the
scripted destination while a no-depth/white diagnostic exposed his geometry through a nearby structure. The old native assigned X/Y
directly, unlike Warsmash, so blocked scripted destinations could leave a unit inside authored building pathing.
Diagnostics
Runtime Harvest logging is off by default:
prints Harvest transitions and fallback reasons. Level 2 adds per-approach route state and reports when a requested tree field becomes ready:
Lumber routing uses the WC3_HARVEST_PATH prefix. Gold-mine entry uses WC3_GOLD_PATH, and gold return/deposit uses WC3_GOLD_RETURN. For map-specific mine/model mismatches, level 2 also emits WC3_GOLD_GEOMETRY; level 3 adds the pathing-texture rows as WC3_GOLD_FOOTPRINT. Generic resumable routing does not emit per-build debug lines. A healthy interior-tree fallback should progress through a nonzero flow generation and then one of:
fallback ... reason=route_goal_out_of_range
fallback ... reason=route_unreachable
fallback ... reason=movement_blocked
followed by start and reached for the replacement tree.
Verification
Focused tests live in games/warcraft-3/game/tests/t_pathfinding.c and t_movement.c. They cover:
- cache separation by collision radius;
- cache separation between incompatible movement policies, including ground/UNWALKABLE and flying/UNFLYABLE fields;
- WPM UNWALKABLE, UNFLYABLE, and UNSWIMMABLE point/line queries;
- blocked/red static path-texture pixels rejecting both ground and
floatmovement while green-channel pixels contribute UNFLYABLE; floatstatic routing through swimmable cells and around unswimmable land;amphstatic routing accepting cells that are walkable or swimmable and rejecting cells that are neither;- requester-aware dynamic blockers for ground, sea, air, and amphibious movers;
SetUnitPosition/unstuck collision uses the same domains, sofloatignores ground units and avoids sea units;- flyer move validation accepting UNWALKABLE-only cells and rejecting UNFLYABLE cells;
- resumable cache misses serialize without losing a later destination;
- collision-radius-aware line walkability;
- water rejection with an explicitly passable bridge lane;
- walkable-destructable deck elevation with terrain restoration outside its footprint;
- direct-line and flow rejection of diagonal
ox/xocorner cuts; - rejection of a corridor too narrow for the mover;
- collision-sized Move, Patrol, and Attack-move route selection;
- collision-sized Move routing around a long wall;
- exact reachable clicks and closest reachable points across a disconnected wall;
- collision-radius expansion of the closest reachable boundary;
- end-to-end settling at the nearest reachable point for a disconnected click;
- a zero outward vector at the flow goal;
- end-to-end lumber retarget from a buried clicked tree to a reachable edge tree;
- gold-mine entry through an authored blocking mine footprint;
- gold return/deposit at an authored Town Hall footprint corner;
- lumber return to a Town Hall through an authored blocking building footprint;
- a distant temporarily blocked plain move keeps its order alive while near-goal jitter still settles;
SetUnitPosition/SetUnitPositionLocuse the Warsmash-style blocked-point unstuck spiral whileSetUnitX/Yremain raw.- flying
SetUnitPositionunstuck checks ignore UNWALKABLE-only cells and obey UNFLYABLE cells.
Run when validating locally:
make test-wc3-engine WC3_PATTERN='wc3_api.set_unit_position*'
make test-wc3-engine WC3_PATTERN='wc3_pathfinding.*'
make test-wc3-engine WC3_PATTERN='wc3_movement.plain_move_*'
make test-wc3-engine WC3_PATTERN='wc3_movement.blocked_move_*'
make test-wc3-engine WC3_PATTERN='wc3_movement.*'
make test-wc3-engine WC3_PATTERN='wc3_movement.lumber_*'
Interaction-owned route endpoints
Radius-0 point fields remain available to callers whose interaction contract specifically needs point routing. Attack chases instead use the attacker's collision radius so their field cannot route through a gap the move-time validator rejects. Both forms strictly descend to their adjusted legal route endpoint. Once that endpoint is reached, unit_changeangle() exposes flow_goal_reached and steers toward the real entity target; the attack behavior continues to use its own range test. Gold Mine entry/return may hand off immediately at the route goal or after Move's bounded near-goal settle detector proves a crowded worker has stopped making progress at the interaction edge. This keeps routing monotonic without turning a distant blocked route into a successful interaction.
See Also
- Unit Altitude And Support Surfaces — vertical support surfaces share the WPM terrain classification but are independent of horizontal routing.
- Naval Movement And Water Pathing —
float/amphreuse this router with water-aware pathing policies and movement collision domains.
Shared SC2 movement consumers
SC2 and WC3 include the same server/sv_routing.c in their server worlds.
CM_AccelerateRoute retains the mover-owned waypoint; CM_SlideRoute is WC3's
bounded generic left/right deflection loop extracted from unit_desired_heading.
WC3 retains its speed-priority ring limit, resource-worker policy, collision
callbacks, and turn-rate handling. SC2 calls the shared search for blocked static
steps instead of repeatedly rejecting the same flow direction at a corner.
See SC2 selection and control for the
separate snapshot-precision defect that made both ground and cinematic movement
appear to advance in whole cells.
Stable formation Move legs (PF-04)
move_selectlocation() assigns distinct legal, collision-radius-aware member
slots at order admission, using deterministic edict iteration and candidate
ordering. Each selected Move submission has a per-map group_move_id and
original group_goal; the member's individual reserved slot remains its
actual point-order target. This is not a physical group entity or a routing
cache: individual movers retain their local paths and collision resolution.
For Shift commands, unitOrder_t retains the group leg identity, authored
click, individual slot and submission speed. Activation reuses the queued
slot instead of calculating a new formation from the unit's later position.
Members may therefore finish or begin a queued leg on different ticks without
losing their original reservations or changing the order FIFO.
The formation speed cap is refreshed from live members currently executing
the same Move leg. Finished, dead, redirected, or otherwise nonparticipating
units stop contributing; speed modifiers are sampled through the existing
unit_effective_speed() function. To avoid a per-mover global scan every
tick, one member refreshes the whole active leg at most once per 100 ms. A
lone remaining member has no cap. The WC3 movement layer owns this policy;
shared routing, workers, other abilities, and other games do not.
Group identity and authored slots persist in existing order/movement pools, while the speed refresh stamps are transient and cleared on load. No route scratch, live group pointers, or separate physical-group scheduler is saved.
Patrol / Attack Move / Follow continuation (PF-ORDER-08)
The authored parent order remains authoritative during opportunistic combat. Patrol reverses its original A/B legs only on actual endpoint arrival, not on a temporary blocked or partial routing result. When a Patrol leg reaches a boundary with queued commands, it retains exactly one owner-local continuation (both endpoints and the next leg) and admits the existing FIFO orders. Once that FIFO finishes normally, the continuation resumes without reallocating user queue slots. Explicit replacement, Stop and death clear it.
Attack Move retains its original destination during combat. A confirmed unreachable auto-chase waits a bounded interval, then returns to its parent while briefly suppressing immediate reacquisition of the same target. Manual Attack still replaces the parent. Follow resumes toward the live target, checks its spawn incarnation at each resume/tick, and finishes only when the followed target becomes invalid, not merely within stop range.
Native save version 151 / browser version 11 records the bounded Patrol continuation and target identity;
temporary chase timing is reset on load. No second task scheduler is added.
Candidate dynamic spatial-link optimisation (PF-PERF-08)
server/sv_world.c already maintains the spatial area tree incrementally
through SV_LinkEntity / SV_UnlinkEntity. SV_AreaEdicts queries only
intersected nodes; it does not scan the world to detect unchanged objects.
A no-op LinkEntity with the exact same collision-sized bounds now keeps
its existing membership instead of unlinking/reinserting. Genuine movement,
size changes, spawn and removal still publish synchronously at their original
call sites. There is no delayed read barrier, independent fine grid or
new WC3 object registry. The reciprocal-link guard prevents unchanged-link
reuse after a cleared world tree.
Compile with -DBZ_PROFILE_SPATIAL to enable SV_GetSpatialProfile()
counters (link_calls, unchanged_links, rebuilt_links, area_queries,
area_candidates). They reset at SV_ClearWorld or by the explicit reset
function; ordinary builds have no increment overhead. Compare an identical
stationary-crowd workload and few movers before/after using route/frame
CPU p95 and max, as well as these counts. This is an unmeasured candidate
fast path, not evidence that a global dirty-publication system is useful or
that the 80/20 performance target was met. Do not add a second dirty index
unless these measurements demonstrate that the existing area tree is a
reproducible hotspot.