Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions tests/nav-city.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@ test('trail tiles: negative heights, many levels and long cell gaps round-trip t
sample.forEach(([, , z, w], n) => assert.deepEqual(got[n], [z, w], `entry ${n}`));
});

test("the city gate starts a landing on the flight master's floor, not the ground under the tower", () => {
const { landOnTower } = require('../tools/lib/nav/city/gate');
const g = { colIndex: () => 0, colNodes: () => [0, 1, 2], nz: [39.5, 61.4, 95] };
test("the city gate's ends: a landing on the flight master's floor, an NPC the match had no height for on the NPC's", () => {
const { anchorEnds } = require('../tools/lib/nav/city/gate');
const g = { colIndex: () => 0, colNodes: () => [0, 1, 2, 3], nz: [39.5, 61.4, 95, -85.1] };
const taxi = [{ c: 1, wx: 1677.5, wy: -4315.7, npc: 3310 }];
const npcZ = (npc) => (npc === 3310 ? 61.7 : null);
const trip = { c: 1, A: { kind: 'land', wx: 1677.5, wy: -4315.7, z: 39.5, node: 0 } };
assert.deepEqual(landOnTower(g, trip, taxi, npcZ).A, { ...trip.A, z: 61.4, node: 1, landed: 39.5 });
assert.equal(landOnTower(g, { ...trip, A: { ...trip.A, kind: 'vendor' } }, taxi, npcZ).A.z, 39.5);
assert.equal(landOnTower(g, { ...trip, A: { ...trip.A, wx: 1900 } }, taxi, npcZ).A.z, 39.5, 'no flight master within 40 yd');
const npcZ = (npc) => ({ 3310: 61.7, 270038: -85.1 })[npc] ?? null;
const B = { kind: 'vendor', wx: 1690, wy: -4400, z: 39.5, node: 0, npc: 3322, anchored: true };
const trip = { c: 1, A: { kind: 'land', wx: 1677.5, wy: -4315.7, z: 39.5, node: 0 }, B };
const moved = anchorEnds(g, trip, taxi, npcZ);
assert.deepEqual(moved.A, { ...trip.A, z: 61.4, node: 1, was: 39.5 });
assert.equal(moved.B, B, 'an anchored end stays');
assert.equal(anchorEnds(g, { ...trip, A: { ...trip.A, wx: 1900 } }, taxi, npcZ).A.z, 39.5, 'no flight master within 40 yd');
const lab = { ...B, npc: 270038, anchored: false };
assert.deepEqual(anchorEnds(g, { ...trip, B: lab }, taxi, npcZ).B, { ...lab, z: -85.1, node: 3, was: 39.5 });
assert.equal(anchorEnds(g, { ...trip, B: { ...lab, npc: 1 } }, taxi, npcZ).B.z, 39.5, 'no height known');
});
7 changes: 6 additions & 1 deletion tools/commands/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const usage = `usage: node tools/polestar.js nav build [--continents 0,1] [--for
node tools/polestar.js nav city match --private <dir> [--maps ...] [--grid <dir>]
node tools/polestar.js nav city freeze --private <dir> [--maps ...] [--max 200] [--force]
node tools/polestar.js nav city trails --private <dir> [--maps ...] [--train] [--out <trails.json>] [--lua addon/Polestar_Nav/Trails/Trails.lua]
node tools/polestar.js nav city gate --private <dir> [--nav <Polestar_Nav dir>] [--ground <Polestar_Nav dir>] [--maps ...] [--arms GAME,WALK,E0,E2,P3] [--policy legacy|a2] [--remeasure <report.json>] [--baseline <report.json>] [--out <report.json>] [--md <file>] [--grid <dir>]
node tools/polestar.js nav city gate --private <dir> [--nav <Polestar_Nav dir>] [--ground <Polestar_Nav dir>] [--spf <dir>] [--maps ...] [--arms GAME,WALK,E0,E2,G1,SPF,P3,P4,P5] [--policy legacy|a2] [--spawnz <file>] [--remeasure <report.json>] [--baseline <report.json>] [--out <report.json>] [--md <file>] [--grid <dir>]
node tools/polestar.js nav city world-sample|world-match|world-gate --private <dir> [--set world|boundary|reported] [--maps world|...] [--per N] [--seed N] [--strata ...] (world-gate: as gate)

build the navigation grid of every continent map-frames.json names (or
--continents): client geometry per ADT tile through the CASC cache
Expand Down Expand Up @@ -93,6 +94,10 @@ city the capitals' walks against players' recordings (tools/lib/nav/city).
harness) and prints the failures per city and arm (GAME: the
player's floor known; WALK: unknown, the addon's fallbacks); with
--baseline exit 1 when a counted arm gets worse in any capital.
world-sample/-match/-gate: the same over every other zone (--set
world: stratified held-out walks), across the capitals' entrances
(boundary) and through the places of open walking-map issues
(reported: tools/lib/nav/city/reported.json).

Retired for Forge (docs/forge/nav.md): pack (forge nav pack), check (forge
nav check), layers (forge nav layers roads|hubs).`;
Expand Down
116 changes: 91 additions & 25 deletions tools/lib/nav/city/gate.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const run = require('../eval/run');
const STEP = 2; // yd: line samples
const DZ = 6; // yd: a line point lies on a surface within this height (the two maps' heights differ up to ~5 yd)
const Z_OFF = 30; // yd, Nav/Walk.lua: a path ending this far off the goal's height missed its floor
const SPAWN_R = 15; // yd, Lookup.SpawnZ: an NPC goal's height is its nearest spawn's this close
const COUNTED = ['GAME', 'WALK'];

// The folder the gate runs: nav, with its Trails/Trails.lua replaced by <priv>/Trails-train.lua when that exists (the
Expand Down Expand Up @@ -75,18 +76,24 @@ function landZ(taxi, npcZ, c, wx, wy) {
return best ? npcZ(best.n.npc, best.n.wx, best.n.wy) : null;
}

// A trip that starts at a landing starts where the flight sets players down, on the flight master's floor: the
// recording has only the taxi node's spot, and the matcher may put it on the ground under the tower (Orgrimmar's,
// Thunder Bluff's), where players then drop to. The start moves to the grid level nearest the flight master's height
// (within 8 yd) at that spot.
function landOnTower(g, t, taxi, npcZ) {
if (t.A.kind !== 'land') return t;
const z = landZ(taxi, npcZ, t.c, t.A.wx, t.A.wy);
const ci = z === null ? -1 : g.colIndex(t.A.wx, t.A.wy);
if (ci < 0) return t;
let node = -1;
for (const v of g.colNodes(ci)) if (Math.abs(g.nz[v] - z) <= 8 && (node < 0 || Math.abs(g.nz[v] - z) < Math.abs(g.nz[node] - z))) node = v;
return node < 0 || node === t.A.node ? t : { ...t, A: { ...t.A, z: g.nz[node], node, landed: t.A.z } };
// A trip's ends on the floor the game puts them on, where the matcher could only guess: a landing on its flight
// master's floor (the recording has only the taxi node's spot, and the matcher may put it on the ground under the
// tower, Orgrimmar's and Thunder Bluff's, where players then drop to), and an NPC's end the match had no spawn height
// for (Forever's own NPCs, whose heights came with the Forever TDB) on that NPC's. Each moves to the grid level
// nearest that height (within 8 yd) at its spot that players walk (walked(node): 3+ training people), else stays;
// `was` keeps the matched height.
function anchorEnds(g, t, taxi, npcZ, walked = () => true) {
const fix = (e) => {
const z = e.kind === 'land' ? landZ(taxi, npcZ, t.c, e.wx, e.wy) : !e.anchored && e.npc ? npcZ(e.npc, e.wx, e.wy) : null;
const ci = z === null ? -1 : g.colIndex(e.wx, e.wy);
if (ci < 0) return e;
let node = -1;
for (const v of g.colNodes(ci)) if (Math.abs(g.nz[v] - z) <= 8 && walked(v) && (node < 0 || Math.abs(g.nz[v] - z) < Math.abs(g.nz[node] - z))) node = v;
return node < 0 || node === e.node ? e : { ...e, z: g.nz[node], node, was: e.z };
};
const A = fix(t.A);
const B = fix(t.B);
return A === t.A && B === t.B ? t : { ...t, A, B };
}

// Line scoring on the judge's grid.
Expand Down Expand Up @@ -334,14 +341,30 @@ async function runArms({ trips, arms, dirs, spawnz, policy, taxi = [] }) {
const B = (t, z) => [t.B.wx, t.B.wy, z === undefined ? null : z];
const npcZs = new Map();
const npcZ = (t, e) => {
if (!npcZs.has(t.c)) npcZs.set(t.c, spawnHeight(spawnz, t.c));
if (!npcZs.has(t.c)) npcZs.set(t.c, spawnHeight(spawnz, t.c, SPAWN_R));
return npcZs.get(t.c)(e.npc, e.wx, e.wy);
};
// what Walk.lua knows of a stop's height: the NPC just talked to (spawn height), or at a landing its flight
// what Walk.lua knows of a stop's height (CityFloor's NpcFloor): the NPC just talked to, from its spawns within 30
// yd of the player, the nearest one's height unless they span more than 10 yd of height; or at a landing its flight
// master's (TaxiNodes' height stands in for it in game)
const npcFloor = (t, e) => {
const s = e.npc && spawnz[String(e.npc)];
if (!s) return null;
let best = null;
let lo = Infinity;
let hi = -Infinity;
for (const [sc, x, y, z] of s) {
const d = sc === t.c ? Math.hypot(x - e.wx, y - e.wy) : Infinity;
if (d > 30) continue;
lo = Math.min(lo, z);
hi = Math.max(hi, z);
if (!best || d < best.d) best = { d, z };
}
return best && hi - lo <= 10 ? best.z : null;
};
const hint = (t, e) => {
if (e.kind !== 'land') return npcZ(t, e);
if (!npcZs.has(t.c)) npcZs.set(t.c, spawnHeight(spawnz, t.c));
if (e.kind !== 'land') return npcFloor(t, e);
if (!npcZs.has(t.c)) npcZs.set(t.c, spawnHeight(spawnz, t.c, SPAWN_R));
return landZ(taxi, npcZs.get(t.c), t.c, e.wx, e.wy);
};
// WALK (CityFloor's rules): the start from the trail floor within 4 yd near the stop's height hint, else the hint,
Expand Down Expand Up @@ -392,6 +415,22 @@ async function runArms({ trips, arms, dirs, spawnz, policy, taxi = [] }) {
const second = navRun(dir, again.map((k) => route(trips[k], `${arm}|${trips[k].i}|retry`, A(trips[k], startOf(trips[k], arm)), B(trips[k], null))));
again.forEach((k, j) => (first[k] = { ...second[j], retried: true }));
}
// a2 (CityFloor's Walk.lua): a WALK whose guessed start height can't reach the goal is asked again starting on
// any surface within 10 yd of that height (from.floors), then with no start height
if (arm === 'WALK' && policy === 'a2') {
for (const step of ['floors', 'none']) {
const again = [];
first.forEach((r, k) => {
const sz = startOf(trips[k], arm);
if (!r.ok && sz !== null && sz !== undefined) again.push(k);
});
const ask = (t) => route(t, `${arm}|${t.i}|${step}`, A(t, null), B(t, goalOf(t, arm)), step === 'floors' ? { reach: 10, floors: [startOf(t, arm)] } : { reach: 10 });
const second = navRun(dir, again.map((k) => ask(trips[k])));
again.forEach((k, j) => {
if (second[j].ok || step === 'none') first[k] = { ...second[j], retried: step };
});
}
}
res[arm] = first;
}
return res;
Expand All @@ -406,8 +445,8 @@ async function gate({ priv, nav, ground = null, spf = null, grid, frames, spawnz
const city = CITIES[map];
const t0 = Date.now();
const area = loadArea(priv, map, grid, frames);
const npcZc = spawnHeight(spawnz, city.c);
const trips = area.trips.map((t) => landOnTower(area.g, { ...t, c: city.c, side: city.side }, taxi, npcZc));
const npcZc = spawnHeight(spawnz, city.c, SPAWN_R);
const trips = area.trips.map((t) => anchorEnds(area.g, { ...t, c: city.c, side: city.side }, taxi, npcZc, (v) => area.train[v] >= 3));
const res = await runArms({ trips, arms, dirs: { nav: gn.dir, ground, spf }, spawnz, policy, taxi });
const rows = scoreRows(area, trips, res, protosFor(area, arms));
const summary = summarize(rows, map, frames, npcs);
Expand All @@ -430,10 +469,12 @@ async function gateWorld({ priv, nav, ground = null, spf = null, grid, frames, s
const all = readWorldTrips(priv, set).filter((t) => !strata || strata.includes(t.stratum));
const keep = new Set(all.map((t) => t.i));
const npcZc = new Map();
const zOf = (c) => npcZc.get(c) || npcZc.set(c, spawnHeight(spawnz, c)).get(c);
const zOf = (c) => npcZc.get(c) || npcZc.set(c, spawnHeight(spawnz, c, SPAWN_R)).get(c);
const trips = all.map((t) => {
const s = { ...t, side: t.fac === 'Alliance' || t.fac === 'Horde' ? t.fac : null };
return s.A.kind === 'land' ? landOnTower(new AreaGraph(s.box, { grid }), s, taxi, zOf(s.c)) : s;
if (!(s.A.kind === 'land' || s.A.npc || s.B.npc)) return s;
const walked = new Set(s.density.filter(([, n]) => n >= 3).map(([v]) => v));
return anchorEnds(new AreaGraph(s.box, { grid }), s, taxi, zOf(s.c), (v) => walked.has(v));
});
const byI = new Map(trips.map((t) => [t.i, t]));
const gn = gateNav(path.resolve(nav), priv);
Expand Down Expand Up @@ -486,15 +527,39 @@ async function gateWorld({ priv, nav, ground = null, spf = null, grid, frames, s
// judge's own desire paths).
function scoreRows(area, trips, res, protos = {}) {
const { measure } = judge(area);
const keep = (pts) => pts.map((p) => p.map((v) => (v === null ? null : +v.toFixed(1))));
// 0.01 yd: --remeasure re-scores these, and the judge's 10 yd thresholds sit close to some walks
const keep = (pts) => pts.map((p) => p.map((v) => (v === null ? null : +v.toFixed(2))));
// an end asked without a height has none on its own point: the walk's height there is its nearest point's that has one
const zAt = (pts, from, step) => {
for (let i = from; i >= 0 && i < pts.length; i += step) if (pts[i][2] !== null && pts[i][2] !== undefined) return pts[i][2];
return null;
};
const score = (r, tt) => {
if (!r.ok) return { ok: false, reason: r.reason, fail: 'no walk' };
const x = { ok: true, ...measure(r.pts), routerYards: r.yards === undefined ? null : r.yards, retried: !!r.retried, startZ: r.pts[0][2], endZ: r.pts[r.pts.length - 1][2], pts: keep(r.pts) };
const x = { ok: true, ...measure(r.pts), routerYards: r.yards === undefined ? null : r.yards, retried: !!r.retried, startZ: zAt(r.pts, 0, 1), endZ: zAt(r.pts, r.pts.length - 1, -1), pts: keep(r.pts) };
x.fail = failOf(x, tt);
return x;
};
// an end anchorEnds moved (a landing onto its tower, an NPC onto its floor) joins the recorded route by the graph's
// own walk between the two (players drop off the tower; a walk can't): the real route is that plus the recorded one
const realPath = (t) => {
let p = t.path;
const join = (from, to) => {
area.g.search([[from, 0]], [to], { bound: 600 });
return area.g.pathTo(to);
};
if (t.A.was !== undefined && t.A.node !== p[0]) {
const pre = join(t.A.node, p[0]);
if (pre) p = pre.concat(p.slice(1));
}
if (t.B.was !== undefined && t.B.node !== p[p.length - 1]) {
const post = join(p[p.length - 1], t.B.node);
if (post) p = p.slice(0, -1).concat(post);
}
return p;
};
return trips.map((t, k) => {
const real = measure(tautPts(area.g, t.path));
const real = measure(tautPts(area.g, realPath(t)));
const tt = { ...t, real: real.yards };
const row = { i: t.i, A: t.A, B: t.B, straight: t.straight, real: real.yards, arms: {} };
for (const [arm, rs] of Object.entries(res)) row.arms[arm] = score(rs[k], tt);
Expand Down Expand Up @@ -531,7 +596,8 @@ function remeasure(report, { priv, grid, frames, npcs = {}, protos: extraArms =
for (const [map, m] of Object.entries(report.maps)) {
const area = loadArea(priv, Number(map), grid, frames);
const byI = new Map(area.trips.map((t) => [t.i, t]));
const trips = m.rows.map((r) => byI.get(r.i));
// the stored rows keep the ends the gate anchored (anchorEnds)
const trips = m.rows.map((r) => ({ ...byI.get(r.i), A: r.A, B: r.B }));
const res = {};
for (const arm of Object.keys(m.rows[0].arms)) if (!PROTO[arm]) res[arm] = m.rows.map((r) => r.arms[arm]);
const protos = protosFor(area, [...new Set([...Object.keys(m.rows[0].arms), ...extraArms])]);
Expand Down Expand Up @@ -583,4 +649,4 @@ function markdown(report, cmp = null) {
return lines.join('\n');
}

module.exports = { gate, gateWorld, remeasure, compareReports, markdown, judge, tautPts, desire, landOnTower, COUNTED };
module.exports = { gate, gateWorld, remeasure, compareReports, markdown, judge, tautPts, desire, anchorEnds, COUNTED };
6 changes: 3 additions & 3 deletions tools/lib/nav/city/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ const JUMP_COST = 20;
const OFF_ANCHORED = 15;
const BEAM = 150;

// The NPC's spawn height nearest (within 12 yd) to a world point on continent c, or null.
function spawnHeight(spawnz, c) {
// The NPC's spawn height nearest (within R yd) to a world point on continent c, or null.
function spawnHeight(spawnz, c, R = 12) {
return (npc, wx, wy) => {
const s = npc && spawnz[String(npc)];
if (!s) return null;
let best = null;
let bd = 12;
let bd = R;
for (const [sc, x, y, z] of s) {
if (sc !== c) continue;
const d = Math.hypot(x - wx, y - wy);
Expand Down
3 changes: 2 additions & 1 deletion tools/lib/nav/city/reported.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{"id": "stormrage-barrow-dens", "issue": "#2027", "title": "Moonglade: the Stormrage Barrow Dens (#1919, #2005)", "zone": 1450, "c": 1, "at": [7337, -2639.3], "r": 90},
{"id": "banethil-barrow-den", "issue": "#2027", "title": "Teldrassil: Ban'ethil Barrow Den (#1341)", "zone": 1438, "c": 1, "at": [9772.6, 1553.9], "r": 70},
{"id": "grizzled-den", "issue": "#2027", "title": "Dun Morogh: Grizzled Den, the wendigo cave under Shimmer Ridge (#2679)", "zone": 1426, "c": 0, "at": [-5502.3, -231.9], "r": 110},
{"id": "freewind-bridges", "issue": "#2027", "title": "Thousand Needles: Freewind Post's rope bridges between the mesas (#1936)", "zone": 1441, "c": 1, "at": [-5430, -2440], "r": 90}
{"id": "freewind-bridges", "issue": "#2027", "title": "Thousand Needles: Freewind Post's rope bridges between the mesas (#1936)", "zone": 1441, "c": 1, "at": [-5430, -2440], "r": 90},
{"id": "cinderscale-hollow", "issue": "#2889", "title": "Riverglades: from Gelinda Coppergleam into the Cinderscale hollow (137 yd, planned 1:50 round the mountain)", "zone": 2548, "c": 0, "at": [-8768.8, -3351.5], "r": 70}
]
}
Loading
Loading