wobblyhead hg > minor_monsters
diff tools/build.py @ 23:2f555a54c332
layout fixes and balancing
| author | ark |
|---|---|
| date | 2026-10-20 12:04 +0200 |
| parents | ad1b478fc4dc |
| children | 3f2811aebb3d |
line wrap: on
line diff
--- a/tools/build.py Tue Oct 20 03:08:56 2026 +0200 +++ b/tools/build.py Tue Oct 20 12:04:42 2026 +0200 @@ -166,28 +166,6 @@ # 4. masks -def apply_corrections(m, routes, fix): - """ - apply routes.toml corrections for map m to a list of route dicts. - each route dict has points, and gets a fixed weight or None. - """ - for r in routes: - r["weight"] = None - for spec in fix.get("route", []): - pts = [tuple(p) for p in spec["points"]] - if "replace" in spec: - routes[spec["replace"]]["points"] = pts - routes[spec["replace"]]["manual"] = True - else: - routes.append({"points": pts, "weight": None, "manual": True}) - for k, v in fix.get("weights", {}).items(): - routes[int(k)]["weight"] = float(v) - drop = set(fix.get("drop", [])) - for i, r in enumerate(routes): - r["number"] = i - return [r for i, r in enumerate(routes) if i not in drop] - - def route_values(routes): """ fill in length, turning and value of each route (balance.md, route @@ -208,8 +186,7 @@ placement = cfg["placement"] settings = {"placement": placement, "maps": [{k: cfg["map"][str(m)][k] for k in MASK_SETTINGS} for m in range(MAPS)]} - routes_toml = CONFIG / "routes.toml" - inputs = [ART / f"map{m}mask.png" for m in range(MAPS)] + [routes_toml] + inputs = [ART / f"map{m}mask.png" for m in range(MAPS)] outputs = [DATA / "maps.js", MAPS_CACHE] cached = None if MAPS_CACHE.exists(): @@ -219,7 +196,6 @@ print("masks: up to date") return cached["maps"], False - fixes = tomllib.loads(routes_toml.read_text()).get("map", {}) out = [] for m in range(MAPS): t0 = time.time() @@ -230,8 +206,7 @@ (found["exit_points"], mc["exit_distance"])] cols, rows, grid = masks.placement_grid(mask, placement, found["centre"], mc["path_half_width"], spaces) - routes = [{"points": pts, "manual": False} for pts in found["routes"]] - routes = apply_corrections(m, routes, fixes.get(str(m), {})) + routes = [{"points": pts} for pts in found["routes"]] route_values(routes) g = found["graph"] out.append({ @@ -281,11 +256,10 @@ "length": rnd(r["length"]), "turning": rnd(r["turning"]), "value": round(r["value"], 3), - "weight": r["weight"], } for r in mp["routes"]], }) body = ",\n".join(json.dumps(m, separators=(",", ":")) for m in js) - write_text(DATA / "maps.js", HEADER.format(src="art/map*mask.png and config/routes.toml") + write_text(DATA / "maps.js", HEADER.format(src="art/map*mask.png") + "window.MM = window.MM || {};\nMM.maps = [\n" + body + "\n];\n") @@ -337,7 +311,7 @@ def check_config(cfg): """raise ConfigError on missing or malformed settings.""" for sec in ("scale", "monster", "animation", "movement", "route_preference", "tower", - "placement", "economy", "waves", "hearts", "coins", "controls", "art", "debug", + "placement", "waves", "hearts", "coins", "controls", "art", "debug", "sound", "map"): if sec not in cfg: raise ConfigError(f"section [{sec}] missing") @@ -380,7 +354,10 @@ where = f"map.{m}" for k in ("starting_coins", "early_bonus", "wave_count") + MASK_SETTINGS: need(mp, k, float, where) - need(mp, "monster_share", list, where) + for k, n in (("monster_share", 5), ("wave_size", 2), ("first_wave", 5)): + v = need(mp, k, list, where) + if len(v) != n or not all(isinstance(x, int) and not isinstance(x, bool) for x in v): + raise ConfigError(f"{where}: {k} should be {n} whole numbers, is {v!r}") if "spawn_interval" in mp: need(mp, "spawn_interval", float, where) for w, wave in enumerate(mp.get("wave", []), start=1): @@ -465,12 +442,10 @@ warn(f"map{m}: no entrance or no exit found") if not mp["routes"]: warn(f"map{m}: no routes") - for r in mp["routes"]: + for k, r in enumerate(mp["routes"]): times = ", ".join(f"{r['length'] / s:.0f}" for s in speeds) - fixed = f", weight {r['weight']}" if r["weight"] is not None else "" - manual = ", manual" if r.get("manual") else "" - print(f" route {r['number']}: length {r['length']:.0f}, turning {r['turning']:.0f} deg," - f" value {r['value']:.2f}{fixed}{manual}; walk time {times} s" + print(f" route {k}: length {r['length']:.0f}, turning {r['turning']:.0f} deg," + f" value {r['value']:.2f}; walk time {times} s" f" at speed {', '.join(str(s) for s in speeds)}") waves = c.get("wave", []) @@ -479,18 +454,15 @@ if not waves: continue counts, reg, boss, hp = wave_totals(cfg, waves) - target = c["starting_coins"] * cfg["economy"]["coin_total_factor"] - total = reg + boss + n_reg = sum(counts.get(k, 0) for k in regular) print(" monsters: " + ", ".join(f"{k} {counts.get(k, 0)}" for k in sorted(counts)) + f", {sum(counts.values())} in all") - share = [100 * counts.get(k, 0) * mons[k]["coins"] / reg if reg else 0 for k in regular] - print(" coin share %: " + ", ".join(f"{k} {s:.0f} ({t})" for k, s, t - in zip(regular, share, c["monster_share"]))) - print(f" coins: regular {reg}, boss {boss}, total {total}, target {target:.0f};" - f" regular hp {hp}") - if abs(total - target) > cfg["economy"]["coin_tolerance"] * target: - warn(f"map{m}: coins {total} are more than" - f" {cfg['economy']['coin_tolerance'] * 100:.0f} % off the target {target:.0f}") + share = [100 * counts.get(k, 0) / n_reg if n_reg else 0 for k in regular] + print(" share by count %: " + ", ".join(f"{k} {s:.0f} ({t})" for k, s, t + in zip(regular, share, c["monster_share"]))) + print(f" coins: regular {reg}, boss {boss}, total {reg + boss}," + f" {reg + boss + c['starting_coins']} with the starting coins;" + f" regular hp {hp}, {reg / hp if hp else 0:.2f} coins per hp") per_wave = [] for w, wave in enumerate(waves, start=1): _, r, b, _ = wave_totals(cfg, [wave])
