""" سیستم مدیریت آب‌وهوایی و تغییرات اقلیمی """ import random from data.events.weather_events import WEATHER_EVENTS class ClimateSystem: """سیستم مدیریت آب‌وهوایی و تغییرات اقلیمی""" def __init__(self, game_state): """ساخت یک نمونه جدید از سیستم آب‌وهوایی""" self.game_state = game_state self.season = "Spring" self.season_progress = 0 self.year_progress = 0 self.season_length = 0.25 # هر فصل 0.25 سال def initialize(self): """راه‌اندازی اولیه سیستم آب‌وهوایی""" # تعیین موقعیت جغرافیایی بر اساس کشور انتخابی country = self.game_state.player_country self.region = country.get("region", "Temperate") # تنظیم پارامترهای اقلیمی اولیه self.temperature = self._get_base_temperature() self.humidity = random.randint(40, 70) self.precipitation = random.randint(20, 50) self.season = self._determine_season() # تنظیم تأثیرات اقلیمی بر کشور self._apply_climate_effects() def _get_base_temperature(self): """دریافت دمای پایه بر اساس منطقه جغرافیایی""" if self.region == "Tropical": return random.randint(25, 35) elif self.region == "Desert": return random.randint(20, 40) elif self.region == "Polar": return random.randint(-20, 10) elif self.region == "Mediterranean": return random.randint(15, 28) else: # Temperate return random.randint(10, 25) def _determine_season(self): """تعیین فصل فعلی بر اساس پیشرفت سال""" if 0 <= self.year_progress < 0.25: return "Spring" elif 0.25 <= self.year_progress < 0.5: return "Summer" elif 0.5 <= self.year_progress < 0.75: return "Autumn" else: return "Winter" def _apply_climate_effects(self): """اعمال تأثیرات آب‌وهوایی بر وضعیت بازی""" # تأثیر دما بر کشاورزی if self.temperature < 10: self.game_state.economy["agriculture"] = max(0, self.game_state.economy["agriculture"] - 5) elif self.temperature > 30: self.game_state.economy["agriculture"] = max(0, self.game_state.economy["agriculture"] - 10) # تأثیر بارش بر کشاورزی if self.precipitation < 20: self.game_state.economy["agriculture"] = max(0, self.game_state.economy["agriculture"] - 8) elif self.precipitation > 60: self.game_state.economy["agriculture"] = min(100, self.game_state.economy["agriculture"] + 5) # تأثیر رطوبت بر بهداشت if self.humidity > 70: self.game_state.health_index = max(0, self.game_state.health_index - 3) def select_weather_event(self): """انتخاب یک رویداد آب‌وهوایی بر اساس شرایط فعلی""" eligible_events = [] for event in WEATHER_EVENTS: # بررسی شرایط فعال‌سازی رویداد if self._check_event_trigger(event): eligible_events.append(event) # اگر رویداد مناسبی وجود نداشت، یک رویداد تصادفی انتخاب کن if not eligible_events: return random.choice(WEATHER_EVENTS) return random.choice(eligible_events) def _check_event_trigger(self, event): """بررسی شرایط فعال‌سازی رویداد آب‌وهوایی""" # اگر تریگری تعریف نشده باشد، همیشه فعال است if "trigger" not in event: return True # ارزیابی تریگر return event["trigger"](self) def apply_weather_event_choice(self, event, choice_idx): """اعمال انتخاب بازیکن برای رویداد آب‌وهوایی""" choice = event["choices"][choice_idx-1] effects = choice["effects"] # اعمال اثرات انتخاب self._apply_effects(effects) # ذخیره رویداد در تاریخچه self.game_state.events_history.append({ "year": self.game_state.current_year, "event": f"[آب‌وهوایی] {event['name']}", "choice": choice["text"] }) def _apply_effects(self, effects): """اعمال اثرات به وضعیت بازی""" # اثرات مالی if "gold" in effects: self.game_state.gold += effects["gold"] # اثرات کشاورزی if "agriculture" in effects: self.game_state.economy["agriculture"] = max(0, min(100, self.game_state.economy["agriculture"] + effects["agriculture"])) # اثرات بهداشت if "health_index" in effects: self.game_state.health_index = max(0, min(100, self.game_state.health_index + effects["health_index"])) # اثرات محیط زیست if "environment" in effects: for factor, value in effects["environment"].items(): if factor in self.game_state.environment: self.game_state.environment[factor] = max(0, min(100, self.game_state.environment[factor] + value)) def annual_update(self): """به‌روزرسانی‌های سالانه سیستم آب‌وهوایی""" # پیشرفت فصل self.season_progress += 0.01 self.year_progress += 0.01 # تغییر فصل if self.season_progress >= self.season_length: self.season_progress = 0 self.season = self._determine_season() # تغییرات تصادفی دما temp_change = random.randint(-2, 2) self.temperature = max(-30, min(50, self.temperature + temp_change)) # تغییرات تصادفی رطوبت humidity_change = random.randint(-5, 5) self.humidity = max(0, min(100, self.humidity + humidity_change)) # تغییرات تصادفی بارش precip_change = random.randint(-10, 10) self.precipitation = max(0, min(100, self.precipitation + precip_change)) # اعمال تأثیرات جدید آب‌وهوایی self._apply_climate_effects() # بررسی رویدادهای آب‌وهوایی if random.random() < 0.2: # 20% احتمال وقوع رویداد آب‌وهوایی weather_event = self.select_weather_event() if weather_event: from ui.console_ui import ConsoleUI ConsoleUI.display_weather_event(weather_event) choice = ConsoleUI.get_player_choice(weather_event["choices"]) self.apply_weather_event_choice(weather_event, choice)