"""Centralized constant values and render assets for zombie_escape."""

from __future__ import annotations

from .level_blueprints import GRID_COLS, GRID_ROWS, TILE_SIZE
from .render_assets import FogRing, RenderAssets

# --- Screen and window configuration ---
SCREEN_WIDTH = 400  # Base logical render width
SCREEN_HEIGHT = 300  # Base logical render height
DEFAULT_WINDOW_SCALE = 2.0  # Keep ~800x600 OS window while rendering at 400x300
WINDOW_SCALE_MIN = 1.0
WINDOW_SCALE_MAX = DEFAULT_WINDOW_SCALE * 2  # Allow up to 1600x1200 windows
FPS = 60
STATUS_BAR_HEIGHT = 18

# --- Survival stage settings ---
SURVIVAL_TIME_ACCEL_SUBSTEPS = 4
SURVIVAL_TIME_ACCEL_MAX_SUBSTEP = 1.0 / 30.0
SURVIVAL_FAKE_CLOCK_RATIO = 12.0  # 20 min -> 4 hr clock
SURVIVAL_NEAR_SPAWN_MIN_DISTANCE = 140
SURVIVAL_NEAR_SPAWN_MAX_DISTANCE = 280
SURVIVAL_NEAR_SPAWN_CAMERA_MARGIN = 20

# --- Level dimensions derived from blueprint grid ---
LEVEL_GRID_COLS = GRID_COLS
LEVEL_GRID_ROWS = GRID_ROWS
CELL_SIZE = TILE_SIZE
LEVEL_WIDTH = LEVEL_GRID_COLS * CELL_SIZE
LEVEL_HEIGHT = LEVEL_GRID_ROWS * CELL_SIZE

# --- Player and companion settings ---
HUMANOID_RADIUS = 6
def interaction_radius(width: float, height: float) -> float:
    """Approximate interaction reach for a humanoid and an object."""
    return HUMANOID_RADIUS + (width + height) / 4


def car_body_radius(width: float, height: float) -> float:
    """Approximate car collision radius using only its own dimensions."""
    return min(width, height) / 2

PLAYER_RADIUS = HUMANOID_RADIUS
PLAYER_SPEED = 1.4
FOV_RADIUS = 124  # approximate legacy FOV (80) * 1.55 cap
FOG_RADIUS_SCALE = 1.2
FOG_HATCH_PIXEL_SCALE = 2
COMPANION_RADIUS = HUMANOID_RADIUS
COMPANION_FOLLOW_SPEED = PLAYER_SPEED * 0.7
COMPANION_COLOR = (0, 200, 70)

# --- Survivor settings (Stage 4) ---
SURVIVOR_RADIUS = HUMANOID_RADIUS
SURVIVOR_COLOR = (220, 220, 255)
SURVIVOR_APPROACH_RADIUS = 48
SURVIVOR_APPROACH_SPEED = PLAYER_SPEED * 0.35
SURVIVOR_SPAWN_RATE = 0.07
SURVIVOR_MAX_SAFE_PASSENGERS = 5
SURVIVOR_SPEED_PENALTY_PER_PASSENGER = 0.08
SURVIVOR_MIN_SPEED_FACTOR = 0.35
SURVIVOR_OVERLOAD_DAMAGE_RATIO = 0.2
SURVIVOR_MESSAGE_DURATION_MS = 2000
SURVIVOR_CONVERSION_LINE_KEYS = [
    "stages.stage4.conversion_lines.line1",
    "stages.stage4.conversion_lines.line2",
    "stages.stage4.conversion_lines.line3",
]
SURVIVOR_STAGE_WAITING_CAR_COUNT = 2

# --- Flashlight settings ---
FLASHLIGHT_FOG_SCALE_STEP = 0.3
FLASHLIGHT_WIDTH = 10
FLASHLIGHT_HEIGHT = 8
DEFAULT_FLASHLIGHT_SPAWN_COUNT = 2

# --- Footprint settings ---
FOOTPRINT_RADIUS = 2
FOOTPRINT_OVERVIEW_RADIUS = 3
FOOTPRINT_COLOR = (110, 200, 255)
FOOTPRINT_STEP_DISTANCE = 40
FOOTPRINT_LIFETIME_MS = 135000
FOOTPRINT_MAX = 320
FOOTPRINT_MIN_FADE = 0.3

# --- Zombie settings ---
ZOMBIE_RADIUS = HUMANOID_RADIUS
ZOMBIE_SPEED = 0.6
NORMAL_ZOMBIE_SPEED_JITTER = 0.15
ZOMBIE_SPAWN_DELAY_MS = 4000
MAX_ZOMBIES = 400
INITIAL_ZOMBIES_INSIDE = 15
ZOMBIE_INTERIOR_SPAWN_RATE = 0.015
ZOMBIE_SPAWN_PLAYER_BUFFER = 140
ZOMBIE_MODE_CHANGE_INTERVAL_MS = 5000
ZOMBIE_SIGHT_RANGE = FOV_RADIUS * 1.2
FAST_ZOMBIE_BASE_SPEED = PLAYER_SPEED * 0.77
FAST_ZOMBIE_SPEED_JITTER = 0.075
ZOMBIE_SEPARATION_DISTANCE = ZOMBIE_RADIUS * 2.2
ZOMBIE_AGING_DURATION_FRAMES = FPS * 60 * 6  # ~6 minutes at target framerate
ZOMBIE_AGING_MIN_SPEED_RATIO = 0.3

# --- Car and fuel settings ---
CAR_WIDTH = 15
CAR_HEIGHT = 25
CAR_SPEED = 2
CAR_HEALTH = 20
CAR_WALL_DAMAGE = 1
CAR_ZOMBIE_DAMAGE = 1
CAR_HINT_DELAY_MS_DEFAULT = 300000
FUEL_CAN_WIDTH = 11
FUEL_CAN_HEIGHT = 15
FUEL_HINT_DURATION_MS = 1600

# --- Wall and beam settings ---
INTERNAL_WALL_GRID_SNAP = CELL_SIZE
INTERNAL_WALL_HEALTH = 40 * 100
OUTER_WALL_HEALTH = 999999
STEEL_BEAM_HEALTH = int(INTERNAL_WALL_HEALTH * 1.5)
PLAYER_WALL_DAMAGE = 100
ZOMBIE_WALL_DAMAGE = 1

# --- Rendering assets shared with draw routines ---
FOG_RINGS = [
    FogRing(radius_factor=0.529, thickness=2),
    FogRing(radius_factor=0.639, thickness=4),
    FogRing(radius_factor=0.748, thickness=6),
    FogRing(radius_factor=0.858, thickness=8),
    FogRing(radius_factor=0.968, thickness=12),
]

RENDER_ASSETS = RenderAssets(
    screen_width=SCREEN_WIDTH,
    screen_height=SCREEN_HEIGHT,
    status_bar_height=STATUS_BAR_HEIGHT,
    player_radius=PLAYER_RADIUS,
    fov_radius=FOV_RADIUS,
    fog_radius_scale=FOG_RADIUS_SCALE,
    fog_hatch_pixel_scale=FOG_HATCH_PIXEL_SCALE,
    fog_rings=FOG_RINGS,
    footprint_radius=FOOTPRINT_RADIUS,
    footprint_overview_radius=FOOTPRINT_OVERVIEW_RADIUS,
    footprint_lifetime_ms=FOOTPRINT_LIFETIME_MS,
    footprint_min_fade=FOOTPRINT_MIN_FADE,
    internal_wall_grid_snap=INTERNAL_WALL_GRID_SNAP,
    flashlight_bonus_step=FLASHLIGHT_FOG_SCALE_STEP,
)

__all__ = [
    "DEFAULT_WINDOW_SCALE",
    "WINDOW_SCALE_MIN",
    "WINDOW_SCALE_MAX",
    "SCREEN_WIDTH",
    "SCREEN_HEIGHT",
    "FPS",
    "LEVEL_GRID_COLS",
    "LEVEL_GRID_ROWS",
    "CELL_SIZE",
    "LEVEL_WIDTH",
    "LEVEL_HEIGHT",
    "HUMANOID_RADIUS",
    "interaction_radius",
    "PLAYER_RADIUS",
    "PLAYER_SPEED",
    "COMPANION_RADIUS",
    "COMPANION_FOLLOW_SPEED",
    "COMPANION_COLOR",
    "SURVIVOR_RADIUS",
    "SURVIVOR_COLOR",
    "SURVIVOR_APPROACH_RADIUS",
    "SURVIVOR_APPROACH_SPEED",
    "SURVIVOR_SPAWN_RATE",
    "SURVIVOR_MAX_SAFE_PASSENGERS",
    "SURVIVOR_SPEED_PENALTY_PER_PASSENGER",
    "SURVIVOR_MIN_SPEED_FACTOR",
    "SURVIVOR_OVERLOAD_DAMAGE_RATIO",
    "SURVIVOR_MESSAGE_DURATION_MS",
    "SURVIVOR_CONVERSION_LINE_KEYS",
    "SURVIVOR_STAGE_WAITING_CAR_COUNT",
    "SURVIVAL_TIME_ACCEL_SUBSTEPS",
    "SURVIVAL_TIME_ACCEL_MAX_SUBSTEP",
    "SURVIVAL_FAKE_CLOCK_RATIO",
    "SURVIVAL_NEAR_SPAWN_MIN_DISTANCE",
    "SURVIVAL_NEAR_SPAWN_MAX_DISTANCE",
    "SURVIVAL_NEAR_SPAWN_CAMERA_MARGIN",
    "FLASHLIGHT_WIDTH",
    "FLASHLIGHT_HEIGHT",
    "DEFAULT_FLASHLIGHT_SPAWN_COUNT",
    "FOOTPRINT_COLOR",
    "FOOTPRINT_STEP_DISTANCE",
    "FOOTPRINT_MAX",
    "ZOMBIE_RADIUS",
    "ZOMBIE_SPEED",
    "NORMAL_ZOMBIE_SPEED_JITTER",
    "ZOMBIE_SPAWN_DELAY_MS",
    "MAX_ZOMBIES",
    "INITIAL_ZOMBIES_INSIDE",
    "ZOMBIE_INTERIOR_SPAWN_RATE",
    "ZOMBIE_SPAWN_PLAYER_BUFFER",
    "ZOMBIE_MODE_CHANGE_INTERVAL_MS",
    "ZOMBIE_SIGHT_RANGE",
    "FAST_ZOMBIE_BASE_SPEED",
    "FAST_ZOMBIE_SPEED_JITTER",
    "ZOMBIE_SEPARATION_DISTANCE",
    "ZOMBIE_AGING_DURATION_FRAMES",
    "ZOMBIE_AGING_MIN_SPEED_RATIO",
    "car_body_radius",
    "CAR_WIDTH",
    "CAR_HEIGHT",
    "CAR_SPEED",
    "CAR_HEALTH",
    "CAR_WALL_DAMAGE",
    "CAR_ZOMBIE_DAMAGE",
    "CAR_HINT_DELAY_MS_DEFAULT",
    "FUEL_CAN_WIDTH",
    "FUEL_CAN_HEIGHT",
    "FUEL_HINT_DURATION_MS",
    "INTERNAL_WALL_HEALTH",
    "OUTER_WALL_HEALTH",
    "STEEL_BEAM_HEALTH",
    "PLAYER_WALL_DAMAGE",
    "ZOMBIE_WALL_DAMAGE",
    "RENDER_ASSETS",
]
