| """
|
| سیستم مدیریت بحرانها و پاسخ به حوادث غیرمنتظره
|
| """
|
|
|
| class CrisisManagement:
|
| """سیستم مدیریت بحرانها و پاسخ به حوادث غیرمنتظره"""
|
|
|
| def __init__(self, game_state):
|
| """ساخت یک نمونه جدید از سیستم مدیریت بحران"""
|
| self.game_state = game_state
|
| self.active_crises = []
|
| self.crisis_history = []
|
|
|
| def initialize(self):
|
| """راهاندازی اولیه سیستم مدیریت بحران"""
|
|
|
| self.game_state.crisis_level = 0
|
|
|
|
|
| country = self.game_state.player_country
|
| if "initial_crises" in country:
|
| self.active_crises.extend(country["initial_crises"])
|
|
|
| def display_crisis_status(self):
|
| """نمایش وضعیت بحرانهای فعلی"""
|
| from ui.console_ui import ConsoleUI
|
|
|
| ConsoleUI.clear_screen()
|
| ConsoleUI.display_section_title("وضعیت بحرانها")
|
|
|
| if not self.active_crises:
|
| ConsoleUI.display_message("هیچ بحران فعالی در حال حاضر وجود ندارد.", indent=2)
|
| else:
|
| ConsoleUI.display_message(f"تعداد بحرانهای فعال: {len(self.active_crises)}", indent=2)
|
| ConsoleUI.display_message(f"سطح کلی بحران: {self.game_state.crisis_level}/100", indent=2)
|
|
|
| ConsoleUI.display_section_title("بحرانهای فعال", width=60)
|
| for i, crisis in enumerate(self.active_crises, 1):
|
| ConsoleUI.display_message(f"{i}. {crisis['name']}", indent=2)
|
| ConsoleUI.display_message(f" شدت: {crisis['severity']}/100", indent=4)
|
| ConsoleUI.display_message(f" توضیحات: {crisis['description']}", indent=4)
|
|
|
| ConsoleUI.wait_for_enter()
|
|
|
| def manage_city_crises(self):
|
| """مدیریت بحرانهای شهری"""
|
| from ui.console_ui import ConsoleUI
|
|
|
| ConsoleUI.clear_screen()
|
| ConsoleUI.display_section_title("بحرانهای شهری")
|
|
|
|
|
| crisis_cities = [city for city in self.game_state.cities
|
| if city.get("crisis_level", 0) > 30]
|
|
|
| if not crisis_cities:
|
| ConsoleUI.display_message("هیچ شهری در وضعیت بحرانی نیست.", indent=2)
|
| ConsoleUI.wait_for_enter()
|
| return
|
|
|
|
|
| city_names = [city["name"] for city in crisis_cities]
|
| city_names.append("برگشت")
|
|
|
| choice = ConsoleUI.get_menu_choice(city_names)
|
|
|
| if choice == len(city_names):
|
| return
|
|
|
| city = crisis_cities[choice-1]
|
| self.handle_city_crisis(city)
|
|
|
| def handle_city_crisis(self, city):
|
| """مدیریت بحران یک شهر خاص"""
|
| from ui.console_ui import ConsoleUI
|
|
|
| ConsoleUI.clear_screen()
|
| ConsoleUI.display_section_title(f"بحران در {city['name']}")
|
|
|
| crisis_level = city.get("crisis_level", 50)
|
| crisis_type = city.get("crisis_type", "Unknown")
|
|
|
| ConsoleUI.display_message(f"نوع بحران: {crisis_type}", indent=2)
|
| ConsoleUI.display_message(f"شدت بحران: {crisis_level}/100", indent=2)
|
| ConsoleUI.display_message("گزینههای پاسخ به بحران:", indent=2)
|
|
|
|
|
| if crisis_type == "Famine":
|
| options = [
|
| "توزیع غذای اضطراری (5000 سکه)",
|
| "واردات غذا از کشورهای دیگر (3000 سکه)",
|
| "سرمایهگذاری در کشاورزی (8000 سکه)",
|
| "بیتفاوتی"
|
| ]
|
| costs = [5000, 3000, 8000, 0]
|
| effects = [
|
| {"crisis_level": -30, "public_dissatisfaction": -15},
|
| {"crisis_level": -20, "relations": {"+": 5}},
|
| {"crisis_level": -40, "economy": {"agriculture": 10}},
|
| {"crisis_level": 20, "public_dissatisfaction": 25}
|
| ]
|
| elif crisis_type == "Rebellion":
|
| options = [
|
| "سرکوب نظامی (7000 سکه)",
|
| "مذاکره با شورشیان (2000 سکه)",
|
| "اصلاحات اجتماعی (5000 سکه)",
|
| "بیتفاوتی"
|
| ]
|
| costs = [7000, 2000, 5000, 0]
|
| effects = [
|
| {"crisis_level": -40, "military_strength": -10, "public_dissatisfaction": 10},
|
| {"crisis_level": -25, "public_dissatisfaction": -15},
|
| {"crisis_level": -35, "political_stability": 10},
|
| {"crisis_level": 30, "public_dissatisfaction": 30}
|
| ]
|
| elif crisis_type == "Disease":
|
| options = [
|
| "تخصیص بودجه به سیستم بهداشت (6000 سکه)",
|
| "همکاری با سازمان جهانی بهداشت (4000 سکه)",
|
| "محدودیتهای شدید (0 سکه)",
|
| "بیتفاوتی"
|
| ]
|
| costs = [6000, 4000, 0, 0]
|
| effects = [
|
| {"crisis_level": -35, "health_index": 15},
|
| {"crisis_level": -25, "relations": {"+": 10}},
|
| {"crisis_level": -20, "economy": {"trade": -10, "industry": -5}},
|
| {"crisis_level": 35, "health_index": -20}
|
| ]
|
| else:
|
| options = [
|
| "ارسال تیم ارزیابی (2000 سکه)",
|
| "درخواست کمک بینالمللی (1000 سکه)",
|
| "بررسی داخلی (0 سکه)",
|
| "بیتفاوتی"
|
| ]
|
| costs = [2000, 1000, 0, 0]
|
| effects = [
|
| {"crisis_level": -10, "diplomacy_points": 5},
|
| {"crisis_level": -15, "relations": {"+": 5}},
|
| {"crisis_level": -5},
|
| {"crisis_level": 20}
|
| ]
|
|
|
|
|
| options.append("برگشت")
|
| costs.append(0)
|
| effects.append({})
|
|
|
| choice = ConsoleUI.get_menu_choice(options)
|
|
|
| if choice == len(options):
|
| return
|
|
|
|
|
| if costs[choice-1] > 0 and self.game_state.gold < costs[choice-1]:
|
| ConsoleUI.display_error("موجودی طلا کافی نیست!")
|
| ConsoleUI.wait_for_enter()
|
| return
|
|
|
|
|
| self._apply_crisis_response(city, costs[choice-1], effects[choice-1])
|
|
|
| def _apply_crisis_response(self, city, cost, effects):
|
| """اعمال پاسخ به بحران و اثرات آن"""
|
| from ui.console_ui import ConsoleUI
|
|
|
|
|
| if cost > 0:
|
| self.game_state.gold -= cost
|
|
|
|
|
| for effect_type, value in effects.items():
|
| if effect_type == "crisis_level":
|
| city["crisis_level"] = max(0, city["crisis_level"] + value)
|
| self.game_state.crisis_level = max(0, self.game_state.crisis_level + value // 2)
|
| elif effect_type == "relations":
|
| for country in self.game_state.relations:
|
| if country != self.game_state.player_country["name"]:
|
| self.game_state.relations[country] = min(100, self.game_state.relations[country] + value["+"])
|
| elif effect_type == "economy":
|
| for sector, val in value.items():
|
| self.game_state.economy[sector] = max(0, min(100, self.game_state.economy[sector] + val))
|
| else:
|
| if effect_type in self.game_state:
|
| self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value))
|
| elif effect_type in self.game_state.economy:
|
| self.game_state.economy[effect_type] = max(0, min(100, self.game_state.economy[effect_type] + value))
|
|
|
|
|
| if city["crisis_level"] <= 0:
|
| ConsoleUI.display_success(f"بحران در {city['name']} با موفقیت حل شد!")
|
| if "crisis_type" in city:
|
| del city["crisis_type"]
|
| if "crisis_level" in city:
|
| del city["crisis_level"]
|
| else:
|
| ConsoleUI.display_message(f"بحران در {city['name']} کاهش یافت، اما هنوز وجود دارد.")
|
|
|
| ConsoleUI.wait_for_enter()
|
|
|
| def generate_random_crisis(self):
|
| """تولید یک بحران تصادفی"""
|
| import random
|
|
|
| crisis_types = [
|
| {
|
| "name": "قحطی",
|
| "description": "خشکسالی شدید باعث کاهش تولیدات کشاورزی شده است.",
|
| "severity": random.randint(30, 70),
|
| "type": "Famine",
|
| "effects": {
|
| "public_dissatisfaction": 5,
|
| "economy": {"agriculture": -10}
|
| }
|
| },
|
| {
|
| "name": "شورش",
|
| "description": "گروهی از مردم علیه دولت شورش کردهاند.",
|
| "severity": random.randint(40, 80),
|
| "type": "Rebellion",
|
| "effects": {
|
| "political_stability": -8,
|
| "public_dissatisfaction": 10
|
| }
|
| },
|
| {
|
| "name": "بیماری همهگیر",
|
| "description": "یک بیماری واگیردار در کشور شیوع یافته است.",
|
| "severity": random.randint(35, 75),
|
| "type": "Disease",
|
| "effects": {
|
| "health_index": -10,
|
| "population": -5
|
| }
|
| },
|
| {
|
| "name": "بحران اقتصادی",
|
| "description": "رکود اقتصادی شدید رخ داده است.",
|
| "severity": random.randint(25, 65),
|
| "type": "Economic",
|
| "effects": {
|
| "economy": {"inflation": 15, "unemployment": 10},
|
| "gold": -2000
|
| }
|
| }
|
| ]
|
|
|
| return random.choice(crisis_types)
|
|
|
| def handle_national_crisis(self):
|
| """مدیریت بحرانهای ملی"""
|
| from ui.console_ui import ConsoleUI
|
|
|
|
|
| if self.game_state.crisis_level < 20:
|
| crisis = self.generate_random_crisis()
|
| self.active_crises.append(crisis)
|
| self.game_state.crisis_level = crisis["severity"]
|
|
|
| ConsoleUI.clear_screen()
|
| ConsoleUI.display_section_title("بحران ملی")
|
|
|
|
|
| crisis = self.active_crises[0]
|
| ConsoleUI.display_message(f"نوع بحران: {crisis['name']}", indent=2)
|
| ConsoleUI.display_message(f"شرح: {crisis['description']}", indent=2)
|
| ConsoleUI.display_message(f"شدت: {self.game_state.crisis_level}/100", indent=2)
|
|
|
|
|
| options = [
|
| "تخصیص منابع مالی (8000 سکه)",
|
| "درخواست کمک بینالمللی (3000 سکه)",
|
| "اصلاحات ساختاری (5000 سکه)",
|
| "بیتفاوتی"
|
| ]
|
| costs = [8000, 3000, 5000, 0]
|
| effects = [
|
| {"crisis_level": -30, "gold": -8000},
|
| {"crisis_level": -20, "relations": {"+": 10}},
|
| {"crisis_level": -40, "political_stability": 15},
|
| {"crisis_level": 25, "public_dissatisfaction": 20}
|
| ]
|
|
|
|
|
| options.append("برگشت")
|
| costs.append(0)
|
| effects.append({})
|
|
|
| choice = ConsoleUI.get_menu_choice(options)
|
|
|
| if choice == len(options):
|
| return
|
|
|
|
|
| if costs[choice-1] > 0 and self.game_state.gold < costs[choice-1]:
|
| ConsoleUI.display_error("موجودی طلا کافی نیست!")
|
| ConsoleUI.wait_for_enter()
|
| return
|
|
|
|
|
| self._apply_national_crisis_response(costs[choice-1], effects[choice-1], crisis)
|
|
|
| def _apply_national_crisis_response(self, cost, effects, crisis):
|
| """اعمال پاسخ به بحران ملی و اثرات آن"""
|
| from ui.console_ui import ConsoleUI
|
|
|
|
|
| if cost > 0:
|
| self.game_state.gold -= cost
|
|
|
|
|
| for effect_type, value in effects.items():
|
| if effect_type == "crisis_level":
|
| self.game_state.crisis_level = max(0, self.game_state.crisis_level + value)
|
| elif effect_type == "relations":
|
| for country in self.game_state.relations:
|
| if country != self.game_state.player_country["name"]:
|
| self.game_state.relations[country] = min(100, self.game_state.relations[country] + value["+"])
|
| elif effect_type == "economy":
|
| for sector, val in value.items():
|
| self.game_state.economy[sector] = max(0, min(100, self.game_state.economy[sector] + val))
|
| else:
|
| if effect_type in self.game_state:
|
| self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value))
|
| elif effect_type in self.game_state.economy:
|
| self.game_state.economy[effect_type] = max(0, min(100, self.game_state.economy[effect_type] + value))
|
|
|
|
|
| if self.game_state.crisis_level <= 0:
|
| ConsoleUI.display_success("بحران ملی با موفقیت حل شد!")
|
| self.active_crises = []
|
| self.game_state.crisis_level = 0
|
| else:
|
| ConsoleUI.display_message("بحران کاهش یافت، اما هنوز وجود دارد.")
|
|
|
| ConsoleUI.wait_for_enter()
|
|
|
| def annual_update(self):
|
| """بهروزرسانیهای سالانه سیستم بحران"""
|
|
|
| for crisis in self.active_crises:
|
| crisis["severity"] = min(100, crisis["severity"] + random.randint(1, 3))
|
|
|
|
|
| if self.active_crises:
|
| total_severity = sum(crisis["severity"] for crisis in self.active_crises)
|
| self.game_state.crisis_level = min(100, total_severity // len(self.active_crises))
|
| else:
|
| self.game_state.crisis_level = max(0, self.game_state.crisis_level - 5)
|
|
|
|
|
| self._apply_crisis_effects()
|
|
|
|
|
| self._check_for_new_crises()
|
|
|
| def _apply_crisis_effects(self):
|
| """اعمال اثرات بحرانها بر وضعیت کلی بازی"""
|
| if self.game_state.crisis_level > 70:
|
| self.game_state.political_stability = max(0, self.game_state.political_stability - 5)
|
| self.game_state.public_dissatisfaction = min(100, self.game_state.public_dissatisfaction + 8)
|
| elif self.game_state.crisis_level > 40:
|
| self.game_state.political_stability = max(0, self.game_state.political_stability - 3)
|
| self.game_state.public_dissatisfaction = min(100, self.game_state.public_dissatisfaction + 4)
|
| elif self.game_state.crisis_level > 20:
|
| self.game_state.political_stability = max(0, self.game_state.political_stability - 1)
|
| self.game_state.public_dissatisfaction = min(100, self.game_state.public_dissatisfaction + 2)
|
|
|
| def _check_for_new_crises(self):
|
| """بررسی ایجاد بحرانهای جدید بر اساس وضعیت فعلی"""
|
| import random
|
|
|
|
|
| base_chance = 0.1
|
| if self.game_state.crisis_level > 50:
|
| base_chance += 0.2
|
| if self.game_state.political_stability < 40:
|
| base_chance += 0.15
|
| if self.game_state.public_dissatisfaction > 60:
|
| base_chance += 0.1
|
|
|
| if random.random() < base_chance:
|
| new_crisis = self.generate_random_crisis()
|
| self.active_crises.append(new_crisis)
|
| self.game_state.crisis_level = max(self.game_state.crisis_level, new_crisis["severity"]) |