-- Scale world positions so every road segment (straight line between town centers)
-- is at least (1.2 world_units/sec) * (1.5 * 3600 sec) = 6480 units.
-- Method: uniform scale from centroid of towns 1..31; factor = 6480 / min_edge
-- where min_edge was ~870.54 (towns 8–2) before this migration.
-- Server recomputes road polylines and Distance in LoadRoadGraph from town coords.

-- Centroid and scale (derived from pre-migration layout including 000030 towns).
-- cx, cy = AVG(world_x), AVG(world_y) over ids 1..31 before scale.
DO $$
DECLARE
  cx double precision := 5365.609677419355;
  cy double precision := 4259.612903225806;
  s  double precision := 6480.0 / 870.5435801842434;
BEGIN
  UPDATE public.towns
  SET world_x = cx + (world_x - cx) * s,
      world_y = cy + (world_y - cy) * s
  WHERE id BETWEEN 1 AND 31;

  UPDATE public.heroes
  SET position_x = cx + (position_x - cx) * s,
      position_y = cy + (position_y - cy) * s;
END $$;

-- Stored road.distance is overwritten at runtime; scale placeholders for any SQL/reporting.
UPDATE public.roads SET distance = distance * (6480.0 / 870.5435801842434);

-- Legacy table not read by Go server; remove stale geometry so DB matches new world.
TRUNCATE TABLE public.road_waypoints;
