"""Gameplay-related constants and helpers."""

from __future__ import annotations

from .screen_constants import FPS

# --- 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

# --- Player and buddy settings ---
HUMANOID_RADIUS = 6
HUMANOID_OUTLINE_COLOR = (0, 80, 200)
HUMANOID_OUTLINE_WIDTH = 1


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
BUDDY_RADIUS = HUMANOID_RADIUS
BUDDY_FOLLOW_SPEED = PLAYER_SPEED * 0.7
BUDDY_COLOR = (0, 180, 63)

# --- Survivor settings (Stage 4) ---
SURVIVOR_RADIUS = HUMANOID_RADIUS
SURVIVOR_COLOR = (198, 198, 198)
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_WIDTH = 10
FLASHLIGHT_HEIGHT = 8
DEFAULT_FLASHLIGHT_SPAWN_COUNT = 2

# --- Footprint settings (gameplay) ---
FOOTPRINT_STEP_DISTANCE = 40
FOOTPRINT_MAX = 320

# --- Zombie settings ---
ZOMBIE_RADIUS = HUMANOID_RADIUS
ZOMBIE_SPEED = PLAYER_SPEED * 0.45
ZOMBIE_SPAWN_DELAY_MS = 4000
MAX_ZOMBIES = 400
ZOMBIE_SPAWN_PLAYER_BUFFER = 140
ZOMBIE_WANDER_INTERVAL_MS = 5000
ZOMBIE_SIGHT_RANGE = FOV_RADIUS * 1.2
ZOMBIE_TRACKER_SIGHT_RANGE = ZOMBIE_SIGHT_RANGE * 0.2
FAST_ZOMBIE_BASE_SPEED = PLAYER_SPEED * 0.77
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
ZOMBIE_TRACKER_SCENT_RADIUS = 70
ZOMBIE_TRACKER_WANDER_INTERVAL_MS = 2500
ZOMBIE_TRACKER_AGING_DURATION_FRAMES = ZOMBIE_AGING_DURATION_FRAMES
ZOMBIE_WALL_FOLLOW_SENSOR_DISTANCE = 24
ZOMBIE_WALL_FOLLOW_PROBE_ANGLE_DEG = 45
ZOMBIE_WALL_FOLLOW_PROBE_STEP = 2.0
ZOMBIE_WALL_FOLLOW_TARGET_GAP = 4.0
ZOMBIE_WALL_FOLLOW_LOST_WALL_MS = 2500

# --- 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_HEALTH = 40 * 100
INTERNAL_WALL_BEVEL_DEPTH = 14
OUTER_WALL_HEALTH = 999999
STEEL_BEAM_HEALTH = int(INTERNAL_WALL_HEALTH * 1.5)
PLAYER_WALL_DAMAGE = 100
ZOMBIE_WALL_DAMAGE = 1

__all__ = [
    "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",
    "HUMANOID_RADIUS",
    "HUMANOID_OUTLINE_COLOR",
    "HUMANOID_OUTLINE_WIDTH",
    "interaction_radius",
    "car_body_radius",
    "PLAYER_RADIUS",
    "PLAYER_SPEED",
    "FOV_RADIUS",
    "BUDDY_RADIUS",
    "BUDDY_FOLLOW_SPEED",
    "BUDDY_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",
    "FLASHLIGHT_WIDTH",
    "FLASHLIGHT_HEIGHT",
    "DEFAULT_FLASHLIGHT_SPAWN_COUNT",
    "FOOTPRINT_STEP_DISTANCE",
    "FOOTPRINT_MAX",
    "ZOMBIE_RADIUS",
    "ZOMBIE_SPEED",
    "ZOMBIE_SPAWN_DELAY_MS",
    "MAX_ZOMBIES",
    "ZOMBIE_SPAWN_PLAYER_BUFFER",
    "ZOMBIE_WANDER_INTERVAL_MS",
    "ZOMBIE_SIGHT_RANGE",
    "ZOMBIE_TRACKER_SIGHT_RANGE",
    "FAST_ZOMBIE_BASE_SPEED",
    "ZOMBIE_SEPARATION_DISTANCE",
    "ZOMBIE_AGING_DURATION_FRAMES",
    "ZOMBIE_AGING_MIN_SPEED_RATIO",
    "ZOMBIE_TRACKER_SCENT_RADIUS",
    "ZOMBIE_TRACKER_WANDER_INTERVAL_MS",
    "ZOMBIE_TRACKER_AGING_DURATION_FRAMES",
    "ZOMBIE_WALL_FOLLOW_SENSOR_DISTANCE",
    "ZOMBIE_WALL_FOLLOW_PROBE_ANGLE_DEG",
    "ZOMBIE_WALL_FOLLOW_PROBE_STEP",
    "ZOMBIE_WALL_FOLLOW_TARGET_GAP",
    "ZOMBIE_WALL_FOLLOW_LOST_WALL_MS",
    "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",
    "INTERNAL_WALL_BEVEL_DEPTH",
    "OUTER_WALL_HEALTH",
    "STEEL_BEAM_HEALTH",
    "PLAYER_WALL_DAMAGE",
    "ZOMBIE_WALL_DAMAGE",
]
