# FIGHT NIGHT, Vertical One-Take (20 s): FUENF Etagen, NUR Kamerabewegung von unten nach oben (Tariq 05.09.2026, "Anfang mit Auto").
# Turm bei x=40, Held immer bei (40, 0). Etage 0 = Strasse am Hintereingang mit SUV (Boden 0, Betondach der Rampe 4,5..5),
# 1 Gym (5), 2 Eisbad (10), 3 Kreis (15), 4 Arena (Boden 20, Canvas 21, Truss 25,3..25,8). Platten 0,5 m, Schnitt im Dunkel.
# Kamera-Saeule (43,3, -3,3) fuer alle Etagen, identische Bewegung je 4 s, Rig crane.
FPS, T = 24, 20.0
def ft(f): return round(f / FPS, 4)
CUT = [96, 192, 288, 384]
t1, t2, t3, t4 = map(ft, CUT)
H0, H1, H2, H3, H4 = (40.0, 0.0, 0.0), (40.0, 0.0, 5.0), (40.0, 0.0, 10.0), (40.0, 0.0, 15.0), (40.0, 0.0, 21.0)

def jump(a, tc, b):
    return [(tc - 1.0 / FPS + 0.001, *a), (tc - 0.001, *a), (tc, *b), (tc + 0.001, *b)]
SUBJ = [(0.0, *H0)] + jump(H0, t1, H1) + jump(H1, t2, H2) + jump(H2, t3, H3) + jump(H3, t4, H4) + [(T, *H4)]

def wp(t, pos, lens, aim=(0, 0, 1.0)):
    return {"t": round(t, 4), "pos": [round(v, 3) for v in pos], "lens": lens, "aim": list(aim)}
# Ramp je Etage (4 s): aus der Platte schnell hoch, langsam am Helden, schnell durch die Decke
LENS = 28   # feste Brennweite, keine Linsen-Rampe (Tariq 05.09.: "soll nicht reinzoomen")
import math
def ramp(z0, z1, T=4.0, n=24, v_peak=3.8, p=6):
    """Speed-Ramp je Etage (Tariq 05.09.: "wenn es nach oben geht muss es schnell gehen"):
    v(t) = v_mid + (v_peak - v_mid) * ((1+cos(2*pi*t/T))/2)**p, kurze scharfe Spitzen an beiden Enden
    (Schub durch die Platte), dazwischen normales Tempo am Helden. v_mid folgt aus der Strecke."""
    N = 480; dt = T / N
    f = lambda t: ((1.0 + math.cos(2 * math.pi * t / T)) / 2.0) ** p
    mean_f = sum(f(i * dt) for i in range(N)) / N
    v_mean = (z1 - z0) / T
    v_mid = (v_mean - v_peak * mean_f) / (1.0 - mean_f)
    assert v_mid > 0.15, ("Mitte zu langsam", v_mid)
    v = lambda t: v_mid + (v_peak - v_mid) * f(t)
    z = [0.0]
    for i in range(N):
        t = i * dt; z.append(z[-1] + 0.5 * (v(t) + v(t + dt)) * dt)
    k = (z1 - z0) / z[-1]
    return [(round(T * j / n, 4), round(z0 + k * z[int(round(T * j / n / dt))], 4), LENS) for j in range(n + 1)]
RISE = ramp(-0.2, 4.8)      # aus der Platte bis in die Decke
RISE0 = ramp(0.35, 4.8)     # Etage 0 startet ueber dem Asphalt: Frame 1 zeigt die Szene
RISE_TOP = RISE             # oberste Etage identisch; der Truss liegt 4,5 m ueber dem Canvas, die Kamera endet darin
DX, DY = 3.3, -3.3   # Kamera-Saeule: 4,7 m schraeg vor dem Helden (Tariq 05.09.: 3,4 m war zu nah)
def rise(H, t0, zs):
    return [wp(t0 + dt, (H[0] + DX, H[1] + DY, H[2] + dz), l) for (dt, dz, l) in zs]

CAM = dict(fit=0.80, aim_distance=5.0, subject_smooth=0, lens_smooth=6)
SHOT = {
  "name": "fightnight-vertical", "fps": FPS, "seconds": T,
  "rig": "crane",
  "limits": {"max_deg_per_s": 60.0},   # der Schub durch die Platte neigt die Kamera kurz schneller als 25 Grad/s
  "subject": {"mode": "waypoints", "size": [0.50, 0.35, 1.80], "waypoints": SUBJ},
  "shots": [
    {"t0": 0.0, "t1": t1, "name": "f0-street-suv", "camera": dict(CAM, waypoints=rise(H0, 0.0, RISE0))},
    {"t0": t1,  "t1": t2, "name": "f1-gym",        "camera": dict(CAM, waypoints=rise(H1, t1, RISE))},
    {"t0": t2,  "t1": t3, "name": "f2-icebath",    "camera": dict(CAM, waypoints=rise(H2, t2, RISE))},
    {"t0": t3,  "t1": t4, "name": "f3-circle",     "camera": dict(CAM, waypoints=rise(H3, t3, RISE))},
    {"t0": t4,  "t1": T,  "name": "f4-ring",       "camera": dict(CAM, waypoints=rise(H4, t4, RISE_TOP))},
  ],
  "beats": [
    (0.0, "level 0, the arena back entrance at night: up out of the wet asphalt, the black SUV, the crew climbing out, the trainer giving the boxer the dap; slow at his height, then up through the concrete canopy of the loading dock"),
    (4.0, "level 1, basement gym: up out of the floor, the boxer alone on the heavy bag under one lamp; slow at his height, up through the ceiling"),
    (8.0, "level 2, tiled recovery room: the boxer in the ice bath, breath steaming, the coach with the stopwatch; slow, up through the ceiling"),
    (12.0, "level 3, warm-up room: the crew in a circle clapping, the boxer shadowboxing in the centre; slow, up through the ceiling"),
    (16.0, "level 4, the arena: up out of the canvas, the boxer alone in the centre of the ring, gloves up; slow at his height, he lifts his eyes to the lens, the camera keeps rising into the lights, the bell, white"),
  ],
}
