"""
STARWASTE - Shared Constants
Common constants used across client and server
"""

# Version
VERSION = "0.1.0-alpha"
PROTOCOL_VERSION = "0.1.0"

# Display
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SCREEN_TITLE = "STARWASTE - Survive the Ruins"

# Game world
TILE_SIZE = 32
CHUNK_SIZE = 16  # tiles per chunk (16×16 = 512×512px textures for better performance)
RENDER_DISTANCE = 16  # chunks

# Physics
PLAYER_SPEED = 200  # pixels per second
PLAYER_SPRINT_MULTIPLIER = 1.5
GRAVITY = 0  # Top-down game, no gravity

# Network
DEFAULT_PORT = 5555
MAX_PACKET_SIZE = 65536
TICK_RATE = 60  # Server ticks per second

# Day/Night Cycle
GAME_MINUTES_PER_REAL_SECOND = 1.0  # 1 real second = 1 game minute (24 real minutes = full day/night cycle)
DAY_DURATION_MINUTES = 24 * 60  # 24 hours in game minutes (1440 game minutes = 24 real minutes)
SUNRISE_TIME = 6 * 60  # 6:00 (360 minutes)
NOON_TIME = 12 * 60  # 12:00 (720 minutes)
SUNSET_TIME = 18 * 60  # 18:00 (1080 minutes)
MIDNIGHT_TIME = 0  # 0:00 or 24:00 (0 or 1440 minutes)

# Player stats
MAX_HEALTH = 100
MAX_HUNGER = 100
MAX_RADIATION = 100
MAX_COLD = 100  # Cold exposure (frozen biome)
HUNGER_DECAY_RATE = 0.1  # per second

# Environmental hazards
ENVIRONMENT_DAMAGE_RATE = 1.0  # HP per second at 100% exposure
ENVIRONMENT_BUILDUP_RATE = 5.0  # Status buildup per second
ENVIRONMENT_DECAY_RATE = 2.0  # Status decay per second (when not exposed)
ENVIRONMENT_WATER_RADIUS = 640  # Distance for water-based hazards (20 tiles × 32px)

# Harvesting
HARVEST_RANGE_CLIENT = 50  # pixels - precise client-side validation (feet→horizon + pixel-perfect)
HARVEST_RANGE_SERVER = 100  # pixels - simple server-side anti-cheat (center→center with safety margin)
HARVEST_DAMAGE = 20  # base damage per harvest action

# Item pickup
PICKUP_RANGE_CLIENT = 20  # pixels - client-side auto pickup radius
PICKUP_RANGE_SERVER = 20  # pixels - server-side anti-cheat radius

# Item dropping
DROP_DISTANCE = 40  # pixels - spawn distance in front of player when dropping

# Player sprite is taller than wide; for mostly vertical interactions, add a small bonus
# so drop/pickup feels symmetric relative to the visible body.
DROP_VERTICAL_BONUS = 20  # pixels - extra drop distance when facing mostly up/down
PICKUP_VERTICAL_BONUS = 20  # pixels - extra pickup range when item is mostly above/below player

# If facing vector has at least this vertical component, treat as vertical for drop spacing.
DROP_VERTICAL_COMPONENT_THRESHOLD = 0.5

# Asset generation
ASSET_SIZES = {
    "tile": 32,
    "sprite": 32,
    "item": 32,
    "ui": 64
}

# Colors (hex)
COLORS = {
    "space_dark": "#0d1b2a",
    "space_gray": "#1b263b",
    "steel_blue": "#415a77",
    "steel_light": "#778da9",
    "off_white": "#e0e1dd",
    "rust_orange": "#ff6b35",
    "warning_yellow": "#f7931e",
    "radioactive_green": "#6a994e",
    "blood_red": "#c1121f",
}

# Biomes
BIOMES = [
    "wasteland",
    "radioactive_zone",
    "ruins",
    "dead_forest",
    "crashed_ships"
]

# Tile types (must match WorldGenerator tile IDs in server/world.py)
TILE_VOID = 0
TILE_WASTELAND = 1
TILE_RADIOACTIVE = 2
TILE_RUINS = 3
TILE_METAL = 4
TILE_DEAD_FOREST = 5
TILE_TOXIC_WATER = 6
TILE_SAND = 7
TILE_ROCK = 8
TILE_CONCRETE = 9

# Tile properties
TILE_WALKABLE = {
    TILE_VOID: False,           # Void = no-walk
    TILE_WASTELAND: True,       # Barren ground = walkable
    TILE_RADIOACTIVE: True,     # Radioactive = walkable but damages player (future)
    TILE_RUINS: True,           # Ruins = walkable
    TILE_METAL: True,           # Metal plates = walkable
    TILE_DEAD_FOREST: True,     # Dead forest floor = walkable
    TILE_TOXIC_WATER: False,    # Toxic water = NOT walkable (swim later?)
    TILE_SAND: True,            # Sand = walkable (slower movement?)
    TILE_ROCK: False,           # Rocky outcrop = NOT walkable (collision)
    TILE_CONCRETE: True,        # Concrete floor = walkable (fast movement?)
}

# Tile blocks line of sight (for future fog of war / AI visibility)
TILE_BLOCKS_SIGHT = {
    TILE_VOID: True,
    TILE_WASTELAND: False,
    TILE_RADIOACTIVE: False,
    TILE_RUINS: True,           # Ruins = blocks sight (buildings)
    TILE_METAL: False,
    TILE_DEAD_FOREST: True,     # Dead forest = partial sight blocking
    TILE_TOXIC_WATER: False,
    TILE_SAND: False,
    TILE_ROCK: True,            # Rock = blocks sight (mountains)
    TILE_CONCRETE: False,
}

# Movement speed multipliers per tile (for future implementation)
TILE_SPEED_MULTIPLIER = {
    TILE_VOID: 0.0,
    TILE_WASTELAND: 1.0,        # Normal speed
    TILE_RADIOACTIVE: 0.9,      # Slightly slower (radiation suit needed)
    TILE_RUINS: 0.8,            # Slower (rubble)
    TILE_METAL: 1.0,            # Normal
    TILE_DEAD_FOREST: 0.85,     # Slower (dead trees)
    TILE_TOXIC_WATER: 0.0,      # Can't walk
    TILE_SAND: 0.9,             # Slightly slower (sand)
    TILE_ROCK: 0.0,             # Can't walk
    TILE_CONCRETE: 1.1,         # Faster (smooth surface)
}

# Tile names (for debugging/UI)
TILE_NAMES = {
    TILE_VOID: "Void",
    TILE_WASTELAND: "Wasteland",
    TILE_RADIOACTIVE: "Radioactive Zone",
    TILE_RUINS: "Ruins",
    TILE_METAL: "Metal Field",
    TILE_DEAD_FOREST: "Dead Forest",
    TILE_TOXIC_WATER: "Toxic Water",
    TILE_SAND: "Sand",
    TILE_ROCK: "Rock",
    TILE_CONCRETE: "Concrete",
}

# Entity types
ENTITY_TYPES = {
    "PLAYER": 0,
    "NPC": 1,
    "ENEMY": 2,
    "ITEM": 3,
    "PROJECTILE": 4,
    "RESOURCE": 5,  # Resource nodes (trees, rocks, etc.)
}


# ============================================================================
# TILE HELPER FUNCTIONS
# ============================================================================

def is_tile_walkable(tile_id: int) -> bool:
    """Check if tile is walkable"""
    return TILE_WALKABLE.get(tile_id, False)


def is_tile_blocking_sight(tile_id: int) -> bool:
    """Check if tile blocks line of sight"""
    return TILE_BLOCKS_SIGHT.get(tile_id, False)


def get_tile_speed_multiplier(tile_id: int) -> float:
    """Get movement speed multiplier for tile"""
    return TILE_SPEED_MULTIPLIER.get(tile_id, 1.0)


def get_tile_name(tile_id: int) -> str:
    """Get human-readable tile name"""
    return TILE_NAMES.get(tile_id, f"Unknown Tile {tile_id}")
