#!/usr/bin/env python3 """Place a neutral `waxseed` actor at the centre of every wax blob on every map. Reads the resource plane straight out of each map.bin, finds blob centroids by flood fill, and appends the actors to map.yaml. Idempotent: strips previously placed waxseed entries first. """ import os, re, struct, glob MAPS = glob.glob(os.path.join(os.path.dirname(__file__), '..', 'mods', 'vinylgod', 'maps', '*')) def resource_cells(path): d = open(path, 'rb').read() fmt, w, h = d[0], *struct.unpack_from('= 6: # ignore specks out.append((round(sum(p[0] for p in blob) / len(blob)), round(sum(p[1] for p in blob) / len(blob)))) return out for mapdir in sorted(MAPS): my, mb = os.path.join(mapdir, 'map.yaml'), os.path.join(mapdir, 'map.bin') if not (os.path.exists(my) and os.path.exists(mb)): continue centres = blobs(resource_cells(mb)) s = open(my).read() s = re.sub(r'\n\twaxseed\d+: waxseed\n\t\tOwner: Neutral\n\t\tLocation: \d+,\d+', '', s) if 'Actors:' not in s: s = s.rstrip() + '\n\nActors:\n' block = ''.join(f'\n\twaxseed{i}: waxseed\n\t\tOwner: Neutral\n\t\tLocation: {x},{y}' for i, (x, y) in enumerate(centres)) # append to the Actors section (it is the last block in our generated maps) head, _, tail = s.partition('Actors:') lines = tail.split('\n') cut = len(lines) for i, ln in enumerate(lines): if ln and not ln.startswith('\t') and i > 0: # next top-level key cut = i break tail = '\n'.join(lines[:cut]).rstrip() + block + '\n' + '\n'.join(lines[cut:]) open(my, 'w').write(head + 'Actors:' + tail) print(f'{os.path.basename(mapdir)}: {len(centres)} seep(s) at {centres}')