Files
WoW-Hybrid-gateway/ops/creature_unit_classes.py

52 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""#87 (2026-11-28): the 1.12 creature query reply carries no unit class, but the 70334 creature template needs
CreatureClassID. The gateway learns the class from a spawned actor; a creature the client never saw (mail sender
Lady Jaina 4968, links, quest text) therefore got no template and showed "Unknown". This table is the server's own
creature_template.unit_class, used only when the actor has not been observed.
usage: creature_unit_classes.py <out.hpp> (reads tw_world via the tortoise-docker-db-1 container)
"""
import subprocess, sys
PRESENTABLE = {0, 1, 2, 4, 8}
def rows():
sql = 'select entry,unit_class from creature_template order by entry'
cmd = ['docker', 'exec', 'tortoise-docker-db-1', 'sh', '-c',
f'mariadb -uroot -p"$MYSQL_ROOT_PASSWORD" tw_world -N -B -e "{sql}"']
out = subprocess.run(cmd, check=True, capture_output=True, text=True).stdout
for line in out.splitlines():
entry, cls = map(int, line.split('\t'))
if 0 < entry <= 0x7fffff and cls in PRESENTABLE:
yield entry, cls
def main(path):
data = list(rows())
assert len(data) > 10000, len(data)
body = ',\n'.join(','.join(f'{{{e},{c}}}' for e, c in data[i:i + 12]) for i in range(0, len(data), 12))
open(path, 'w').write(f'''// Generated by ops/creature_unit_classes.py from tw_world.creature_template (unit_class); do not edit.
#pragma once
#include <algorithm>
#include <cstdint>
#include <iterator>
#include <optional>
namespace gateway::creature_unit_classes {{
struct Row {{ uint32_t entry; uint8_t unit_class; }};
inline constexpr Row Rows[] = {{
{body}
}};
inline std::optional<uint8_t> find(uint32_t entry) {{
auto it = std::lower_bound(std::begin(Rows), std::end(Rows), entry, [](const Row& r, uint32_t e) {{ return r.entry < e; }});
if (it == std::end(Rows) || it->entry != entry) return std::nullopt;
return it->unit_class;
}}
}} // namespace gateway::creature_unit_classes
''')
print(len(data), 'rows')
if __name__ == '__main__':
main(sys.argv[1])