83 lines
2.3 KiB
Python
83 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate 'Pressing District' — 64x64 4-player skirmish map (yaml + bin + preview)."""
|
|
import os, struct
|
|
from PIL import Image
|
|
|
|
W = H = 66 # 64 playable + 1 border each side
|
|
MAP = os.path.join(os.path.dirname(__file__), '..', 'mods', 'vinylgod', 'maps', 'district')
|
|
os.makedirs(MAP, exist_ok=True)
|
|
|
|
SPAWNS = [(8, 8), (57, 8), (8, 57), (57, 57)]
|
|
WAX = [(16, 16, 5), (49, 16, 5), (16, 49, 5), (49, 49, 5), (32, 32, 7), (32, 10, 3), (32, 55, 3), (10, 32, 3), (55, 32, 3)]
|
|
|
|
# map.bin: fmt2 header, tiles (template 255 idx 0), resources
|
|
data = bytearray()
|
|
data += struct.pack('<BHH', 2, W, H)
|
|
data += struct.pack('<III', 17, 0, 3 * W * H + 17)
|
|
data += b'\xff\x00\x00' * (W * H)
|
|
res = bytearray(2 * W * H)
|
|
for cx, cy, r in WAX:
|
|
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 - 1 and 0 < y < H - 1:
|
|
o = 2 * (x * H + y)
|
|
res[o], res[o + 1] = 1, max(2, round(12 * (1 - (d2 ** 0.5) / (r + 1))))
|
|
data += res
|
|
open(os.path.join(MAP, 'map.bin'), 'wb').write(data)
|
|
|
|
players = '\n'.join(f""" PlayerReference@Multi{i}:
|
|
Name: Multi{i}
|
|
Playable: True
|
|
Faction: Random
|
|
Enemies: Creeps""" for i in range(4))
|
|
actors = '\n'.join(f""" Actor{i}: mpspawn
|
|
Owner: Multi{i}
|
|
Location: {x},{y}""" for i, (x, y) in enumerate(SPAWNS))
|
|
|
|
open(os.path.join(MAP, 'map.yaml'), 'w').write(f"""MapFormat: 12
|
|
|
|
RequiresMod: vinylgod
|
|
|
|
Title: Pressing District
|
|
|
|
Author: Monster Robot Party
|
|
|
|
Tileset: VINYLGOD
|
|
|
|
MapSize: {W},{H}
|
|
|
|
Bounds: 1,1,64,64
|
|
|
|
Visibility: Lobby
|
|
|
|
Categories: Maps
|
|
|
|
Players:
|
|
PlayerReference@Neutral:
|
|
Name: Neutral
|
|
OwnsWorld: True
|
|
NonCombatant: True
|
|
Faction: Random
|
|
PlayerReference@Creeps:
|
|
Name: Creeps
|
|
NonCombatant: True
|
|
Faction: Random
|
|
{players}
|
|
|
|
Actors:
|
|
{actors}
|
|
""")
|
|
|
|
# preview
|
|
im = Image.new('RGB', (W, H), (55, 50, 52))
|
|
for cx, cy, r in WAX:
|
|
for x in range(cx - r, cx + r + 1):
|
|
for y in range(cy - r, cy + r + 1):
|
|
if (x - cx) ** 2 + (y - cy) ** 2 <= r * r and 0 <= x < W and 0 <= y < H:
|
|
im.putpixel((x, y), (255, 45, 150))
|
|
for x, y in SPAWNS:
|
|
im.putpixel((x, y), (255, 255, 255))
|
|
im.resize((W * 3, H * 3), Image.NEAREST).save(os.path.join(MAP, 'map.png'))
|
|
print('district map written')
|