mud/src/mudlib/visibility.py
Jared Miller 4c4d947ce2
Add visibility system for time and weather effects
Night, fog, and storms now reduce viewport size. Night reduces by 6
width and 2 height (21x11 -> 15x9). Thick fog reduces by 8 width and 4
height. Storm reduces by 4 width and 2 height. Effects stack but clamp
to minimum 7x5. Dawn and dusk subtly dim by 2 width.
2026-02-14 16:20:00 -05:00

54 lines
1.3 KiB
Python

"""Visibility calculations based on time and weather."""
from mudlib.weather import WeatherCondition, WeatherState
def get_visibility(
hour: int,
weather: WeatherState,
base_width: int = 21,
base_height: int = 11,
) -> tuple[int, int]:
"""Calculate effective viewport dimensions.
Night, fog, and storms reduce visibility. Multiple effects stack
but never reduce below minimum (7x5).
Returns:
Tuple of (effective_width, effective_height)
"""
width = base_width
height = base_height
# Time-based reductions
if hour >= 20 or hour <= 4:
# Night (hours 20-4)
width -= 6
height -= 2
elif 5 <= hour <= 6:
# Dawn (hours 5-6)
width -= 2
elif 18 <= hour <= 19:
# Dusk (hours 18-19)
width -= 2
# Weather-based reductions
if weather.condition == WeatherCondition.fog:
if weather.intensity >= 0.7:
# Thick fog
width -= 8
height -= 4
elif weather.intensity >= 0.4:
# Moderate fog
width -= 4
height -= 2
elif weather.condition == WeatherCondition.storm:
# Storm
width -= 4
height -= 2
# Clamp to minimum
width = max(7, width)
height = max(5, height)
return width, height