diff tools/build.py @ 15:c1c7e4f54bf6

balance work prep
author ark
date 2026-10-19 23:36 +0200
parents 7fda634d15ad
children 30bd10284fd8
line wrap: on
line diff
--- a/tools/build.py	Mon Oct 19 22:50:52 2026 +0200
+++ b/tools/build.py	Mon Oct 19 23:36:08 2026 +0200
@@ -71,6 +71,11 @@
 ROUTE_DECIMALS = 1
 # per map settings used by the mask step
 MASK_SETTINGS = ("path_half_width", "spawn_distance", "exit_distance")
+# tower levels, and the tower settings given as [level 1, last level]
+TOWER_LEVELS = 5
+TOWER_BY_LEVEL = ("damage", "range", "cost", "slow")
+# number of decimals of tower values filled in between non-whole ends
+TOWER_DECIMALS = 3
 
 warnings = []
 
@@ -336,15 +341,17 @@
         for k in ("hp", "coins", "speed"):
             need(mon, k, float, f"monster.{mid}")
     for tid, tw in cfg["tower"].items():
-        for k in ("damage", "range"):
+        for k in TOWER_BY_LEVEL:
+            if k == "slow" and k not in tw:
+                continue
             v = need(tw, k, list, f"tower.{tid}")
-            if len(v) != 5:
-                raise ConfigError(f"tower.{tid}: {k} needs 5 levels, has {len(v)}")
-        for k in ("cost", "attack_time", "projectile_speed"):
+            if len(v) != 2 or not all(isinstance(x, (int, float)) and not isinstance(x, bool)
+                                      for x in v):
+                raise ConfigError(f"tower.{tid}: {k} should be [level 1, level "
+                                  f"{TOWER_LEVELS}], is {v!r}")
+        for k in ("attack_time", "projectile_speed"):
             need(tw, k, float, f"tower.{tid}")
         need(tw, "projectile", str, f"tower.{tid}")
-        if "slow" in tw and len(tw["slow"]) != 5:
-            raise ConfigError(f"tower.{tid}: slow needs 5 levels")
     for k in ("speed_variation", "offset", "lean", "wander_step", "fade_in"):
         need(cfg["movement"], k, float, "movement")
     for k in ("footprint_radius", "max_gap", "min_tower_distance", "edge_distance",
@@ -380,6 +387,21 @@
                 need(wave["monsters"], mon, int, ww)
 
 
+def tower_levels(ends):
+    """
+    the values for all tower levels from [level 1, last level], in equal
+    steps. whole numbers when both ends are whole (halves round up),
+    otherwise rounded to TOWER_DECIMALS.
+    """
+    first, last = ends
+    whole = isinstance(first, int) and isinstance(last, int)
+    out = []
+    for i in range(TOWER_LEVELS):
+        v = first + (last - first) * i / (TOWER_LEVELS - 1)
+        out.append(math.floor(v + 0.5) if whole else round(v, TOWER_DECIMALS))
+    return out
+
+
 def sprite_table():
     """name -> [width, height] of every image in game/assets/ except maps."""
     out = {}
@@ -396,6 +418,9 @@
         print("config: up to date")
         return
     out = {k: v for k, v in cfg.items() if k != "map"}
+    out["tower"] = {tid: {k: tower_levels(v) if k in TOWER_BY_LEVEL else v
+                          for k, v in tw.items()}
+                    for tid, tw in cfg["tower"].items()}
     out["maps"] = []
     for m in range(MAPS):
         mp = dict(cfg["map"][str(m)])