"""Entity-related constants and helpers."""

from __future__ import annotations

from enum import Enum

from .screen_constants import FPS


class ZombieKind(str, Enum):
    NORMAL = "normal"
    TRACKER = "tracker"
    WALL_HUGGER = "wall_hugging"
    LINEFORMER = "lineformer"
    SOLITARY = "solitary"
    DOG = "dog"


class MovingFloorDirection(str, Enum):
    UP = "U"
    DOWN = "D"
    LEFT = "L"
    RIGHT = "R"


# --- Player and buddy settings ---
HUMANOID_RADIUS = 6
PLAYER_RADIUS = HUMANOID_RADIUS
PLAYER_SPEED = 1.4
MOVING_FLOOR_SPEED = 1.6
FOV_RADIUS = 124  # approximate legacy FOV (80) * 1.55 cap
BUDDY_RADIUS = HUMANOID_RADIUS
BUDDY_FOLLOW_SPEED = PLAYER_SPEED * 0.7
BUDDY_FOLLOW_START_DISTANCE = 30
BUDDY_FOLLOW_STOP_DISTANCE = 100
BUDDY_WALL_DAMAGE_RANGE = 50
BUDDY_MERGE_DISTANCE = 40
HUMANOID_WALL_BUMP_FRAMES = 7
HUMANOID_WALL_BUMP_HOLD_FRAMES = 4
HUMANOID_WALL_BUMP_HOLD_FRAMES = 4

# --- Jump settings ---
PLAYER_JUMP_RANGE = 15  # px (enough to clear one 50px cell)
SURVIVOR_JUMP_RANGE = int(PLAYER_JUMP_RANGE * 0.7)  # px
JUMP_DURATION_MS = 200
JUMP_SCALE_MAX = 0.15
JUMP_SHADOW_OFFSET = 5

# --- Survivor settings (Stage 4) ---
SURVIVOR_RADIUS = HUMANOID_RADIUS
SURVIVOR_APPROACH_RADIUS = 48
SURVIVOR_APPROACH_SPEED = PLAYER_SPEED * 0.35
SURVIVOR_MAX_SAFE_PASSENGERS = 5
SURVIVOR_MIN_SPEED_FACTOR = 0.35

# --- Flashlight settings ---
FLASHLIGHT_WIDTH = 12
FLASHLIGHT_HEIGHT = 10

# --- Shoes settings ---
SHOES_WIDTH = 14
SHOES_HEIGHT = 12

# --- Zombie settings ---
ZOMBIE_RADIUS = HUMANOID_RADIUS
ZOMBIE_SPEED = PLAYER_SPEED * 0.45
ZOMBIE_WANDER_INTERVAL_MS = 5000
ZOMBIE_SIGHT_RANGE = FOV_RADIUS * 1.2
FAST_ZOMBIE_BASE_SPEED = PLAYER_SPEED * 0.77
ZOMBIE_SEPARATION_DISTANCE = ZOMBIE_RADIUS * 2.2
ZOMBIE_DECAY_DURATION_FRAMES = FPS * 60 * 6  # ~6 minutes at target framerate
ZOMBIE_DECAY_MIN_SPEED_RATIO = 0.4
ZOMBIE_TRACKER_SIGHT_RANGE = ZOMBIE_SIGHT_RANGE * 0.2
ZOMBIE_TRACKER_SCENT_RADIUS = 70
ZOMBIE_TRACKER_FAR_SCENT_RADIUS = 140
ZOMBIE_TRACKER_NEWER_FOOTPRINT_MS = 5000
ZOMBIE_TRACKER_SCENT_TOP_K = 3
ZOMBIE_TRACKER_SCAN_INTERVAL_MS = int(1000 * 30 / FPS)
ZOMBIE_TRACKER_WANDER_INTERVAL_MS = 2500
ZOMBIE_TRACKER_CROWD_BAND_WIDTH = 32
ZOMBIE_TRACKER_GRID_CROWD_COUNT = 3
ZOMBIE_TRACKER_RELOCK_DELAY_MS = 3000
ZOMBIE_SOLITARY_SIGHT_RANGE = ZOMBIE_TRACKER_SIGHT_RANGE
ZOMBIE_WALL_HUG_SENSOR_DISTANCE = 30.0
ZOMBIE_WALL_HUG_SENSOR_DIST_RATIO = 0.6
ZOMBIE_WALL_HUG_PROBE_ANGLE_DEG = 55.0
ZOMBIE_WALL_HUG_PROBE_ANGLE_PERP_DEG = 90.0
ZOMBIE_WALL_HUG_TARGET_GAP = 4.2
ZOMBIE_WALL_HUG_LOST_WALL_MS = 2500
ZOMBIE_WALL_HUG_TURN_STEP_DEG = 10.0
ZOMBIE_LINEFORMER_SPEED_MULTIPLIER = 1.4
ZOMBIE_LINEFORMER_JOIN_RADIUS = 50
ZOMBIE_LINEFORMER_FOLLOW_DISTANCE = ZOMBIE_RADIUS * 2.5
ZOMBIE_LINEFORMER_FOLLOW_TOLERANCE = ZOMBIE_RADIUS * 0.6
ZOMBIE_LINEFORMER_DISSOLVE_SPAWN_MS = 120
ZOMBIE_SOLITARY_EVAL_INTERVAL_FRAMES = 10
ZOMBIE_CARBONIZE_DECAY_FRAMES = FPS * 30

# --- Zombie dog settings ---
ZOMBIE_DOG_PATROL_SPEED = PLAYER_SPEED * 0.3
ZOMBIE_DOG_ASSAULT_SPEED = PLAYER_SPEED * 1.6
ZOMBIE_DOG_SIGHT_RANGE = 150
ZOMBIE_DOG_SURVIVOR_SIGHT_RANGE = 50
ZOMBIE_DOG_LONG_AXIS_RATIO = 1.2
ZOMBIE_DOG_SHORT_AXIS_RATIO = 0.6
ZOMBIE_DOG_WANDER_INTERVAL_MS = 1200
ZOMBIE_DOG_PACK_CHASE_RANGE = 50
ZOMBIE_DOG_CHARGE_OFFSET_MIN_NORMAL = 6.0
ZOMBIE_DOG_CHARGE_OFFSET_MAX_NORMAL = 18.0
ZOMBIE_DOG_CHARGE_OFFSET_MIN_NIMBLE = 24.0
ZOMBIE_DOG_CHARGE_OFFSET_MAX_NIMBLE = 60.0
ZOMBIE_DOG_CHARGE_DISTANCE_NORMAL = 480.0
ZOMBIE_DOG_CHARGE_DISTANCE_NIMBLE = 40.0
ZOMBIE_DOG_CHARGE_COOLDOWN_MS_NORMAL = 120
ZOMBIE_DOG_CHARGE_COOLDOWN_MS_NIMBLE = 1200
ZOMBIE_DOG_DECAY_DURATION_FRAMES = max(1, int(ZOMBIE_DECAY_DURATION_FRAMES * 0.5))
ZOMBIE_DOG_DECAY_MIN_SPEED_RATIO = 0.6

# --- Patrol bot settings ---
PATROL_BOT_SPRITE_SIZE = 20
PATROL_BOT_COLLISION_RADIUS = 10.0
PATROL_BOT_DIRECTION_COMMAND_RADIUS = PATROL_BOT_COLLISION_RADIUS * 0.625
PATROL_BOT_DIRECTION_COMMAND_HOLD_MS = 1800
PATROL_BOT_SPEED = PLAYER_SPEED * 0.6
PATROL_BOT_HUMANOID_PAUSE_MS = 500
PATROL_BOT_ZOMBIE_DAMAGE_INTERVAL_FRAMES = 4
PATROL_BOT_PARALYZE_MS = 3000
PATROL_BOT_PARALYZE_BLINK_MS = 200
PATROL_BOT_PARALYZE_MARKER_COLOR = (250, 240, 170)
PATROL_BOT_COLLISION_MARGIN = 4.0

# --- Car and fuel settings ---
CAR_WIDTH = 16
CAR_HEIGHT = 24
CAR_SPEED = 2
CAR_HEALTH = 1000
CAR_WALL_DAMAGE = 20
CAR_PITFALL_FALL_CENTER_RATIO = 0.18
FUEL_CAN_WIDTH = 12
FUEL_CAN_HEIGHT = 15
EMPTY_FUEL_CAN_WIDTH = 12
EMPTY_FUEL_CAN_HEIGHT = 15
FUEL_STATION_WIDTH = 14
FUEL_STATION_HEIGHT = 18

# --- Spiky plant settings ---
SPIKY_PLANT_HEALTH = 300
SPIKY_PLANT_RADIUS = 8
SPIKY_PLANT_COLLISION_RADIUS = 8
SPIKY_PLANT_HUMANOID_SPEED_FACTOR = 0.2
SPIKY_PLANT_CAR_SPEED_FACTOR = 0.2

# --- Puddle settings ---
PUDDLE_SPEED_FACTOR = 0.3
ZOMBIE_CONTAMINATED_SPEED_FACTOR = SPIKY_PLANT_HUMANOID_SPEED_FACTOR
TRAPPED_ZOMBIE_SLOW_FACTOR = SPIKY_PLANT_HUMANOID_SPEED_FACTOR
TRAPPED_ZOMBIE_REPEL_PER_STACK = 0.18
TRAPPED_ZOMBIE_REPEL_MAX_MULT = 1.2
TRAPPED_ZOMBIE_REPEL_RADIUS_CELLS = 1.2

# --- Wall and beam settings ---
INTERNAL_WALL_HEALTH = 40 * 100
INTERNAL_WALL_BEVEL_DEPTH = 6
STEEL_BEAM_HEALTH = int(INTERNAL_WALL_HEALTH * 1.5)
PLAYER_WALL_DAMAGE = 100
BUDDY_WALL_DAMAGE = int(PLAYER_WALL_DAMAGE * 0.7)
ZOMBIE_WALL_DAMAGE = 1
PATROL_BOT_ZOMBIE_DAMAGE = 1

__all__ = [
    "HUMANOID_RADIUS",
    "PLAYER_RADIUS",
    "PLAYER_SPEED",
    "FOV_RADIUS",
    "BUDDY_RADIUS",
    "BUDDY_FOLLOW_SPEED",
    "BUDDY_FOLLOW_START_DISTANCE",
    "BUDDY_FOLLOW_STOP_DISTANCE",
    "BUDDY_WALL_DAMAGE_RANGE",
    "BUDDY_MERGE_DISTANCE",
    "HUMANOID_WALL_BUMP_FRAMES",
    "HUMANOID_WALL_BUMP_HOLD_FRAMES",
    "HUMANOID_WALL_BUMP_HOLD_FRAMES",
    "SURVIVOR_RADIUS",
    "SURVIVOR_APPROACH_RADIUS",
    "SURVIVOR_APPROACH_SPEED",
    "SURVIVOR_MAX_SAFE_PASSENGERS",
    "SURVIVOR_MIN_SPEED_FACTOR",
    "FLASHLIGHT_WIDTH",
    "FLASHLIGHT_HEIGHT",
    "SHOES_WIDTH",
    "SHOES_HEIGHT",
    "ZombieKind",
    "ZOMBIE_RADIUS",
    "ZOMBIE_SPEED",
    "ZOMBIE_WANDER_INTERVAL_MS",
    "ZOMBIE_SIGHT_RANGE",
    "ZOMBIE_TRACKER_SIGHT_RANGE",
    "FAST_ZOMBIE_BASE_SPEED",
    "ZOMBIE_SEPARATION_DISTANCE",
    "ZOMBIE_DECAY_DURATION_FRAMES",
    "ZOMBIE_DECAY_MIN_SPEED_RATIO",
    "ZOMBIE_CARBONIZE_DECAY_FRAMES",
    "ZOMBIE_DOG_DECAY_DURATION_FRAMES",
    "ZOMBIE_DOG_DECAY_MIN_SPEED_RATIO",
    "ZOMBIE_TRACKER_SCENT_RADIUS",
    "ZOMBIE_TRACKER_FAR_SCENT_RADIUS",
    "ZOMBIE_TRACKER_NEWER_FOOTPRINT_MS",
    "ZOMBIE_TRACKER_SCENT_TOP_K",
    "ZOMBIE_TRACKER_SCAN_INTERVAL_MS",
    "ZOMBIE_TRACKER_WANDER_INTERVAL_MS",
    "ZOMBIE_TRACKER_CROWD_BAND_WIDTH",
    "ZOMBIE_TRACKER_GRID_CROWD_COUNT",
    "ZOMBIE_TRACKER_RELOCK_DELAY_MS",
    "ZOMBIE_SOLITARY_SIGHT_RANGE",
    "ZOMBIE_WALL_HUG_SENSOR_DISTANCE",
    "ZOMBIE_WALL_HUG_SENSOR_DIST_RATIO",
    "ZOMBIE_WALL_HUG_PROBE_ANGLE_DEG",
    "ZOMBIE_WALL_HUG_TARGET_GAP",
    "ZOMBIE_WALL_HUG_LOST_WALL_MS",
    "ZOMBIE_LINEFORMER_SPEED_MULTIPLIER",
    "ZOMBIE_LINEFORMER_JOIN_RADIUS",
    "ZOMBIE_LINEFORMER_FOLLOW_DISTANCE",
    "ZOMBIE_LINEFORMER_FOLLOW_TOLERANCE",
    "ZOMBIE_LINEFORMER_DISSOLVE_SPAWN_MS",
    "ZOMBIE_SOLITARY_EVAL_INTERVAL_FRAMES",
    "ZOMBIE_DOG_PATROL_SPEED",
    "ZOMBIE_DOG_ASSAULT_SPEED",
    "ZOMBIE_DOG_SIGHT_RANGE",
    "ZOMBIE_DOG_SURVIVOR_SIGHT_RANGE",
    "ZOMBIE_DOG_LONG_AXIS_RATIO",
    "ZOMBIE_DOG_SHORT_AXIS_RATIO",
    "ZOMBIE_DOG_WANDER_INTERVAL_MS",
    "ZOMBIE_DOG_PACK_CHASE_RANGE",
    "ZOMBIE_DOG_CHARGE_OFFSET_MIN_NORMAL",
    "ZOMBIE_DOG_CHARGE_OFFSET_MAX_NORMAL",
    "ZOMBIE_DOG_CHARGE_OFFSET_MIN_NIMBLE",
    "ZOMBIE_DOG_CHARGE_OFFSET_MAX_NIMBLE",
    "ZOMBIE_DOG_CHARGE_DISTANCE_NORMAL",
    "ZOMBIE_DOG_CHARGE_DISTANCE_NIMBLE",
    "ZOMBIE_DOG_CHARGE_COOLDOWN_MS_NORMAL",
    "ZOMBIE_DOG_CHARGE_COOLDOWN_MS_NIMBLE",
    "MovingFloorDirection",
    "MOVING_FLOOR_SPEED",
    "PATROL_BOT_SPRITE_SIZE",
    "PATROL_BOT_COLLISION_RADIUS",
    "PATROL_BOT_DIRECTION_COMMAND_RADIUS",
    "PATROL_BOT_DIRECTION_COMMAND_HOLD_MS",
    "PATROL_BOT_SPEED",
    "PATROL_BOT_HUMANOID_PAUSE_MS",
    "PATROL_BOT_ZOMBIE_DAMAGE_INTERVAL_FRAMES",
    "PATROL_BOT_PARALYZE_MS",
    "PATROL_BOT_PARALYZE_BLINK_MS",
    "PATROL_BOT_PARALYZE_MARKER_COLOR",
    "PATROL_BOT_COLLISION_MARGIN",
    "CAR_WIDTH",
    "CAR_HEIGHT",
    "CAR_SPEED",
    "CAR_HEALTH",
    "CAR_WALL_DAMAGE",
    "CAR_PITFALL_FALL_CENTER_RATIO",
    "FUEL_CAN_WIDTH",
    "FUEL_CAN_HEIGHT",
    "EMPTY_FUEL_CAN_WIDTH",
    "EMPTY_FUEL_CAN_HEIGHT",
    "FUEL_STATION_WIDTH",
    "FUEL_STATION_HEIGHT",
    "SPIKY_PLANT_HEALTH",
    "SPIKY_PLANT_RADIUS",
    "SPIKY_PLANT_COLLISION_RADIUS",
    "SPIKY_PLANT_HUMANOID_SPEED_FACTOR",
    "SPIKY_PLANT_CAR_SPEED_FACTOR",
    "PUDDLE_SPEED_FACTOR",
    "TRAPPED_ZOMBIE_SLOW_FACTOR",
    "TRAPPED_ZOMBIE_REPEL_PER_STACK",
    "TRAPPED_ZOMBIE_REPEL_MAX_MULT",
    "TRAPPED_ZOMBIE_REPEL_RADIUS_CELLS",
    "INTERNAL_WALL_HEALTH",
    "INTERNAL_WALL_BEVEL_DEPTH",
    "STEEL_BEAM_HEALTH",
    "PLAYER_WALL_DAMAGE",
    "BUDDY_WALL_DAMAGE",
    "ZOMBIE_WALL_DAMAGE",
    "PATROL_BOT_ZOMBIE_DAMAGE",
]
