Ship Routes: solid sea lanes around the continents, labelled edge markers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-11 15:33:04 +00:00
parent 63eebfc8bd
commit 216e6f90b8
6 changed files with 555 additions and 301 deletions

View file

@ -4,6 +4,11 @@ usage: python3 generate.py <TaxiPathNode.db2> <Data.lua>
Transports sail along TaxiPath node lists. The client has no record of which paths are
transports, so the paths and the dock names below are curated by hand. A path whose stops
don't match a known dock fails the run instead of guessing.
Each route is drawn as legs between consecutive stops. A leg the ship sails without a
teleport follows its real path. A leg across a teleport (another continent, or a zeppelin
that vanishes mid-flight) follows hand-placed waypoints on the Azeroth world map instead,
so it goes around the continents rather than straight through them.
"""
import collections, math, os, sys
@ -57,29 +62,55 @@ ROUTES = [
(11457, "Airship", "air", None),
]
# Where each continent sits on the Azeroth world map (uiMap 947), from UiMapAssignment.db2:
# instance -> (u min, u max, v min, v max, world x min, x max, y min, y max)
ON_WORLD_MAP = {
0: (0.5505, 0.8966, 0.0994, 0.8691, -16000, 6933, -7467, 8000),
1: (0.0399, 0.4083, 0.0855, 0.9234, -12800, 12267, -9600, 6933),
}
# Sea lanes for legs across a teleport, as points on the world map. They were placed on a
# 1517 x 1019 pixel render of uiMap 947; keys are (from, to) and are reversed as needed.
WAYPOINTS_PX = {
("Booty Bay", "Ratchet"): [(930, 770), (880, 710), (770, 600), (600, 585), (430, 550)],
("Menethil Harbor", "Theramore Isle"): [(960, 450), (700, 520), (430, 600)],
("Southshore", "Auberdine"): [(1010, 385), (930, 405), (700, 300), (440, 165), (300, 135), (205, 180)],
("Auberdine", "Menethil Harbor"): [(205, 180), (300, 135), (440, 165), (700, 300), (960, 430)],
("Stormwind Harbor", "Auberdine"): [(900, 590), (700, 380), (440, 165), (300, 135), (205, 180)],
("Steamwheedle Port", "Riverglades"): [(520, 770), (800, 830), (1050, 860), (1150, 770), (1235, 660)],
}
PX_W, PX_H, PX_X, PX_Y = 1517, 1019, 92, 32 # render size and the crop it was taken from
AIR_BEND = 0.12 # air legs without waypoints bow out by this share of their length
TELEPORT = 0x1
WORLD = -1 # instance marker for a point given in world map coordinates
def dock_name(m, x, y):
best = min((math.hypot(x - dx, y - dy), n) for n, dm, dx, dy in DOCKS if dm == m) if any(d[1] == m for d in DOCKS) else None
if not best or best[0] > 300:
near = [(math.hypot(x - dx, y - dy), n) for n, dm, dx, dy in DOCKS if dm == m]
if not near or min(near)[0] > 300:
raise SystemExit("no dock near %d %.0f %.0f" % (m, x, y))
return best[1]
return min(near)[1]
def catmull(points, closed):
def to_world_map(m, x, y):
if m not in ON_WORLD_MAP:
return None
u0, u1, v0, v1, xmin, xmax, ymin, ymax = ON_WORLD_MAP[m]
return u0 + (ymax - y) / (ymax - ymin) * (u1 - u0), v0 + (xmax - x) / (xmax - xmin) * (v1 - v0)
def catmull(points, steps_for):
"""Subdivide a polyline along a uniform Catmull-Rom spline."""
n = len(points)
if n < 3:
return points
out = []
segs = n if closed else n - 1
for i in range(segs):
p0 = points[(i - 1) % n] if closed or i > 0 else points[i]
p1 = points[i]
p2 = points[(i + 1) % n]
p3 = points[(i + 2) % n] if closed or i + 2 < n else p2
steps = max(1, min(6, int(math.hypot(p2[0] - p1[0], p2[1] - p1[1]) // 60)))
for i in range(n - 1):
p0, p1, p2 = points[max(i - 1, 0)], points[i], points[i + 1]
p3 = points[min(i + 2, n - 1)]
steps = steps_for(p1, p2)
for s in range(steps):
t = s / steps
t2, t3 = t * t, t * t * t
@ -87,60 +118,83 @@ def catmull(points, closed):
0.5 * (2 * p1[k] + (-p0[k] + p2[k]) * t + (2 * p0[k] - 5 * p1[k] + 4 * p2[k] - p3[k]) * t2
+ (-p0[k] + 3 * p1[k] - 3 * p2[k] + p3[k]) * t3)
for k in (0, 1)))
if not closed:
out.append(points[-1])
out.append(points[-1])
return out
def build(path, nodes):
def waypoints(kind, a, b):
"""World map points between stops a and b (name, m, x, y), or [] if none apply."""
if (a[0], b[0]) in WAYPOINTS_PX:
px = WAYPOINTS_PX[(a[0], b[0])]
elif (b[0], a[0]) in WAYPOINTS_PX:
px = list(reversed(WAYPOINTS_PX[(b[0], a[0])]))
else:
pa, pb = to_world_map(*a[1:]), to_world_map(*b[1:])
if kind == "air" and pa and pb:
# a gentle arc: a quadratic curve whose middle sits AIR_BEND of the length off
# the straight line (measured with the map's 1.5 aspect), sampled at a few points
dx, dy = (pb[0] - pa[0]) * 1.5, pb[1] - pa[1]
cx = (pa[0] + pb[0]) / 2 - dy * 2 * AIR_BEND / 1.5
cy = (pa[1] + pb[1]) / 2 + dx * 2 * AIR_BEND
return [((1 - t) ** 2 * pa[0] + 2 * (1 - t) * t * cx + t * t * pb[0],
(1 - t) ** 2 * pa[1] + 2 * (1 - t) * t * cy + t * t * pb[1]) for t in (0.25, 0.5, 0.75)]
if pa and pb:
raise SystemExit("no sea lane for %s - %s" % (a[0], b[0]))
return [] # one end isn't on the world map (Zephras Isle): nothing to draw between them
return [((x + PX_X) / PX_W, (y + PX_Y) / PX_H) for x, y in px]
def build(kind, nodes):
nodes = sorted(nodes) # (index, map, x, y, flags, delay)
n = len(nodes)
brk = [bool(nodes[i][4] & TELEPORT) or nodes[i][1] != nodes[(i + 1) % n][1] for i in range(n)]
closed = not any(brk)
start = 0 if closed else (brk.index(True) + 1) % n
order = nodes[start:] + nodes[:start]
brk = brk[start:] + brk[:start]
# stops in loop order, merging a stop that is split across the loop's seam
stops, stop_at = [], {}
for i, (_, m, x, y, _, delay) in enumerate(order):
# stops in node order, merging a stop that is split across the loop's seam
stops, at = [], []
for i, (_, m, x, y, _, delay) in enumerate(nodes):
if delay:
name = dock_name(m, x, y)
if stops and stops[-1][0] == name and stops[-1][1] == m:
stop_at[i] = len(stops) - 1
continue
stops.append((name, m, x, y))
stop_at[i] = len(stops) - 1
at.append(i)
if len(stops) > 2 and stops[0][0] == stops[-1][0]:
stops.pop()
stop_at = {i: (s if s < len(stops) else 0) for i, s in stop_at.items()}
at.pop()
parts, cur = [], []
for i, node in enumerate(order):
cur.append(i)
if brk[i] or i == n - 1:
parts.append(cur)
cur = []
out_parts = []
for p in parts:
if len(p) < 2: # a lone node between two teleports draws nothing
continue
pts = catmull([(order[i][2], order[i][3]) for i in p], closed)
# first stop reached after this part ends, in loop order
nxt = None
for k in list(range(p[-1] + 1, n)) + list(range(0, p[-1] + 1)):
if k in stop_at:
nxt = stop_at[k]
# a two-stop route is one line; longer loops draw every leg
pairs = [(0, 1)] if len(stops) == 2 else [(i, (i + 1) % len(stops)) for i in range(len(stops))]
legs = []
for i, j in pairs:
span = []
k = at[i]
while True:
span.append(k)
if k == at[j]:
break
out_parts.append({"m": order[p[0]][1], "pts": pts, "next": nxt})
return stops, out_parts, closed
k = (k + 1) % n
if not any(brk[k] for k in span[:-1]):
m = nodes[at[i]][1]
pts = catmull([(nodes[k][2], nodes[k][3]) for k in span],
lambda p, q: max(1, min(3, int(math.hypot(q[0] - p[0], q[1] - p[1]) // 80))))
legs.append({"from": i, "to": j, "smooth": False, "pts": [(m, x, y) for x, y in pts]})
else:
a, b = stops[i], stops[j]
mid = [(WORLD, u, v) for u, v in waypoints(kind, a, b)]
legs.append({"from": i, "to": j, "smooth": True, "pts": [a[1:]] + mid + [b[1:]]})
return stops, legs
def lua_str(s):
return '"' + s.replace("\\", "\\\\").replace('"', '\\"') + '"'
def fmt(m, a, b):
if m == WORLD:
return "%d, %.4f, %.4f" % (m, a, b)
return "%d, %.0f, %.0f" % (m, a, b)
def main():
src, dst = sys.argv[1], sys.argv[2]
rows, _ = read(src)
@ -152,27 +206,27 @@ def main():
lines = [
"-- Generated by tools/generate.py from TaxiPathNode.db2. Do not edit by hand.",
"-- stops: { name, instance, worldX, worldY }",
"-- parts: sailed in order; a gap between parts is a teleport or a change of map.",
"-- next: index of the first stop reached after the part ends.",
"-- legs: from / to stop index, then points as (instance, worldX, worldY) triples;",
"-- instance -1 is a point on the Azeroth world map (u, v). smooth legs are drawn as a curve.",
"local _, ns = ...",
"ns.routes = {",
]
for path, noun, kind, faction in ROUTES:
if path not in paths:
raise SystemExit("path %d missing" % path)
stops, parts, closed = build(path, paths[path])
print(path, noun, " -> ".join(s[0] for s in stops), "%d parts" % len(parts), file=sys.stderr)
lines.append(" { path = %d, noun = %s, kind = %s, faction = %s, closed = %s," % (
path, lua_str(noun), lua_str(kind), lua_str(faction) if faction else "nil", "true" if closed else "false"))
stops, legs = build(kind, paths[path])
print(path, noun, " -> ".join(s[0] for s in stops), "%d legs" % len(legs), file=sys.stderr)
lines.append(" { path = %d, noun = %s, kind = %s, faction = %s," % (
path, lua_str(noun), lua_str(kind), lua_str(faction) if faction else "nil"))
lines.append(" stops = {")
for name, m, x, y in stops:
lines.append(" { %s, %d, %.1f, %.1f }," % (lua_str(name), m, x, y))
lines.append(" },")
lines.append(" parts = {")
for part in parts:
coords = ", ".join("%.0f, %.0f" % pt for pt in part["pts"])
lines.append(" { m = %d, next = %s, %s }," % (
part["m"], part["next"] + 1 if part["next"] is not None else "nil", coords))
lines.append(" legs = {")
for leg in legs:
lines.append(" { from = %d, to = %d, smooth = %s, %s }," % (
leg["from"] + 1, leg["to"] + 1, "true" if leg["smooth"] else "false",
", ".join(fmt(*p) for p in leg["pts"])))
lines.append(" },")
lines.append(" },")
lines.append("}")