| | """
|
| | سیستم مدیریت آبوهوایی و تغییرات اقلیمی
|
| | """
|
| |
|
| | 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
|
| |
|
| | 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:
|
| | 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:
|
| | 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) |