91 lines
5.9 KiB
Python
91 lines
5.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate include/gateway/mo_transport_timelines.hpp (2026-11-24).
|
|
|
|
Turtle (tortoise-wow TransportMgr::GeneratePath) and the 70334 client (TrinityCore GeneratePath/InitializeLeg, which
|
|
mirrors the client) time the same ship path slightly differently. At a map change the server's clock can be a few
|
|
ms short of the client's leg end, so a transport re-created on the new map is placed by the client on the old leg
|
|
and the passenger is dropped into the void. Per route this emits anchor pairs (server ms -> client ms) at every
|
|
stop arrival/departure and map switch, the client's leg windows per map and its total period (TrinityCore sends it
|
|
as GameObjectData.Level), and the node where the server lands the transport after each teleport.
|
|
|
|
gen_mo_timelines.py <server TaxiPathNode.dbc> <client TaxiPathNode.csv (DBCD dump)> <out.hpp>
|
|
"""
|
|
import csv, math, sys, os
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from mo_timing import turtle, client, nodes_from_dbc, f32
|
|
|
|
ROUTES = [ # entry, server path, client path (transport_periods.hpp MoTransportPaths), template speed/accel (data1/data2)
|
|
(164871, 121, 302, 30.0, 1.0), (175080, 110, 285, 30.0, 1.0), (176231, 116, 292, 30.0, 1.0),
|
|
(176495, 120, 301, 30.0, 1.0), (177233, 122, 303, 30.0, 1.0),
|
|
# Turtle-only routes: client paths 12000+P baked from the Octo client's TaxiPathNode (content taxiroutes, build f5213778)
|
|
(20808, 72, 12072, 30.0, 1.0), (176244, 117, 12117, 30.0, 1.0), (181646, 294, 12294, 30.0, 1.0),
|
|
(190549, 295, 12295, 30.0, 1.0), (176310, 295, 12295, 30.0, 1.0), (190550, 296, 12296, 30.0, 1.0),
|
|
(190552, 297, 12297, 30.0, 1.0), (176250, 323, 12323, 30.0, 1.0), (20809, 348, 12348, 30.0, 1.0)]
|
|
|
|
def client_nodes(path, pid):
|
|
rows = [r for r in csv.DictReader(open(path)) if int(r['PathID']) == pid]
|
|
rows.sort(key=lambda r: int(r['NodeIndex']))
|
|
return [dict(i=int(r['NodeIndex']), map=int(r['ContinentID']), pos=tuple(float(v) for v in r['Loc'].split('|')),
|
|
flags=int(r['Flags']), delay=int(r['Delay'])) for r in rows]
|
|
|
|
def arrival_headings(nodes):
|
|
# GeneratePath evaluates the original route's Catmull-Rom derivative at
|
|
# t=0 before it discards teleport helper nodes. Its nonzero weights are
|
|
# -0.5 for the previous point and +0.5 for the next point.
|
|
headings = {}
|
|
for previous, current, following in zip(nodes, nodes[1:], nodes[2:]):
|
|
dx = f32(0.5 * (following['pos'][0] - previous['pos'][0]))
|
|
dy = f32(0.5 * (following['pos'][1] - previous['pos'][1]))
|
|
headings[current['i']] = f32(math.atan2(dy, dx) + math.pi) % f32(math.tau)
|
|
return headings
|
|
|
|
def main(dbc, tpn, out):
|
|
lines = ['#pragma once', '#include <cstdint>', '// Generated by ops/mo-transports/gen_mo_timelines.py; do not edit.',
|
|
'namespace gateway {', 'struct MoTimelineAnchor{uint32_t server,client;};',
|
|
'struct MoClientLeg{uint32_t map,start,end;};',
|
|
'struct MoTransportArrival{uint32_t entry,map;float x,y,z,heading;};']
|
|
tables = []; arrivals = []
|
|
for entry, sp, cp, speed, accel in ROUTES:
|
|
sn, cn = nodes_from_dbc(dbc, sp), client_nodes(tpn, cp)
|
|
same = len(sn) == len(cn) and all(a['map'] == b['map'] and a['flags'] == b['flags'] and a['delay'] == b['delay'] and
|
|
all(abs(a['pos'][d] - b['pos'][d]) < 0.05 for d in range(3)) for a, b in zip(sn, cn))
|
|
if not same: raise SystemExit(f'{entry}: client path {cp} differs from server path {sp}')
|
|
kf, speriod = turtle(sn, speed, accel)
|
|
legs, cperiod = client(cn, speed, accel)
|
|
stops = {i: (a, d) for l in legs for i, a, d in l['stops']}
|
|
ends = [l['end'] for l in legs] # n-th server teleport frame <-> n-th client leg end (nodes may differ)
|
|
anchors = [(0, 0)]
|
|
for k in kf:
|
|
n = k['n']['i']
|
|
if k['n']['flags'] == 2:
|
|
if k is kf[0]: anchors.append((k['dep'], stops[n][1]) if n in stops else None); continue
|
|
anchors += [(k['arr'], stops[n][0]), (k['dep'], stops[n][1])]
|
|
elif k['tp'] and k is not kf[-1]:
|
|
anchors.append((k['arr'], ends[sum(1 for a in anchors[1:] if a and a[2:] == ('tp',))]) + ('tp',))
|
|
anchors.append((speriod, cperiod))
|
|
anchors = [a[:2] for a in anchors if a]
|
|
assert len(legs) == 1 + sum(1 for k in kf[:-1] if k['tp'] and k['n']['flags'] != 2), (entry, 'leg count')
|
|
assert all(b[0] >= a[0] and b[1] >= a[1] for a, b in zip(anchors, anchors[1:])), (entry, anchors)
|
|
headings = arrival_headings(sn)
|
|
for frame, following in zip(kf, kf[1:] + kf[:1]):
|
|
node = following['n']
|
|
if frame['tp'] and node['map'] != frame['n']['map']:
|
|
arrivals.append((entry, node['map'], node['pos'], headings[node['i']]))
|
|
name = f'MoTimeline{entry}'
|
|
lines.append(f'inline constexpr MoTimelineAnchor {name}Anchors[]={{' + ','.join(f'{{{a},{b}}}' for a, b in anchors) + '};')
|
|
lines.append(f'inline constexpr MoClientLeg {name}Legs[]={{' + ','.join(f"{{{l['map']},{l['start']},{l['end']}}}" for l in legs) + '};')
|
|
tables.append((entry, speriod, cperiod, name, len(anchors), len(legs)))
|
|
print(entry, 'server', speriod, 'client', cperiod, 'anchors', anchors)
|
|
lines.append('struct MoTimeline{uint32_t entry,server_period,client_period;const MoTimelineAnchor* anchors;uint32_t anchor_count;const MoClientLeg* legs;uint32_t leg_count;};')
|
|
lines.append('inline constexpr MoTimeline MoTimelines[]={')
|
|
for e, s, c, n, na, nl in tables: lines.append(f' {{{e},{s},{c},{n}Anchors,{na},{n}Legs,{nl}}},')
|
|
lines.append('};')
|
|
lines.append('inline constexpr MoTransportArrival MoTransportArrivals[]={')
|
|
for e, m, p, heading in arrivals:
|
|
lines.append(f' {{{e},{m},{p[0]:.2f}f,{p[1]:.2f}f,{p[2]:.2f}f,{heading:.9f}f}},')
|
|
lines.append('};')
|
|
lines.append('}')
|
|
open(out, 'w').write('\n'.join(lines) + '\n')
|
|
|
|
if __name__ == '__main__': main(*sys.argv[1:4])
|