Files
2026-11-05 23:06:20 +00:00

279 lines
11 KiB
Python

"""Build Wood and Seeds Gather Data.lua from the Octo database exports (trees.txt, seeds.txt) and
the client's WorldMapArea/AreaTable (client.json).
usage: py -I build_data.py trees.txt seeds.txt client.json ..\\Data.lua"""
import json
import sys
trees_txt, seeds_txt, client_json, out_lua = sys.argv[1:5]
client = json.load(open(client_json, encoding="utf-8"))
# Type numbers must match TYPES in WoodAndSeedsGather.lua.
# trees per object id: 1 Simple, 2 Bright, 3 Shade, 4 Tropical, 5 Dead, 6 Star
TYPE = {}
for i in list(range(2020267, 2020282)) + [2020301]:
TYPE[i] = 1
for i in range(2020282, 2020288):
TYPE[i] = 2
for i in list(range(2020288, 2020298)) + [2020309]:
TYPE[i] = 3
TYPE[2020298] = 4
TYPE[2020300] = 5
TYPE[2020299] = 6
# seed plants: 7 pumpkin, 8 mountain berry, 9 watermelon, 10 Northwind grapes, 11 Wildhammer yams, 12 Sandswept carrots
TYPE.update({1000370: 7, 1000371: 8, 1000372: 9, 2020260: 10, 2020261: 11, 2020262: 12})
# seed vendors: npc id -> (type, name, title, side, price, note); 13 cabbage seeds, 14 mushroom spores.
# A note is short tooltip lines split by ";".
PLANTER_QUEST = "Quest You Reap What You Sow (level 20);rewards a Simple Wooden Planter."
VENDORS = {
51531: (13, "Betty", "Gardener's Apprentice", "Alliance", "40c",
"Mortimer Stansfield <Gardener> stands here too.;" + PLANTER_QUEST),
51533: (13, "Yrta Younghoof", "Gardener's Apprentice", "Horde", "40c",
"Kern Mosshoof <Gardener> stands here too.;" + PLANTER_QUEST),
9047: (14, "Jenal", "Ditch Digger", "Alliance", "2g 50s", ""),
9076: (14, "Ghede", "", "Horde", "2g 50s", ""),
12384: (14, "Augustus the Touched", "", "Alliance and Horde", "2g 50s", ""),
}
# vendors standing inside a city's map rectangle also get a pin on that city's map
CITIES = ["Stormwind", "Ironforge", "Darnassus", "Orgrimmar", "ThunderBluff", "Undercity"]
# zone level ranges (Turtle wiki Zone Level Chart; a few custom zones from the client's AreaTable)
LEVELS = {
"DunMorogh": "1-10", "Elwynn": "1-10", "Tirisfal": "1-10", "LochModan": "10-20", "Westfall": "10-20",
"Silverpine": "10-20", "Redridge": "15-25", "Wetlands": "15-25", "Duskwood": "20-30", "Hilsbrad": "20-35",
"Alterac": "30-40", "Arathi": "30-40", "Badlands": "30-45", "Stranglethorn": "35-45",
"SwampOfSorrows": "35-45", "Gilneas": "35-45", "BlastedLands": "40-55", "SearingGorge": "40-50",
"Hinterlands": "40-50", "Gillijim": "45-55", "Lapidis": "45-55", "BurningSteppes": "50-60",
"DeadwindPass": "55-60", "EasternPlaguelands": "55-60", "WesternPlaguelands": "55-60",
"Durotar": "1-10", "Mulgore": "1-10", "Teldrassil": "1-10", "Darkshore": "10-20", "Barrens": "10-30",
"Ashenvale": "15-30", "StonetalonMountains": "20-30", "ThousandNeedles": "25-35", "Desolace": "30-40",
"Dustwallow": "35-45", "Feralas": "40-50", "Tanaris": "40-50", "UngoroCrater": "45-55",
"Aszhara": "50-60", "Felwood": "50-60", "Moonglade": "50-60", "Winterspring": "50-60",
"TelAbim": "50-60", "Hyjal": "55-60", "Silithus": "55-60",
"ThalassianHighlands": "1-10", "BlackstoneIsland": "1-10",
"Northwind": "30+", "Balor": "30+", "GrimReaches": "35+", "Moonwhisper": "55+",
}
areas = client["areas"]
maps = {} # mapFile -> [mapId, left, right, top, bottom, name, levels]
by_area = {} # areaId -> mapFile (continents 0/1 only)
for wid, mapid, area, name, left, right, top, bottom in client["wma"]:
if mapid not in (0, 1) or not name or left == right:
continue
if area == 0:
nice = "Kalimdor" if mapid == 1 else "Eastern Kingdoms"
else:
nice = areas.get(str(area), [0, 0, 0, name])[3]
maps[name] = [mapid, left, right, top, bottom, nice, LEVELS.get(name, "")]
if area and area not in by_area:
by_area[area] = name
CONT = {0: "Azeroth", 1: "Kalimdor"}
CUSTOM = {
0: ["Gilneas", "Lapidis", "Gillijim", "ThalassianHighlands", "GrimReaches", "Balor", "Northwind", "ScarletEnclave"],
1: ["Hyjal", "TelAbim", "Icepoint", "BlackstoneIsland", "Moonwhisper"],
}
LABEL = {2020281: 1, 2020299: 1} # continent the database listed these under; the rest were "Azeroth"
def to_world(mapfile, x, y):
_, left, right, top, bottom = maps[mapfile][:5]
return left - x * (left - right), top - y * (top - bottom) # (worldY, worldX)
def to_zone(mapfile, wy, wx):
_, left, right, top, bottom = maps[mapfile][:5]
return (left - wy) / (left - right), (top - wx) / (top - bottom)
def place_custom(obj, x, y):
found = []
for cont in (0, 1):
wy, wx = to_world(CONT[cont], x, y)
for z in CUSTOM[cont]:
zx, zy = to_zone(z, wy, wx)
if 0 <= zx <= 1 and 0 <= zy <= 1:
found.append((cont != LABEL.get(obj, 0), max(abs(zx - 0.5), abs(zy - 0.5)), z, zx, zy))
if not found:
return None
found.sort()
return found[0][2:]
# The database files a spot under the first known zone whose map rectangle holds it, so
# trees in Octo's custom zones that overlap a vanilla zone's rectangle get that zone's name
# (Tel'Abim trees show up as Tanaris). Fix those:
# A) an object's whole group in a vanilla zone sits inside the rectangle of a custom zone
# where the same object also grows: the group belongs to that custom zone;
# B) checked by hand: island trees split off from a vanilla zone by open sea.
SPLITS = [
(2020298, 440, lambda x, y: x >= 0.85, "TelAbim"), # Tanaris east of the coast
(2020298, 33, lambda x, y: x < 0.10, "Gillijim"), # Stranglethorn's far west edge
]
def inside(mapfile, wy, wx):
zx, zy = to_zone(mapfile, wy, wx)
return 0 <= zx <= 1 and 0 <= zy <= 1, zx, zy
nodes = {} # mapFile -> type -> list of (x10, y10)
counts = {"placed_db": 0, "placed_custom": 0, "unplaced": 0, "nozone": 0, "moved": 0, "duplicates": 0}
custom_where = {}
moves = {}
groups = [] # (obj, zone, [(a, b)])
npc_lines = [] # (npc, zone, [(a, b)])
def parse_pts(pts):
return [tuple(int(v) for v in p.split(",")) for p in pts.split(" ")]
for line in open(trees_txt, encoding="utf-8"):
line = line.strip()
if not line:
continue
obj, zone, pts = line.split("|")
groups.append((int(obj), int(zone), parse_pts(pts)))
for line in open(seeds_txt, encoding="utf-8"):
line = line.strip()
if not line:
continue
kind, ident, zone, pts = line.split("|")
if kind == "obj":
groups.append((int(ident), int(zone), parse_pts(pts)))
elif kind == "npc":
npc_lines.append((int(ident), int(zone), parse_pts(pts)))
def put(z, t, p):
lst = nodes.setdefault(z, {}).setdefault(t, [])
if p in lst: # the database lists a few spots twice
counts["duplicates"] += 1
return False
lst.append(p)
return True
def add(z, t, zx, zy):
put(z, t, (round(zx * 1000), round(zy * 1000)))
# first the custom-zone spots, which also tell us which custom zones each object grows in
anchors = {}
for obj, zone, pts in groups:
if zone != 0:
continue
for a, b in pts:
hit = place_custom(obj, a / 10000.0, b / 10000.0)
if not hit:
counts["unplaced"] += 1
continue
z, zx, zy = hit
counts["placed_custom"] += 1
custom_where[(obj, z)] = custom_where.get((obj, z), 0) + 1
anchors.setdefault(obj, set()).add(z)
add(z, TYPE[obj], zx, zy)
for obj, zone, pts in groups:
if zone == 0:
continue
z = by_area.get(zone)
if not z:
counts["nozone"] += len(pts)
continue
t = TYPE[obj]
world = [to_world(z, a / 1000.0, b / 1000.0) for a, b in pts]
target = [None] * len(pts)
for c in sorted(anchors.get(obj, ())): # rule A
if all(inside(c, wy, wx)[0] for wy, wx in world):
target = [c] * len(pts)
break
for sobj, szone, test, c in SPLITS: # rule B
if sobj == obj and szone == zone:
for i, (a, b) in enumerate(pts):
if test(a / 1000.0, b / 1000.0) and inside(c, *world[i])[0]:
target[i] = c
for i, (a, b) in enumerate(pts):
c = target[i]
if c:
ok, zx, zy = inside(c, *world[i])
add(c, t, zx, zy)
counts["moved"] += 1
key = (obj, z, c)
moves[key] = moves.get(key, 0) + 1
else:
if put(z, t, (a, b)):
counts["placed_db"] += 1
vendors = [] # (mapFile, x10, y10, type, name, title, side, price, note, city, cx10, cy10)
for npc, zone, pts in npc_lines:
z = by_area.get(zone)
if not z or npc not in VENDORS:
print("vendor not placed:", npc, zone)
continue
t, name, title, side, price, note = VENDORS[npc]
for a, b in pts:
row = [z, a, b, t, name, title, side, price, note]
wy, wx = to_world(z, a / 1000.0, b / 1000.0)
for c in CITIES:
if c in maps and maps[c][0] == maps[z][0]:
ok, zx, zy = inside(c, wy, wx)
if ok:
row += [c, round(zx * 1000), round(zy * 1000)]
break
vendors.append(row)
def lua_str(s):
return '"' + s.replace("\\", "\\\\").replace('"', '\\"') + '"'
out = []
out.append("-- Wood and Seeds Gather data. Generated by tools/build_data.py; do not edit by hand.")
out.append("-- Tree, seed plant and vendor spots: OctoWoW database (octowow.st/db), November 2026.")
out.append("-- Map rectangles and zone names: the game's WorldMapArea.dbc and AreaTable.dbc.")
out.append("")
out.append("-- [mapFile] = { continent (0 = Eastern Kingdoms, 1 = Kalimdor), left, right, top, bottom, name, levels }")
out.append("WoodAndSeedsGather_Maps = {")
for name in sorted(maps):
m = maps[name]
out.append(' [%s] = { %d, %.1f, %.1f, %.1f, %.1f, %s, %s },' % (
lua_str(name), m[0], m[1], m[2], m[3], m[4], lua_str(m[5]), lua_str(m[6])))
out.append("}")
out.append("")
out.append("-- [mapFile] = { [type] = \"x,y x,y ...\" } with x, y in tenths of a percent of that zone's map")
out.append("-- types 1-6 are trees, 7-12 seed plants (see TYPES in WoodAndSeedsGather.lua)")
out.append("WoodAndSeedsGather_Nodes = {")
total = 0
per_type = {}
for z in sorted(nodes):
out.append(" [%s] = {" % lua_str(z))
for t in sorted(nodes[z]):
pts = nodes[z][t]
total += len(pts)
per_type[t] = per_type.get(t, 0) + len(pts)
out.append(" [%d] = \"%s\"," % (t, " ".join("%d,%d" % p for p in pts)))
out.append(" },")
out.append("}")
out.append("")
out.append("-- seed vendors: { mapFile, x, y, type, name, title, side, price, note (lines split by \";\"),")
out.append("-- and a city map with x, y when the vendor also stands inside a city's map }")
out.append("WoodAndSeedsGather_Vendors = {")
for v in vendors:
cells = []
for val in v:
cells.append(lua_str(val) if isinstance(val, str) else "%d" % val)
out.append(" { %s }," % ", ".join(cells))
out.append("}")
open(out_lua, "w", encoding="utf-8", newline="\n").write("\n".join(out) + "\n")
print(counts, "total written", total)
print("per type:", sorted(per_type.items()))
print("vendors:", [(v[4], v[0], v[9] if len(v) > 9 else "-") for v in vendors])
print("custom zone placements:", sorted(custom_where.items()))
print("moved from vanilla zones:", sorted(moves.items()))
print("zones with trees:", len(nodes))