31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Seed Wax resource cells into an OpenRA map.bin (format 2, no height data).
|
|
|
|
Layout (engine Map.cs SaveBinaryData): u8 fmt, u16 w, u16 h, u32 tilesOff(17),
|
|
u32 heightsOff(0), u32 resOff; tiles = w*h*(u16,u8) column-major (i*h+j);
|
|
resources = w*h*(u8 type, u8 density), same order.
|
|
|
|
Usage: seed_wax.py <map.bin> cx,cy,r [cx,cy,r ...] (circular blobs, density
|
|
scales down toward each blob's edge; type byte 1 = Wax ResourceIndex)
|
|
"""
|
|
import struct, sys
|
|
|
|
path = sys.argv[1]
|
|
data = bytearray(open(path, 'rb').read())
|
|
fmt, w, h = data[0], *struct.unpack_from('<HH', data, 1)
|
|
tiles_off, heights_off, res_off = struct.unpack_from('<III', data, 5)
|
|
assert fmt == 2 and heights_off == 0 and res_off == 3 * w * h + 17, 'unexpected map format'
|
|
|
|
for spec in sys.argv[2:]:
|
|
cx, cy, r = map(int, spec.split(','))
|
|
for x in range(cx - r, cx + r + 1):
|
|
for y in range(cy - r, cy + r + 1):
|
|
d2 = (x - cx) ** 2 + (y - cy) ** 2
|
|
if d2 <= r * r and 0 <= x < w and 0 <= y < h:
|
|
density = max(2, round(12 * (1 - (d2 ** 0.5) / (r + 1))))
|
|
o = res_off + 2 * (x * h + y)
|
|
data[o], data[o + 1] = 1, density
|
|
|
|
open(path, 'wb').write(data)
|
|
print(f'{path}: seeded {len(sys.argv) - 2} blob(s) on {w}x{h} map')
|