tools/data/extract_profession_resources.py (1722B)
1 import hashlib 2 import json 3 import pathlib 4 import struct 5 6 import ao_database 7 8 9 def main(): 10 client = pathlib.Path('anarchy-vanilla-14.9.1') 11 assert (client / 'version.id').read_text().strip() == '14.9.1' 12 database = ao_database.Database(client) 13 14 # Extract only the original twelve professions supported by player profiles. 15 lines = ['# Generated from 14.9.1 resource type 1000200.'] 16 records = [] 17 for profession in range(1, 13): 18 raw = database.read(1000200, profession) 19 rows = list(struct.iter_unpack('<4i', raw)) 20 assert [row[0] for row in rows] == [1, 15, 50, 100, 150, 190] 21 health = [row[2] for row in rows] 22 nano = [row[1] for row in rows] 23 ip = [row[3] for row in rows] 24 assert all(value >= 0 for value in health + nano + ip) 25 lines.extend([f'{profession}:', f' health: {json.dumps(health)}', 26 f' nano: {json.dumps(nano)}', f' ip: {json.dumps(ip)}']) 27 records.append(dict(profession=profession, rows=rows, payload_hex=raw.hex(), 28 payload_sha256=hashlib.sha256(raw).hexdigest())) 29 database.close() 30 31 # Keep the consumed coefficients small and retain exact source bytes separately. 32 output = pathlib.Path('server/gamedata/profession_resources.yaml') 33 output.write_text('\n'.join(lines) + '\n') 34 report = pathlib.Path('local/reports/profession-resources-14.9.1.json') 35 report.parent.mkdir(parents=True, exist_ok=True) 36 report.write_text(json.dumps(dict(index_sha256=hashlib.sha256(database.index).hexdigest(), 37 records=records), indent=2) + '\n') 38 print(output) 39 print(report) 40 41 42 if __name__ == '__main__': 43 main()