133 lines
5.6 KiB
Python
133 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
|
# pfQuest SmartArrow
|
|
# Copyright (C) 2026 pfQuest SmartArrow contributors
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version. It is distributed WITHOUT ANY
|
|
# WARRANTY; see LICENSE.md.
|
|
"""Show what the navmesh and the path network have around one spot.
|
|
|
|
python3 probe_paths.py 10444.9 867.0 (the "you:" numbers of /smartarrow debug)
|
|
python3 probe_paths.py 10444.9 867.0 --map 1 --size 12
|
|
|
|
Prints a map of the 4 yard cells round the spot, north up and west left.
|
|
Each cell shows its levels, lowest first: the piece of ground it belongs to
|
|
(a letter), then its height (last two digits; -- where the cell has one
|
|
level and the navmesh keeps no height). Marks: * the piece's point, x not
|
|
usable (inside a building's base), s steep slope, ^ a steep cell, ~ water,
|
|
@ the spot asked for. Under the map: the pieces, and the joins between them.
|
|
"""
|
|
import argparse
|
|
import math
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import bake_waypoints as bw
|
|
import bake_paths as bp
|
|
|
|
CELL = bw.CELL
|
|
NAMES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
here = os.path.dirname(os.path.abspath(__file__))
|
|
addon = os.path.dirname(here)
|
|
ap.add_argument('n', type=float)
|
|
ap.add_argument('w', type=float)
|
|
ap.add_argument('--map', type=int, default=1, help='0 Eastern Kingdoms, 1 Kalimdor (default)')
|
|
ap.add_argument('--size', type=int, default=11, help='cells shown each side of the spot (default 11)')
|
|
ap.add_argument('--navmesh', default=os.path.join(os.path.dirname(addon), 'pfQuest-SmartArrow-Navmesh'))
|
|
args = ap.parse_args()
|
|
|
|
version, maps = bw.load_navmesh(args.navmesh)
|
|
zones = bw.load_zones(addon)
|
|
net = bp.Net(bw.Grid(maps[args.map]), bw.load_solids(addon, zones).get(args.map, []),
|
|
bw.load_roads(addon, zones).get(args.map, []), lambda s: None)
|
|
net.build_nodes()
|
|
net.relocate()
|
|
net.heights()
|
|
net.build_joins()
|
|
net.bypasses()
|
|
b, g = net.b, net.g
|
|
|
|
ci, cj = int(math.floor(args.n / CELL)), int(math.floor(args.w / CELL))
|
|
size = args.size
|
|
shown = {}
|
|
|
|
def name(k):
|
|
if k not in shown:
|
|
shown[k] = NAMES[len(shown) % len(NAMES)]
|
|
return shown[k]
|
|
|
|
points = set(node['cell'] for node in net.nodes)
|
|
width = 0
|
|
rows = []
|
|
for i in range(ci + size, ci - size - 1, -1):
|
|
row = []
|
|
for j in range(cj + size, cj - size - 1, -1):
|
|
parts = []
|
|
for s in range(g.count(i, j)):
|
|
c = (i, j, s)
|
|
cls, h = g.surface(i, j, s)
|
|
hh = '--' if h is None else '%02d' % (int(round(h)) % 100)
|
|
k = net.label.get(c)
|
|
if k is not None:
|
|
tag = name(k)
|
|
elif b.solid(i, j, s):
|
|
tag = 'x'
|
|
elif b.slope(i, j, s):
|
|
tag = 's'
|
|
else:
|
|
tag = '?'
|
|
parts.append(tag + hh + ('*' if c in points else '') + ('~' if cls == 2 else '') + ('^' if cls == 3 else ''))
|
|
text = '/'.join(parts) or '.'
|
|
if (i, j) == (ci, cj):
|
|
text = '@' + text
|
|
width = max(width, len(text))
|
|
row.append(text)
|
|
rows.append(((i + 0.5) * CELL, row))
|
|
print('North up, west left. Columns from W %.0f (left) to W %.0f (right), 4 yards each.' % ((cj + size + 0.5) * CELL, (cj - size + 0.5) * CELL))
|
|
for n, row in rows:
|
|
print('N %6.0f ' % n + ' '.join(t.ljust(width) for t in row))
|
|
|
|
print()
|
|
print('Missing steps between neighbouring cells shown (a wall, a drop, too steep):')
|
|
count = 0
|
|
for i in range(ci - size, ci + size + 1):
|
|
for j in range(cj - size, cj + size + 1):
|
|
for s in range(g.count(i, j)):
|
|
for d in (0, 1): # each pair once
|
|
ni, nj = i + bw.DI[d], j + bw.DJ[d]
|
|
if abs(ni - ci) > size or abs(nj - cj) > size or g.count(ni, nj) == 0:
|
|
continue
|
|
if not (g.links(i, j, s, d) or ()):
|
|
count += 1
|
|
if count <= 80:
|
|
print(' N %.0f W %.0f level %d -/- N %.0f W %.0f' % ((i + 0.5) * CELL, (j + 0.5) * CELL, s, (ni + 0.5) * CELL, (nj + 0.5) * CELL))
|
|
print(' (%d in all)' % count)
|
|
|
|
print()
|
|
print('Pieces shown, and what each is joined to:')
|
|
for k, tag in sorted(shown.items(), key=lambda e: e[1]):
|
|
node = net.nodes[k]
|
|
pn, pw = net.pos(k)
|
|
z = node['zlo']
|
|
joins = []
|
|
for o, (vias, length) in sorted(net.adj[k].items()):
|
|
on, ow = net.pos(o)
|
|
via = ''.join(' via N %.0f W %.0f' % ((v[0] + 0.5) * CELL, (v[1] + 0.5) * CELL) for v in vias)
|
|
joins.append('%s (N %.0f W %.0f%s, %.0f yd%s)' % (shown.get(o, 'off the map'), on, ow,
|
|
'' if net.nodes[o]['z'] is None else ' height %.0f' % net.nodes[o]['z'], length, via))
|
|
print(' %s: point N %.0f W %.0f%s, %d cells, room %d; joined to: %s' % (
|
|
tag, pn, pw, '' if z is None else ' heights %.0f-%.0f%s' % (z, node['zhi'], ' (estimated)' if node['zkind'] == 2 else ''),
|
|
len(node['cells']), b.clearance(node['cell']),
|
|
'; '.join(joins) or 'nothing'))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|