File size: 7,613 Bytes
89dc309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
"""

سیستم مدیریت آب‌وهوایی و تغییرات اقلیمی

"""

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)