diff --git "a/Shadows_of_Empires/st_txt.text" "b/Shadows_of_Empires/st_txt.text" new file mode 100644--- /dev/null +++ "b/Shadows_of_Empires/st_txt.text" @@ -0,0 +1,12516 @@ +### USER +کد پایتون کامل کامل تمام این فایل ها به طور کامل + +```structure +empire_shadows/ +│ +├── main.py +├── config.py +├── requirements.txt +│ +├── game/ +│ ├── __init__.py +│ ├── game.py +│ ├── game_state.py +│ │ +│ ├── calendar/ +│ │ ├── __init__.py +│ │ ├── calendar_system.py +│ │ └── historical_events.py +│ │ +│ ├── climate/ +│ │ ├── __init__.py +│ │ ├── climate_system.py +│ │ └── weather_events.py +│ │ +│ ├── demographics/ +│ │ ├── __init__.py +│ │ ├── population_system.py +│ │ └── migration_system.py +│ │ +│ ├── technology/ +│ │ ├── __init__.py +│ │ ├── tech_tree.py +│ │ ├── research_system.py +│ │ └── tech_effects.py +│ │ +│ ├── religion/ +│ │ ├── __init__.py +│ │ ├── religious_system.py +│ │ └── religious_events.py +│ │ +│ ├── espionage/ +│ │ ├── __init__.py +│ │ ├── espionage_system.py +│ │ └── spy_network.py +│ │ +│ ├── cities/ +│ │ ├── __init__.py +│ │ ├── city_management.py +│ │ ├── construction_system.py +│ │ └── city_events.py +│ │ +│ ├── warfare/ +│ │ ├── __init__.py +│ │ ├── warfare_system.py +│ │ ├── battle_simulator.py +│ │ └── military_tactics.py +│ │ +│ ├── trade/ +│ │ ├── __init__.py +│ │ ├── trade_system.py +│ │ ├── global_market.py +│ │ └── trade_routes.py +│ │ +│ ├── politics/ +│ │ ├── __init__.py +│ │ ├── domestic_policy.py +│ │ ├── political_parties.py +│ │ └── election_system.py +│ │ +│ ├── society/ +│ │ ├── __init__.py +│ │ ├── social_classes.py +│ │ ├── social_issues.py +│ │ └── happiness_system.py +│ │ +│ ├── culture/ +│ │ ├── __init__.py +│ │ ├── cultural_system.py +│ │ ├── language_system.py +│ │ └── cultural_influence.py +│ │ +│ ├── diplomacy/ +│ │ ├── __init__.py +│ │ ├── diplomacy_system.py +│ │ ├── embassies.py +│ │ └── international_orgs.py +│ │ +│ ├── economy/ +│ │ ├── __init__.py +│ │ ├── macro_economy.py +│ │ ├── resource_management.py +│ │ └── economic_policies.py +│ │ +│ ├── military/ +│ │ ├── __init__.py +│ │ ├── army_management.py +│ │ ├── military_production.py +│ │ └── military_units.py +│ │ +│ ├── health/ +│ │ ├── __init__.py +│ │ ├── healthcare_system.py +│ │ └── disease_system.py +│ │ +│ ├── education/ +│ │ ├── __init__.py +│ │ ├── education_system.py +│ │ └── knowledge_system.py +│ │ +│ ├── environment/ +│ │ ├── __init__.py +│ │ ├── environmental_system.py +│ │ └── climate_change.py +│ │ +│ ├── crisis/ +│ │ ├── __init__.py +│ │ ├── crisis_management.py +│ │ └── disaster_response.py +│ │ +│ ├── succession/ +│ │ ├── __init__.py +│ │ ├── succession_system.py +│ │ └── royal_family.py +│ │ +│ └── achievements/ +│ ├── __init__.py +│ ├── achievements_system.py +│ └── personal_objectives.py +│ +├── data/ +│ ├── __init__.py +│ ├── countries/ +│ │ ├── __init__.py +│ │ ├── base_countries.py +│ │ ├── historical_countries.py +│ │ └── custom_countries.py +│ │ +│ ├── events/ +│ │ ├── __init__.py +│ │ ├── event_definitions.py +│ │ ├── historical_events.py +│ │ └── dynamic_events.py +│ │ +│ ├── tech/ +│ │ ├── __init__.py +│ │ ├── tech_definitions.py +│ │ └── tech_trees.py +│ │ +│ ├── religion/ +│ │ ├── __init__.py +│ │ ├── religions.py +│ │ └── religious_groups.py +│ │ +│ ├── military/ +│ │ ├── __init__.py +│ │ ├── units.py +│ │ ├── weapons.py +│ │ └── fortifications.py +│ │ +│ ├── resources/ +│ │ ├── __init__.py +│ │ ├── natural_resources.py +│ │ └── resource_map.py +│ │ +│ ├── cities/ +│ │ ├── __init__.py +│ │ ├── city_templates.py +│ │ └── building_types.py +│ │ +│ └── achievements/ +│ ├── __init__.py +│ └── achievement_definitions.py +│ +├── plugins/ +│ ├── __init__.py +│ ├── base_plugin.py +│ ├── plugin_manager.py +│ ├── example_plugin.py +│ ├── advanced_diplomacy_plugin.py +│ ├── trade_expansion_plugin.py +│ └── climate_change_plugin.py +│ +├── ui/ +│ ├── __init__.py +│ ├── console_ui.py +│ ├── colors.py +│ ├── display.py +│ ├── menus.py +│ └── animations.py +│ +└── utils/ + ├── __init__.py + ├── save_load.py + ├── logger.py + ├── helpers.py + ├── randomizer.py + └── data_loader.py +``` + +### ASSISTANT +# 🌍 سایه‌های امپراتوری - کد کامل پایتون + +در این پاسخ، تمام فایل‌های پروژه "سایه‌های امپراتوری" را به صورت کامل ارائه می‌دهم. این یک بازی استراتژی تاریخی با ساختار پلاگینی و ماژولار است که امکان گسترش و سفارشی‌سازی آسان فراهم می‌کند. + +## فایل‌های پروژه + +### 1. `main.py` (فایل اجرایی اصلی) +```python +#!/usr/bin/env python3 +""" +فایل اصلی برای راه‌اندازی بازی "سایه‌های امپراتوری" +""" + +import sys +import os +import logging +from datetime import datetime + +# اضافه کردن مسیر جاری به سیستم +current_dir = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, current_dir) + +from game.game import EmpireGame +from plugins.plugin_manager import PluginManager +from ui.console_ui import ConsoleUI +from utils.logger import setup_logger +from config import ADVANCED_CONFIG + +def main(): + """تابع اصلی برای راه‌اندازی بازی""" + # راه‌اندازی سیستم لاگ + logger = setup_logger() + logger.info("شروع بازی 'سایه‌های امپراتوری'") + + try: + # نمایش صفحه اصلی + ConsoleUI.display_title_screen() + + # راه‌اندازی مدیر پلاگین‌ها + plugin_manager = PluginManager() + plugin_manager.load_plugins() + logger.info(f"{len(plugin_manager.plugins)} پلاگین بارگیری شد") + + # ایجاد نمونه بازی + game = EmpireGame() + + # اعمال پلاگین‌ها به بازی + for plugin in plugin_manager.plugins: + plugin.apply(game) + logger.info(f"پلاگین '{plugin.name}' به بازی اعمال شد") + + # شروع بازی + game.start() + + except Exception as e: + logger.exception("خطای غیرمنتظره در حین اجرای بازی") + ConsoleUI.display_error(f"خطای جدی رخ داد: {str(e)}") + sys.exit(1) + +if __name__ == "__main__": + main() +``` + +### 2. `config.py` (فایل تنظیمات) +```python +""" +فایل تنظیمات مرکزی برای بازی +""" + +# تنظیمات کلی بازی +GAME_CONFIG = { + "initial_year": 1500, + "max_year": 2000, + "victory_conditions": { + "world_domination": 12, # تعداد کشورهای تحت کنترل + "economic_domination": 500000, # حداقل سکه طلا + "cultural_domination": 90, # حداقل امتیاز فرهنگی + "technological_domination": 8, # حداقل سطح فناوری + "religious_domination": 75 # درصد گسترش دین + }, + "event_probability": { + "common": 0.7, # احتمال وقوع رویدادهای رایج + "rare": 0.3, # احتمال وقوع رویدادهای نادر + "historical": 0.1 # احتمال وقوع رویدادهای تاریخی + }, + "auto_save_interval": 1, # هر چند سال ذخیره خودکار انجام شود + "max_history_length": 100, # حداکثر طول تاریخچه رویدادها + "difficulty_levels": { + "easy": { + "stability_factor": 1.2, + "economy_factor": 1.3, + "military_factor": 0.8 + }, + "normal": { + "stability_factor": 1.0, + "economy_factor": 1.0, + "military_factor": 1.0 + }, + "hard": { + "stability_factor": 0.8, + "economy_factor": 0.9, + "military_factor": 1.2 + } + } +} + +# تنظیمات رابط کاربری +UI_CONFIG = { + "use_color": True, + "display_width": 120, + "animation_speed": 0.03, + "show_tooltips": True, + "language": "fa" # fa: فارسی، en: انگلیسی +} + +# تنظیمات پیشرفته +ADVANCED_CONFIG = { + "debug_mode": False, + "save_file": "saves/latest_save.json", + "log_file": "logs/game.log", + "max_save_slots": 10, + "autosave_slots": 5, + "max_undo_steps": 5, + "random_seed": None +} +``` + +### 3. `requirements.txt` (وابستگی‌های پروژه) +``` +colorama==0.4.6 +``` + +### 4. `game/__init__.py` +```python +""" +پکیج بازی سایه‌های امپراتوری +""" + +# وارد کردن کلاس‌های اصلی برای دسترسی آسان +from .game import EmpireGame +from .game_state import GameState +``` + +### 5. `game/game.py` (هسته اصلی بازی) +```python +""" +کلاس اصلی بازی که سیستم‌های مختلف را مدیریت می‌کند +""" + +import time +from game_state import GameState +from calendar.calendar_system import CalendarSystem +from climate.climate_system import ClimateSystem +from demographics.population_system import PopulationSystem +from technology.research_system import ResearchSystem +from religion.religious_system import ReligiousSystem +from espionage.espionage_system import EspionageSystem +from cities.city_management import CityManagement +from warfare.warfare_system import WarfareSystem +from trade.trade_system import TradeSystem +from politics.domestic_policy import DomesticPolicy +from society.happiness_system import HappinessSystem +from culture.cultural_system import CulturalSystem +from diplomacy.diplomacy_system import DiplomacySystem +from economy.macro_economy import MacroEconomy +from military.army_management import ArmyManagement +from health.healthcare_system import HealthcareSystem +from education.education_system import EducationSystem +from environment.environmental_system import EnvironmentalSystem +from crisis.crisis_management import CrisisManagement +from succession.succession_system import SuccessionSystem +from achievements.achievements_system import AchievementsSystem +from ui.console_ui import ConsoleUI +from utils.save_load import SaveLoadManager +from config import GAME_CONFIG, UI_CONFIG, ADVANCED_CONFIG + +class EmpireGame: + """کلاس اصلی بازی سایه‌های امپراتوری""" + + def __init__(self): + """ساخت یک نمونه جدید از بازی""" + self.game_state = GameState() + self.calendar = CalendarSystem(self.game_state) + self.climate = ClimateSystem(self.game_state) + self.population = PopulationSystem(self.game_state) + self.technology = ResearchSystem(self.game_state) + self.religion = ReligiousSystem(self.game_state) + self.espionage = EspionageSystem(self.game_state) + self.cities = CityManagement(self.game_state) + self.warfare = WarfareSystem(self.game_state) + self.trade = TradeSystem(self.game_state) + self.politics = DomesticPolicy(self.game_state) + self.society = HappinessSystem(self.game_state) + self.culture = CulturalSystem(self.game_state) + self.diplomacy = DiplomacySystem(self.game_state) + self.economy = MacroEconomy(self.game_state) + self.military = ArmyManagement(self.game_state) + self.health = HealthcareSystem(self.game_state) + self.education = EducationSystem(self.game_state) + self.environment = EnvironmentalSystem(self.game_state) + self.crisis = CrisisManagement(self.game_state) + self.succession = SuccessionSystem(self.game_state) + self.achievements = AchievementsSystem(self.game_state) + self.save_manager = SaveLoadManager() + self.running = False + self.plugins = [] + self.difficulty = "normal" + self.undo_stack = [] + self.redo_stack = [] + + def start(self): + """شروع بازی و ورود به حلقه اصلی""" + self.running = True + ConsoleUI.clear_screen() + + # نمایش مقدمه بازی + ConsoleUI.display_intro() + + # انتخاب سطح دشواری + self.select_difficulty() + + # انتخاب کشور توسط بازیکن + self.game_state.select_country() + + # راه‌اندازی سیستم‌های بازی + self.initialize_game_systems() + + # نمایش راهنما + self.show_tutorial() + + # ورود به حلقه اصلی بازی + self.game_loop() + + def select_difficulty(self): + """انتخاب سطح دشواری بازی""" + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("انتخاب سطح دشواری") + + difficulties = ["آسان", "معمولی", "سخت"] + choice = ConsoleUI.get_menu_choice(difficulties) + + if choice == 1: + self.difficulty = "easy" + elif choice == 2: + self.difficulty = "normal" + else: + self.difficulty = "hard" + + # اعمال ضرایب دشواری + self.game_state.difficulty = self.difficulty + self.game_state.difficulty_factors = GAME_CONFIG["difficulty_levels"][self.difficulty] + + ConsoleUI.display_success(f"سطح دشواری '{difficulties[choice-1]}' انتخاب شد.") + time.sleep(1) + + def initialize_game_systems(self): + """راه‌اندازی اولیه سیستم‌های بازی""" + # راه‌اندازی سیستم‌های مختلف بازی + self.calendar.initialize() + self.climate.initialize() + self.population.initialize() + self.technology.initialize() + self.religion.initialize() + self.espionage.initialize() + self.cities.initialize() + self.warfare.initialize() + self.trade.initialize() + self.politics.initialize() + self.society.initialize() + self.culture.initialize() + self.diplomacy.initialize() + self.economy.initialize() + self.military.initialize() + self.health.initialize() + self.education.initialize() + self.environment.initialize() + self.crisis.initialize() + self.succession.initialize() + self.achievements.initialize() + + # نمایش وضعیت اولیه + ConsoleUI.display_country_info(self.game_state.player_country) + + def game_loop(self): + """حلقه اصلی بازی""" + while self.running: + try: + ConsoleUI.clear_screen() + + # نمایش وضعیت فعلی بازی + ConsoleUI.display_game_status(self.game_state) + + # بررسی شرایط پایان بازی + if self.check_victory_conditions(): + break + + # پردازش رویدادهای سالانه + self.process_yearly_events() + + # پردازش اقدامات بازیکن + self.process_player_actions() + + # به‌روزرسانی‌های سالانه + self.annual_updates() + + # افزایش سال + self.game_state.current_year += 1 + + # ذخیره خودکار + if self.game_state.current_year % GAME_CONFIG["auto_save_interval"] == 0: + self.save_manager.auto_save(self.game_state) + + except KeyboardInterrupt: + # مدیریت خروج با Ctrl+C + if ConsoleUI.confirm_action("آیا می‌خواهید بازی را ذخیره و خارج شوید؟"): + self.save_manager.save_game(self.game_state) + ConsoleUI.display_message("بازی ذخیره شد. خداحافظ!") + break + else: + ConsoleUI.display_warning("ادامه بازی...") + except Exception as e: + ConsoleUI.display_error(f"خطای غیرمنتظره: {str(e)}") + if ConsoleUI.confirm_action("آیا می‌خواهید بازی را ذخیره و خارج شوید؟"): + self.save_manager.save_game(self.game_state) + break + + def process_yearly_events(self): + """پردازش رویدادهای سالانه""" + # بررسی احتمال وقوع رویدادهای مختلف + if self.game_state.random.random() < GAME_CONFIG["event_probability"]["common"]: + event = self.calendar.select_random_event() + if event: + ConsoleUI.display_event(event) + choice = ConsoleUI.get_player_choice(event["choices"]) + self.calendar.apply_event_choice(event, choice) + + # بررسی احتمال وقوع رویدادهای آب‌وهوایی + if self.game_state.random.random() < GAME_CONFIG["event_probability"]["rare"]: + event = self.climate.select_weather_event() + if event: + ConsoleUI.display_weather_event(event) + choice = ConsoleUI.get_player_choice(event["choices"]) + self.climate.apply_weather_event_choice(event, choice) + + # بررسی احتمال وقوع رویدادهای تاریخی + if self.game_state.random.random() < GAME_CONFIG["event_probability"]["historical"]: + event = self.calendar.select_historical_event() + if event: + ConsoleUI.display_historical_event(event) + choice = ConsoleUI.get_player_choice(event["choices"]) + self.calendar.apply_historical_event_choice(event, choice) + + def process_player_actions(self): + """پردازش اقدامات بازیکن""" + main_actions = [ + "مشاهده وضعیت کشور", + "مدیریت اقتصاد", + "دیپلماسی و روابط خارجی", + "مدیریت نظامی", + "سیاست داخلی", + "مدیریت شهرها", + "سیستم فناوری", + "سیستم فرهنگی", + "سیستم دینی", + "سیستم جمعیت", + "ذخیره بازی", + "بازیابی آخرین اقدام (Undo)", + "خروج از بازی" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("اقدامات اصلی") + + choice = ConsoleUI.get_menu_choice(main_actions) + + if choice == 1: + self.handle_country_status() + elif choice == 2: + self.handle_economy_management() + elif choice == 3: + self.handle_diplomacy() + elif choice == 4: + self.handle_military() + elif choice == 5: + self.handle_domestic_policy() + elif choice == 6: + self.handle_city_management() + elif choice == 7: + self.handle_technology() + elif choice == 8: + self.handle_culture() + elif choice == 9: + self.handle_religion() + elif choice == 10: + self.handle_population() + elif choice == 11: + self.save_manager.save_game(self.game_state) + ConsoleUI.display_success("بازی با موفقیت ذخیره شد!") + time.sleep(1) + elif choice == 12: + self.undo_last_action() + elif choice == 13: + if ConsoleUI.confirm_action("آیا می‌خواهید بازی را ذخیره و خارج شوید؟"): + self.save_manager.save_game(self.game_state) + self.running = False + return + + def handle_country_status(self): + """مدیریت نمایش وضعیت کشور""" + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت کشور") + ConsoleUI.display_country_status(self.game_state) + ConsoleUI.wait_for_enter() + + def handle_economy_management(self): + """مدیریت اقتصاد کشور""" + economy_actions = [ + "مدیریت مالیات و بودجه", + "سرمایه‌گذاری در زیرساخت", + "تجارت با کشورهای دیگر", + "مدیریت منابع طبیعی", + "سیاست‌های اقتصادی کلان", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("مدیریت اقتصاد") + + choice = ConsoleUI.get_menu_choice(economy_actions) + + if choice == 1: + self.economy.manage_taxes() + elif choice == 2: + self.economy.invest_in_infrastructure() + elif choice == 3: + self.trade.trade_with_countries() + elif choice == 4: + self.economy.manage_resources() + elif choice == 5: + self.economy.set_economic_policy() + elif choice == 6: + return + + def handle_diplomacy(self): + """مدیریت دیپلماسی و روابط خارجی""" + diplomacy_actions = [ + "مشاهده روابط فعلی", + "پیشنهاد اتحاد یا پیمان", + "مذاکره برای صلح", + "ارسال سفیر و ایجاد سفارتخانه", + "عضویت در سازمان‌های بین‌المللی", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("دیپلماسی") + + choice = ConsoleUI.get_menu_choice(diplomacy_actions) + + if choice == 1: + self.diplomacy.display_relations() + elif choice == 2: + self.diplomacy.propose_alliance() + elif choice == 3: + self.diplomacy.negotiate_peace() + elif choice == 4: + self.diplomacy.send_envoy() + elif choice == 5: + self.diplomacy.join_international_orgs() + elif choice == 6: + return + + def handle_military(self): + """مدیریت امور نظامی""" + military_actions = [ + "مشاهده نیروهای نظامی", + "آموزش ارتش", + "تولید تسلیحات", + "حمله به کشور دیگر", + "دفاع از قلمرو", + "استراتژی‌های نظامی", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("مدیریت نظامی") + + choice = ConsoleUI.get_menu_choice(military_actions) + + if choice == 1: + self.military.display_forces() + elif choice == 2: + self.military.train_army() + elif choice == 3: + self.military.produce_weapons() + elif choice == 4: + self.warfare.attack_country() + elif choice == 5: + self.warfare.defend_territory() + elif choice == 6: + self.warfare.select_military_tactics() + elif choice == 7: + return + + def handle_domestic_policy(self): + """مدیریت سیاست داخلی""" + politics_actions = [ + "مدیریت احزاب و گروه‌های فشار", + "اجرای اصلاحات اجتماعی", + "سیاست‌های بهداشت و درمان", + "سیاست‌های آموزشی", + "انتخابات و حکومت‌های مردمی", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("سیاست داخلی") + + choice = ConsoleUI.get_menu_choice(politics_actions) + + if choice == 1: + self.politics.manage_political_parties() + elif choice == 2: + self.politics.implement_social_reforms() + elif choice == 3: + self.health.manage_healthcare() + elif choice == 4: + self.education.manage_education() + elif choice == 5: + self.politics.hold_elections() + elif choice == 6: + return + + def handle_city_management(self): + """مدیریت شهرها""" + city_actions = [ + "مشاهده شهرها", + "ساخت بناهای جدید", + "مدیریت جمعیت شهری", + "برنامه‌ریزی شهری", + "مدیریت بحران‌های شهری", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("مدیریت شهرها") + + choice = ConsoleUI.get_menu_choice(city_actions) + + if choice == 1: + self.cities.display_cities() + elif choice == 2: + self.cities.build_new_structures() + elif choice == 3: + self.population.manage_urban_population() + elif choice == 4: + self.cities.city_planning() + elif choice == 5: + self.crisis.manage_city_crises() + elif choice == 6: + return + + def handle_technology(self): + """مدیریت سیستم فناوری""" + tech_actions = [ + "مشاهده درخت فناوری", + "تحقیق در فناوری‌های جدید", + "مدیریت مراکز تحقیقاتی", + "همکاری‌های فناوری", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("سیستم فناوری") + + choice = ConsoleUI.get_menu_choice(tech_actions) + + if choice == 1: + self.technology.display_tech_tree() + elif choice == 2: + self.technology.conduct_research() + elif choice == 3: + self.technology.manage_research_centers() + elif choice == 4: + self.technology.technology_cooperation() + elif choice == 5: + return + + def handle_culture(self): + """مدیری�� سیستم فرهنگی""" + culture_actions = [ + "مشاهده وضعیت فرهنگی", + "سرمایه‌گذاری در گسترش فرهنگ", + "فرهنگ‌سازی در کشورهای تحت کنترل", + "مدیریت زبان و هنر", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("گسترش فرهنگ") + + choice = ConsoleUI.get_menu_choice(culture_actions) + + if choice == 1: + self.culture.display_culture_status() + elif choice == 2: + self.culture.invest_in_cultural_spread() + elif choice == 3: + self.culture.cultural_assimilation() + elif choice == 4: + self.culture.manage_language_and_art() + elif choice == 5: + return + + def handle_religion(self): + """مدیریت سیستم دینی""" + religion_actions = [ + "مشاهده وضعیت دینی", + "گسترش دین", + "مدیریت گروه‌های مذهبی", + "اجرای سیاست‌های دینی", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("سیستم دینی") + + choice = ConsoleUI.get_menu_choice(religion_actions) + + if choice == 1: + self.religion.display_religious_status() + elif choice == 2: + self.religion.spread_religion() + elif choice == 3: + self.religion.manage_religious_groups() + elif choice == 4: + self.religion.implement_religious_policies() + elif choice == 5: + return + + def handle_population(self): + """مدیریت سیستم جمعیت""" + population_actions = [ + "مشاهده ساختار جمعیت", + "مدیریت مهاجرت", + "برنامه‌ریزی خانواده", + "مدیریت طبقات اجتماعی", + "برگشت" + ] + + while True: + ConsoleUI.clear_screen() + ConsoleUI.display_game_status(self.game_state) + ConsoleUI.display_section_title("سیستم جمعیت") + + choice = ConsoleUI.get_menu_choice(population_actions) + + if choice == 1: + self.population.display_population_structure() + elif choice == 2: + self.population.manage_migration() + elif choice == 3: + self.population.family_planning() + elif choice == 4: + self.society.manage_social_classes() + elif choice == 5: + return + + def annual_updates(self): + """به‌روزرسانی‌های سالانه بازی""" + # به‌روزرسانی تقویم + self.calendar.annual_update() + + # به‌روزرسانی آب‌وهوایی + self.climate.annual_update() + + # به‌روزرسانی جمعیت + self.population.annual_update() + + # به‌روزرسانی فناوری + self.technology.annual_update() + + # به‌روزرسانی دینی + self.religion.annual_update() + + # به‌روزرسانی جاسوسی + self.espionage.annual_update() + + # به‌روزرسانی شهرها + self.cities.annual_update() + + # به‌روزرسانی نظامی + self.warfare.annual_update() + + # به‌روزرسانی تجارت + self.trade.annual_update() + + # به‌روزرسانی سیاست داخلی + self.politics.annual_update() + + # به‌روزرسانی اجتماعی + self.society.annual_update() + + # به‌روزرسانی فرهنگی + self.culture.annual_update() + + # به‌روزرسانی دیپلماسی + self.diplomacy.annual_update() + + # به‌روزرسانی اقتصاد کلان + self.economy.annual_update() + + # به‌روزرسانی نظامی + self.military.annual_update() + + # به‌روزرسانی بهداشت + self.health.annual_update() + + # به‌روزرسانی آموزش + self.education.annual_update() + + # به‌روزرسانی محیط زیست + self.environment.annual_update() + + # به‌روزرسانی مدیریت بحران + self.crisis.annual_update() + + # به‌روزرسانی جانشینی + self.succession.annual_update() + + # به‌روزرسانی دستاوردها + self.achievements.annual_update() + + # بررسی شرایط پایان بازی + self.check_victory_conditions() + + def check_victory_conditions(self): + """بررسی شرایط پیروزی یا شکست""" + # تسلط جهانی + if self.game_state.controlled_territories >= GAME_CONFIG["victory_conditions"]["world_domination"]: + self.show_victory_screen("تسلط جهانی", + "شما موفق شدید بیش از نصف کشورهای جهان را تحت کنترل خود درآورید!") + return True + + # تسلط اقتصادی + if self.game_state.gold >= GAME_CONFIG["victory_conditions"]["economic_domination"]: + self.show_victory_screen("تسلط اقتصادی", + "شما به غنی‌ترین کشور جهان تبدیل شدید و اقتصاد جهانی را کنترل می‌کنید!") + return True + + # تسلط فرهنگی + if self.game_state.culture_score >= GAME_CONFIG["victory_conditions"]["cultural_domination"]: + self.show_victory_screen("تسلط فرهنگی", + "فرهنگ و زبان شما به تمام نقاط جهان گسترش یافت!") + return True + + # تسلط فناوری + if self.game_state.technology_level >= GAME_CONFIG["victory_conditions"]["technological_domination"]: + self.show_victory_screen("تسلط فناوری", + "شما به پیشرفته‌ترین کشور جهان تبدیل شدید و فناوری را کنترل می‌کنید!") + return True + + # تسلط دینی + if self.game_state.religious_influence >= GAME_CONFIG["victory_conditions"]["religious_domination"]: + self.show_victory_screen("تسلط دینی", + "دین شما به بیش از 75% جمعیت جهان گسترش یافت!") + return True + + # شرایط شکست + if self.game_state.political_stability <= 0: + self.show_defeat_screen("ناپایداری سیاسی", + "ثبات سیاسی شما به صفر رسید و مردم علیه شما شورش کردند!") + return True + + if self.game_state.gold <= 0: + self.show_defeat_screen("ورشکستگی مالی", + "منابع مالی شما به پایان رسید و امپراتوری شما از بین رفت!") + return True + + # بررسی سال پایانی + if self.game_state.current_year >= GAME_CONFIG["max_year"]: + self.show_defeat_screen("پایان دوره تاریخی", + f"شما توانستید تا سال {GAME_CONFIG['max_year']} دوام بیاورید، اما هنوز به پیروزی نرسیدید.") + return True + + return False + + def show_victory_screen(self, victory_type, description): + """نمایش صفحه پیروزی""" + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("پیروزی!") + ConsoleUI.display_success(f"تبریک! شما با {victory_type} پیروز شدید!") + ConsoleUI.display_message(description) + ConsoleUI.display_message(f"سال پایانی: {self.game_state.current_year}") + ConsoleUI.display_message(f"ثروت نهایی: {self.game_state.gold} سکه طلا") + ConsoleUI.display_message(f"امتیاز فرهنگی: {self.game_state.culture_score}/100") + ConsoleUI.display_message(f"سطح فناوری: {self.game_state.technology_level}") + ConsoleUI.display_message(f"نفوذ دینی: {self.game_state.religious_influence}%") + + # ذخیره نتیجه بازی + self.save_manager.save_game_result(self.game_state, victory_type) + + ConsoleUI.wait_for_enter() + self.running = False + + def show_defeat_screen(self, defeat_type, description): + """نمایش صفحه شکست""" + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("شکست") + ConsoleUI.display_error(f"متأسفانه با {defeat_type} باختید!") + ConsoleUI.display_message(description) + ConsoleUI.display_message(f"سال پایانی: {self.game_state.current_year}") + ConsoleUI.display_message(f"ثروت نهایی: {self.game_state.gold} سکه طلا") + ConsoleUI.display_message(f"امتیاز فرهنگی: {self.game_state.culture_score}/100") + ConsoleUI.display_message(f"سطح فن��وری: {self.game_state.technology_level}") + ConsoleUI.display_message(f"نفوذ دینی: {self.game_state.religious_influence}%") + + # ذخیره نتیجه بازی + self.save_manager.save_game_result(self.game_state, f"شکست: {defeat_type}") + + ConsoleUI.wait_for_enter() + self.running = False + + def undo_last_action(self): + """بازگرداندن آخرین اقدام""" + if not self.undo_stack: + ConsoleUI.display_warning("هیچ اقدامی برای بازگرداندن وجود ندارد.") + time.sleep(1) + return + + # ذخیره وضعیت فعلی برای redo + self.redo_stack.append(self.game_state.copy()) + + # بازگرداندن آخرین وضعیت + self.game_state = self.undo_stack.pop() + + ConsoleUI.display_success("آخرین اقدام با موفقیت بازگردانده شد.") + time.sleep(1) + + def save_state_for_undo(self): + """ذخیره وضعیت فعلی برای امکان undo""" + if len(self.undo_stack) >= GAME_CONFIG["max_undo_steps"]: + self.undo_stack.pop(0) # حذف قدیمی‌ترین وضعیت + + self.undo_stack.append(self.game_state.copy()) + self.redo_stack = [] # پاک کردن redo stack + + def show_tutorial(self): + """نمایش راهنمای اولیه بازی""" + if ConsoleUI.confirm_action("آیا می‌خواهید راهنمای اولیه بازی را ببینید؟"): + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("راهنمای اولیه بازی") + + tutorial_steps = [ + "در این بازی شما رهبر یک کشور تاریخی هستید که باید با تصمیمات استراتژیک، کشور خود را گسترش دهید.", + "در هر سال می‌توانید اقدامات مختلفی انجام دهید: مدیریت اقتصاد، دیپلماسی، نظامی، و...", + "توجه به تعادل بین ثبات سیاسی، نارضایتی عمومی و منابع مالی بسیار مهم است.", + "رویدادهای تصادفی و تاریخی در طول بازی رخ خواهند داد که باید به آنها پاسخ دهید.", + "هدف نهایی شما رسیدن به یکی از شرایط پیروزی است: تسلط جهانی، اقتصادی، فرهنگی یا فناوری." + ] + + for step in tutorial_steps: + ConsoleUI.typewriter_effect(step) + time.sleep(0.5) + print() + + ConsoleUI.wait_for_enter() +``` + +### 6. `game/game_state.py` (مدیریت وضعیت بازی) +```python +""" +مدیریت وضعیت فعلی بازی و اطلاعات کشور بازیکن +""" + +import random +import copy +from data.countries.base_countries import COUNTRIES +from data.tech.tech_trees import TECH_TREES +from data.religion.religions import RELIGIONS + +class GameState: + """کلاس مدیریت وضعیت بازی""" + + def __init__(self): + """ساخت یک نمونه جدید از وضعیت بازی""" + # اطلاعات پایه + self.current_year = 1500 + self.player_country = None + self.difficulty = "normal" + self.difficulty_factors = { + "stability_factor": 1.0, + "economy_factor": 1.0, + "military_factor": 1.0 + } + + # منابع مالی + self.gold = 15000 + self.tax_rate = 20 + self.budget = { + "military": 40, + "infrastructure": 20, + "education": 15, + "healthcare": 15, + "welfare": 10 + } + + # وضعیت سیاسی + self.public_dissatisfaction = 20 + self.political_stability = 75 + self.government_type = "Absolute Monarchy" + self.ruling_party = None + self.political_parties = [] + self.loyalty_levels = {} + + # نظامی + self.military_strength = 50 + self.army = { + "infantry": 10000, + "cavalry": 5000, + "artillery": 2000, + "navy": 3000 + } + self.military_tech = 1 + self.fortifications = 30 + + # اقتصاد + self.controlled_territories = 1 + self.economy = { + "trade": 50, + "agriculture": 50, + "industry": 30, + "inflation": 5, + "unemployment": 8, + "gdp_growth": 2.5 + } + self.resources = { + "food": 100, + "wood": 80, + "stone": 60, + "iron": 40, + "gold": 20, + "oil": 0 + } + self.trade_routes = [] + + # جمعیت + self.population = 8000000 + self.population_growth = 1.2 + self.urban_population = 25 + self.literacy_rate = 15 + self.health_index = 60 + self.happiness = 70 + + # فرهنگ و دین + self.culture_score = 40 + self.cultural_influence = 30 + self.religious_influence = 50 + self.religion = "Shia Islam" + self.religious_groups = {} + + # فناوری + self.technology_level = 1 + self.technology = { + "military": 1, + "agriculture": 1, + "trade": 1, + "industry": 1, + "medicine": 1, + "education": 1 + } + self.research_progress = {} + self.unlocked_technologies = [] + + # روابط بین‌المللی + self.controlled_countries = [] + self.relations = {} + self.alliances = [] + self.international_orgs = [] + + # سیستم‌های پیشرفته + self.diplomacy_points = 10 + self.spy_network = { + "size": 5, + "effectiveness": 30, + "targets": [] + } + self.cities = [] + self.environment = { + "pollution": 20, + "deforestation": 15, + "climate_impact": 10 + } + self.crisis_level = 0 + self.achievements = [] + self.royal_family = { + "ruler": {"name": "Unknown", "age": 40, "health": 80}, + "heir": {"name": "Unknown", "age": 20, "popularity": 50}, + "family_members": [] + } + + # سایر + self.events_history = [] + self.random = random.Random() + self.plugins = [] + + def select_country(self): + """انتخاب کشور توسط بازیکن""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_section_title("انتخاب کشور") + ConsoleUI.display_message("لطفاً یکی از کشورهای زیر را انتخاب کنید:") + + # نمایش لیست کشورها + country_names = [country["name"] for country in COUNTRIES] + choice = ConsoleUI.get_menu_choice(country_names) + + # تنظیم کشور انتخابی + self.player_country = COUNTRIES[choice-1] + self.controlled_countries = [self.player_country["name"]] + + # راه‌اندازی اولیه بر اساس کشور انتخابی + self.initialize_country() + + def initialize_country(self): + """راه‌اندازی اولیه وضعیت بازی بر اساس کشور انتخابی""" + country = self.player_country + base = country["base_attributes"] + + # تنظیم اولیه وضعیت بازی + self.gold = base["gold"] + self.political_stability = base["stability"] + self.military_strength = base["military"]["army"] * 0.6 + base["military"]["navy"] * 0.4 + self.culture_score = base["culture"] + self.diplomacy_points = 10 + self.population = int(base["population"] * 1000000) + + # تنظیم روابط اولیه + self.relations = {} + for c in COUNTRIES: + if c["name"] == country["name"]: + self.relations[c["name"]] = 100 # رابطه با خود + elif c["name"] in country["starting_relations"]: + self.relations[c["name"]] = country["starting_relations"][c["name"]] + else: + self.relations[c["name"]] = self.random.randint(-20, 30) + + # تنظیم اقتصاد اولیه + self.economy = { + "trade": base["economy"]["trade"], + "agriculture": base["economy"]["agriculture"], + "industry": base["economy"]["industry"], + "inflation": 5, + "unemployment": 10, + "gdp_growth": 2.0 + } + + # تنظیم دین + self.religion = base["religion"] + self.religious_influence = 50 + + # تنظیم شهرها + self.cities = [{ + "name": "Tehran", + "population": 500000, + "development": 50, + "happiness": 70, + "buildings": ["Castle", "Market"] + }] + + # تنظیم فناوری + self.technology_level = 1 + self.unlocked_technologies = [] + if self.player_country["name"] in TECH_TREES: + self.unlocked_technologies = TECH_TREES[self.player_country["name"]]["starting_technologies"] + + # تنظیم گروه‌های مذهبی + if self.religion in RELIGIONS: + self.religious_groups = {group: 100 for group in RELIGIONS[self.religion]["groups"]} + + # تنظیم خاندان سلطنتی + self.royal_family = { + "ruler": { + "name": self.random.choice(["Ismail I", "Tahmasp I", "Abbas I"]), + "age": self.random.randint(30, 50), + "health": self.random.randint(60, 90), + "popularity": self.random.randint(40, 70) + }, + "heir": { + "name": "Unknown", + "age": self.random.randint(10, 25), + "popularity": self.random.randint(30, 60) + }, + "family_members": [] + } + + def apply_plugin(self, plugin): + """اعمال تغییرات پلاگین به وضعیت بازی""" + if hasattr(plugin, 'modify_game_state'): + plugin.modify_game_state(self) + self.plugins.append(plugin) + + def copy(self): + """ساخت کپی از وضعیت فعلی بازی برای سیستم undo/redo""" + new_state = GameState() + + # کپی اطلاعات پایه + new_state.current_year = self.current_year + new_state.player_country = self.player_country + new_state.difficulty = self.difficulty + new_state.difficulty_factors = self.difficulty_factors.copy() + + # کپی منابع مالی + new_state.gold = self.gold + new_state.tax_rate = self.tax_rate + new_state.budget = self.budget.copy() + + # کپی وضعیت سیاسی + new_state.public_dissatisfaction = self.public_dissatisfaction + new_state.political_stability = self.political_stability + new_state.government_type = self.government_type + new_state.ruling_party = self.ruling_party + new_state.political_parties = self.political_parties.copy() + new_state.loyalty_levels = self.loyalty_levels.copy() + + # کپی نظامی + new_state.military_strength = self.military_strength + new_state.army = self.army.copy() + new_state.military_tech = self.military_tech + new_state.fortifications = self.fortifications + + # کپی اقتصاد + new_state.controlled_territories = self.controlled_territories + new_state.economy = self.economy.copy() + new_state.resources = self.resources.copy() + new_state.trade_routes = self.trade_routes.copy() + + # کپی جمعیت + new_state.population = self.population + new_state.population_growth = self.population_growth + new_state.urban_population = self.urban_population + new_state.literacy_rate = self.literacy_rate + new_state.health_index = self.health_index + new_state.happiness = self.happiness + + # کپی فرهنگ و دین + new_state.culture_score = self.culture_score + new_state.cultural_influence = self.cultural_influence + new_state.religious_influence = self.religious_influence + new_state.religion = self.religion + new_state.religious_groups = self.religious_groups.copy() + + # کپی فناوری + new_state.technology_level = self.technology_level + new_state.technology = self.technology.copy() + new_state.research_progress = self.research_progress.copy() + new_state.unlocked_technologies = self.unlocked_technologies.copy() + + # کپی روابط بین‌المللی + new_state.controlled_countries = self.controlled_countries.copy() + new_state.relations = self.relations.copy() + new_state.alliances = self.alliances.copy() + new_state.international_orgs = self.international_orgs.copy() + + # کپی سیستم‌های پیشرفته + new_state.diplomacy_points = self.diplomacy_points + new_state.spy_network = { + "size": self.spy_network["size"], + "effectiveness": self.spy_network["effectiveness"], + "targets": self.spy_network["targets"].copy() + } + new_state.cities = [city.copy() for city in self.cities] + new_state.environment = self.environment.copy() + new_state.crisis_level = self.crisis_level + new_state.achievements = self.achievements.copy() + new_state.royal_family = { + "ruler": self.royal_family["ruler"].copy(), + "heir": self.royal_family["heir"].copy(), + "family_members": [member.copy() for member in self.royal_family["family_members"]] + } + + # کپی سایر + new_state.events_history = self.events_history.copy() + + return new_state +``` + +### 7. `game/calendar/__init__.py` +```python +""" +پکیج سیستم تقویم +""" + +from .calendar_system import CalendarSystem +``` + +### 8. `game/calendar/calendar_system.py` (سیستم تقویم) +```python +""" +سیستم تقویم و رویدادهای تاریخی +""" + +from data.events.event_definitions import EVENTS +from data.events.historical_events import HISTORICAL_EVENTS + +class CalendarSystem: + """سیستم مدیریت تقویم و رویدادهای تاریخی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم تقویم""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم تقویم""" + # تنظیم تقویم بر اساس کشور انتخابی + country = self.game_state.player_country + self.calendar_type = country.get("calendar", "Gregorian") + self.starting_year = country.get("starting_year", 1500) + + # تنظیم رویدادهای تاریخی خاص کشور + self.country_historical_events = [] + if "historical_events" in country: + self.country_historical_events = country["historical_events"] + + def select_random_event(self): + """انتخاب یک رویداد تصادفی بر اساس شرایط فعلی""" + eligible_events = [] + + for event in EVENTS: + # بررسی شرایط فعال‌سازی رویداد + if self._check_event_trigger(event): + eligible_events.append(event) + + # اگر رویداد مناسبی وجود نداشت، یک رویداد تصادفی انتخاب کن + if not eligible_events: + return self.game_state.random.choice(EVENTS) + + return self.game_state.random.choice(eligible_events) + + def select_historical_event(self): + """انتخاب یک رویداد تاریخی بر اساس سال فعلی""" + # ابتدا رویدادهای کشور خاص را بررسی می‌کنیم + for event in self.country_historical_events: + if event["year"] == self.game_state.current_year: + return event + + # سپس رویدادهای جهانی را بررسی می‌کنیم + for event in HISTORICAL_EVENTS: + if event["year"] == self.game_state.current_year: + return event + + # اگر رویدادی برای این سال وجود نداشت، یک رویداد تصادفی انتخاب کن + return self.game_state.random.choice(HISTORICAL_EVENTS) + + def _check_event_trigger(self, event): + """بررسی شرایط فعال‌سازی رویداد""" + # اگر تریگری تعریف نشده باشد، همیشه فعال است + if "trigger" not in event: + return True + + # ارزیابی تریگر + return event["trigger"](self.game_state) + + def apply_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": event["name"], + "choice": choice["text"] + }) + + def apply_historical_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 "public_dissatisfaction" in effects: + self.game_state.public_dissatisfaction = max(0, min(100, + self.game_state.public_dissatisfaction + effects["public_dissatisfaction"])) + + # اثرات ثبات سیاسی + if "political_stability" in effects: + self.game_state.political_stability = max(0, min(100, + self.game_state.political_stability + effects["political_stability"])) + + # اثرات اقتصادی + if "economy" in effects: + for sector, value in effects["economy"].items(): + if sector in self.game_state.economy: + self.game_state.economy[sector] = max(0, min(100, + self.game_state.economy[sector] + value)) + + # اثرات روابط + if "relations" in effects: + change = effects["relations"].get("+", 0) - effects["relations"].get("-", 0) + for name in self.game_state.relations: + if name != self.game_state.player_country["name"]: + self.game_state.relations[name] = max(-100, min(100, + self.game_state.relations[name] + change)) + + # اثرات دیپلماسی + if "diplomacy_points" in effects: + self.game_state.diplomacy_points = max(0, + self.game_state.diplomacy_points + effects["diplomacy_points"]) + + # اثرات فرهنگی + if "culture_score" in effects: + self.game_state.culture_score = max(0, min(100, + self.game_state.culture_score + effects["culture_score"])) + + # اثرات دینی + if "religious_influence" in effects: + self.game_state.religious_influence = max(0, min(100, + self.game_state.religious_influence + effects["religious_influence"])) + + # اثرات فناوری + if "technology" in effects: + for tech, value in effects["technology"].items(): + if tech in self.game_state.technology: + self.game_state.technology[tech] = max(1, + self.game_state.technology[tech] + value) + + # اثرات جمعیت + if "population" in effects: + self.game_state.population = max(100000, + self.game_state.population + effects["population"]) + + # اثرات محیط زیست + 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): + """به‌روزرسانی‌های سالانه تقویم""" + # بررسی رویدادهای سالانه تاریخی + historical_event = self.select_historical_event() + if historical_event and historical_event["year"] == self.game_state.current_year: + from ui.console_ui import ConsoleUI + ConsoleUI.display_historical_event(historical_event) + choice = ConsoleUI.get_player_choice(historical_event["choices"]) + self.apply_historical_event_choice(historical_event, choice) +``` + +### 9. `game/calendar/historical_events.py` (رویدادهای تاریخی) +```python +""" +تعریف رویدادهای تاریخی برای بازی +""" + +HISTORICAL_EVENTS = [ + { + "year": 1492, + "name": "اکتشاف آمریکا", + "description": "کریستف کلمب سرزمین‌های آمریکایی را کشف کرد.", + "choices": [ + { + "text": "سرمایه‌گذاری گسترده در استعمار", + "effects": { + "gold": -10000, + "economy": {"trade": 20}, + "controlled_territories": 2 + }, + "description": "ایجاد مستعمرات گسترده در آمریکا با هزینه بالا." + }, + { + "text": "تمرکز بر استخراج منابع طلا و نقره", + "effects": { + "gold": 15000, + "public_dissatisfaction": 15, + "relations": {"-": 10} + }, + "description": "استخراج سریع منابع با پیامدهای اجتماعی و دیپلماتیک." + } + ] + }, + { + "year": 1500, + "name": "کشف سواحل برزیل", + "description": "کاشفان پرتغالی سواحل برزیل را کشف کردند.", + "choices": [ + { + "text": "ارسال اکسپدیسیون بزرگ برای استعمار", + "effects": { + "gold": -8000, + "economy": {"trade": 15}, + "controlled_territories": 1 + }, + "description": "سرمایه‌گذاری در استعمار برزیل با هزینه بالا." + }, + { + "text": "مذاکره با اسپانیا برای تقسیم مناطق", + "effects": { + "gold": -3000, + "relations": {"+": 10}, + "economy": {"trade": 5} + }, + "description": "استفاده از دیپلماسی برای کاهش هزینه‌های استعمار." + } + ] + }, + { + "year": 1517, + "name": "اصلاحات مارتن لوتر", + "description": "مارتن لوتر با انتشار 95 مقاله، اصلاحات پروتستانتی را آغاز کرد.", + "choices": [ + { + "text": "حمایت از اصلاحات", + "effects": { + "religion": "Protestantism", + "political_stability": -10, + "culture_score": 10 + }, + "description": "حمایت از اصلاحات با خطر شورش و تغییرات فرهنگی." + }, + { + "text": "مبارزه با اصلاحات", + "effects": { + "religion": "Catholicism", + "relations": {"-": 15}, + "public_dissatisfaction": 10 + }, + "description": "مبارزه با اصلاحات با ایجاد تنش‌های داخلی و خارجی." + } + ] + }, + { + "year": 1520, + "name": "دوران طلایی عثمانی‌ها", + "description": "دوران طلایی امپراتوری عثمانی تحت حکومت سلیمان قانونی آغاز شد.", + "choices": [ + { + "text": "گسترش نظامی به اروپا", + "effects": { + "controlled_territories": 2, + "military_strength": -10, + "public_dissatisfaction": 15 + }, + "description": "حمله به اروپا برای گسترش قلمرو با هزینه‌های نظامی و اجتماعی." + }, + { + "text": "تقویت اقتصاد و فرهنگ", + "effects": { + "economy": {"trade": 15, "industry": 10}, + "culture_score": 15, + "political_stability": 10 + }, + "description": "تمرکز بر توسعه داخلی به جای گسترش نظامی." + } + ] + }, + { + "year": 1526, + "name": "نبرد موحاس", + "description": "نبرد مهم با امپراتوری عثمانی در موحاس رخ داد.", + "choices": [ + { + "text": "شکست عثمانی‌ها", + "effects": { + "military_strength": 15, + "controlled_territories": 1, + "public_dissatisfaction": -10 + }, + "description": "پیروزی در نبرد با افزایش قلمرو و معنویه." + }, + { + "text": "شکست و اشغال توسط عثمانی‌ها", + "effects": { + "controlled_territories": -1, + "political_stability": -20, + "gold": -5000 + }, + "description": "شکست در نبرد با کاهش قلمرو و ثبات." + } + ] + }, + { + "year": 1534, + "name": "انفصال از کلیسای کاتولیک", + "description": "هنری هشتم انگلستان را از کلیسای کاتولیک جدا کرد.", + "choices": [ + { + "text": "تقویت کلیسای انگلیسی", + "effects": { + "religion": "Anglicanism", + "political_stability": 10, + "relations": {"-": 20} + }, + "description": "ایجاد کلیسای ملی انگلیسی با تأثیرات سیاسی و دیپلماتیک." + }, + { + "text": "حفظ روابط با پاپ", + "effects": { + "public_dissatisfaction": 25, + "political_stability": -15 + }, + "description": "تلاش برای حفظ روابط با کلیسای کاتولیک با پیامدهای داخلی." + } + ] + }, + { + "year": 1543, + "name": "ورود اولین اروپایی‌ها", + "description": "اولین اروپایی‌ها (پرتغالی‌ها) به ژاپن وارد شدند.", + "choices": [ + { + "text": "باز کردن روابط تجاری", + "effects": { + "economy": {"trade": 15}, + "technology": {"trade": 1}, + "religion": "Mixed" + }, + "description": "گشودن روابط تجاری با اروپا و ورود فناوری‌های جدید." + }, + { + "text": "بستن مرزها به اروپایی‌ها", + "effects": { + "economy": {"trade": -5}, + "political_stability": 5, + "technology": {"trade": -1} + }, + "description": "بستن مرزها برای حفظ فرهنگ و ثبات داخلی." + } + ] + }, + { + "year": 1547, + "name": "تاج‌گذاری ایوان سوم", + "description": "ایوان سوم خود را به عنوان تزار روسیه تاج‌گذاری کرد.", + "choices": [ + { + "text": "گسترش به سمت آسیا", + "effects": { + "controlled_territories": 2, + "military_strength": -10, + "public_dissatisfaction": 10 + }, + "description": "گسترش قلمرو به سمت سیبری و آسیا." + }, + { + "text": "تمرکز بر اروپا", + "effects": { + "relations": {"+": 15}, + "economy": {"trade": 10}, + "political_stability": 5 + }, + "description": "تقویت روابط با کشورهای اروپایی." + } + ] + }, + { + "year": 1555, + "name": "صلح آوسپورگ", + "description": "صلح آوسپورگ برای خاتمه دادن به جنگ‌های دینی امضا شد.", + "choices": [ + { + "text": "پذیرش آزادی دینی", + "effects": { + "political_stability": 15, + "public_dissatisfaction": -10, + "religion": "Multi-religious" + }, + "description": "پذیرش تنوع دینی با افزایش ثبات داخلی." + }, + { + "text": "ادامه سیاست یکدستی دینی", + "effects": { + "political_stability": -10, + "relations": {"-": 15}, + "public_dissatisfaction": 15 + }, + "description": "ادامه سیاست یکدستی دینی با خطر شورش و تنش‌های خارجی." + } + ] + }, + { + "year": 1562, + "name": "جنگ‌های دینی", + "description": "جنگ‌های داخلی بین کاتولیک‌ها و پروتستان‌ها آغاز شد.", + "choices": [ + { + "text": "حمایت از کاتولیک‌ها", + "effects": { + "religion": "Catholicism", + "political_stability": 5, + "public_dissatisfaction": 15 + }, + "description": "حمایت از گروه اکثریت با ایجاد نارضایتی در گروه اقلیت." + }, + { + "text": "حمایت از پروتستان‌ها", + "effects": { + "religion": "Protestantism", + "relations": {"-": 25}, + "political_stability": -10 + }, + "description": "حمایت از گروه اقلیت با خطر شورش و تنش‌های بین‌المللی." + }, + { + "text": "اعلان بی‌طرفی و تلاش برای صلح", + "effects": { + "political_stability": -5, + "diplomacy_points": 10 + }, + "description": "تلاش برای حل و فصل صلح‌آمیز با پیامدهای سیاسی." + } + ] + } +] +``` + +### 10. `game/climate/__init__.py` +```python +""" +پکیج سیستم آب‌وهوایی +""" + +from .climate_system import ClimateSystem +``` + +### 11. `game/climate/climate_system.py` (سیستم آب‌وهوایی) +```python +""" +سیستم مدیریت آب‌وهوایی و تغییرات اقلیمی +""" + +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) +``` + +### 12. `game/climate/weather_events.py` (رویدادهای آب‌وهوایی) +```python +""" +تعریف رویدادهای آب‌وهوایی برای بازی +""" + +WEATHER_EVENTS = [ + { + "name": "خشکسالی شدید", + "description": "خشکسالی طولانی‌مدت باعث کاهش شدید بارش‌ها شده است.", + "trigger": lambda climate: climate.precipitation < 20, + "choices": [ + { + "text": "ساخت سیستم‌های آبیاری پیشرفته", + "effects": { + "gold": -5000, + "economy": {"agriculture": 10}, + "environment": {"water_usage": 15} + }, + "description": "سرمایه‌گذاری در سیستم‌های آبیاری برای کاهش اثرات خشکسالی." + }, + { + "text": "کاهش کشت محصولات آب‌بر", + "effects": { + "economy": {"agriculture": -5}, + "public_dissatisfaction": 5 + }, + "description": "تغییر الگوی کشت برای سازگاری با خشکسالی." + } + ] + }, + { + "name": "سیل شدید", + "description": "بارش‌های شدید باعث سیل در مناطق پایین‌دست شده است.", + "trigger": lambda climate: climate.precipitation > 70, + "choices": [ + { + "text": "ساخت سد و کانال‌های آب‌گذر", + "effects": { + "gold": -8000, + "economy": {"agriculture": 5}, + "environment": {"deforestation": -5} + }, + "description": "ساخت سازه‌های کنترل سیل برای کاهش خسارات آینده." + }, + { + "text": "کمک‌های اضطراری به مناطق سیل‌زده", + "effects": { + "gold": -3000, + "happiness": 5, + "public_dissatisfaction": -5 + }, + "description": "کمک به مناطق سیل‌زده برای کاهش رنج مردم." + } + ] + }, + { + "name": "موج گرما", + "description": "دمای هوا به شدت افزایش یافته و باعث افزایش مرگ‌ومیر شده است.", + "trigger": lambda climate: climate.temperature > 35, + "choices": [ + { + "text": "ساخت سیستم‌های خنک‌کننده عمومی", + "effects": { + "gold": -6000, + "health_index": 5, + "economy": {"industry": 5} + }, + "description": "سرمایه‌گذاری در زیرساخت‌های خنک‌کننده برای کاهش مرگ‌ومیر." + }, + { + "text": "اعلام تعطیلی مدارس و ادارات", + "effects": { + "economy": {"industry": -5, "trade": -3}, + "happiness": 3, + "public_dissatisfaction": -3 + }, + "description": "کاهش فعالیت‌های اجتماعی برای کاهش قربانیان." + } + ] + }, + { + "name": "موج سرما", + "description": "دمای هوا به شدت کاهش یافته و باعث مشکلات سرمایشی شده است.", + "trigger": lambda climate: climate.temperature < -10, + "choices": [ + { + "text": "توزیع سوخت گرمایشی رایگان", + "effects": { + "gold": -4000, + "happiness": 8, + "public_dissatisfaction": -8 + }, + "description": "کمک به مردم برای گذران زمستان سرد." + }, + { + "text": "ساخت سیستم‌های گرمایشی مدرن", + "effects": { + "gold": -7000, + "economy": {"industry": 8}, + "environment": {"pollution": 5} + }, + "description": "سرمایه‌گذاری در فناوری‌های گرمایشی پیشرفته." + } + ] + }, + { + "name": "طوفان شدید", + "description": "طوفان شدیدی در سواحل کشور شما رخ داده است.", + "trigger": lambda climate: climate.region in ["Mediterranean", "Tropical"], + "choices": [ + { + "text": "تقویت سواحل و ساخت دیوارهای سواحلی", + "effects": { + "gold": -9000, + "economy": {"trade": 3}, + "environment": {"deforestation": -5} + }, + "description": "سرمایه‌گذاری در دفاع ساحلی برای کاهش خطرات آینده." + }, + { + "text": "تقویت سیستم‌های هشدار زودهنگام", + "effects": { + "gold": -5000, + "happiness": 5, + "public_dissatisfaction": -5 + }, + "description": "ساخت سیستم‌های هشدار برای کاهش قربانیان." + } + ] + } +] +``` + +### 13. `game/demographics/__init__.py` +```python +""" +پکیج سیستم جمعیت‌شناسی +""" + +from .population_system import PopulationSystem +``` + +### 14. `game/demographics/population_system.py` (سیستم جمعیت‌شناسی) +```python +""" +سیستم جمعیت‌شناسی پیشرفته با رشد جمعیت، مهاجرت و ساختار سنی +""" + +class PopulationSystem: + """سیستم جمعیت‌شناسی پیشرفته""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم جمعیت""" + self.game_state = game_state + self.age_distribution = { + "0-14": 35, + "15-64": 60, + "65+": 5 + } + self.birth_rate = 25 + self.death_rate = 10 + self.migration_rate = 0 + + def initialize(self): + """راه‌اندازی اولیه سیستم جمعیت""" + # تنظیم توزیع سنی بر اساس کشور انتخابی + country = self.game_state.player_country + if "population_profile" in country: + self.age_distribution = country["population_profile"]["age_distribution"] + + # تنظیم نرخ‌های جمعیتی + self.birth_rate = country["base_attributes"].get("birth_rate", 25) + self.death_rate = country["base_attributes"].get("death_rate", 10) + self.migration_rate = country["base_attributes"].get("migration_rate", 0) + + def display_population_structure(self): + """نمایش ساختار جمعیت کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("ساختار جمعیت") + + # نمایش اطلاعات کلی جمعیت + ConsoleUI.display_message(f"جمعیت کل: {self.game_state.population:,} نفر") + ConsoleUI.display_message(f"رشد جمعیت: {self.game_state.population_growth:.1f}%") + ConsoleUI.display_message(f"نرخ باروری: {self.birth_rate} در هزار") + ConsoleUI.display_message(f"نرخ مرگ‌ومیر: {self.death_rate} در هزار") + ConsoleUI.display_message(f"نرخ مهاجرت: {self.migration_rate} در هزار") + ConsoleUI.display_message(f"جمعیت شهری: {self.game_state.urban_population}%") + + # نمایش توزیع سنی + ConsoleUI.display_section_title("توزیع سنی") + for age_group, percentage in self.age_distribution.items(): + ConsoleUI.display_message(f"{age_group}: {percentage}%") + + # نمایش سطح سواد + ConsoleUI.display_section_title("آموزش") + ConsoleUI.display_message(f"نرخ سواد: {self.game_state.literacy_rate}%") + + ConsoleUI.wait_for_enter() + + def manage_migration(self): + """مدیریت سیاست‌های مهاجرتی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت مهاجرت") + + migration_options = [ + "سیاست مهاجرت آزاد (افزایش جمعیت و تنوع فرهنگی)", + "محدودیت‌های شدید مهاجرتی (حفاظت از هویت ملی)", + "سیاست مهاجرت انتخابی (جذب نیروهای متخصص)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(migration_options) + + if choice == 1: + self._apply_open_migration_policy() + elif choice == 2: + self._apply_restricted_migration_policy() + elif choice == 3: + self._apply_selective_migration_policy() + # choice == 4: برگشت + + def _apply_open_migration_policy(self): + """اعمال سیاست مهاجرت آزاد""" + from ui.console_ui import ConsoleUI + + self.migration_rate = 15 + self.game_state.population_growth += 0.8 + self.game_state.cultural_influence += 5 + self.game_state.public_dissatisfaction += 3 + + ConsoleUI.display_success("سیاست مهاجرت آزاد اعمال شد.") + ConsoleUI.display_message("• نرخ مهاجرت به 15 در هزار افزایش یافت") + ConsoleUI.display_message("• رشد جمعیت 0.8% افزایش یافت") + ConsoleUI.display_message("• نفوذ فرهنگی 5% افزایش یافت") + ConsoleUI.display_warning("• نارضایتی عمومی 3% افزایش یافت (به دلیل تنش‌های فرهنگی)") + + ConsoleUI.wait_for_enter() + + def _apply_restricted_migration_policy(self): + """اعمال سیاست مهاجرت محدود""" + from ui.console_ui import ConsoleUI + + self.migration_rate = -5 + self.game_state.population_growth -= 0.5 + self.game_state.cultural_influence -= 3 + self.game_state.political_stability += 2 + + ConsoleUI.display_success("سیاست مهاجرت محدود اعمال شد.") + ConsoleUI.display_message("• نرخ مهاجرت به -5 در هزار کاهش یافت") + ConsoleUI.display_message("• رشد جمعیت 0.5% کاهش یافت") + ConsoleUI.display_message("• نفوذ فرهنگی 3% کاهش یافت") + ConsoleUI.display_success("• ثبات سیاسی 2% افزایش یافت (به دلیل کاهش تنش‌های فرهنگی)") + + ConsoleUI.wait_for_enter() + + def _apply_selective_migration_policy(self): + """اعمال سیاست مهاجرت انتخابی""" + from ui.console_ui import ConsoleUI + + self.migration_rate = 5 + self.game_state.population_growth += 0.3 + self.game_state.technology["education"] += 1 + self.game_state.technology["industry"] += 1 + self.game_state.public_dissatisfaction += 1 + + ConsoleUI.display_success("سیاست مهاجرت انتخابی اعمال شد.") + ConsoleUI.display_message("• نرخ مهاجرت به 5 در هزار افزایش یافت") + ConsoleUI.display_message("• رشد جمعیت 0.3% افزایش یافت") + ConsoleUI.display_message("• فناوری آموزشی 1 سطح افزایش یافت") + ConsoleUI.display_message("• فناوری صنعتی 1 سطح افزایش یافت") + ConsoleUI.display_warning("• نارضایتی عمومی 1% افزایش یافت (به دلیل رقابت برای شغل)") + + ConsoleUI.wait_for_enter() + + def family_planning(self): + """مدیریت برنامه‌ریزی خانواده و سیاست‌های جمعیتی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("برنامه‌ریزی خانواده") + + planning_options = [ + "سیاست افزایش جمعیت (تشویق به افزایش تولد)", + "سیاست کنترل جمعیت (کاهش نرخ باروری)", + "برنامه‌ریزی خانواده خنثی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(planning_options) + + if choice == 1: + self._apply_population_growth_policy() + elif choice == 2: + self._apply_population_control_policy() + elif choice == 3: + self._apply_neutral_family_policy() + # choice == 4: برگشت + + def _apply_population_growth_policy(self): + """اعمال سیاست افزایش جمعیت""" + from ui.console_ui import ConsoleUI + + self.birth_rate += 5 + self.game_state.population_growth += 0.7 + self.game_state.resources["food"] -= 10 + self.game_state.public_dissatisfaction += 2 + + ConsoleUI.display_success("سیاست افزایش جمعیت اعمال شد.") + ConsoleUI.display_message("• نرخ باروری 5 واحد افزایش یافت") + ConsoleUI.display_message("• رشد جمعیت 0.7% افزایش یافت") + ConsoleUI.display_warning("• منابع غذایی 10 واحد کاهش یافت") + ConsoleUI.display_warning("• نارضایتی عمومی 2% افزایش یافت (به دلیل فشار بر منابع)") + + ConsoleUI.wait_for_enter() + + def _apply_population_control_policy(self): + """اعمال سیاست کنترل جمعیت""" + from ui.console_ui import ConsoleUI + + self.birth_rate -= 8 + self.game_state.population_growth -= 0.5 + self.game_state.literacy_rate += 3 + self.game_state.happiness += 2 + + ConsoleUI.display_success("سیاست کنترل جمعیت اعمال شد.") + ConsoleUI.display_message("• نرخ باروری 8 واحد کاهش یافت") + ConsoleUI.display_message("• رشد جمعیت 0.5% کاهش یافت") + ConsoleUI.display_success("• نرخ سواد 3% افزایش یافت") + ConsoleUI.display_success("• شادی مردم 2% افزایش یافت") + + ConsoleUI.wait_for_enter() + + def _apply_neutral_family_policy(self): + """اعمال سیاست خنثی برنامه‌ریزی خانواده""" + from ui.console_ui import ConsoleUI + + self.birth_rate = max(15, self.birth_rate - 2) + self.game_state.population_growth = max(0.2, self.game_state.population_growth - 0.2) + self.game_state.literacy_rate += 1 + + ConsoleUI.display_success("سیاست خنثی برنامه‌ریزی خانواده اعمال شد.") + ConsoleUI.display_message("• نرخ باروری کمی کاهش یافت") + ConsoleUI.display_message("• رشد جمعیت کمی کاهش یافت") + ConsoleUI.display_success("• نرخ سواد 1% افزایش یافت") + + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم جمعیت""" + # محاسبه رشد جمعیت + natural_growth = (self.birth_rate - self.death_rate) / 10 + migration_effect = self.migration_rate / 10 + total_growth = natural_growth + migration_effect + + # اعمال رشد جمعیت + population_increase = int(self.game_state.population * total_growth / 100) + self.game_state.population += population_increase + self.game_state.population_growth = total_growth + + # به‌روزرسانی توزیع سنی + self._update_age_distribution() + + # تأثیرات اجتماعی + self._apply_social_effects() + + def _update_age_distribution(self): + """به‌روزرسانی توزیع سنی جمعیت""" + # تغییرات طبیعی توزیع سنی + self.age_distribution["0-14"] = max(15, self.age_distribution["0-14"] - 0.5) + self.age_distribution["15-64"] = min(70, self.age_distribution["15-64"] + 0.3) + self.age_distribution["65+"] = min(20, self.age_distribution["65+"] + 0.2) + + # تأثیر نرخ باروری + if self.birth_rate > 20: + self.age_distribution["0-14"] = min(40, self.age_distribution["0-14"] + 0.3) + self.age_distribution["15-64"] = max(50, self.age_distribution["15-64"] - 0.2) + + # تأثیر نرخ مرگ‌ومیر + if self.death_rate < 8: + self.age_distribution["65+"] = min(25, self.age_distribution["65+"] + 0.3) + self.age_distribution["0-14"] = max(10, self.age_distribution["0-14"] - 0.1) + + def _apply_social_effects(self): + """اعمال تأثیرات اجتماعی تغییرات جمعیتی""" + # تأثیر جمعیت پیر شونده + if self.age_distribution["65+"] > 15: + self.game_state.health_index = max(0, self.game_state.health_index - 1) + self.game_state.resources["food"] -= 2 + self.game_state.public_dissatisfaction += 1 + + # تأثیر جمعیت جوان + if self.age_distribution["0-14"] > 30: + self.game_state.literacy_rate = min(100, self.game_state.literacy_rate + 0.5) + self.game_state.resources["food"] += 3 + self.game_state.happiness += 1 + + # تأثیر جمعیت شهری + if self.game_state.urban_population > 50: + self.game_state.economy["industry"] = min(100, self.game_state.economy["industry"] + 1) + self.game_state.economy["agriculture"] = max(0, self.game_state.economy["agriculture"] - 1) + self.game_state.environment["pollution"] = min(100, self.game_state.environment["pollution"] + 2) +``` + +### 15. `game/demographics/migration_system.py` (سیستم مهاجرت) +```python +""" +سیستم مدیریت مهاجرت و جریان‌های انسانی +""" + +class MigrationSystem: + """سیستم مدیریت مهاجرت و جریان‌های انسانی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم مهاجرت""" + self.game_state = game_state + self.migration_routes = [] + self.migration_policies = { + "open": {"cost": 3000, "effect": 15}, + "selective": {"cost": 2000, "effect": 8}, + "restricted": {"cost": 1000, "effect": -5} + } + + def initialize(self): + """راه‌اندازی اولیه سیستم مهاجرت""" + # تنظیم مسیرهای مهاجرت اولیه بر اساس کشور انتخابی + country = self.game_state.player_country["name"] + if country == "پادشاهی ایران": + self.migration_routes = [ + {"from": "ترکیه", "rate": -5}, + {"from": "عراق", "rate": 10}, + {"from": "افغانستان", "rate": 15} + ] + elif country == "امپراتوری عثمانی": + self.migration_routes = [ + {"from": "یونان", "rate": -10}, + {"from": "بلغارستان", "rate": 8}, + {"from": "ایتالیا", "rate": 5} + ] + else: + self.migration_routes = [ + {"from": "کشور همسایه 1", "rate": self.game_state.random.randint(-10, 10)}, + {"from": "کشور همسایه 2", "rate": self.game_state.random.randint(-10, 10)}, + {"from": "کشور دوردست", "rate": self.game_state.random.randint(-5, 5)} + ] + + def display_migration_status(self): + """نمایش وضعیت مهاجرت کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت مهاجرت") + + # نمایش نرخ مهاجرت کلی + ConsoleUI.display_message(f"نرخ مهاجرت کلی: {self.game_state.migration_rate} در هزار", indent=2) + + # نمایش سیاست مهاجرتی فعلی + policy = self._get_current_policy() + ConsoleUI.display_message(f"سیاست مهاجرتی: {policy}", indent=2) + + # نمایش مسیرهای مهاجرت + ConsoleUI.display_section_title("مسیرهای مهاجرت", width=60) + for route in self.migration_routes: + direction = "ورودی" if route["rate"] > 0 else "خروجی" + ConsoleUI.display_message( + f"{route['from']}: {abs(route['rate'])} در هزار ({direction})", + indent=2 + ) + + ConsoleUI.wait_for_enter() + + def _get_current_policy(self): + """دریافت سیاست مهاجرتی فعلی بر اساس نرخ مهاجرت""" + if self.game_state.migration_rate > 5: + return "مهاجرت آزاد" + elif self.game_state.migration_rate > -2: + return "مهاجرت انتخابی" + else: + return "مهاجرت محدود" + + def set_migration_policy(self): + """تنظیم سیاست مهاجرتی جدید""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تنظیم سیاست مهاجرتی") + + policy_options = [ + "مهاجرت آزاد (نرخ مهاجرت: +15)", + "مهاجرت انتخابی (نرخ مهاجرت: +5)", + "مهاجرت محدود (نرخ مهاجرت: -5)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(policy_options) + + if choice == 4: + return # برگشت + + # انتخاب سیاست + policies = list(self.migration_policies.keys()) + selected_policy = policies[choice-1] + policy_info = self.migration_policies[selected_policy] + + # بررسی هزینه + if self.game_state.gold < policy_info["cost"]: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال سیاست جدید + self.game_state.gold -= policy_info["cost"] + self.game_state.migration_rate = policy_info["effect"] + + # به‌روزرسانی مسیرهای مهاجرت + self._update_migration_routes(selected_policy) + + ConsoleUI.display_success(f"سیاست مهاجرتی '{policy_options[choice-1]}' اعمال شد.") + ConsoleUI.display_message(f"هزینه: {policy_info['cost']} سکه طلا") + ConsoleUI.display_message(f"نرخ مهاجرت جدید: {self.game_state.migration_rate} در هزار") + + ConsoleUI.wait_for_enter() + + def _update_migration_routes(self, policy): + """به‌روزرسانی مسیرهای مهاجرت بر اساس سیاست جدید""" + if policy == "open": + for route in self.migration_routes: + route["rate"] = max(-5, route["rate"] + 5) + elif policy == "selective": + for route in self.migration_routes: + route["rate"] = route["rate"] + 2 + else: # restricted + for route in self.migration_routes: + route["rate"] = min(5, route["rate"] - 5) + + def manage_migration_crisis(self): + """مدیریت بحران‌های مهاجرتی""" + from ui.console_ui import ConsoleUI + + # بررسی احتمال بحران مهاجرتی + if abs(self.game_state.migration_rate) > 10 and self.game_state.random.random() < 0.3: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران مهاجرتی") + + if self.game_state.migration_rate > 10: + crisis_type = "جریان زیاد مهاجر" + description = "جریان زیاد مهاجر به کشور شما باعث ایجاد فشار بر زیرساخت‌ها شده است." + else: + crisis_type = "مهاجرت انبوه" + description = "مهاجرت انبوه شهروندان شما به کشورهای دیگر رخ داده است." + + ConsoleUI.display_warning(description, indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "تقویت زیرساخت‌ها (6000 سکه)", + "اصلاحات سیاست مهاجرتی (3000 سکه)", + "مذاکره با کشورهای مبدا/مقصد (2000 سکه)", + "بی‌تفاوتی" + ] + costs = [6000, 3000, 2000, 0] + effects = [ + {"migration_rate": -5, "public_dissatisfaction": -5, "economy": {"infrastructure": 10}}, + {"migration_rate": -3, "political_stability": 5}, + {"migration_rate": -2, "relations": {"+": 5}}, + {"migration_rate": 5, "public_dissatisfaction": 15} + ] + + # نمایش گزینه‌ها + 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_migration_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_migration_crisis_response(self, 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 == "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)) + + ConsoleUI.display_success("بحران مهاجرتی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم مهاجرت""" + # به‌روزرسانی مسیرهای مهاجرت + self._update_migration_routes_randomly() + + # محاسبه نرخ مهاجرت کلی + total_rate = sum(route["rate"] for route in self.migration_routes) + self.game_state.migration_rate = total_rate / len(self.migration_routes) + + # بررسی بحران‌های مهاجرتی + self.manage_migration_crisis() + + def _update_migration_routes_randomly(self): + """به‌روزرسانی تصادفی مسیرهای مهاجرت""" + for route in self.migration_routes: + change = self.game_state.random.randint(-2, 2) + route["rate"] = max(-15, min(15, route["rate"] + change)) +``` + +### 16. `game/technology/__init__.py` +```python +""" +پکیج سیستم فناوری +""" + +from .research_system import ResearchSystem +``` + +### 17. `game/technology/tech_tree.py` (درخت فناوری) +```python +""" +مدیریت درخت فناوری و پیش‌نیازها +""" + +class TechTree: + """مدیریت درخت فناوری و پیش‌نیازها""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از درخت فناوری""" + self.game_state = game_state + self.tech_categories = [ + "military", "agriculture", "trade", + "industry", "medicine", "education" + ] + + def get_available_technologies(self, category=None): + """دریافت لیست فناوری‌های قابل تحقیق""" + available = [] + + # فیلتر بر اساس دسته‌بندی + categories = [category] if category else self.tech_categories + + for tech_id, tech in self.game_state.technology.items(): + # بررسی آنکه فناوری قبلاً تحقیق نشده باشد + if tech_id in self.game_state.unlocked_technologies: + continue + + # بررسی دسته‌بندی + if tech["category"] not in categories: + continue + + # بررسی پیش‌نیازها + if not self._check_technology_prerequisites(tech_id): + continue + + available.append(tech_id) + + return available + + def _check_technology_prerequisites(self, tech_id): + """بررسی پیش‌نیازهای فناوری""" + tech = self.game_state.technology[tech_id] + + # بررسی پیش‌نیازهای فناوری + for prereq in tech.get("prerequisites", []): + if prereq not in self.game_state.unlocked_technologies: + return False + + # بررسی پیش‌نیازهای سطح فناوری + if "tech_level_req" in tech and self.game_state.technology_level < tech["tech_level_req"]: + return False + + return True + + def display_tech_tree(self, category=None): + """نمایش درخت فناوری و پیشرفت فعلی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + title = "درخت فناوری" if not category else f"درخت فناوری - {category}" + ConsoleUI.display_section_title(title) + + # نمایش سطح فناوری کلی + ConsoleUI.display_message(f"سطح فناوری کلی: {self.game_state.technology_level}") + ConsoleUI.display_message(f"کارایی تحقیق: {self.game_state.research_efficiency:.1f}x") + + # نمایش فناوری‌های قابل تحقیق + ConsoleUI.display_section_title("فناوری‌های قابل تحقیق") + + available_techs = self.get_available_technologies(category) + if not available_techs: + ConsoleUI.display_message("هیچ فناوری جدیدی برای تحقیق در دسترس نیست.") + else: + for i, tech_id in enumerate(available_techs, 1): + tech = self.game_state.technology[tech_id] + cost = self.calculate_research_cost(tech_id) + ConsoleUI.display_message(f"{i}. {tech['name']} - هزینه: {cost} واحد تحقیق") + ConsoleUI.display_message(f" {tech['description']}") + + # نمایش فناوری‌های تحقیق شده + ConsoleUI.display_section_title("فناوری‌های تحقیق شده") + researched = [tech for tech in self.game_state.unlocked_technologies + if tech in self.game_state.technology] + + if not researched: + ConsoleUI.display_message("شما هنوز هیچ فناوری را تحقیق نکرده‌اید.") + else: + for tech_id in researched: + tech = self.game_state.technology[tech_id] + ConsoleUI.display_message(f"• {tech['name']}") + ConsoleUI.display_message(f" {tech['description']}") + + ConsoleUI.wait_for_enter() + + def calculate_research_cost(self, tech_id): + """محاسبه هزینه تحقیق برای یک فناوری""" + tech = self.game_state.technology[tech_id] + base_cost = tech["base_cost"] + + # تأثیر سطح فناوری فعلی + level_factor = 1 + (self.game_state.technology_level * 0.1) + + # تأثیر کارایی تحقیق + efficiency_factor = 1 / self.game_state.research_efficiency + + # تأثیر سیاست‌های آموزشی + education_factor = 1 - (self.game_state.budget["education"] * 0.01) + + return int(base_cost * level_factor * efficiency_factor * education_factor) + + def get_tech_category_color(self, category): + """دریافت رنگ مناسب برای دسته‌بندی فناوری""" + colors = { + "military": "\033[91m", # قرمز روشن + "agriculture": "\033[92m", # سبز روشن + "trade": "\033[93m", # زرد روشن + "industry": "\033[94m", # آبی روشن + "medicine": "\033[95m", # بنفش روشن + "education": "\033[96m", # فیروزه‌ای روشن + "environment": "\033[92m", # سبز روشن + "communication": "\033[94m" # آبی روشن + } + return colors.get(category, "\033[0m") # رنگ پیش‌فرض +``` + +### 18. `game/technology/research_system.py` (سیستم تحقیق) +```python +""" +سیستم تحقیق و توسعه فناوری با درخت فناوری و پیش‌نیازها +""" + +from data.tech.tech_definitions import TECHNOLOGIES +from data.tech.tech_trees import TECH_TREES + +class ResearchSystem: + """سیستم تحقیق و توسعه فناوری""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم تحقیق""" + self.game_state = game_state + self.research_fields = ["military", "agriculture", "trade", "industry", "medicine", "education"] + self.current_research = None + self.research_progress = 0 + self.research_efficiency = 1.0 + + def initialize(self): + """راه‌اندازی اولیه سیستم تحقیق""" + # تنظیم درخت فناوری بر اساس کشور انتخابی + country_name = self.game_state.player_country["name"] + if country_name in TECH_TREES: + self.tech_tree = TECH_TREES[country_name] + else: + self.tech_tree = TECH_TREES["Generic"] + + # تنظیم فناوری‌های اولیه + self.game_state.unlocked_technologies = self.tech_tree["starting_technologies"].copy() + + # محاسبه سطح فناوری + self._calculate_technology_level() + + def display_tech_tree(self): + """نمایش درخت فناوری و پیشرفت فعلی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("درخت فناوری") + + # نمایش سطح فناوری کلی + ConsoleUI.display_message(f"سطح فناوری کلی: {self.game_state.technology_level}") + ConsoleUI.display_message(f"فناوری جاری در دست تحقیق: {self.current_research or 'هیچ‌کدام'}") + ConsoleUI.display_message(f"پیشرفت تحقیق: {self.research_progress}%") + ConsoleUI.display_message(f"کارایی تحقیق: {self.research_efficiency:.1f}x") + + # نمایش فناوری‌های قابل تحقیق + ConsoleUI.display_section_title("فناوری‌های قابل تحقیق") + + available_techs = self.get_available_technologies() + if not available_techs: + ConsoleUI.display_message("هیچ فناوری جدیدی برای تحقیق در دسترس نیست.") + else: + for i, tech_id in enumerate(available_techs, 1): + tech = TECHNOLOGIES[tech_id] + cost = self.calculate_research_cost(tech_id) + ConsoleUI.display_message(f"{i}. {tech['name']} - هزینه: {cost} واحد تحقیق") + ConsoleUI.display_message(f" {tech['description']}") + + ConsoleUI.wait_for_enter() + + def get_available_technologies(self): + """دریافت لیست فناوری‌های قابل تحقیق""" + available = [] + + for tech_id, tech in TECHNOLOGIES.items(): + # بررسی آنکه فناوری قبلاً تحقیق نشده باشد + if tech_id in self.game_state.unlocked_technologies: + continue + + # بررسی پیش‌نیازها + if not self._check_technology_prerequisites(tech_id): + continue + + available.append(tech_id) + + return available + + def _check_technology_prerequisites(self, tech_id): + """بررسی پیش‌نیازهای فناوری""" + tech = TECHNOLOGIES[tech_id] + + # بررسی پیش‌نیازهای فناوری + for prereq in tech.get("prerequisites", []): + if prereq not in self.game_state.unlocked_technologies: + return False + + # بررسی پیش‌نیازهای سطح فناوری + if "tech_level_req" in tech and self.game_state.technology_level < tech["tech_level_req"]: + return False + + return True + + def conduct_research(self): + """شروع یا ادامه تحقیق در یک فناوری""" + from ui.console_ui import ConsoleUI + + available_techs = self.get_available_technologies() + + if not available_techs: + ConsoleUI.display_warning("هیچ فناوری جدیدی برای تحقیق در دسترس نیست.") + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + tech_options = [TECHNOLOGIES[tech_id]["name"] for tech_id in available_techs] + tech_options.append("برگشت") + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تحقیق فناوری") + choice = ConsoleUI.get_menu_choice(tech_options) + + if choice == len(tech_options): + return # برگشت + + selected_tech = available_techs[choice-1] + self.start_research(selected_tech) + + def start_research(self, tech_id): + """شروع تحقیق در یک فناوری جدید""" + from ui.console_ui import ConsoleUI + + tech = TECHNOLOGIES[tech_id] + cost = self.calculate_research_cost(tech_id) + + # بررسی هزینه تحقیق + if self.game_state.gold < cost: + ConsoleUI.display_error(f"موجودی طلا کافی نیست! هزینه تحقیق: {cost} سکه") + ConsoleUI.wait_for_enter() + return + + # کسر هزینه و شروع تحقیق + self.game_state.gold -= cost + self.current_research = tech_id + self.research_progress = 0 + + ConsoleUI.display_success(f"تحقیق در '{tech['name']}' آغاز شد.") + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message(f"شرح: {tech['description']}") + ConsoleUI.wait_for_enter() + + def calculate_research_cost(self, tech_id): + """محاسبه هزینه تحقیق برای یک فناوری""" + tech = TECHNOLOGIES[tech_id] + base_cost = tech["base_cost"] + + # تأثیر سطح فناوری فعلی + level_factor = 1 + (self.game_state.technology_level * 0.1) + + # تأثیر کارایی تحقیق + efficiency_factor = 1 / self.research_efficiency + + # تأثیر سیاست‌های آموزشی + education_factor = 1 - (self.game_state.budget["education"] * 0.01) + + return int(base_cost * level_factor * efficiency_factor * education_factor) + + def manage_research_centers(self): + """مدیریت مراکز تحقیقاتی و افزایش کارایی تحقیق""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت مراکز تحقیقاتی") + + options = [ + f"افزایش بودجه تحقیقات ({self.game_state.budget['education']}%)", + "ساخت مرکز تحقیقاتی جدید", + "همکاری تحقیقاتی با کشورهای دیگر", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(options) + + if choice == 1: + self.increase_research_budget() + elif choice == 2: + self.build_research_center() + elif choice == 3: + self.research_cooperation() + # choice == 4: برگشت + + def increase_research_budget(self): + """افزایش بودجه تحقیقات از طریق بودجه آموزش""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("افزایش بودجه تحقیقات") + + # محاسب�� هزینه و تأثیر + current_budget = self.game_state.budget["education"] + increase_amount = min(5, 100 - current_budget) + cost = increase_amount * 500 + + ConsoleUI.display_message(f"افزایش بودجه آموزش از {current_budget}% به {current_budget + increase_amount}%") + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• کارایی تحقیق 0.1x افزایش می‌یابد") + ConsoleUI.display_message("• نرخ سواد 1% افزایش می‌یابد") + + if not ConsoleUI.confirm_action("آیا مایل به انجام این تغییر هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.budget["education"] += increase_amount + self.research_efficiency += 0.1 + self.game_state.literacy_rate = min(100, self.game_state.literacy_rate + 1) + + ConsoleUI.display_success("بودجه آموزش افزایش یافت.") + ConsoleUI.wait_for_enter() + + def build_research_center(self): + """ساخت مرکز تحقیقاتی جدید""" + from ui.console_ui import ConsoleUI + + cost = 10000 + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("ساخت مرکز تحقیقاتی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• کارایی تحقیق 0.3x افزایش می‌یابد") + ConsoleUI.display_message("• هزینه تحقیقات 5% کاهش می‌یابد") + ConsoleUI.display_message("• هزینه نگهداری سالانه: 500 سکه") + + if not ConsoleUI.confirm_action("آیا مایل به ساخت مرکز تحقیقاتی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.research_efficiency += 0.3 + self.game_state.budget["education"] += 2 # هزینه نگهداری + + ConsoleUI.display_success("مرکز تحقیقاتی جدید ساخته شد.") + ConsoleUI.wait_for_enter() + + def research_cooperation(self): + """همکاری تحقیقاتی با کشورهای دیگر""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("همکاری تحقیقاتی") + + # فیلتر کشورهایی که روابط خوبی داریم + potential_partners = [] + for country, relation in self.game_state.relations.items(): + if relation > 50 and country != self.game_state.player_country["name"]: + potential_partners.append(country) + + if not potential_partners: + ConsoleUI.display_warning("هیچ کشوری برای همکاری تحقیقاتی در دسترس نیست.") + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_partners.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_partners) + + if choice == len(potential_partners): + return # برگشت + + partner = potential_partners[choice-1] + cost = 5000 + + ConsoleUI.display_message(f"همکاری تحقیقاتی با {partner}") + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• زمان تحقیق 20% کاهش می‌یابد") + ConsoleUI.display_message("• امکان دسترسی به فناوری‌های پیشرفته‌تر") + ConsoleUI.display_message("• روابط با {partner} 10 واحد افزایش می‌یابد") + + if not ConsoleUI.confirm_action("آیا مایل به انجام همکاری تحقیقاتی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.research_efficiency += 0.2 + self.game_state.relations[partner] = min(100, self.game_state.relations[partner] + 10) + + ConsoleUI.display_success(f"همکاری تحقیقاتی با {partner} برقرار شد.") + ConsoleUI.wait_for_enter() + + def technology_cooperation(self): + """همکاری‌های فناوری پیشرفته""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("همکاری‌های فناوری") + + options = [ + "تبادل فناوری با کشورهای متحد", + "شرکت در پروژه‌های فناوری جهانی", + "گسترش فناوری به کشورهای در حال توسعه", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(options) + + if choice == 1: + self.technology_exchange() + elif choice == 2: + self.global_technology_projects() + elif choice == 3: + self.technology_aid() + # choice == 4: برگشت + + def technology_exchange(self): + """تبادل فناوری با کشورهای متحد""" + from ui.console_ui import ConsoleUI + + # فیلتر کشورهایی که اتحاد با آنها برقرار است + allies = [c for c, relation in self.game_state.relations.items() + if relation > 70 and c != self.game_state.player_country["name"]] + + if not allies: + ConsoleUI.display_warning("هیچ متحدی برای تبادل فناوری وجود ندارد.") + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + allies.append("برگشت") + choice = ConsoleUI.get_menu_choice(allies) + + if choice == len(allies): + return # برگشت + + ally = allies[choice-1] + + # انتخاب فناوری برای تبادل + available_techs = self.game_state.unlocked_technologies.copy() + available_techs.append("برگشت") + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"انتخاب فناوری برای تبادل با {ally}") + tech_choice = ConsoleUI.get_menu_choice(available_techs) + + if tech_choice == len(available_techs): + return # برگشت + + tech_id = available_techs[tech_choice-1] + tech = TECHNOLOGIES[tech_id] + + ConsoleUI.display_message(f"شما فناوری '{tech['name']}' را برای تبادل انتخاب کردید.") + ConsoleUI.display_message("در ازای آن، ممکن است فناوری‌های جدیدی دریافت کنید.") + + if ConsoleUI.confirm_action("آیا مایل به انجام تبادل فناوری هستید؟"): + # شبیه‌سازی تبادل فناوری + self._simulate_technology_exchange(ally, tech_id) + + def _simulate_technology_exchange(self, ally, tech_id): + """شبیه‌سازی تبادل فناوری با یک کشور متحد""" + from ui.console_ui import ConsoleUI + import random + + # انتخاب تصادفی فناوری‌های دریافتی + possible_techs = [t for t in TECHNOLOGIES.keys() + if t not in self.game_state.unlocked_technologies + and self._check_technology_prerequisites(t)] + + if not possible_techs: + ConsoleUI.display_warning("هیچ فناوری جدیدی برای دریافت وجود ندارد.") + ConsoleUI.wait_for_enter() + return + + received_techs = random.sample(possible_techs, min(2, len(possible_techs))) + + # اعمال تغییرات + for tech_id in received_techs: + self.game_state.unlocked_technologies.append(tech_id) + + # به‌روزرسانی سطح فناوری + self._calculate_technology_level() + + # نمایش نتایج + ConsoleUI.display_success(f"تبادل فناوری با {ally} موفقیت‌آمیز بود!") + ConsoleUI.display_message("فناوری‌های دریافتی:") + for tech_id in received_techs: + tech = TECHNOLOGIES[tech_id] + ConsoleUI.display_message(f"• {tech['name']}: {tech['description']}") + + ConsoleUI.wait_for_enter() + + def global_technology_projects(self): + """شرکت در پروژه‌های فناوری جهانی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("پروژه‌های فناوری جهانی") + + projects = [ + { + "name": "شبکه جهانی اینترنت", + "description": "مشارکت در ایجاد زیرساخت‌های اینترنت جهانی", + "cost": 20000, + "effects": { + "technology": {"trade": 2, "education": 1}, + "relations": {"+": 5}, + "economy": {"trade": 10} + } + }, + { + "name": "پروژه ژنوم انسان", + "description": "مشارکت در تحقیقات ژنتیک انسان", + "cost": 25000, + "effects": { + "technology": {"medicine": 3}, + "health_index": 15, + "gold": -500 # هزینه نگهداری سالانه + } + }, + { + "name": "برنامه فضایی جهانی", + "description": "مشارکت در برنامه‌های فضایی بین‌المللی", + "cost": 30000, + "effects": { + "technology": {"military": 2, "industry": 2}, + "political_stability": 10, + "prestige": 20 + } + } + ] + + # نمایش پروژه‌ها + project_names = [p["name"] for p in projects] + project_names.append("برگشت") + + choice = ConsoleUI.get_menu_choice(project_names) + + if choice == len(project_names): + return # برگشت + + project = projects[choice-1] + + ConsoleUI.display_message(f"پروژه: {project['name']}") + ConsoleUI.display_message(f"شرح: {project['description']}") + ConsoleUI.display_message(f"هزینه: {project['cost']} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + + # نمایش تأثیرات + for effect_type, values in project["effects"].items(): + if effect_type == "technology": + for tech, value in values.items(): + ConsoleUI.display_message(f"• فناوری {tech}: +{value}") + elif effect_type == "relations": + ConsoleUI.display_message(f"• روابط بین‌المللی: +{values['+']}") + else: + ConsoleUI.display_message(f"• {effect_type}: +{values}") + + if ConsoleUI.confirm_action("آیا مایل به شرکت در این پروژه هستید؟"): + self._join_global_project(project) + + def _join_global_project(self, project): + """شرکت در یک پروژه فناوری جهانی""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < project["cost"]: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= project["cost"] + + # اعمال تأثیرات + for effect_type, values in project["effects"].items(): + if effect_type == "technology": + for tech, value in values.items(): + self.game_state.technology[tech] = min(10, self.game_state.technology[tech] + 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] + values["+"]) + elif effect_type == "prestige": + # پرستیژ را در جایی ذخیره کنیم + if not hasattr(self.game_state, 'prestige'): + self.game_state.prestige = 0 + self.game_state.prestige += values + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, self.game_state[effect_type] + values) + elif effect_type in self.game_state.economy: + self.game_state.economy[effect_type] = min(100, self.game_state.economy[effect_type] + values) + + ConsoleUI.display_success(f"شما در پروژه '{project['name']}' شرکت کردید.") + ConsoleUI.wait_for_enter() + + def technology_aid(self): + """گسترش فناوری به کشورهای در حال توسعه""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("کمک فناوری به کشورهای در حال توسعه") + + # فیلتر کشورهایی که روابط خوبی داریم و سطح فناوری پایینی دارند + potential_recipients = [] + for country, relation in self.game_state.relations.items(): + if relation > 30 and country != self.game_state.player_country["name"]: + # فرض می‌کنیم سطح فناوری کشورها را می‌دانیم + potential_recipients.append(country) + + if not potential_recipients: + ConsoleUI.display_warning("هیچ کشوری برای کمک فناوری در دسترس نیست.") + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_recipients.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_recipients) + + if choice == len(potential_recipients): + return # برگشت + + recipient = potential_recipients[choice-1] + + # انتخاب نوع کمک + aid_types = [ + "کمک آموزشی (افزایش نرخ سواد)", + "کمک صنعتی (افزایش سطح صنعت)", + "کمک بهداشتی (افزایش شاخص سلامت)", + "برگشت" + ] + + aid_choice = ConsoleUI.get_menu_choice(aid_types) + + if aid_choice == 4: + return # برگشت + + costs = [3000, 4000, 3500] + effects = [ + {"literacy_rate": 5, "relations": {"+": 3}}, + {"economy": {"industry": 5}, "relations": {"+": 4}}, + {"health_index": 8, "relations": {"+": 5}} + ] + + cost = costs[aid_choice-1] + effect = effects[aid_choice-1] + + ConsoleUI.display_message(f"کمک فناوری به {recipient}") + ConsoleUI.display_message(f"نوع کمک: {aid_types[aid_choice-1]}") + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "relations": + ConsoleUI.display_message(f"• روابط با {recipient}: +{value['+']}") + elif effect_type == "economy": + for sector, val in value.items(): + ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}") + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}") + + if ConsoleUI.confirm_action("آیا مایل به انجام این کمک فناوری هستید؟"): + self._provide_technology_aid(recipient, effect, cost) + + def _provide_technology_aid(self, recipient, effect, cost): + """ارائه کمک فناوری به یک کشور""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # اعمال تأثیرات + for effect_type, value in effect.items(): + if effect_type == "relations": + self.game_state.relations[recipient] = min(100, self.game_state.relations[recipient] + value["+"]) + elif effect_type == "economy": + for sector, val in value.items(): + # فرض می‌کنیم کشور گیرنده اطلاعات اقتصادی دارد + pass # در واقعیت، باید اطلاعات کشور گیرنده را به‌روز کنیم + else: + if effect_type == "literacy_rate": + self.game_state.literacy_rate = min(100, self.game_state.literacy_rate + value) + elif effect_type == "health_index": + self.game_state.health_index = min(100, self.game_state.health_index + value) + + ConsoleUI.display_success(f"کمک فناوری به {recipient} ارسال شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم تحقیق""" + # ادامه تحقیق جاری + if self.current_research: + research_speed = self._calculate_research_speed() + self.research_progress += research_speed + + # بررسی تکمیل تحقیق + if self.research_progress >= 100: + self._complete_research() + + def _calculate_research_speed(self): + """محاسبه سرعت تحقیق فعلی""" + base_speed = 5 + + # تأثیر کارایی تحقیق + speed = base_speed * self.research_efficiency + + # تأثیر بودجه آموزش + speed *= (1 + self.game_state.budget["education"] * 0.01) + + # تأثیر مراکز تحقیقاتی + if "Research Centers" in self.game_state.unlocked_technologies: + speed *= 1.2 + + return speed + + def _complete_research(self): + """تکمیل تحقیق و اعمال اثرات فناوری""" + from ui.console_ui import ConsoleUI + + tech = TECHNOLOGIES[self.current_research] + + # اضافه کردن فناوری به لیست فناوری‌های آشکار شده + self.game_state.unlocked_technologies.append(self.current_research) + + # اعمال اثرات فناوری + self._apply_technology_effects(tech) + + # محاسبه مجدد سطح فناوری + self._calculate_technology_level() + + # نمایش پیام تکمیل تحقیق + ConsoleUI.display_success(f"تحقیق در '{tech['name']}' کامل شد!") + ConsoleUI.display_message(f"شرح: {tech['description']}") + + # نمایش اثرات + ConsoleUI.display_section_title("اثرات فناوری") + for effect_type, value in tech["effects"].items(): + if effect_type == "technology": + for tech_field, val in value.items(): + ConsoleUI.display_message(f"• فناوری {tech_field}: +{val}") + elif effect_type == "economy": + for sector, val in value.items(): + ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}") + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}") + + ConsoleUI.wait_for_enter() + + # ریست تحقیق جاری + self.current_research = None + self.research_progress = 0 + + def _apply_technology_effects(self, tech): + """اعمال اثرات یک فناوری به وضعیت بازی""" + for effect_type, value in tech["effects"].items(): + if effect_type == "technology": + for tech_field, val in value.items(): + self.game_state.technology[tech_field] = min(10, self.game_state.technology[tech_field] + val) + elif effect_type == "economy": + for sector, val in value.items(): + self.game_state.economy[sector] = min(100, self.game_state.economy[sector] + val) + elif effect_type == "military": + self.game_state.military_strength = min(100, self.game_state.military_strength + value) + elif effect_type == "culture": + self.game_state.culture_score = min(100, self.game_state.culture_score + value) + elif effect_type == "religion": + self.game_state.religious_influence = min(100, self.game_state.religious_influence + value) + elif effect_type == "population": + self.game_state.population = int(self.game_state.population * (1 + value/100)) + elif effect_type == "environment": + for factor, val in value.items(): + self.game_state.environment[factor] = max(0, min(100, self.game_state.environment[factor] + val)) + + def _calculate_technology_level(self): + """محاسبه سطح فناوری کلی بر اساس فناوری‌های آشکار شده""" + total_level = 0 + count = 0 + + for tech_id in self.game_state.unlocked_technologies: + tech = TECHNOLOGIES[tech_id] + total_level += tech.get("level", 1) + count += 1 + + self.game_state.technology_level = total_level // count if count > 0 else 1 +``` + +### 19. `game/technology/tech_effects.py` (اثرات فناوری) +```python +""" +مدیریت اثرات فناوری بر سایر سیستم‌ها +""" + +class TechEffects: + """مدیریت اثرات فناوری بر سایر سیستم‌ها""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم اثرات فناوری""" + self.game_state = game_state + + def apply_technology_effects(self, tech_id): + """اعمال اثرات یک فناوری به سیستم‌های مختلف""" + from data.tech.tech_definitions import TECHNOLOGIES + + if tech_id not in TECHNOLOGIES: + return + + tech = TECHNOLOGIES[tech_id] + + # اعمال اثرات فناوری بر اقتصاد + if "economy" in tech["effects"]: + self._apply_economy_effects(tech["effects"]["economy"]) + + # اعمال اثرات فناوری بر جمعیت + if "population" in tech["effects"]: + self._apply_population_effects(tech["effects"]["population"]) + + # اعمال اثرات فناوری بر محیط زیست + if "environment" in tech["effects"]: + self._apply_environment_effects(tech["effects"]["environment"]) + + # اعمال اثرات فناوری بر سیستم‌های دیگر + self._apply_other_effects(tech["effects"]) + + def _apply_economy_effects(self, effects): + """اعمال اثرات فناوری بر سیستم اقتصادی""" + for sector, value in effects.items(): + if sector in self.game_state.economy: + self.game_state.economy[sector] = min(100, + self.game_state.economy[sector] + value) + + def _apply_population_effects(self, effects): + """اعمال اثرات فناوری بر سیستم جمعیت""" + # تأثیر بر نرخ رشد جمعیت + if "growth" in effects: + self.game_state.population_growth += effects["growth"] + + # تأثیر بر ساختار جمعیت + if "age_distribution" in effects: + for age_group, value in effects["age_distribution"].items(): + if age_group in self.game_state.population.age_distribution: + self.game_state.population.age_distribution[age_group] = max(0, min(100, + self.game_state.population.age_distribution[age_group] + value)) + + def _apply_environment_effects(self, effects): + """اعمال اثرات فناوری بر سیستم محیط زیست""" + for factor, value in effects.items(): + if factor in self.game_state.environment: + self.game_state.environment[factor] = max(0, min(100, + self.game_state.environment[factor] + value)) + + def _apply_other_effects(self, effects): + """اعمال اثرات فناوری بر سایر سیستم‌ها""" + # تأثیر بر دیپلماسی + if "diplomacy_points" in effects: + self.game_state.diplomacy_points += effects["diplomacy_points"] + + # تأثیر بر فرهنگ + if "culture_score" in effects: + self.game_state.culture_score = min(100, + self.game_state.culture_score + effects["culture_score"]) + + # تأثیر بر دین + if "religious_influence" in effects: + self.game_state.religious_influence = min(100, + self.game_state.religious_influence + effects["religious_influence"]) + + # تأثیر بر ثبات سیاسی + if "political_stability" in effects: + self.game_state.political_stability = min(100, + self.game_state.political_stability + effects["political_stability"]) +``` + +### 20. `game/religion/__init__.py` +```python +""" +پکیج سیستم دینی +""" + +from .religious_system import ReligiousSystem +``` + +### 21. `game/religion/religious_system.py` (سیستم دینی) +```python +""" +سیستم مدیریت دین و گروه‌های مذهبی +""" + +from data.religion.religions import RELIGIONS + +class ReligiousSystem: + """سیستم مدیریت دین و گروه‌های مذهبی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم دینی""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم دینی""" + # تنظیم دین اولیه بر اساس کشور انتخابی + country = self.game_state.player_country + self.game_state.religion = country["base_attributes"]["religion"] + + # تنظیم گروه‌های مذهبی + self._initialize_religious_groups() + + def _initialize_religious_groups(self): + """راه‌اندازی گروه‌های مذهبی اولیه""" + religion = self.game_state.religion + + if religion in RELIGIONS: + # ایجاد گروه‌های مذهبی با نفوذ اولیه + self.game_state.religious_groups = { + group: 50 for group in RELIGIONS[religion]["groups"] + } + else: + # اگر دین شناخته شده نبود، یک گروه عمومی ایجاد کن + self.game_state.religious_groups = {"General": 100} + + def display_religious_status(self): + """نمایش وضعیت دینی کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت دینی") + + # نمایش دین رسمی + ConsoleUI.display_message(f"دین رسمی: {self.game_state.religion}", indent=2) + + # نمایش نفوذ دینی + ConsoleUI.display_message(f"نفوذ دینی: {self.game_state.religious_influence}%", indent=2) + + # نمایش گروه‌های مذهبی + ConsoleUI.display_section_title("گروه‌های مذهبی", width=60) + for group, influence in self.game_state.religious_groups.items(): + ConsoleUI.display_message(f"{group}: {influence}%", indent=2) + + # نمایش تأثیرات دینی + ConsoleUI.display_section_title("تأثیرات دینی", width=60) + ConsoleUI.display_message(f"ثبات سیاسی: {'+' if self._get_religious_stability() > 0 else ''}{self._get_religious_stability()}", indent=2) + ConsoleUI.display_message(f"نارضایتی عمومی: {'+' if self._get_religious_dissatisfaction() > 0 else ''}{self._get_religious_dissatisfaction()}", indent=2) + + ConsoleUI.wait_for_enter() + + def _get_religious_stability(self): + """دریافت تأثیر دین بر ثبات سیاسی""" + # محاسبه بر اساس نفوذ گروه‌های مذهبی + avg_influence = sum(self.game_state.religious_groups.values()) / len(self.game_state.religious_groups) + return int(avg_influence * 0.1) + + def _get_religious_dissatisfaction(self): + """دریافت تأثیر دین بر نارضایتی عمومی""" + # محاسبه بر اساس ناهمگونی گروه‌های مذهبی + max_influence = max(self.game_state.religious_groups.values()) + min_influence = min(self.game_state.religious_groups.values()) + disparity = max_influence - min_influence + + return int(disparity * 0.05) + + def spread_religion(self): + """گسترش دین به کشورهای دیگر""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("گسترش دین") + + # فیلتر کشورهایی که روابط خوبی داریم + potential_countries = [] + for country, relation in self.game_state.relations.items(): + if relation > 30 and country != self.game_state.player_country["name"]: + potential_countries.append(country) + + if not potential_countries: + ConsoleUI.display_warning("هیچ کشوری برای گسترش دین در دسترس نیست.") + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_countries.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_countries) + + if choice == len(potential_countries): + return # برگشت + + target_country = potential_countries[choice-1] + + # انتخاب روش گسترش + spread_methods = [ + "مأمورین مذهبی (6000 سکه)", + "شبکه‌های رسانه‌ای (8000 سکه)", + "همکاری‌های فرهنگی (5000 سکه)", + "برگشت" + ] + costs = [6000, 8000, 5000, 0] + + spread_choice = ConsoleUI.get_menu_choice(spread_methods) + + if spread_choice == 4: + return # برگشت + + cost = costs[spread_choice-1] + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال گسترش دین + self._apply_religious_spread(target_country, cost, spread_choice) + + def _apply_religious_spread(self, target_country, cost, method): + """اعمال گسترش دین و اثرات آن""" + from ui.console_ui import ConsoleUI + import random + + # محاسبه میزان گسترش + base_spread = 5 + if method == 1: # مأمورین مذهبی + spread_amount = base_spread + random.randint(3, 8) + elif method == 2: # شبکه‌های رسانه‌ای + spread_amount = base_spread + random.randint(5, 10) + else: # همکاری‌های فرهنگی + spread_amount = base_spread + random.randint(2, 6) + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.religious_influence = min(100, self.game_state.religious_influence + spread_amount) + + # تأثیر بر روابط + self.game_state.relations[target_country] = min(100, + self.game_state.relations[target_country] + random.randint(2, 5)) + + # نمایش نتایج + ConsoleUI.display_success(f"دین شما به {target_country} گسترش یافت!") + ConsoleUI.display_message(f"میزان گسترش: {spread_amount}%") + ConsoleUI.display_message(f"نفوذ دینی کلی: {self.game_state.religious_influence}%") + + ConsoleUI.wait_for_enter() + + def manage_religious_groups(self): + """مدیریت گروه‌های مذهبی داخلی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت گروه‌های مذهبی") + + # نمایش گروه‌های فعلی + groups = list(self.game_state.religious_groups.keys()) + group_options = [f"{group} ({self.game_state.religious_groups[group]}%)" for group in groups] + group_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(group_options) + + if choice == len(group_options): + return # برگشت + + selected_group = groups[choice-1] + self._manage_specific_religious_group(selected_group) + + def _manage_specific_religious_group(self, group): + """مدیریت یک گروه مذهبی خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت گروه {group}") + + group_actions = [ + "تقویت گروه (افزایش نفوذ)", + "مذاکره با گروه", + "سرکوب گروه", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(group_actions) + + if choice == 1: + self._strengthen_religious_group(group) + elif choice == 2: + self._negotiate_with_religious_group(group) + elif choice == 3: + self._suppress_religious_group(group) + # choice == 4: برگشت + + def _strengthen_religious_group(self, group): + """تقویت یک گروه مذهبی""" + from ui.console_ui import ConsoleUI + + cost = 4000 + influence_increase = 8 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"تقویت گروه {group}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message(f"افزایش نفوذ: {influence_increase}%") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• ثبات سیاسی: +3") + ConsoleUI.display_message("• نارضایتی عمومی: -2") + + if not ConsoleUI.confirm_action("آیا مایل به تقویت این گروه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.religious_groups[group] = min(100, + self.game_state.religious_groups[group] + influence_increase) + self.game_state.political_stability = min(100, + self.game_state.political_stability + 3) + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 2) + + ConsoleUI.display_success(f"گروه {group} تقویت شد.") + ConsoleUI.wait_for_enter() + + def _negotiate_with_religious_group(self, group): + """مذاکره با یک گروه مذهبی""" + from ui.console_ui import ConsoleUI + + cost = 2000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مذاکره با گروه {group}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• ثبات سیاسی: +5") + ConsoleUI.display_message("• نارضایتی عمومی: -5") + + if not ConsoleUI.confirm_action("آیا مایل به مذاکره با این گروه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.political_stability = min(100, + self.game_state.political_stability + 5) + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 5) + + ConsoleUI.display_success(f"مذاکره با گروه {group} موفقیت‌آمیز بود.") + ConsoleUI.wait_for_enter() + + def _suppress_religious_group(self, group): + """سرکوب یک گروه مذهبی""" + from ui.console_ui import ConsoleUI + + cost = 6000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"سرکوب گروه {group}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• نفوذ گروه: -15%") + ConsoleUI.display_message("• ثبات سیاسی: +8") + ConsoleUI.display_message("• نارضایتی عمومی: +12") + + if not ConsoleUI.confirm_action("آیا مایل به سرکوب این گروه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.religious_groups[group] = max(0, + self.game_state.religious_groups[group] - 15) + self.game_state.political_stability = min(100, + self.game_state.political_stability + 8) + self.game_state.public_dissatisfaction = min(100, + self.game_state.public_dissatisfaction + 12) + + ConsoleUI.display_warning(f"گروه {group} سرکوب شد.") + ConsoleUI.wait_for_enter() + + def implement_religious_policies(self): + """اجرای سیاست‌های دینی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("سیاست‌های دینی") + + policy_options = [ + "تقویت دین رسمی (افزایش نفوذ دین)", + "سیاست چند دینی (کاهش تنش‌های مذهبی)", + "آزادی مذهبی (افزایش شادی مردم)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(policy_options) + + if choice == 1: + self._reinforce_official_religion() + elif choice == 2: + self._multi_religious_policy() + elif choice == 3: + self._religious_freedom_policy() + # choice == 4: برگشت + + def _reinforce_official_religion(self): + """سیاست تقویت دین رسمی""" + from ui.console_ui import ConsoleUI + + cost = 7000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تقویت دین رسمی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• نفوذ دینی: +10%") + ConsoleUI.display_message("• ثبات سیاسی: +5") + ConsoleUI.display_message("• نارضایتی عمومی: +3") + + if not ConsoleUI.confirm_action("آیا مایل به تقویت دین رسمی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.religious_influence = min(100, + self.game_state.religious_influence + 10) + self.game_state.political_stability = min(100, + self.game_state.political_stability + 5) + self.game_state.public_dissatisfaction = min(100, + self.game_state.public_dissatisfaction + 3) + + ConsoleUI.display_success("دین رسمی تقویت شد.") + ConsoleUI.wait_for_enter() + + def _multi_religious_policy(self): + """سیاست چند دینی""" + from ui.console_ui import ConsoleUI + + cost = 5000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("سیاست چند دینی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• نارضایتی عمومی: -8") + ConsoleUI.display_message("• ثبات سیاسی: -3") + ConsoleUI.display_message("• روابط بین‌المللی: +5") + + if not ConsoleUI.confirm_action("آیا مایل به اجرای سیاست چند دینی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 8) + self.game_state.political_stability = max(0, + self.game_state.political_stability - 3) + 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] + 5) + + ConsoleUI.display_success("سیاست چند دینی اعمال شد.") + ConsoleUI.wait_for_enter() + + def _religious_freedom_policy(self): + """سیاست آزادی مذهبی""" + from ui.console_ui import ConsoleUI + + cost = 8000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("آزادی مذهبی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• شادی مردم: +10") + ConsoleUI.display_message("• نارضایتی عمومی: -10") + ConsoleUI.display_message("• ثبات سیاسی: -5") + + if not ConsoleUI.confirm_action("آیا مایل به اجرای آزادی مذهبی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.happiness = min(100, + self.game_state.happiness + 10) + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 10) + self.game_state.political_stability = max(0, + self.game_state.political_stability - 5) + + ConsoleUI.display_success("آزادی مذهبی اعمال شد.") + ConsoleUI.wait_for_enter() + + def religious_crisis_management(self): + """مدیریت بحران‌های دینی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران دینی + if random.random() < 0.15: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران دینی") + + # انتخاب نوع بحران + crisis_types = [ + "اختلافات میان گروه‌های مذهبی", + "تهدید به جدایی گروه مذهبی", + "نفوذ دین‌های خارجی", + "شورش مذهبی" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "مذاکره با گروه‌های مذهبی (3000 سکه)", + "تقویت دین رسمی (5000 سکه)", + "مداخله نظامی (7000 سکه)", + "بی‌تفاوتی" + ] + costs = [3000, 5000, 7000, 0] + effects = [ + {"public_dissatisfaction": -5, "political_stability": 3}, + {"religious_influence": 8, "public_dissatisfaction": 3}, + {"political_stability": 10, "public_dissatisfaction": 15}, + {"public_dissatisfaction": 10, "political_stability": -10} + ] + + # نمایش گزینه‌ها + 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_religious_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_religious_crisis_response(self, 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 in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران دینی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم دینی""" + # به‌روزرسانی نفوذ گروه‌های مذهبی + self._update_religious_group_influence() + + # بررسی بحران‌های دینی + self.religious_crisis_management() + + def _update_religious_group_influence(self): + """به‌روزرسانی نفوذ گروه‌های مذهبی""" + for group in self.game_state.religious_groups: + # تغییر تصادفی نفوذ + change = self.game_state.random.randint(-2, 2) + self.game_state.religious_groups[group] = max(0, min(100, + self.game_state.religious_groups[group] + change)) +``` + +### 22. `game/religion/religious_events.py` (رویدادهای دینی) +```python +""" +تعریف رویدادهای دینی برای بازی +""" + +RELIGIOUS_EVENTS = [ + { + "name": "تظاهرات مذهبی", + "description": "تظاهرات گسترده مذهبی در سراسر کشور رخ داده است.", + "trigger": lambda state: state.religious_groups and max(state.religious_groups.values()) > 70, + "choices": [ + { + "text": "حمایت از تظاهرات", + "effects": { + "religious_influence": 10, + "political_stability": -5, + "public_dissatisfaction": -8 + }, + "description": "حمایت از تظاهرات برای افزایش نفوذ دینی." + }, + { + "text": "محدود کردن تظاهرات", + "effects": { + "religious_influence": -5, + "political_stability": 8, + "public_dissatisfaction": 10 + }, + "description": "محدود کردن تظاهرات برای حفظ ثبات سیاسی." + } + ] + }, + { + "name": "اختلافات مذهبی", + "description": "اختلافات شدید بین گروه‌های مذهبی در حال گسترش است.", + "trigger": lambda state: state.religious_groups and + (max(state.religious_groups.values()) - min(state.religious_groups.values()) > 50), + "choices": [ + { + "text": "تشکیل شورای مذهبی", + "effects": { + "public_dissatisfaction": -5, + "political_stability": 3, + "diplomacy_points": 5 + }, + "description": "تشکیل شورایی برای حل اختلافات میان گروه‌های مذهبی." + }, + { + "text": "حمایت از گروه غالب", + "effects": { + "religious_influence": 8, + "public_dissatisfaction": 12, + "political_stability": -5 + }, + "description": "حمایت از گروه مذهبی غالب برای افزایش نفوذ دینی." + } + ] + }, + { + "name": "گسترش دین خارجی", + "description": "دین‌های خارجی در حال گسترش در کشور شما هستند.", + "trigger": lambda state: state.relations and + any(rel > 60 for rel in state.relations.values()), + "choices": [ + { + "text": "تقویت دین رسمی", + "effects": { + "religious_influence": 10, + "gold": -5000, + "public_dissatisfaction": 3 + }, + "description": "سرمایه‌گذاری در تقویت دین رسمی برای مقابله با گسترش دین‌های خارجی." + }, + { + "text": "پذیرش تنوع دینی", + "effects": { + "religious_influence": -5, + "public_dissatisfaction": -8, + "political_stability": 5 + }, + "description": "پذیرش تنوع دینی برای کاهش تنش‌های اجتماعی." + } + ] + }, + { + "name": "کشف آثار مقدس", + "description": "آثار مقدس مهمی در کشور شما کشف شده است.", + "trigger": lambda state: state.random.random() < 0.1, + "choices": [ + { + "text": "تبلیغات گسترده", + "effects": { + "religious_influence": 15, + "gold": -3000, + "happiness": 5 + }, + "description": "استفاده از کشف آثار مقدس برای افزایش نفوذ دینی." + }, + { + "text": "پنهان کردن کشفیات", + "effects": { + "religious_influence": 5, + "public_dissatisfaction": -3, + "diplomacy_points": 3 + }, + "description": "پنهان کردن کشفیات برای جلوگیری از سوءاستفاده سیاسی." + } + ] + }, + { + "name": "کنفرانس مذهبی جهانی", + "description": "دعوت به شرکت در کنفرانس مذهبی جهانی.", + "trigger": lambda state: state.religious_influence > 60, + "choices": [ + { + "text": "شرکت فعالانه", + "effects": { + "religious_influence": 10, + "relations": {"+": 8}, + "gold": -7000 + }, + "description": "شرکت فعالانه در کنفرانس برای افزایش نفوذ دینی." + }, + { + "text": "انصراف از شرکت", + "effects": { + "religious_influence": -5, + "relations": {"-": 5}, + "political_stability": 3 + }, + "description": "انصراف از شرکت برای تمرکز بر امور داخلی." + } + ] + } +] +``` + +### 23. `game/espionage/__init__.py` +```python +""" +پکیج سیستم جاسوسی +""" + +from .espionage_system import EspionageSystem +``` + +### 24. `game/espionage/espionage_system.py` (سیستم جاسوسی) +```python +""" +سیستم مدیریت جاسوسی و اطلاعات +""" + +class EspionageSystem: + """سیستم مدیریت جاسوسی و اطلاعات""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم جاسوسی""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم جاسوسی""" + # تنظیم شبکه جاسوسی اولیه + self.game_state.spy_network = { + "size": 5, + "effectiveness": 30, + "targets": [] + } + + def display_spy_network_status(self): + """نمایش وضعیت شبکه جاسوسی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت شبکه جاسوسی") + + # نمایش اطلاعات شبکه جاسوسی + ConsoleUI.display_message(f"اندازه شبکه: {self.game_state.spy_network['size']}", indent=2) + ConsoleUI.display_message(f"کارایی: {self.game_state.spy_network['effectiveness']}%", indent=2) + + # نمایش اهداف جاسوسی + ConsoleUI.display_section_title("اهداف جاسوسی", width=60) + if not self.game_state.spy_network["targets"]: + ConsoleUI.display_message("هیچ هدفی برای جاسوسی انتخاب نشده است.", indent=2) + else: + for target in self.game_state.spy_network["targets"]: + ConsoleUI.display_message(f"• {target}", indent=2) + + ConsoleUI.wait_for_enter() + + def manage_spy_network(self): + """مدیریت شبکه جاسوسی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت شبکه جاسوسی") + + network_actions = [ + "افزایش اندازه شبکه", + "بهبود کارایی شبکه", + "انتخاب اهداف جاسوسی", + "اقدامات جاسوسی فعال", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(network_actions) + + if choice == 1: + self.expand_spy_network() + elif choice == 2: + self.improve_spy_efficiency() + elif choice == 3: + self.select_spy_targets() + elif choice == 4: + self.conduct_spy_operations() + # choice == 5: برگشت + + def expand_spy_network(self): + """افزایش اندازه شبکه جاسوسی""" + from ui.console_ui import ConsoleUI + + cost = 3000 + size_increase = 2 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("افزایش شبکه جاسوسی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message(f"افزایش اندازه: {size_increase}") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• توانایی انتخاب اهداف بیشتر") + ConsoleUI.display_message("• هزینه نگهداری سالانه: 500 سکه") + + if not ConsoleUI.confirm_action("آیا مایل به افزایش شبکه جاسوسی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.spy_network["size"] += size_increase + self.game_state.budget["military"] += 1 # هزینه نگهداری + + ConsoleUI.display_success("شبکه جاسوسی گسترش یافت.") + ConsoleUI.wait_for_enter() + + def improve_spy_efficiency(self): + """بهبود کارایی شبکه جاسوسی""" + from ui.console_ui import ConsoleUI + + cost = 5000 + efficiency_increase = 10 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بهبود کارایی شبکه جاسوسی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا") + ConsoleUI.display_message(f"افزایش کارایی: {efficiency_increase}%") + ConsoleUI.display_message("تأثیرات:") + ConsoleUI.display_message("• اطلاعات دقیق‌تر") + ConsoleUI.display_message("• احتمال کشف کمتر") + ConsoleUI.display_message("• هزینه نگهداری سالانه: 800 سکه") + + if not ConsoleUI.confirm_action("آیا مایل به بهبود کارایی شبکه جاسوسی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.spy_network["effectiveness"] = min(100, + self.game_state.spy_network["effectiveness"] + efficiency_increase) + self.game_state.budget["military"] += 1.5 # هزینه نگهداری + + ConsoleUI.display_success("کارایی شبکه جاسوسی بهبود یافت.") + ConsoleUI.wait_for_enter() + + def select_spy_targets(self): + """انتخاب اهداف جاسوسی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("انتخاب اهداف جاسوسی") + + # فیلتر کشورهایی که می‌توانیم جاسوسی کنیم + potential_targets = [] + for country in self.game_state.relations: + if country != self.game_state.player_country["name"]: + potential_targets.append(country) + + if not potential_targets: + ConsoleUI.display_warning("هیچ کشوری برای جاسوسی در دسترس نیست.") + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_targets.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_targets) + + if choice == len(potential_targets): + return # برگشت + + target = potential_targets[choice-1] + + # بررسی اینکه آیا قبلاً انتخاب شده است + if target in self.game_state.spy_network["targets"]: + ConsoleUI.display_warning(f"{target} قبلاً به عنوان هدف جاسوسی انتخاب شده است.") + ConsoleUI.wait_for_enter() + return + + # بررسی فضای کافی + if len(self.game_state.spy_network["targets"]) >= self.game_state.spy_network["size"]: + ConsoleUI.display_warning("فضای کافی برای اهداف جدید وجود ندارد. ابتدا شبکه را گسترش دهید.") + ConsoleUI.wait_for_enter() + return + + # اضافه کردن هدف + self.game_state.spy_network["targets"].append(target) + + ConsoleUI.display_success(f"{target} به عنوان هدف جاسوسی انتخاب شد.") + ConsoleUI.wait_for_enter() + + def conduct_spy_operations(self): + """اجرای اقدامات جاسوسی فعال""" + from ui.console_ui import ConsoleUI + + if not self.game_state.spy_network["targets"]: + ConsoleUI.display_warning("هیچ هدفی برای جاسوسی انتخاب نشده است.") + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("اقدامات جاسوسی فعال") + + # نمایش اهداف + targets = self.game_state.spy_network["targets"] + target_options = [f"{target}" for target in targets] + target_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(target_options) + + if choice == len(target_options): + return # برگشت + + target = targets[choice-1] + self._perform_spy_operation(target) + + def _perform_spy_operation(self, target): + """اجرای یک اقدام جاسوسی بر روی یک هدف خاص""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"اقدام جاسوسی علیه {target}") + + # انتخاب نوع عملیات + operation_types = [ + "جمع‌آوری اطلاعات نظامی", + "جمع‌آوری اطلاعات اقتصادی", + "عملیات سایبری", + "تخریب روابط دیپلماتیک", + "برگشت" + ] + + operation_choice = ConsoleUI.get_menu_choice(operation_types) + + if operation_choice == 5: + return # برگشت + + # محاسبه هزینه و احتمال موفقیت + base_cost = 4000 + success_chance = self.game_state.spy_network["effectiveness"] / 100 + + # اعمال تأثیرات نوع عملیات + if operation_choice == 1: # اطلاعات نظامی + cost = base_cost + success_effect = { + "military_strength": 5, + "relations": {"-": 10} + } + failure_effect = { + "political_stability": -5, + "relations": {"-": 15} + } + + elif operation_choice == 2: # اطلاعات اقتصادی + cost = base_cost + success_effect = { + "economy": {"trade": 5, "industry": 3}, + "relations": {"-": 8} + } + failure_effect = { + "gold": -2000, + "relations": {"-": 10} + } + + elif operation_choice == 3: # عملیات سایبری + cost = base_cost + 2000 + success_effect = { + "technology": {"military": 2}, + "relations": {"-": 15} + } + failure_effect = { + "political_stability": -10, + "relations": {"-": 20} + } + + else: # تخریب روابط دیپلماتیک + cost = base_cost + 1000 + success_effect = { + "relations": {"-": 20}, + "diplomacy_points": 5 + } + failure_effect = { + "political_stability": -8, + "relations": {"-": 25} + } + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + ConsoleUI.display_message(f"نوع عملیات: {operation_types[operation_choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message(f"احتمال موفقیت: {int(success_chance * 100)}%", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به انجام این عملیات هستید؟"): + return + + # انجام عملیات + self.game_state.gold -= cost + + # بررسی موفقیت + if random.random() < success_chance: + self._apply_spy_success(target, success_effect) + else: + self._apply_spy_failure(target, failure_effect) + + def _apply_spy_success(self, target, effects): + """اعمال اثرات موفقیت در عملیات جاسوسی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_success(f"عملیات جاسوسی علیه {target} موفقیت‌آمیز بود!") + + # اعمال اثرات موفقیت + for effect_type, value in effects.items(): + if effect_type == "relations": + self.game_state.relations[target] = max(-100, + self.game_state.relations[target] - value["-"]) + elif effect_type == "economy": + for sector, val in value.items(): + self.game_state.economy[sector] = min(100, + self.game_state.economy[sector] + val) + elif effect_type == "technology": + for tech, val in value.items(): + self.game_state.technology[tech] = min(10, + self.game_state.technology[tech] + val) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + ConsoleUI.wait_for_enter() + + def _apply_spy_failure(self, target, effects): + """اعمال اثرات شکست در عملیات جاسوسی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_error(f"عملیات جاسوسی علیه {target} شکست خورد!") + + # اعمال اثرات شکست + for effect_type, value in effects.items(): + if effect_type == "relations": + self.game_state.relations[target] = max(-100, + self.game_state.relations[target] - value["-"]) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, + self.game_state[effect_type] + value) + + ConsoleUI.wait_for_enter() + + def espionage_crisis_management(self): + """مدیریت بحران‌های جاسوسی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران جاسوسی + if random.random() < 0.1: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران جاسوسی") + + # انتخاب نوع بحران + crisis_types = [ + "کشف شبکه جاسوسی", + "جنگ سایبری دشمن", + "فرار جاسوسان", + "افشاگری اطلاعات" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "تقویت امنیت (5000 سکه)", + "مذاکره با کشور دشمن (3000 سکه)", + "سرکوب داخلی (7000 سکه)", + "بی‌تفاوتی" + ] + costs = [5000, 3000, 7000, 0] + effects = [ + {"spy_network": {"effectiveness": 5}, "political_stability": 3}, + {"relations": {"+": 5}, "public_dissatisfaction": 2}, + {"political_stability": 8, "public_dissatisfaction": 10}, + {"spy_network": {"effectiveness": -10}, "political_stability": -5} + ] + + # نمایش گزینه‌ها + 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_espionage_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_espionage_crisis_response(self, 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 == "spy_network": + self.game_state.spy_network["effectiveness"] = max(0, min(100, + self.game_state.spy_network["effectiveness"] + value["effectiveness"])) + 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["+"]) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران جاسوسی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم جاسوسی""" + # به‌روزرسانی کارایی شبکه جاسوسی + self._update_spy_efficiency() + + # بررسی بحران‌های جاسوسی + self. espionage_crisis_management() + + def _update_spy_efficiency(self): + """به‌روزرسانی کار��یی شبکه جاسوسی""" + # کاهش تدریجی کارایی به دلیل تغییرات فناوری دشمن + self.game_state.spy_network["effectiveness"] = max(0, + self.game_state.spy_network["effectiveness"] - 2) +``` + +### 25. `game/espionage/spy_network.py` (شبکه جاسوسی) +```python +""" +مدیریت شبکه جاسوسی و عملیات‌های اطلاعاتی +""" + +class SpyNetwork: + """مدیریت شبکه جاسوسی و عملیات‌های اطلاعاتی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از شبکه جاسوسی""" + self.game_state = game_state + self.operation_types = [ + "military_intelligence", + "economic_intelligence", + "cyber_operations", + "diplomatic_sabotage" + ] + + def get_available_targets(self): + """دریافت لیست کشورهای قابل جاسوسی""" + available = [] + + for country in self.game_state.relations: + if country != self.game_state.player_country["name"]: + # فقط کشورهایی که روابط آنها بیشتر از -50 است + if self.game_state.relations[country] > -50: + available.append(country) + + return available + + def conduct_operation(self, target, operation_type): + """اجرای یک عملیات جاسوسی بر روی یک هدف""" + from ui.console_ui import ConsoleUI + import random + + # بررسی اینکه آیا هدف معتبر است + if target not in self.get_available_targets(): + ConsoleUI.display_error("هدف نامعتبر است!") + return False + + # بررسی اینکه آیا شبکه جاسوسی کافی است + if len(self.game_state.spy_network["targets"]) >= self.game_state.spy_network["size"]: + ConsoleUI.display_error("شبکه جاسوسی پر است! ابتدا آن را گسترش دهید.") + return False + + # محاسبه هزینه و احتمال موفقیت + base_cost = 4000 + success_chance = self.game_state.spy_network["effectiveness"] / 100 + + # اعمال تأثیرات نوع عملیات + if operation_type == "military_intelligence": + cost = base_cost + success_effect = { + "military_strength": 5, + "relations": {"-": 10} + } + failure_effect = { + "political_stability": -5, + "relations": {"-": 15} + } + + elif operation_type == "economic_intelligence": + cost = base_cost + success_effect = { + "economy": {"trade": 5, "industry": 3}, + "relations": {"-": 8} + } + failure_effect = { + "gold": -2000, + "relations": {"-": 10} + } + + elif operation_type == "cyber_operations": + cost = base_cost + 2000 + success_effect = { + "technology": {"military": 2}, + "relations": {"-": 15} + } + failure_effect = { + "political_stability": -10, + "relations": {"-": 20} + } + + else: # diplomatic_sabotage + cost = base_cost + 1000 + success_effect = { + "relations": {"-": 20}, + "diplomacy_points": 5 + } + failure_effect = { + "political_stability": -8, + "relations": {"-": 25} + } + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + return False + + # انجام عملیات + self.game_state.gold -= cost + + # بررسی موفقیت + if random.random() < success_chance: + self._apply_operation_success(target, success_effect) + return True + else: + self._apply_operation_failure(target, failure_effect) + return False + + def _apply_operation_success(self, target, effects): + """اعمال اثرات موفقیت در عملیات جاسوسی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_success(f"عملیات جاسوسی علیه {target} موفقیت‌آمیز بود!") + + # اعمال اثرات موفقیت + for effect_type, value in effects.items(): + if effect_type == "relations": + self.game_state.relations[target] = max(-100, + self.game_state.relations[target] - value["-"]) + elif effect_type == "economy": + for sector, val in value.items(): + self.game_state.economy[sector] = min(100, + self.game_state.economy[sector] + val) + elif effect_type == "technology": + for tech, val in value.items(): + self.game_state.technology[tech] = min(10, + self.game_state.technology[tech] + val) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + ConsoleUI.wait_for_enter() + + def _apply_operation_failure(self, target, effects): + """اعمال اثرات شکست در عملیات جاسوسی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_error(f"عملیات جاسوسی علیه {target} شکست خورد!") + + # اعمال اثرات شکست + for effect_type, value in effects.items(): + if effect_type == "relations": + self.game_state.relations[target] = max(-100, + self.game_state.relations[target] - value["-"]) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, + self.game_state[effect_type] + value) + + ConsoleUI.wait_for_enter() + + def display_operations_log(self): + """نمایش سوابق عملیات جاسوسی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("سوابق عملیات جاسوسی") + + if not self.game_state.events_history: + ConsoleUI.display_message("هیچ عملیات جاسوسی ثبت نشده است.", indent=2) + else: + # فیلتر رویدادهای جاسوسی + espionage_events = [event for event in self.game_state.events_history + if "جاسوسی" in event["event"]] + + for event in espionage_events: + status = "موفق" if "موفقیت‌آمیز" in event["choice"] else "شکست" + color = ConsoleUI.SUCCESS if status == "موفق" else ConsoleUI.ERROR + ConsoleUI.display_message(f"• {event['year']}: {event['event']} - {status}", + indent=2, color=color) + + ConsoleUI.wait_for_enter() +``` + +### 26. `game/cities/__init__.py` +```python +""" +پکیج سیستم مدیریت شهرها +""" + +from .city_management import CityManagement +``` + +### 27. `game/cities/city_management.py` (مدیریت شهرها) +```python +""" +سیستم مدیریت شهرها و توسعه شهری +""" + +class CityManagement: + """سیستم مدیریت شهرها و توسعه شهری""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم مدیریت شهرها""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم مدیریت شهرها""" + # اگر شهری وجود نداشت، یک شهر پایتخت ایجاد کن + if not self.game_state.cities: + self.game_state.cities = [{ + "name": "Tehran", + "population": 500000, + "development": 50, + "happiness": 70, + "buildings": ["Castle", "Market"], + "crisis_level": 0, + "crisis_type": None + }] + + def display_cities(self): + """نمایش لیست شهرها و وضعیت آنها""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("لیست شهرها") + + if not self.game_state.cities: + ConsoleUI.display_message("شما هیچ شهری ندارید!", indent=2) + ConsoleUI.wait_for_enter() + return + + for i, city in enumerate(self.game_state.cities, 1): + status = self._get_city_status(city) + ConsoleUI.display_message(f"{i}. {city['name']} ({status})", indent=2) + ConsoleUI.display_message(f" جمعیت: {city['population']:,}", indent=4) + ConsoleUI.display_message(f" توسعه: {city['development']}%", indent=4) + ConsoleUI.display_message(f" شادی: {city['happiness']}%", indent=4) + + ConsoleUI.wait_for_enter() + + def _get_city_status(self, city): + """دریافت وضعیت شهر بر اساس سطح توسعه""" + if city["development"] >= 80: + return "پیشرفته" + elif city["development"] >= 60: + return "متوسط" + elif city["development"] >= 40: + return "در حال توسعه" + else: + return "عقب‌مانده" + + def build_new_structures(self): + """ساخت ساختمان‌های جدید در شهرها""" + from ui.console_ui import ConsoleUI + + if not self.game_state.cities: + ConsoleUI.display_warning("شما هیچ شهری ندارید!") + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("ساخت ساختمان جدید") + + # انتخاب شهر + city_names = [city["name"] for city in self.game_state.cities] + city_names.append("برگشت") + city_choice = ConsoleUI.get_menu_choice(city_names) + + if city_choice == len(city_names): + return # برگشت + + selected_city = self.game_state.cities[city_choice-1] + self._select_building_type(selected_city) + + def _select_building_type(self, city): + """انتخاب نوع ساختمان برای ساخت""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"ساخت ساختمان در {city['name']}") + + # لیست ساختمان‌های قابل ساخت + building_types = [ + "ساختمان نظامی (قلعه، ثکنه)", + "ساختمان اقتصادی (بازار، کارخانه)", + "ساختمان اجتماعی (بیمارستان، مدرسه)", + "ساختمان فرهنگی (مسجد، کتابخانه)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(building_types) + + if choice == 5: + return # برگشت + + # تعیین هزینه و تأثیرات + costs = [8000, 6000, 7000, 5000] + effects = [ + {"military_strength": 5, "development": 3}, + {"economy": {"trade": 5, "industry": 3}, "development": 4}, + {"health_index": 3, "literacy_rate": 2, "development": 5}, + {"culture_score": 4, "happiness": 3, "development": 4} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"نوع ساختمان: {building_types[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "economy": + for sector, val in value.items(): + ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به ساخت این ساختمان هستید؟"): + self._construct_building(city, cost, effect) + + def _construct_building(self, city, cost, effects): + """ساخت ساختمان و اعمال اثرات آن""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + city["development"] = min(100, city["development"] + effects["development"]) + + # اعمال تأثیرات بر سیستم‌های کلی + for effect_type, value in effects.items(): + if effect_type == "economy": + for sector, val in value.items(): + self.game_state.economy[sector] = min(100, + self.game_state.economy[sector] + val) + elif effect_type not in ["development"]: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + ConsoleUI.display_success(f"ساختمان در {city['name']} ساخته شد.") + ConsoleUI.wait_for_enter() + + def city_planning(self): + """برنامه‌ریزی شهری و توسعه شهرها""" + from ui.console_ui import ConsoleUI + + if not self.game_state.cities: + ConsoleUI.display_warning("شما هیچ شهری ندارید!") + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("برنامه‌ریزی شهری") + + # انتخاب شهر + city_names = [city["name"] for city in self.game_state.cities] + city_names.append("برگشت") + city_choice = ConsoleUI.get_menu_choice(city_names) + + if city_choice == len(city_names): + return # برگشت + + selected_city = self.game_state.cities[city_choice-1] + self._plan_city_development(selected_city) + + def _plan_city_development(self, city): + """برنامه‌ریزی توسعه شهری برای یک شهر خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"برنامه‌ریزی {city['name']}") + + # گزینه‌های برنامه‌ریزی + planning_options = [ + "توسعه اقتصادی (افزایش تجارت و صنعت)", + "توسعه اجتماعی (بهبود سلامت و آموزش)", + "توسعه فرهنگی (گسترش فرهنگ و هنر)", + "توسعه نظامی (تقویت دفاع)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(planning_options) + + if choice == 5: + return # برگشت + + # تعیین هزینه و تأثیرات + costs = [7000, 6000, 5000, 8000] + effects = [ + {"economy": {"trade": 8, "industry": 5}, "development": 6}, + {"health_index": 5, "literacy_rate": 4, "development": 7}, + {"culture_score": 6, "happiness": 5, "development": 5}, + {"military_strength": 7, "development": 4} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"نوع برنامه‌ریزی: {planning_options[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "economy": + for sector, val in value.items(): + ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به اجرای این برنامه‌ریزی هستید؟"): + self._execute_city_plan(city, cost, effect) + + def _execute_city_plan(self, city, cost, effects): + """اجرای برنامه‌ریزی شهری و اعمال اثرات آن""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + city["development"] = min(100, city["development"] + effects["development"]) + + # اعمال تأثیرات بر سیستم‌های کلی + for effect_type, value in effects.items(): + if effect_type == "economy": + for sector, val in value.items(): + self.game_state.economy[sector] = min(100, + self.game_state.economy[sector] + val) + elif effect_type not in ["development"]: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + ConsoleUI.display_success(f"برنامه‌ریزی شهری برای {city['name']} اجرا شد.") + ConsoleUI.wait_for_enter() + + def manage_city_crises(self): + """مدیریت بحران‌های شهری""" + from ui.console_ui import ConsoleUI + + # فیلتر شهرهایی که بحران دارند + 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 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران‌های شهری") + + # نمایش شهرهای در بحران + 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: # Unknown crisis + 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) + 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)) + + # بررسی اگر بحران حل شده است + 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_city_crisis(self): + """تولید بحران‌های شهری تصادفی""" + import random + + # احتمال وقوع بحران در هر شهر + for city in self.game_state.cities: + if random.random() < 0.1: # 10% احتمال + crisis_types = [ + {"name": "قحطی", "severity": random.randint(30, 70)}, + {"name": "شورش", "severity": random.randint(40, 80)}, + {"name": "بیماری همه‌گیر", "severity": random.randint(35, 75)} + ] + + crisis = random.choice(crisis_types) + city["crisis_type"] = crisis["name"] + city["crisis_level"] = crisis["severity"] + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم شهرها""" + # به‌روزرسانی شهرها + self._update_cities() + + # تولید بحران‌های شهری + self.generate_city_crisis() + + def _update_cities(self): + """به‌روزرسانی وضعیت شهرها""" + for city in self.game_state.cities: + # به‌روزرسانی جمعیت شهری + population_growth = self.game_state.population_growth * 0.8 + city["population"] = int(city["population"] * (1 + population_growth/100)) + + # به‌روزرسانی شادی مردم + if "happiness" in city: + base_happiness = 50 + if city["development"] > 70: + base_happiness += 20 + elif city["development"] > 50: + base_happiness += 10 + + # تأثیرات منفی + if city.get("crisis_level", 0) > 0: + base_happiness -= city["crisis_level"] * 0.5 + + city["happiness"] = max(0, min(100, int(base_happiness))) + + # به‌روزرسانی توسعه شهری + if city["development"] < 100: + development_speed = 2 + (self.game_state.budget["infrastructure"] * 0.1) + city["development"] = min(100, city["development"] + development_speed) +``` + +### 28. `game/cities/construction_system.py` (سیستم ساخت‌وساز) +```python +""" +سیستم مدیریت ساخت‌وساز و زیرساخت‌ها +""" + +from data.cities.building_types import BUILDING_TYPES + +class ConstructionSystem: + """سیستم مدیریت ساخت‌وساز و زیرساخت‌ها""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم ساخت‌وساز""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم ساخت‌وساز""" + # بررسی و ایجاد ساختمان‌های پیش‌فرض + for city in self.game_state.cities: + if "buildings" not in city: + city["buildings"] = [] + + # اگر ساختمان پایتخت وجود نداشت، اضافه کن + if not any("Castle" in b for b in city["buildings"]): + city["buildings"].append("Castle") + + def display_construction_options(self): + """نمایش گزینه‌های ساخت‌وساز""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("گزینه‌های ساخت‌وساز") + + # نمایش دسته‌بندی‌ها + categories = list(BUILDING_TYPES.keys()) + for i, category in enumerate(categories, 1): + ConsoleUI.display_message(f"{i}. {category}", indent=2) + + ConsoleUI.display_message(f"{len(categories)+1}. برگشت", indent=2) + + choice = ConsoleUI.get_player_choice(range(1, len(categories)+2)) + + if choice == len(categories)+1: + return # برگشت + + selected_category = categories[choice-1] + self._display_buildings_in_category(selected_category) + + def _display_buildings_in_category(self, category): + """نمایش ساختمان‌های موجود در یک دسته‌بندی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"ساختمان‌های {category}") + + buildings = BUILDING_TYPES[category] + for i, building in enumerate(buildings, 1): + ConsoleUI.display_message(f"{i}. {building['name']}", indent=2) + ConsoleUI.display_message(f" هزینه: {building['cost']} سکه طلا", indent=4) + ConsoleUI.display_message(f" {building['description']}", indent=4) + + ConsoleUI.display_message(f"{len(buildings)+1}. برگشت", indent=2) + + choice = ConsoleUI.get_player_choice(range(1, len(buildings)+2)) + + if choice == len(buildings)+1: + return # برگشت + + selected_building = buildings[choice-1] + self._select_construction_city(selected_building) + + def _select_construction_city(self, building): + """انتخاب شهر برای ساخت ساختمان""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"انتخاب شهر برای {building['name']}") + + # نمایش شهرها + city_names = [city["name"] for city in self.game_state.cities] + city_names.append("برگشت") + + choice = ConsoleUI.get_menu_choice(city_names) + + if choice == len(city_names): + return # برگشت + + city = self.game_state.cities[choice-1] + self._confirm_construction(city, building) + + def _confirm_construction(self, city, building): + """تایید نهایی ساخت ساختمان""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"تایید ساخت {building['name']} در {city['name']}") + + ConsoleUI.display_message(f"هزینه: {building['cost']} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in building["effects"].items(): + if isinstance(value, dict): + for sub_type, sub_value in value.items(): + ConsoleUI.display_message(f"• {effect_type} {sub_type}: +{sub_value}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به ساخت این ساختمان هستید؟"): + self._construct_building(city, building) + + def _construct_building(self, city, building): + """اجرای ساخت ساختمان و اعمال اثرات آن""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < building["cost"]: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # بررسی شرایط ساخت + if not self._check_construction_requirements(city, building): + ConsoleUI.display_warning("شرایط لازم برای ساخت این ساختمان فراهم نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= building["cost"] + + # اضافه کردن ساختمان به شهر + if "buildings" not in city: + city["buildings"] = [] + + city["buildings"].append(building["name"]) + + # اعمال تأثیرات + self._apply_building_effects(city, building) + + ConsoleUI.display_success(f"{building['name']} در {city['name']} ساخته شد.") + ConsoleUI.wait_for_enter() + + def _check_construction_requirements(self, city, building): + """بررسی شرایط لازم برای ساخت ساختمان""" + # بررسی سطح توسعه شهر + if "min_development" in building and city["development"] < building["min_development"]: + return False + + # بررسی ساختمان‌های پیش‌نیاز + if "prerequisites" in building: + for prereq in building["prerequisites"]: + if prereq not in city["buildings"]: + return False + + return True + + def _apply_building_effects(self, city, building): + """اعمال تأثیرات ساختمان بر شهر و کشور""" + # اعمال تأثیرات بر شهر + if "city_effects" in building: + for effect_type, value in building["city_effects"].items(): + if effect_type in city: + city[effect_type] = min(100, city[effect_type] + value) + + # اعمال تأثیرات بر کشور + for effect_type, value in building["effects"].items(): + if effect_type == "economy": + for sector, val in value.items(): + self.game_state.economy[sector] = min(100, + self.game_state.economy[sector] + val) + elif effect_type == "technology": + for tech, val in value.items(): + self.game_state.technology[tech] = min(10, + self.game_state.technology[tech] + val) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + def get_building_effectiveness(self, city, building_type): + """محاسبه اثربخشی یک ساختمان در شهر خاص""" + # پایه اثربخشی + effectiveness = 1.0 + + # تأثیر سطح توسعه شهر + if city["development"] > 70: + effectiveness *= 1.2 + elif city["development"] < 30: + effectiveness *= 0.8 + + # تأثیر سایر ساختمان‌ها + if building_type == "Market" and "Bank" in city["buildings"]: + effectiveness *= 1.1 + + return effectiveness + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم ساخت‌وساز""" + # به‌روزرسانی اثربخشی ساختمان‌ها + self._update_building_effectiveness() + + def _update_building_effectiveness(self): + """به‌روزرسانی اثربخشی ساختمان‌ها""" + for city in self.game_state.cities: + for building in city.get("buildings", []): + # در این نسخه ساده، فقط یک پیام لاگ نمایش می‌دهیم + pass # در نسخه‌های پیشرفته‌تر، اثربخشی ساختمان‌ها محاسبه می‌شود +``` + +### 29. `game/cities/city_events.py` (رویدادهای شهری) +```python +""" +تعریف رویدادهای شهری برای بازی +""" + +CITY_EVENTS = [ + { + "name": "توسعه شهری", + "description": "شهر شما به سطح توسعه بیشتری رسیده است.", + "trigger": lambda city: city["development"] > 70, + "choices": [ + { + "text": "سرمایه‌گذاری در فناوری‌های پیشرفته", + "effects": { + "technology": {"trade": 2, "industry": 1}, + "development": 5, + "gold": -5000 + }, + "description": "سرمایه‌گذاری در فناوری‌های پیشرفته برای افزایش رشد شهر." + }, + { + "text": "تقویت زیرساخت‌های اجتماعی", + "effects": { + "happiness": 8, + "health_index": 5, + "development": 3, + "gold": -3000 + }, + "description": "تقویت زیرساخت‌های اجتماعی برای بهبود کیفیت زندگی." + } + ] + }, + { + "name": "رشد جمعیت سریع", + "description": "جمعیت شهر به سرعت در حال افزایش است.", + "trigger": lambda city: city["population"] > 1000000, + "choices": [ + { + "text": "ساخت شهرک‌های جدید", + "effects": { + "development": 8, + "public_dissatisfaction": -5, + "gold": -8000 + }, + "description": "ساخت شهرک‌های جدید برای جایگزینی جمعیت رو به رشد." + }, + { + "text": "تقویت زیرساخت‌های موجود", + "effects": { + "development": 5, + "happiness": -3, + "public_dissatisfaction": 5, + "gold": -5000 + }, + "description": "تقویت زیرساخت‌های موجود برای جمعیت بیشتر." + } + ] + }, + { + "name": "بحران زیست‌محیطی", + "description": "آلودگی هوا و آب در شهر در حال اف��ایش است.", + "trigger": lambda city: city["development"] > 60, + "choices": [ + { + "text": "سرمایه‌گذاری در فناوری‌های پاک", + "effects": { + "environment": {"pollution": -15}, + "technology": {"environment": 2}, + "gold": -7000 + }, + "description": "سرمایه‌گذاری در فناوری‌های پاک برای کاهش آلودگی." + }, + { + "text": "محدودیت‌های صنعتی", + "effects": { + "economy": {"industry": -5}, + "environment": {"pollution": -10}, + "public_dissatisfaction": 5 + }, + "description": "اعمال محدودیت‌های صنعتی برای کاهش آلودگی." + } + ] + }, + { + "name": "جشنواره فرهنگی", + "description": "جشنواره فرهنگی بزرگی در شهر برگزار می‌شود.", + "trigger": lambda city: city["development"] > 50, + "choices": [ + { + "text": "سرمایه‌گذاری گسترده", + "effects": { + "culture_score": 10, + "happiness": 8, + "gold": -6000 + }, + "description": "سرمایه‌گذاری در جشنواره برای افزایش نفوذ فرهنگی." + }, + { + "text": "همکاری با شهرهای دیگر", + "effects": { + "relations": {"+": 5}, + "culture_score": 5, + "happiness": 5 + }, + "description": "همکاری با شهرهای دیگر برای گسترش فرهنگ." + } + ] + }, + { + "name": "بحران امنیتی", + "description": "تعداد جرایم در شهر به شدت افزایش یافته است.", + "trigger": lambda city: city.get("crime_rate", 0) > 40, + "choices": [ + { + "text": "تقویت پلیس", + "effects": { + "crime_rate": -15, + "public_dissatisfaction": 3, + "gold": -5000 + }, + "description": "تقویت نیروهای پلیس برای کاهش جرم و جنایت." + }, + { + "text": "برنامه‌های اجتماعی", + "effects": { + "crime_rate": -10, + "happiness": 5, + "public_dissatisfaction": -3 + }, + "description": "اجرای برنامه‌های اجتماعی برای کاهش جرم و جنایت." + } + ] + } +] +``` + +### 30. `game/warfare/__init__.py` +```python +""" +پکیج سیستم جنگ +""" + +from .warfare_system import WarfareSystem +``` + +### 31. `game/warfare/warfare_system.py` (سیستم جنگ) +```python +""" +سیستم مدیریت جنگ و استراتژی‌های نظامی +""" + +class WarfareSystem: + """سیستم مدیریت جنگ و استراتژی‌های نظامی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم جنگ""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم جنگ""" + # تنظیم قدرت نظامی اولیه + self._calculate_military_strength() + + def _calculate_military_strength(self): + """محاسبه قدرت نظامی کلی کشور""" + # محاسبه بر اساس نیروها و فناوری + infantry_value = self.game_state.army["infantry"] * 0.5 + cavalry_value = self.game_state.army["cavalry"] * 1.0 + artillery_value = self.game_state.army["artillery"] * 1.5 + navy_value = self.game_state.army["navy"] * 1.2 + + total = infantry_value + cavalry_value + artillery_value + navy_value + tech_factor = 1 + (self.game_state.technology["military"] * 0.1) + + self.game_state.military_strength = min(100, int(total * tech_factor / 1000)) + + def display_military_status(self): + """نمایش وضعیت نظامی کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت نظامی") + + # نمایش قدرت نظامی کلی + ConsoleUI.display_message(f"قدرت نظامی: {self.game_state.military_strength}/100", indent=2) + + # نمایش نیروهای نظامی + ConsoleUI.display_section_title("نیروهای نظامی", width=60) + ConsoleUI.display_message(f"پیاده‌نظام: {self.game_state.army['infantry']:,}", indent=2) + ConsoleUI.display_message(f"سواره‌نظام: {self.game_state.army['cavalry']:,}", indent=2) + ConsoleUI.display_message(f"توپخانه: {self.game_state.army['artillery']:,}", indent=2) + ConsoleUI.display_message(f"نیروی دریایی: {self.game_state.army['navy']:,}", indent=2) + + # نمایش سطح فناوری نظامی + ConsoleUI.display_section_title("فناوری نظامی", width=60) + ConsoleUI.display_message(f"سطح فناوری: {self.game_state.technology['military']}/10", indent=2) + ConsoleUI.display_message(f"ساختارهای دفاعی: {self.game_state.fortifications}/100", indent=2) + + ConsoleUI.wait_for_enter() + + def attack_country(self): + """حمله به یک کشور دیگر""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("حمله به کشور دیگر") + + # فیلتر کشورهایی که می‌توانیم به آنها حمله کنیم + potential_targets = [] + for country, relation in self.game_state.relations.items(): + if relation < 0 and country != self.game_state.player_country["name"]: + potential_targets.append(country) + + if not potential_targets: + ConsoleUI.display_warning("هیچ کشوری برای حمله در دسترس نیست.") + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_targets.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_targets) + + if choice == len(potential_targets): + return # برگشت + + target_country = potential_targets[choice-1] + self._conduct_attack(target_country) + + def _conduct_attack(self, target_country): + """اجرای عملیات حمله به یک کشور خاص""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"حمله به {target_country}") + + # محاسبه شانس پیروزی + attacker_strength = self.game_state.military_strength + defender_strength = self._estimate_enemy_strength(target_country) + victory_chance = attacker_strength / (attacker_strength + defender_strength) + + ConsoleUI.display_message(f"قدرت شما: {attacker_strength}", indent=2) + ConsoleUI.display_message(f"قدرت دشمن: {defender_strength}", indent=2) + ConsoleUI.display_message(f"شانس پیروزی: {int(victory_chance * 100)}%", indent=2) + + # انتخاب تاکتیک + tactics = [ + "حمله مستقیم (شانس پیروزی بالا)", + "حمله غافلگیرکننده (شانس پیروزی متوسط)", + "جوسازی و جنگ روانی (شانس پیروزی پایین)", + "برگشت" + ] + + tactic_choice = ConsoleUI.get_menu_choice(tactics) + + if tactic_choice == 4: + return # برگشت + + # اعمال تأثیرات تاکتیک + if tactic_choice == 1: # حمله مستقیم + victory_chance *= 1.2 + cost_factor = 1.5 + elif tactic_choice == 2: # حمله غافلگیرکننده + victory_chance *= 1.0 + cost_factor = 1.0 + else: # جوسازی و جنگ روانی + victory_chance *= 0.8 + cost_factor = 0.7 + + # محاسبه هزینه + base_cost = 10000 + cost = int(base_cost * cost_factor) + + ConsoleUI.display_message(f"نوع تاکتیک: {tactics[tactic_choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه تخمینی: {cost} سکه طلا", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به انجام این حمله هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # انجام حمله + self.game_state.gold -= cost + + # بررسی پیروزی + if random.random() < victory_chance: + self._apply_victory(target_country) + else: + self._apply_defeat(target_country) + + def _estimate_enemy_strength(self, country): + """تخمین قدرت نظامی یک کشور دشمن""" + # در نسخه ساده، از روابط برای تخم��ن استفاده می‌کنیم + base_strength = 50 + relation_factor = (100 + self.game_state.relations[country]) / 100 + + return int(base_strength * relation_factor) + + def _apply_victory(self, target_country): + """اعمال اثرات پیروزی در جنگ""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.display_success(f"شما بر {target_country} پیروز شدید!") + + # محاسبه اثرات + territory_gain = random.randint(1, 3) + gold_gain = random.randint(5000, 15000) + + # اعمال تغییرات + self.game_state.controlled_territories += territory_gain + self.game_state.gold += gold_gain + self.game_state.relations[target_country] = -100 # رابطه کاملاً منفی + + # کاهش قدرت نظامی به دلیل جنگ + self.game_state.military_strength = max(0, + self.game_state.military_strength - random.randint(5, 15)) + + ConsoleUI.display_message(f"تعداد مناطق کسب شده: {territory_gain}", indent=2) + ConsoleUI.display_message(f"غنایمت جنگی: {gold_gain} سکه طلا", indent=2) + ConsoleUI.display_warning("قدرت نظامی شما کاهش یافت.", indent=2) + + ConsoleUI.wait_for_enter() + + def _apply_defeat(self, target_country): + """اعمال اثرات شکست در جنگ""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.display_error(f"شما در جنگ با {target_country} شکست خوردید!") + + # محاسبه اثرات + territory_loss = random.randint(0, 2) + gold_loss = random.randint(3000, 8000) + + # اعمال تغییرات + self.game_state.controlled_territories = max(1, + self.game_state.controlled_territories - territory_loss) + self.game_state.gold = max(0, self.game_state.gold - gold_loss) + self.game_state.relations[target_country] = min(100, + self.game_state.relations[target_country] - random.randint(10, 20)) + + # کاهش قدرت نظامی + self.game_state.military_strength = max(0, + self.game_state.military_strength - random.randint(10, 20)) + + ConsoleUI.display_message(f"تعداد مناطق از دست رفته: {territory_loss}", indent=2) + ConsoleUI.display_message(f"هزینه‌های جنگی: {gold_loss} سکه طلا", indent=2) + ConsoleUI.display_warning("قدرت نظامی شما کاهش یافت.", indent=2) + + ConsoleUI.wait_for_enter() + + def defend_territory(self): + """دفاع از قلمرو در برابر حملات دشمن""" + from ui.console_ui import ConsoleUI + import random + + # بررسی احتمال حمله + if random.random() < 0.2: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("حمله دشمن") + + # انتخاب کشور مهاجم + potential_attackers = [c for c, rel in self.game_state.relations.items() + if rel < 0 and c != self.game_state.player_country["name"]] + + if not potential_attackers: + return # بدون حمله + + attacker = random.choice(potential_attackers) + ConsoleUI.display_warning(f"{attacker} به قلمرو شما حمله کرد!", indent=2) + + # محاسبه شانس پیروزی در دفاع + defender_strength = self.game_state.military_strength + attacker_strength = self._estimate_enemy_strength(attacker) + victory_chance = defender_strength / (defender_strength + attacker_strength) + + ConsoleUI.display_message(f"قدرت شما: {defender_strength}", indent=2) + ConsoleUI.display_message(f"قدرت دشمن: {attacker_strength}", indent=2) + ConsoleUI.display_message(f"شانس دفاع موفق: {int(victory_chance * 100)}%", indent=2) + + # انتخاب تاکتیک دفاعی + tactics = [ + "دفاع مستحکم (شانس دفاع بالا)", + "تله‌گذاری (شانس دفاع متوسط)", + "سرکوب سریع (شانس دفاع پایین)", + "برگشت" + ] + + tactic_choice = ConsoleUI.get_menu_choice(tactics) + + if tactic_choice == 4: + return # برگشت + + # اعمال تأثیرات تاکتیک + if tactic_choice == 1: # دفاع مستحکم + victory_chance *= 1.2 + cost_factor = 1.5 + elif tactic_choice == 2: # تله‌گذاری + victory_chance *= 1.0 + cost_factor = 1.0 + else: # سرکوب سریع + victory_chance *= 0.8 + cost_factor = 0.7 + + # محاسبه هزینه + base_cost = 8000 + cost = int(base_cost * cost_factor) + + ConsoleUI.display_message(f"نوع تاکتیک: {tactics[tactic_choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه تخمینی: {cost} سکه طلا", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به دفاع با این تاکتیک هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # انجام دفاع + self.game_state.gold -= cost + + # بررسی موفقیت دفاع + if random.random() < victory_chance: + self._apply_successful_defense(attacker) + else: + self._apply_failed_defense(attacker) + else: + ConsoleUI.display_message("هیچ حمله‌ای به قلمرو شما رخ نداده است.", indent=2) + ConsoleUI.wait_for_enter() + + def _apply_successful_defense(self, attacker): + """اعمال اثرات دفاع موفقیت‌آمیز""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.display_success("دفاع از قلمرو با موفقیت انجام شد!") + + # محاسبه اثرات + morale_boost = random.randint(3, 8) + + # اعمال تغییرات + self.game_state.political_stability = min(100, + self.game_state.political_stability + morale_boost) + self.game_state.relations[attacker] = max(-100, + self.game_state.relations[attacker] - random.randint(5, 10)) + + ConsoleUI.display_message(f"افزایش معنویات: +{morale_boost}", indent=2) + ConsoleUI.display_message("قدرت نظامی بدون تغییر ماند.", indent=2) + + ConsoleUI.wait_for_enter() + + def _apply_failed_defense(self, attacker): + """اعمال اثرات دفاع ناموفق""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.display_error("دفاع از قلمرو ناموفق بود!") + + # محاسبه اثرات + territory_loss = random.randint(1, 2) + strength_loss = random.randint(5, 15) + + # اعمال تغییرات + self.game_state.controlled_territories = max(1, + self.game_state.controlled_territories - territory_loss) + self.game_state.military_strength = max(0, + self.game_state.military_strength - strength_loss) + self.game_state.relations[attacker] = min(100, + self.game_state.relations[attacker] + random.randint(5, 10)) + + ConsoleUI.display_message(f"تعداد مناطق از دست رفته: {territory_loss}", indent=2) + ConsoleUI.display_warning(f"کاهش قدرت نظامی: {strength_loss}", indent=2) + + ConsoleUI.wait_for_enter() + + def select_military_tactics(self): + """انتخاب تاکتیک‌های نظامی پیشرفته""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تاکتیک‌های نظامی") + + tactics_options = [ + "تاکتیک‌های دفاعی", + "تاکتیک‌های حمله‌ای", + "جنگ روانی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(tactics_options) + + if choice == 1: + self._select_defensive_tactics() + elif choice == 2: + self._select_offensive_tactics() + elif choice == 3: + self._psychological_warfare() + # choice == 4: برگشت + + def _select_defensive_tactics(self): + """انتخاب تاکتیک‌های دفاعی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تاکتیک‌های دفاعی") + + defensive_tactics = [ + "ساخت ساختارهای دفاعی (افزایش دفاع)", + "شبکه جاسوسی دفاعی (افزایش اطلاعات)", + "آموزش نیروهای دفاعی (افزایش مهارت)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(defensive_tactics) + + if choice == 4: + return # برگشت + + # انتخاب هزینه و تأثیرات + costs = [7000, 5000, 6000] + effects = [ + {"fortifications": 10, "military_strength": 5}, + {"spy_network": {"effectiveness": 8}, "diplomacy_points": 3}, + {"military_strength": 7, "public_dissatisfaction": -3} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"تاکتیک: {defensive_tactics[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "spy_network": + ConsoleUI.display_message(f"• شبکه جاسوسی: +{value['effectiveness']}%", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به اجرای این تاکتیک هستید؟"): + self._apply_military_tactic(cost, effect) + + def _select_offensive_tactics(self): + """انتخاب تاکتیک‌های حمله‌ای""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تاکتیک‌های حمله‌ای") + + offensive_tactics = [ + "حمله غافلگیرکننده (شانس پیروزی بالا)", + "جنگ چرخشی (شانس پیروزی متوسط)", + "حمله هوایی (شانس پیروزی پایین)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(offensive_tactics) + + if choice == 4: + return # برگشت + + # انتخاب هزینه و تأثیرات + costs = [8000, 6000, 10000] + effects = [ + {"victory_chance": 0.15, "military_strength": -3}, + {"victory_chance": 0.10, "military_strength": -5}, + {"victory_chance": 0.20, "military_strength": -8} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"تاکتیک: {offensive_tactics[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "victory_chance": + ConsoleUI.display_message(f"• افزایش شانس پیروزی: {int(value * 100)}%", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: {value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به اجرای این تاکتیک هستید؟"): + self._apply_military_tactic(cost, effect) + + def _psychological_warfare(self): + """جنگ روانی و تأثیرات آن""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("جنگ روانی") + + psychological_options = [ + "تبلیغات منفی علیه دشمن (کاهش معنویات)", + "تقویت روحیه مردم (افزایش ثبات)", + "پخش شایعات (کاهش اعتماد دشمن)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(psychological_options) + + if choice == 4: + return # برگشت + + # انتخاب هزینه و تأثیرات + costs = [5000, 4000, 3000] + effects = [ + {"enemy_morale": -10, "relations": {"-": 5}}, + {"political_stability": 8, "happiness": 5}, + {"enemy_relations": -15, "diplomacy_points": 3} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"روش: {psychological_options[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "enemy_morale": + ConsoleUI.display_message(f"• معنویات دشمن: {value}", indent=4) + elif effect_type == "relations": + ConsoleUI.display_message(f"• روابط: {value['-']}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: {value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به اجرای این روش هستید؟"): + self._apply_military_tactic(cost, effect) + + def _apply_military_tactic(self, cost, effects): + """اعمال یک تاکتیک نظامی و اثرات آن""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # اعمال تأثیرات + for effect_type, value in effects.items(): + if effect_type == "fortifications": + self.game_state.fortifications = min(100, + self.game_state.fortifications + value) + elif effect_type == "spy_network": + self.game_state.spy_network["effectiveness"] = min(100, + self.game_state.spy_network["effectiveness"] + value["effectiveness"]) + elif effect_type == "victory_chance": + # این تأثیر در زمان جنگ اعمال می‌شود + pass + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + ConsoleUI.display_success("تاکتیک نظامی اعمال شد.") + ConsoleUI.wait_for_enter() + + def warfare_crisis_management(self): + """مدیریت بحران‌های نظامی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران نظامی + if random.random() < 0.15: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران نظامی") + + # انتخاب نوع بحران + crisis_types = [ + "شورش نظامی", + "سرکوب شورش", + "جنگ داخلی", + "تهاجم خارجی" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "تقویت نیروهای نظامی (8000 سکه)", + "مذاکره با شورشیان (5000 سکه)", + "درخواست کمک بین‌المللی (6000 سکه)", + "بی‌تفاوتی" + ] + costs = [8000, 5000, 6000, 0] + effects = [ + {"military_strength": 10, "public_dissatisfaction": 5}, + {"political_stability": 8, "public_dissatisfaction": -10}, + {"relations": {"+": 10}, "military_strength": 5}, + {"political_stability": -15, "military_strength": -10} + ] + + # نمایش گزینه‌ها + 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_warfare_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_warfare_crisis_response(self, 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 == "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["+"]) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران نظامی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم جنگ""" + # به‌روزرسانی قدرت نظامی + self._calculate_military_strength() + + # بررسی بحران‌های نظامی + self.warfare_crisis_management() +``` + +### 32. `game/warfare/battle_simulator.py` (شبیه‌ساز نبرد) +```python +""" +شبیه‌ساز نبرد و محاسبه نتایج جنگ +""" + +class BattleSimulator: + """شبیه‌ساز نبرد و محاسبه نتایج جنگ""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از شبیه‌ساز نبرد""" + self.game_state = game_state + + def simulate_battle(self, attacker, defender, terrain=None, weather=None): + """ + شبیه‌سازی یک نبرد بین دو طرف + + :param attacker: دیکشنری اطلاعات مهاجم + :param defender: دیکشنری اطلاعات مدافع + :param terrain: نوع زمین (اختیاری) + :param weather: شرایط آب‌وهوایی (اختیاری) + :return: نتیجه نبرد و اتلافات + """ + # محاسبه قدرت مهاجم + attacker_strength = self._calculate_force_strength(attacker, terrain, weather, is_attacker=True) + + # محاسبه قدرت مدافع + defender_strength = self._calculate_force_strength(defender, terrain, weather, is_attacker=False) + + # محاسبه شانس پیروزی + total_strength = attacker_strength + defender_strength + attacker_chance = attacker_strength / total_strength + + # شبیه‌سازی نبرد + result = { + "attacker_victory": False, + "attacker_losses": 0, + "defender_losses": 0, + "attacker_strength": attacker_strength, + "defender_strength": defender_strength + } + + # تعیین پیروز + if self.game_state.random.random() < attacker_chance: + result["attacker_victory"] = True + + # محاسبه اتلافات + result["attacker_losses"] = int(attacker["total_units"] * + self._calculate_loss_rate(defender_strength, attacker_strength)) + result["defender_losses"] = int(defender["total_units"] * + self._calculate_loss_rate(attacker_strength, defender_strength) * 1.2) + else: + # دفاع موفق + result["attacker_losses"] = int(attacker["total_units"] * + self._calculate_loss_rate(defender_strength, attacker_strength) * 1.2) + result["defender_losses"] = int(defender["total_units"] * + self._calculate_loss_rate(attacker_strength, defender_strength)) + + return result + + def _calculate_force_strength(self, force, terrain, weather, is_attacker): + """محاسبه قدرت یک نیرو با در نظر گرفتن عوامل مختلف""" + base_strength = force["base_strength"] + + # تأثیر فناوری + tech_factor = 1 + (force["technology"] * 0.1) + + # تأثیر تعداد نیروها + unit_factor = 0.7 + (min(1.0, force["total_units"] / 100000) * 0.3) + + # تأثیر زمین + terrain_factor = self._get_terrain_factor(terrain, is_attacker) + + # تأثیر آب‌وهوایی + weather_factor = self._get_weather_factor(weather, is_attacker) + + # تأثیر تاکتیک + tactic_factor = 1.0 + if "tactics" in force: + tactic_factor = 1 + (force["tactics"] * 0.05) + + return base_strength * tech_factor * unit_factor * terrain_factor * weather_factor * tactic_factor + + def _get_terrain_factor(self, terrain, is_attacker): + """دریافت ضریب تأثیر زمین بر نبرد""" + if not terrain: + return 1.0 + + terrain_factors = { + "mountain": (0.8, 1.3), # (مهاجم، مدافع) + "forest": (0.9, 1.2), + "desert": (1.1, 0.9), + "plains": (1.0, 1.0), + "urban": (0.7, 1.4) + } + + factors = terrain_factors.get(terrain, (1.0, 1.0)) + return factors[0] if is_attacker else factors[1] + + def _get_weather_factor(self, weather, is_attacker): + """دریافت ضریب تأثیر آب‌وهوایی بر نبرد""" + if not weather: + return 1.0 + + weather_factors = { + "clear": (1.0, 1.0), + "rain": (0.8, 0.9), + "snow": (0.6, 0.7), + "fog": (0.7, 0.8), + "wind": (0.9, 0.95) + } + + factors = weather_factors.get(weather, (1.0, 1.0)) + return factors[0] if is_attacker else factors[1] + + def _calculate_loss_rate(self, winner_strength, loser_strength): + """محاسبه نرخ اتلافات بر اساس اختلاف قدرت""" + strength_ratio = loser_strength / (winner_strength + loser_strength) + base_loss_rate = 0.15 + (0.35 * strength_ratio) + + # تأثیر فاکتورهای تصادفی + random_factor = self.game_state.random.uniform(0.8, 1.2) + + return base_loss_rate * random_factor + + def display_battle_results(self, results): + """نمایش نتایج نبرد به صورت گرافیکی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("نتایج نبرد") + + if results["attacker_victory"]: + ConsoleUI.display_success("مهاجم پیروز شد!", indent=2) + else: + ConsoleUI.display_error("مدافع پیروز شد!", indent=2) + + ConsoleUI.display_message(f"قدرت مهاجم: {results['attacker_strength']:.1f}", indent=2) + ConsoleUI.display_message(f"قدرت مدافع: {results['defender_strength']:.1f}", indent=2) + + ConsoleUI.display_section_title("اتلافات", width=60) + ConsoleUI.display_message(f"مهاجم: {results['attacker_losses']:,} واحد", indent=2) + ConsoleUI.display_message(f"مدافع: {results['defender_losses']:,} واحد", indent=2) + + ConsoleUI.wait_for_enter() +``` + +### 33. `game/warfare/military_tactics.py` (تاکتیک‌های نظامی) +```python +""" +مدیریت تاکتیک‌های نظامی پیشرفته +""" + +class MilitaryTactics: + """مدیریت تاکتیک‌های نظامی پیشرفته""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم تاکتیک‌های نظامی""" + self.game_state = game_state + self.available_tactics = self._load_available_tactics() + + def _load_available_tactics(self): + """بارگیری تاکتیک‌های نظامی موجود""" + return { + "defensive": [ + { + "name": "دفاع غیرمتمرکز", + "description": "توزیع نیروها در مناطق مختلف برای کاهش آسیب‌پذیری", + "cost": 5000, + "effects": { + "fortifications": 5, + "military_strength": 3, + "enemy_victory_chance": -0.1 + } + }, + { + "name": "دیوارهای دفاعی", + "description": "ساخت ساختارهای دفاعی برای افزایش مقاومت", + "cost": 7000, + "effects": { + "fortifications": 10, + "military_strength": 5 + } + }, + { + "name": "تله‌گذاری", + "description": "گذاشتن تله‌های نظامی برای کاهش قدرت دشمن", + "cost": 4000, + "effects": { + "enemy_military_strength": -8, + "military_strength": 2 + } + } + ], + "offensive": [ + { + "name": "حمله غافلگیرکننده", + "description": "حمله غافلگیرکننده در زمان و مکان غیرمنتظره", + "cost": 6000, + "effects": { + "victory_chance": 0.15, + "military_strength": -3 + } + }, + { + "name": "جنگ چرخشی", + "description": "تغییر مداوم موقعیت نیروها برای گیج کردن دشمن", + "cost": 5000, + "effects": { + "victory_chance": 0.10, + "military_strength": -5 + } + }, + { + "name": "حمله هوایی", + "description": "استفاده از نیروهای هوایی برای ضربه زدن به دشمن", + "cost": 8000, + "effects": { + "victory_chance": 0.20, + "military_strength": -8 + } + } + ], + "psychological": [ + { + "name": "تبلیغات منفی", + "description": "تبلیغات منفی علیه دشمن برای کاهش معنویات", + "cost": 4000, + "effects": { + "enemy_morale": -10, + "relations": {"-": 5} + } + }, + { + "name": "تقویت روحیه", + "description": "تقویت روحیه نیروها برای افزایش معنویات", + "cost": 3000, + "effects": { + "political_stability": 8, + "happiness": 5 + } + }, + { + "name": "پخش شایعات", + "description": "پخش شایعات برای ایجاد ناامنی در صفوف دشمن", + "cost": 2000, + "effects": { + "enemy_relations": -15, + "diplomacy_points": 3 + } + } + ] + } + + def display_tactics_menu(self): + """نمایش منوی تاکتیک‌های نظامی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تاکتیک‌های نظامی") + + tactics_categories = ["دفاعی", "حمله‌ای", "روانی", "برگشت"] + + choice = ConsoleUI.get_menu_choice(tactics_categories) + + if choice == 1: + self.display_defensive_tactics() + elif choice == 2: + self.display_offensive_tactics() + elif choice == 3: + self.display_psychological_tactics() + # choice == 4: برگشت + + def display_defensive_tactics(self): + """نمایش تاکتیک‌های دفاعی""" + self._display_tactics_by_category("defensive", "تاکتیک‌های دفاعی") + + def display_offensive_tactics(self): + """نمایش تاکتیک‌های حمله‌ای""" + self._display_tactics_by_category("offensive", "تاکتیک‌های حمله‌ای") + + def display_psychological_tactics(self): + """نمایش تاکتیک‌های روانی""" + self._display_tactics_by_category("psychological", "تاکتیک‌های روانی") + + def _display_tactics_by_category(self, category, title): + """نمایش تاکتیک‌ها بر اساس دسته‌بندی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(title) + + tactics = self.available_tactics[category] + + for i, tactic in enumerate(tactics, 1): + ConsoleUI.display_message(f"{i}. {tactic['name']}", indent=2) + ConsoleUI.display_message(f" هزینه: {tactic['cost']} سکه طلا", indent=4) + ConsoleUI.display_message(f" {tactic['description']}", indent=4) + + ConsoleUI.display_message(f"{len(tactics)+1}. برگشت", indent=2) + + choice = ConsoleUI.get_player_choice(range(1, len(tactics)+2)) + + if choice == len(tactics)+1: + return # برگشت + + selected_tactic = tactics[choice-1] + self._apply_tactic(selected_tactic) + + def _apply_tactic(self, tactic): + """اعمال یک تاکتیک نظامی""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < tactic["cost"]: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # تایید اجرا + if not ConsoleUI.confirm_action(f"آیا مایل به اجرای '{tactic['name']}' هستید؟"): + return + + # کسر هزینه + self.game_state.gold -= tactic["cost"] + + # اعمال تأثیرات + self._apply_tactic_effects(tactic["effects"]) + + ConsoleUI.display_success(f"تاکتیک '{tactic['name']}' اعمال شد.") + ConsoleUI.wait_for_enter() + + def _apply_tactic_effects(self, effects): + """اعمال اثرات تاکتیک بر سیستم‌های مختلف""" + # اعمال اثرات بر سیستم‌های کلی + for effect_type, value in effects.items(): + if effect_type == "enemy_military_strength": + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + pass + elif effect_type == "enemy_victory_chance": + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + pass + elif effect_type == "enemy_morale": + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + pass + elif effect_type == "relations": + for country in self.game_state.relations: + if country != self.game_state.player_country["name"]: + self.game_state.relations[country] = max(-100, + self.game_state.relations[country] + value["-"]) + else: + if effect_type in self.game_state: + if isinstance(value, dict): + for sub_type, sub_value in value.items(): + if sub_type in self.game_state[effect_type]: + self.game_state[effect_type][sub_type] = min(10, + self.game_state[effect_type][sub_type] + sub_value) + else: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) +``` + +### 34. `game/trade/__init__.py` +```python +""" +پکیج سیستم تجارت +""" + +from .trade_system import TradeSystem +``` + +### 35. `game/trade/trade_system.py` (سیستم تجارت) +```python +""" +سیستم مدیریت تجارت و روابط اقتصادی +""" + +class TradeSystem: + """سیستم مدیریت تجارت و روابط اقتصادی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم تجارت""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم تجارت""" + # تنظیم مسیرهای تجاری اولیه + self._setup_initial_trade_routes() + + def _setup_initial_trade_routes(self): + """تنظیم مسیرهای تجاری اولیه بر اساس کشور انتخابی""" + country = self.game_state.player_country["name"] + + if country == "پادشاهی ایران": + self.game_state.trade_routes = [ + {"partner": "ترکیه", "value": 5000, "type": "Spice"}, + {"partner": "عراق", "value": 3000, "type": "Oil"}, + {"partner": "هندوستان", "value": 4000, "type": "Textile"} + ] + elif country == "امپراتوری عثمانی": + self.game_state.trade_routes = [ + {"partner": "ایتالیا", "value": 6000, "type": "Silk"}, + {"partner": "مصر", "value": 4000, "type": "Grain"}, + {"partner": "روسیه", "value": 3000, "type": "Fur"} + ] + else: + # ایجاد مسیرهای تجاری تصادفی + potential_partners = [c for c in self.game_state.relations + if c != self.game_state.player_country["name"]] + for _ in range(3): + if potential_partners: + partner = self.game_state.random.choice(potential_partners) + potential_partners.remove(partner) + + trade_types = ["Spice", "Silk", "Textile", "Oil", "Grain", "Fur"] + trade_type = self.game_state.random.choice(trade_types) + value = self.game_state.random.randint(2000, 6000) + + self.game_state.trade_routes.append({ + "partner": partner, + "value": value, + "type": trade_type + }) + + def display_trade_status(self): + """نمایش وضعیت تجارت کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت تجارت") + + # نمایش درآمد تجاری + ConsoleUI.display_message(f"درآمد تجاری: {self.game_state.economy['trade']}%", indent=2) + + # نمایش مسیرهای تجاری + ConsoleUI.display_section_title("مسیرهای تجاری", width=60) + if not self.game_state.trade_routes: + ConsoleUI.display_message("شما هیچ مسیر تجاری فعالی ندارید.", indent=2) + else: + total_value = 0 + for route in self.game_state.trade_routes: + value = route["value"] + total_value += value + ConsoleUI.display_message( + f"{route['partner']} ({route['type']}): {value} سکه طلا", + indent=2 + ) + + ConsoleUI.display_message(f"جمع درآمد تجاری: {total_value} سکه طلا", indent=2) + + # نمایش تأثیرات تجارت + ConsoleUI.display_section_title("تأثیرات تجارت", width=60) + ConsoleUI.display_message(f"روابط دیپلماتیک: {'+' if self._get_trade_relations() > 0 else ''}{self._get_trade_relations()}", indent=2) + ConsoleUI.display_message(f"رشد اقتصادی: {'+' if self._get_trade_growth() > 0 else ''}{self._get_trade_growth()}", indent=2) + + ConsoleUI.wait_for_enter() + + def _get_trade_relations(self): + """دریافت تأثیر تجارت بر روابط دیپلماتیک""" + # محاسبه بر اساس ارزش مسیرهای تجاری + avg_value = sum(route["value"] for route in self.game_state.trade_routes) / len(self.game_state.trade_routes) if self.game_state.trade_routes else 0 + return int(avg_value / 1000) + + def _get_trade_growth(self): + """دریافت تأثیر تجارت بر رشد اقتصادی""" + # محاسبه بر اساس درآمد تجاری + return int(self.game_state.economy["trade"] * 0.05) + + def trade_with_countries(self): + """تجارت با کشورهای دیگر""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تجارت با کشورها") + + # فیلتر کشورهایی که می‌توانیم با آنها تجارت کنیم + potential_partners = [] + for country, relation in self.game_state.relations.items(): + if relation > 0 and country != self.game_state.player_country["name"]: + potential_partners.append(country) + + if not potential_partners: + ConsoleUI.display_warning("هیچ کشوری برای تجارت در دسترس نیست.") + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_partners.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_partners) + + if choice == len(potential_partners): + return # برگشت + + partner = potential_partners[choice-1] + self._negotiate_trade_deal(partner) + + def _negotiate_trade_deal(self, partner): + """مذاکره برای بستن یک قرارداد تجاری""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مذاکره تجاری با {partner}") + + # تعیین نوع کالا + trade_types = ["Spice", "Silk", "Textile", "Oil", "Grain", "Fur"] + trade_type = random.choice(trade_types) + + # تعیین ارزش تجارت + base_value = 3000 + relation_factor = (self.game_state.relations[partner] + 100) / 200 + value = int(base_value * relation_factor) + + ConsoleUI.display_message(f"نوع کالا: {trade_type}", indent=2) + ConsoleUI.display_message(f"ارزش تخمینی: {value} سکه طلا", indent=2) + ConsoleUI.display_message("شرایط تجارت:", indent=2) + ConsoleUI.display_message("• امنیت مسیر تجاری", indent=4) + ConsoleUI.display_message("• کیفیت کالا", indent=4) + ConsoleUI.display_message("• زمان تحویل", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به بستن این قرارداد هستید؟"): + return + + # شبیه‌سازی مذاکره + negotiation_success = self._simulate_trade_negotiation(partner) + + if negotiation_success: + self._finalize_trade_deal(partner, trade_type, value) + else: + ConsoleUI.display_error("مذاکره تجاری شکست خورد!") + ConsoleUI.wait_for_enter() + + def _simulate_trade_negotiation(self, partner): + """شبیه‌سازی مذاکره تجاری""" + import random + + # محاسبه شانس موفقیت + base_chance = 0.5 + diplomacy_factor = self.game_state.diplomacy_points / 100 + relation_factor = self.game_state.relations[partner] / 200 + + success_chance = base_chance + diplomacy_factor + relation_factor + success_chance = max(0.2, min(0.9, success_chance)) + + return random.random() < success_chance + + def _finalize_trade_deal(self, partner, trade_type, value): + """نهایی کردن قرارداد تجاری و افزودن آن به مسیرهای تجاری""" + from ui.console_ui import ConsoleUI + + # افزودن مسیر تجاری جدید + self.game_state.trade_routes.append({ + "partner": partner, + "value": value, + "type": trade_type + }) + + # افزایش روابط + relation_increase = min(10, int(value / 1000)) + self.game_state.relations[partner] = min(100, + self.game_state.relations[partner] + relation_increase) + + ConsoleUI.display_success(f"قرار��اد تجاری با {partner} بسته شد!") + ConsoleUI.display_message(f"نوع کالا: {trade_type}", indent=2) + ConsoleUI.display_message(f"ارزش: {value} سکه طلا", indent=2) + ConsoleUI.display_message(f"افزایش روابط: +{relation_increase}", indent=2) + + ConsoleUI.wait_for_enter() + + def manage_trade_routes(self): + """مدیریت مسیرهای تجاری موجود""" + from ui.console_ui import ConsoleUI + + if not self.game_state.trade_routes: + ConsoleUI.display_warning("شما هیچ مسیر تجاری فعالی ندارید.") + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت مسیرهای تجاری") + + # نمایش مسیرها + route_options = [] + for route in self.game_state.trade_routes: + route_options.append(f"{route['partner']} ({route['type']}): {route['value']} سکه") + + route_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(route_options) + + if choice == len(route_options): + return # برگشت + + selected_route = self.game_state.trade_routes[choice-1] + self._manage_specific_trade_route(selected_route) + + def _manage_specific_trade_route(self, route): + """مدیریت یک مسیر تجاری خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت {route['partner']}") + + route_actions = [ + "افزایش ارزش تجارت", + "تضمین امنیت مسیر", + "توسعه نوع کالا", + "قطع رابطه تجاری", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(route_actions) + + if choice == 1: + self._increase_trade_value(route) + elif choice == 2: + self._ensure_route_security(route) + elif choice == 3: + self._expand_trade_products(route) + elif choice == 4: + self._terminate_trade_route(route) + # choice == 5: برگشت + + def _increase_trade_value(self, route): + """افزایش ارزش یک مسیر تجاری""" + from ui.console_ui import ConsoleUI + + cost = 2000 + value_increase = 1000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش ارزش تجارت با {route['partner']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message(f"افزایش ارزش: {value_increase} سکه", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش ارزش تجارت هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + route["value"] += value_increase + + ConsoleUI.display_success(f"ارزش تجارت با {route['partner']} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _ensure_route_security(self, route): + """تضمین امنیت یک مسیر تجاری""" + from ui.console_ui import ConsoleUI + + cost = 3000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"تضمین امنیت مسیر تجارت با {route['partner']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• کاهش خطر دزدی", indent=4) + ConsoleUI.display_message("• افزایش اعتماد", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به تضمین امنیت مسیر هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + # در نسخه پیشرفته‌تر، امنیت مسیر را افزایش می‌دهیم + + ConsoleUI.display_success(f"امنیت مسیر تجارت با {route['partner']} تضمین شد.") + ConsoleUI.wait_for_enter() + + def _expand_trade_products(self, route): + """توسعه انواع کالاهای تجاری""" + from ui.console_ui import ConsoleUI + + cost = 4000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"توسعه کالاهای تجارت با {route['partner']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• تنوع بیشتر کالا", indent=4) + ConsoleUI.display_message("• افزایش ارزش تجارت", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به توسعه کالاهای تجارت هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + # در نسخه پیشرفته‌تر، انواع کالا را افزایش می‌دهیم + + ConsoleUI.display_success(f"کالاهای تجارت با {route['partner']} گسترش یافت.") + ConsoleUI.wait_for_enter() + + def _terminate_trade_route(self, route): + """قطع یک مسیر تجاری""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"قطع رابطه تجاری با {route['partner']}") + + ConsoleUI.display_warning("هشدار: قطع رابطه تجاری ممکن است تأثیرات منفی داشته باشد!", indent=2) + + if not ConsoleUI.confirm_action("آیا مطمئن هستید که می‌خواهید این رابطه تجاری را قطع کنید؟"): + return + + # حذف مسیر تجاری + self.game_state.trade_routes.remove(route) + + # کاهش روابط + self.game_state.relations[route["partner"]] = max(-100, + self.game_state.relations[route["partner"]] - 15) + + ConsoleUI.display_warning(f"رابطه تجاری با {route['partner']} قطع شد.") + ConsoleUI.wait_for_enter() + + def trade_crisis_management(self): + """مدیریت بحران‌های تجاری""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران تجاری + if random.random() < 0.15: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران تجاری") + + # انتخاب نوع بحران + crisis_types = [ + "قطع مسیر تجاری توسط دشمن", + "افزایش شدید هزینه‌های حمل و نقل", + "کاهش تقاضا برای کالاهای شما", + "تهاجم دزدان دریایی" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "یافتن مسیر جایگزین (5000 سکه)", + "مذاکره با کشورهای دیگر (3000 سکه)", + "سرمایه‌گذاری در امنیت (6000 سکه)", + "بی‌تفاوتی" + ] + costs = [5000, 3000, 6000, 0] + effects = [ + {"economy": {"trade": 3}, "relations": {"+": 2}}, + {"relations": {"+": 5}, "economy": {"trade": 2}}, + {"trade_routes": {"security": 10}, "economy": {"trade": 5}}, + {"economy": {"trade": -8}, "public_dissatisfaction": 10} + ] + + # نمایش گزینه‌ها + 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_trade_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_trade_crisis_response(self, 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 == "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)) + elif effect_type == "trade_routes": + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + pass + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران تجاری مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم تجارت""" + # به‌روزرسانی مسیرهای تجاری + self._update_trade_routes() + + # بررسی بحران‌های تجاری + self.trade_crisis_management() + + def _update_trade_routes(self): + """به‌روزرسانی مسیرهای تجاری""" + for route in self.game_state.trade_routes: + # تغییر تصادفی ارزش تجارت + change = self.game_state.random.randint(-500, 500) + route["value"] = max(1000, route["value"] + change) +``` + +### 36. `game/trade/global_market.py` (بازار جهانی) +```python +""" +سیستم مدیریت بازار جهانی و نوسانات قیمت +""" + +class GlobalMarket: + """سیستم مدیریت بازار جهانی و نوسانات قیمت""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم بازار جهانی""" + self.game_state = game_state + self.commodity_prices = self._initialize_commodity_prices() + + def _initialize_commodity_prices(self): + """راه‌اندازی اولیه قیمت کالاهای مختلف""" + return { + "Spice": 100, + "Silk": 150, + "Textile": 80, + "Oil": 200, + "Grain": 60, + "Fur": 120, + "Metals": 180, + "Timber": 70 + } + + def display_market_status(self): + """نمایش وضعیت بازار جهانی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت بازار جهانی") + + # نمایش قیمت کالاها + ConsoleUI.display_section_title("قیمت کالاها", width=60) + for commodity, price in self.commodity_prices.items(): + ConsoleUI.display_message(f"{commodity}: {price} واحد پول", indent=2) + + # نمایش تأثیرات بر کشور + ConsoleUI.display_section_title("تأثیرات بر کشور شما", width=60) + total_value = 0 + for route in self.game_state.trade_routes: + if route["type"] in self.commodity_prices: + value = route["value"] * (self.commodity_prices[route["type"]] / 100) + total_value += value + ConsoleUI.display_message( + f"{route['partner']} ({route['type']}): {int(value)} واحد پول", + indent=2 + ) + + ConsoleUI.display_message(f"جمع درآمد تجاری: {int(total_value)} واحد پول", indent=2) + + ConsoleUI.wait_for_enter() + + def simulate_market_fluctuations(self): + """شبیه‌سازی نوسانات بازار جهانی""" + import random + + for commodity in self.commodity_prices: + # تغییر تصادفی قیمت (بین -10% تا +10%) + change_percent = random.uniform(-0.1, 0.1) + self.commodity_prices[commodity] = max(50, + int(self.commodity_prices[commodity] * (1 + change_percent))) + + def manage_commodity_prices(self): + """مدیریت قیمت کالاهای خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت قیمت کالاها") + + # نمایش کالاها + commodities = list(self.commodity_prices.keys()) + commodity_options = [f"{commodity}: {self.commodity_prices[commodity]}" for commodity in commodities] + commodity_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(commodity_options) + + if choice == len(commodity_options): + return # برگشت + + selected_commodity = commodities[choice-1] + self._adjust_commodity_price(selected_commodity) + + def _adjust_commodity_price(self, commodity): + """تنظیم قیمت یک کالای خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"تنظیم قیمت {commodity}") + + price_actions = [ + "افزایش عرضه (کاهش قیمت)", + "کاهش عرضه (افزایش قیمت)", + "ثبت قیمت فعلی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(price_actions) + + if choice == 1: + self._increase_supply(commodity) + elif choice == 2: + self._decrease_supply(commodity) + elif choice == 3: + ConsoleUI.display_message(f"قیمت {commodity} ثبت شد.", indent=2) + ConsoleUI.wait_for_enter() + # choice == 4: برگشت + + def _increase_supply(self, commodity): + """افزایش عرضه یک کالا و کاهش قیمت آن""" + from ui.console_ui import ConsoleUI + + cost = 3000 + price_decrease = 10 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش عرضه {commodity}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message(f"کاهش قیمت: {price_decrease}%", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش عرضه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.commodity_prices[commodity] = max(50, + int(self.commodity_prices[commodity] * 0.9)) + + ConsoleUI.display_success(f"عرضه {commodity} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _decrease_supply(self, commodity): + """کاهش عرضه یک کالا و افزایش قیمت آن""" + from ui.console_ui import ConsoleUI + + cost = 4000 + price_increase = 15 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"کاهش عرضه {commodity}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message(f"افزایش قیمت: {price_increase}%", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به کاهش عرضه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.commodity_prices[commodity] = min(300, + int(self.commodity_prices[commodity] * 1.15)) + + ConsoleUI.display_success(f"عرضه {commodity} کاهش یافت.") + ConsoleUI.wait_for_enter() + + def analyze_market_trends(self): + """تحلیل روندهای بازار و پیش‌بینی آینده""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تحلیل روندهای بازار") + + # تحلیل یک کالای تصادفی + commodity = random.choice(list(self.commodity_prices.keys())) + current_price = self.commodity_prices[commodity] + + # پیش‌بینی روند آینده + trend = random.choice(["صعودی", "نزولی", "ثابت"]) + confidence = random.randint(60, 90) + + ConsoleUI.display_message(f"کالا: {commodity}", indent=2) + ConsoleUI.display_message(f"قیمت فعلی: {current_price} واحد پول", indent=2) + ConsoleUI.display_message(f"روند پیش‌بینی شده: {trend}", indent=2) + ConsoleUI.display_message(f"اطمینان پیش‌بینی: {confidence}%", indent=2) + + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم بازار جهانی""" + # شبیه‌سازی نوسانات بازار + self.simulate_market_fluctuations() +``` + +### 37. `game/trade/trade_routes.py` (مسیرهای تجاری) +```python +""" +مدیریت مسیرهای تجاری و ارتباطات بین‌المللی +""" + +class TradeRoutes: + """مدیریت مسیرهای تجاری و ارتباطات بین‌المللی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم مسیرهای تجاری""" + self.game_state = game_state + + def get_active_routes(self): + """دریافت لیست مسیرهای تجاری فعال""" + return self.game_state.trade_routes + + def add_trade_route(self, partner, trade_type, value): + """افزودن یک مسیر تجاری جدید""" + # بررسی اینکه آیا مسیر تجاری قبلاً وجود دارد + for route in self.game_state.trade_routes: + if route["partner"] == partner and route["type"] == trade_type: + return False + + # افزودن مسیر جدید + self.game_state.trade_routes.append({ + "partner": partner, + "type": trade_type, + "value": value, + "security": 50, # سطح امنیت اولیه + "quality": 60 # کیفیت اولیه + }) + + return True + + def remove_trade_route(self, partner, trade_type=None): + """حذف یک مسیر تجاری""" + routes_to_remove = [] + + for i, route in enumerate(self.game_state.trade_routes): + if route["partner"] == partner and (not trade_type or route["type"] == trade_type): + routes_to_remove.append(i) + + # حذف مسیرها از انتها به ابتدا تا ایندکس‌ها تغییر نکنند + for i in sorted(routes_to_remove, reverse=True): + del self.game_state.trade_routes[i] + + return len(routes_to_remove) > 0 + + def upgrade_trade_route(self, index, upgrade_type): + """ارتقای یک مسیر تجاری""" + if index < 0 or index >= len(self.game_state.trade_routes): + return False + + route = self.game_state.trade_routes[index] + + if upgrade_type == "security": + cost = 3000 + improvement = 10 + route["security"] = min(100, route["security"] + improvement) + elif upgrade_type == "quality": + cost = 4000 + improvement = 15 + route["quality"] = min(100, route["quality"] + improvement) + route["value"] = int(route["value"] * 1.1) + else: # value + cost = 2000 + improvement = 1000 + route["value"] += improvement + + # بررسی موجودی + if self.game_state.gold < cost: + return False + + # کسر هزینه + self.game_state.gold -= cost + + return True + + def calculate_route_value(self, index): + """محاسبه ارزش واقعی یک مسیر تجاری با در نظر گرفتن عوامل مختلف""" + if index < 0 or index >= len(self.game_state.trade_routes): + return 0 + + route = self.game_state.trade_routes[index] + + # محاسبه بر اساس ارزش پایه، امنیت و کیفیت + base_value = route["value"] + security_factor = route["security"] / 100 + quality_factor = route["quality"] / 100 + + return int(base_value * security_factor * quality_factor) + + def display_route_details(self, index): + """نمایش جزئیات یک مسیر تجاری خاص""" + from ui.console_ui import ConsoleUI + + if index < 0 or index >= len(self.game_state.trade_routes): + ConsoleUI.display_error("مسیر تجاری نامعتبر است!") + return + + route = self.game_state.trade_routes[index] + actual_value = self.calculate_route_value(index) + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"جزئیات {route['partner']}") + + ConsoleUI.display_message(f"نوع کالا: {route['type']}", indent=2) + ConsoleUI.display_message(f"ارزش پایه: {route['value']} سکه", indent=2) + ConsoleUI.display_message(f"ارزش واقعی: {actual_value} سکه", indent=2) + ConsoleUI.display_message(f"امنیت: {route['security']}%", indent=2) + ConsoleUI.display_message(f"کیفیت: {route['quality']}%", indent=2) + + ConsoleUI.wait_for_enter() + + def manage_all_routes(self): + """مدیریت تمام مسیرهای ��جاری""" + from ui.console_ui import ConsoleUI + + if not self.game_state.trade_routes: + ConsoleUI.display_warning("شما هیچ مسیر تجاری فعالی ندارید.") + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت مسیرهای تجاری") + + # نمایش مسیرها + route_options = [] + for i, route in enumerate(self.game_state.trade_routes, 1): + actual_value = self.calculate_route_value(i-1) + route_options.append(f"{i}. {route['partner']} ({route['type']}): {actual_value} سکه") + + route_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(route_options) + + if choice == len(route_options): + return # برگشت + + self._manage_specific_route(choice-1) + + def _manage_specific_route(self, index): + """مدیریت یک مسیر تجاری خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت مسیر تجاری") + + route_actions = [ + "ارتقای امنیت", + "ارتقای کیفیت", + "افزایش ارزش", + "مشاهده جزئیات", + "حذف مسیر", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(route_actions) + + if choice == 1: + if self.upgrade_trade_route(index, "security"): + ConsoleUI.display_success("امنیت مسیر ارتقا یافت.") + else: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + elif choice == 2: + if self.upgrade_trade_route(index, "quality"): + ConsoleUI.display_success("کیفیت مسیر ارتقا یافت.") + else: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + elif choice == 3: + if self.upgrade_trade_route(index, "value"): + ConsoleUI.display_success("ارزش مسیر افزایش یافت.") + else: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + elif choice == 4: + self.display_route_details(index) + elif choice == 5: + partner = self.game_state.trade_routes[index]["partner"] + if self.remove_trade_route(partner): + ConsoleUI.display_warning(f"مسیر تجاری با {partner} حذف شد.") + else: + ConsoleUI.display_error("حذف مسیر تجاری ناموفق بود!") + ConsoleUI.wait_for_enter() + # choice == 6: برگشت + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم مسیرهای تجاری""" + # به‌روزرسانی امنیت و کیفیت مسیرها + self._update_route_security() + self._update_route_quality() + + def _update_route_security(self): + """به‌روزرسانی امنیت مسیرهای تجاری""" + for route in self.game_state.trade_routes: + # کاهش تدریجی امنیت به دلیل فرسودگی + route["security"] = max(0, route["security"] - 2) + + def _update_route_quality(self): + """به‌روزرسانی کیفیت مسیرهای تجاری""" + for route in self.game_state.trade_routes: + # کاهش تدریجی کیفیت به دلیل فرسودگی + route["quality"] = max(0, route["quality"] - 3) +``` + +### 38. `game/politics/__init__.py` +```python +""" +پکیج سیستم سیاست داخلی +""" + +from .domestic_policy import DomesticPolicy +``` + +### 39. `game/politics/domestic_policy.py` (سیاست داخلی) +```python +""" +سیستم مدیریت سیاست داخلی و اصلاحات اجتماعی +""" + +class DomesticPolicy: + """سیستم مدیریت سیاست داخلی و اصلاحات اجتماعی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم سیاست داخلی""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم سیاست داخلی""" + # تنظیم احزاب سیاسی اولیه + self._setup_initial_political_parties() + + def _setup_initial_political_parties(self): + """راه‌اندازی احزاب سیاسی اولیه بر اساس کشور انتخابی""" + country = self.game_state.player_country["name"] + + if country == "پادشاهی ایران": + self.game_state.political_parties = [ + {"name": "اصلاح‌طلبان", "support": 35, "ideology": "Reformist"}, + {"name": "محافظه‌کاران", "support": 40, "ideology": "Conservative"}, + {"name": "روستاییان", "support": 25, "ideology": "Rural"} + ] + elif country == "امپراتوری عثمانی": + self.game_state.political_parties = [ + {"name": "مدرنیست‌ها", "support": 45, "ideology": "Modernist"}, + {"name": "سنت‌گرایان", "support": 30, "ideology": "Traditionalist"}, + {"name": "ملی‌گرایان", "support": 25, "ideology": "Nationalist"} + ] + else: + # ایجاد احزاب سیاسی تصادفی + party_types = ["Reformist", "Conservative", "Nationalist", "Socialist", "Liberal"] + for _ in range(3): + party_type = self.game_state.random.choice(party_types) + party_types.remove(party_type) + + support = self.game_state.random.randint(20, 40) + self.game_state.political_parties.append({ + "name": self._generate_party_name(party_type), + "support": support, + "ideology": party_type + }) + + # تنظیم حزب رابین + total_support = sum(party["support"] for party in self.game_state.political_parties) + if total_support < 100: + self.game_state.political_parties[0]["support"] += (100 - total_support) + + def _generate_party_name(self, ideology): + """تولید نام حزب بر اساس ایدئولوژی""" + prefixes = { + "Reformist": ["نیروهای", "جبهه", "ائتلاف"], + "Conservative": ["نهضت", "جمعیت", "سازمان"], + "Nationalist": ["حزب", "جبهه", "ائتلاف"], + "Socialist": ["اتحادیه", "فدراسیون", "کنفدراسیون"], + "Liberal": ["حرکت", "گروه", "شبکه"] + } + + names = { + "Reformist": ["اصلاح", "نوسازی", "تغییر"], + "Conservative": ["حفاظت", "حفظ", "سنت"], + "Nationalist": ["ملی", "وطن", "سرزمین"], + "Socialist": ["کارگر", "عوام", "مردم"], + "Liberal": ["آزادی", "دموکراسی", "حقوق"] + } + + prefix = self.game_state.random.choice(prefixes[ideology]) + name = self.game_state.random.choice(names[ideology]) + + return f"{prefix} {name}" + + def display_political_status(self): + """نمایش وضعیت سیاسی کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت سیاسی") + + # نمایش ثبات سیاسی + ConsoleUI.display_message(f"ثبات سیاسی: {self.game_state.political_stability}%", indent=2) + + # نمایش نارضایتی عمومی + ConsoleUI.display_message(f"نارضایتی عمومی: {self.game_state.public_dissatisfaction}%", indent=2) + + # نمایش احزاب سیاسی + ConsoleUI.display_section_title("احزاب سیاسی", width=60) + for party in self.game_state.political_parties: + ConsoleUI.display_message(f"{party['name']} ({party['ideology']}): {party['support']}%", indent=2) + + # نمایش گروه‌های فشار + ConsoleUI.display_section_title("گروه‌های فشار", width=60) + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + ConsoleUI.display_message("گروه‌های فشار خاصی فعال نیستند.", indent=2) + + ConsoleUI.wait_for_enter() + + def manage_political_parties(self): + """مدیریت احزاب سیاسی و روابط با آنها""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("احزاب سیاسی") + + # نمایش احزاب + party_names = [party["name"] for party in self.game_state.political_parties] + party_names.append("برگشت") + + choice = ConsoleUI.get_menu_choice(party_names) + + if choice == len(party_names): + return # برگشت + + selected_party = self.game_state.political_parties[choice-1] + self._manage_specific_party(selected_party) + + def _manage_specific_party(self, party): + """مدیریت یک حزب سیاسی خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت {party['name']}") + + party_actions = [ + "گفت‌وگو و مذاکره", + "حمایت مالی", + "سرکوب سیاسی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(party_actions) + + if choice == 1: + self._negotiate_with_party(party) + elif choice == 2: + self._financial_support(party) + elif choice == 3: + self._political_suppression(party) + # choice == 4: برگشت + + def _negotiate_with_party(self, party): + """مذاکره با یک حزب سیاسی""" + from ui.console_ui import ConsoleUI + + cost = 2000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مذاکره با {party['name']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش وفاداری", indent=4) + ConsoleUI.display_message("• کاهش نارضایتی عمومی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به مذاکره با این حزب هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # افزایش وفاداری + loyalty_increase = self.game_state.random.randint(3, 7) + if party["name"] not in self.game_state.loyalty_levels: + self.game_state.loyalty_levels[party["name"]] = 50 + + self.game_state.loyalty_levels[party["name"]] = min(100, + self.game_state.loyalty_levels[party["name"]] + loyalty_increase) + + # کاهش نارضایتی عمومی + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 2) + + ConsoleUI.display_success(f"مذاکره با {party['name']} موفقیت‌آمیز بود.") + ConsoleUI.wait_for_enter() + + def _financial_support(self, party): + """حمایت مالی از یک حزب سیاسی""" + from ui.console_ui import ConsoleUI + + cost = 5000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"حمایت مالی از {party['name']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش حمایت حزب", indent=4) + ConsoleUI.display_message("• افزایش وفاداری", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به حمایت مالی از این حزب هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # افزایش حمایت حزب + party["support"] = min(60, party["support"] + 5) + + # افزایش وفاداری + if party["name"] not in self.game_state.loyalty_levels: + self.game_state.loyalty_levels[party["name"]] = 50 + + self.game_state.loyalty_levels[party["name"]] = min(100, + self.game_state.loyalty_levels[party["name"]] + 8) + + ConsoleUI.display_success(f"حمایت مالی از {party['name']} انجام شد.") + ConsoleUI.wait_for_enter() + + def _political_suppression(self, party): + """سرکوب سیاسی یک حزب""" + from ui.console_ui import ConsoleUI + + cost = 7000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"سرکوب {party['name']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• کاهش حمایت حزب", indent=4) + ConsoleUI.display_message("• افزایش ثبات سیاسی", indent=4) + ConsoleUI.display_message("• افزایش نارضایتی عمومی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به سرکوب این حزب هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # کاهش حمایت حزب + party["support"] = max(5, party["support"] - 10) + + # افزایش ثبات سیاسی + self.game_state.political_stability = min(100, + self.game_state.political_stability + 5) + + # افزایش نارضایتی عمومی + self.game_state.public_dissatisfaction = min(100, + self.game_state.public_dissatisfaction + 8) + + ConsoleUI.display_warning(f"{party['name']} سرکوب شد.") + ConsoleUI.wait_for_enter() + + def implement_social_reforms(self): + """اجرای اصلاحات اجتماعی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("اصلاحات اجتماعی") + + reform_options = [ + "اصلاحات آموزشی (افزایش سواد)", + "اصلاحات بهداشتی (بهبود سلامت)", + "اصلاحات کارگری (حقوق و دستمزد)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(reform_options) + + if choice == 1: + self._educational_reforms() + elif choice == 2: + self._healthcare_reforms() + elif choice == 3: + self._labor_reforms() + # choice == 4: برگشت + + def _educational_reforms(self): + """اصلاحات آموزشی""" + from ui.console_ui import ConsoleUI + + cost = 6000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("اصلاحات آموزشی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• نرخ سواد: +8%", indent=4) + ConsoleUI.display_message("• شادی مردم: +5%", indent=4) + ConsoleUI.display_message("• نارضایتی عمومی: -3%", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به اجرای اصلاحات آموزشی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.literacy_rate = min(100, + self.game_state.literacy_rate + 8) + self.game_state.happiness = min(100, + self.game_state.happiness + 5) + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 3) + + ConsoleUI.display_success("اصلاحات آموزشی اعمال شد.") + ConsoleUI.wait_for_enter() + + def _healthcare_reforms(self): + """اصلاحات بهداشتی""" + from ui.console_ui import ConsoleUI + + cost = 7000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("اصلاحات بهداشتی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• شاخص سلامت: +10", indent=4) + ConsoleUI.display_message("• شادی مردم: +7%", indent=4) + ConsoleUI.display_message("• نارضایتی عمومی: -5%", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به اجرای اصلاحات بهداشتی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.health_index = min(100, + self.game_state.health_index + 10) + self.game_state.happiness = min(100, + self.game_state.happiness + 7) + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 5) + + ConsoleUI.display_success("اصلاحات بهداشتی اعمال شد.") + ConsoleUI.wait_for_enter() + + def _labor_reforms(self): + """اصلاحات کارگری""" + from ui.console_ui import ConsoleUI + + cost = 8000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("اصلاحات کارگری") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• نارضایتی کارگران: -10%", indent=4) + ConsoleUI.display_message("• شادی مردم: +6%", indent=4) + ConsoleUI.display_message("• هزینه‌های دولتی: +5%", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به اجرای اصلاحات کارگری هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 10) + self.game_state.happiness = min(100, + self.game_state.happiness + 6) + self.game_state.budget["welfare"] = min(100, + self.game_state.budget["welfare"] + 5) + + ConsoleUI.display_success("اصلاحات کارگری اعمال شد.") + ConsoleUI.wait_for_enter() + + def hold_elections(self): + """برگزاری انتخابات""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("برگزاری انتخابات") + + if self.game_state.government_type not in ["Republic", "Democracy"]: + ConsoleUI.display_warning("شما در یک حکومت غیرمردمی هستید و نمی‌توانید انتخابات برگزار کنید.", indent=2) + ConsoleUI.wait_for_enter() + return + + ConsoleUI.display_message("انتخابات در حال برگزاری است...", indent=2) + + # شبیه‌سازی انتخابات + election_results = self._simulate_elections() + + # نمایش نتایج + ConsoleUI.display_section_title("نتایج انتخابات", width=60) + for party, votes in election_results.items(): + ConsoleUI.display_message(f"{party}: {votes}%", indent=2) + + # تعیین حزب برنده + winning_party = max(election_results, key=election_results.get) + ConsoleUI.display_success(f"حزب برنده: {winning_party} با {election_results[winning_party]}%", indent=2) + + # اعمال تغییرات + self._apply_election_results(winning_party) + + ConsoleUI.wait_for_enter() + + def _simulate_elections(self): + """شبیه‌سازی نتایج انتخابات""" + results = {} + total_votes = 0 + + # محاسبه نتایج بر اساس حمایت احزاب و ثبات سیاسی + for party in self.game_state.political_parties: + base_support = party["support"] + stability_factor = self.game_state.political_stability / 100 + random_factor = self.game_state.random.uniform(0.9, 1.1) + + votes = int(base_support * stability_factor * random_factor) + results[party["name"]] = votes + total_votes += votes + + # نرمال‌سازی نتایج + normalized_results = {} + for party, votes in results.items(): + normalized_results[party] = int((votes / total_votes) * 100) + + return normalized_results + + def _apply_election_results(self, winning_party): + """اعمال نتایج انتخابات""" + # در نسخه ساده، فقط ثبات سیاسی را تغییر می‌دهیم + self.game_state.political_stability = min(100, + self.game_state.political_stability + 5) + + # نمایش پیام + from ui.console_ui import ConsoleUI + ConsoleUI.display_message("حکومت جدید بر سر کار آمد.", indent=2) + + def political_crisis_management(self): + """مدیریت بحران‌های سیاسی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران سیاسی + if random.random() < 0.15: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران سیاسی") + + # انتخاب نوع بحران + crisis_types = [ + "اعتراضات عمومی گسترده", + "اختلافات بین احزاب", + "شکست انتخابات", + "کودتا" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "مذاکره با گروه‌های اعتراض‌کننده (4000 سکه)", + "اعمال اصلاحات فوری (6000 سکه)", + "تقویت امنیت (8000 سکه)", + "بی‌تفاوتی" + ] + costs = [4000, 6000, 8000, 0] + effects = [ + {"public_dissatisfaction": -8, "political_stability": 3}, + {"public_dissatisfaction": -12, "political_stability": 5}, + {"political_stability": 10, "public_dissatisfaction": 5}, + {"political_stability": -15, "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_political_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_political_crisis_response(self, 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 in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران سیاسی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم سیاست داخلی""" + # به‌روزرسانی احزاب سیاسی + self._update_political_parties() + + # بررسی بحران‌های سیاسی + self.political_crisis_management() + + def _update_political_parties(self): + """به‌روزرسانی احزاب سیاسی""" + for party in self.game_state.political_parties: + # تغییر تصادفی حمایت + change = self.game_state.random.randint(-3, 3) + party["support"] = max(5, min(60, party["support"] + change)) +``` + +### 40. `game/politics/political_parties.py` (احزاب سیاسی) +```python +""" +مدیریت احزاب سیاسی و گروه‌های فشار +""" + +class PoliticalParties: + """مدیریت احزاب سیاسی و گروه‌های فشار""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم احزاب سیاسی""" + self.game_state = game_state + self.party_ideologies = [ + "Reformist", "Conservative", "Nationalist", + "Socialist", "Liberal", "Religious" + ] + + def get_active_parties(self): + """دریافت لیست احزاب فعال""" + return self.game_state.political_parties + + def create_new_party(self, name, ideology): + """ایجاد یک حزب سیاسی جدید""" + # بررسی تکراری نبودن نام + if any(party["name"] == name for party in self.game_state.political_parties): + return False + + # بررسی معتبر بودن ایدئولوژی + if ideology not in self.party_ideologies: + return False + + # ایجاد حزب جدید + self.game_state.political_parties.append({ + "name": name, + "ideology": ideology, + "support": 10, # حمایت اولیه 10% + "influence": 20 # نفوذ اولیه 20% + }) + + return True + + def remove_party(self, party_name): + """حذف یک حزب سیاسی""" + for i, party in enumerate(self.game_state.political_parties): + if party["name"] == party_name: + del self.game_state.political_parties[i] + return True + + return False + + def influence_party(self, party_name, influence_type, value): + """ + تأثیرگذاری بر یک حزب سیاسی + + :param party_name: نام حزب + :param influence_type: نوع تأثیر (support, influence, loyalty) + :param value: مقدار تأثیر + :return: موفقیت عملیات + """ + for party in self.game_state.political_parties: + if party["name"] == party_name: + if influence_type == "support": + party["support"] = max(5, min(60, party["support"] + value)) + elif influence_type == "influence": + party["influence"] = max(0, min(100, party["influence"] + value)) + elif influence_type == "loyalty": + if party_name not in self.game_state.loyalty_levels: + self.game_state.loyalty_levels[party_name] = 50 + self.game_state.loyalty_levels[party_name] = max(0, min(100, + self.game_state.loyalty_levels[party_name] + value)) + return True + + return False + + def display_party_details(self, party_name): + """نمایش جزئیات یک حزب سیاسی خاص""" + from ui.console_ui import ConsoleUI + + for party in self.game_state.political_parties: + if party["name"] == party_name: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"جزئیات {party['name']}") + + ConsoleUI.display_message(f"ایدئولوژی: {party['ideology']}", indent=2) + ConsoleUI.display_message(f"حمایت عمومی: {party['support']}%", indent=2) + ConsoleUI.display_message(f"نفوذ سیاسی: {party['influence']}%", indent=2) + + # نمایش وفاداری اگر وجود داشته باشد + if party_name in self.game_state.loyalty_levels: + ConsoleUI.display_message(f"وفاداری: {self.game_state.loyalty_levels[party_name]}%", indent=2) + + ConsoleUI.wait_for_enter() + return + + ConsoleUI.display_error("حزب مورد نظر یافت نشد!") + ConsoleUI.wait_for_enter() + + def manage_all_parties(self): + """مدیریت تمام احزاب سیاسی""" + from ui.console_ui import ConsoleUI + + if not self.game_state.political_parties: + ConsoleUI.display_warning("هیچ حزب سیاسی فعالی وجود ندارد.") + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت احزاب سیاسی") + + # نمایش احزاب + party_options = [party["name"] for party in self.game_state.political_parties] + party_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(party_options) + + if choice == len(party_options): + return # برگشت + + selected_party = self.game_state.political_parties[choice-1]["name"] + self._manage_specific_party(selected_party) + + def _manage_specific_party(self, party_name): + """مدیریت یک حزب سیاسی خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت {party_name}") + + party_actions = [ + "افزایش حمایت عمومی", + "افزایش نفوذ سیاسی", + "افزایش وفاداری", + "مشاهده جزئیات", + "حذف حزب", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(party_actions) + + if choice == 1: + self._increase_party_support(party_name) + elif choice == 2: + self._increase_party_influence(party_name) + elif choice == 3: + self._increase_loyalty(party_name) + elif choice == 4: + self.display_party_details(party_name) + elif choice == 5: + if self.remove_party(party_name): + ConsoleUI.display_warning(f"حزب {party_name} حذف شد.") + else: + ConsoleUI.display_error("حذف حزب ناموفق بود!") + ConsoleUI.wait_for_enter() + # choice == 6: برگشت + + def _increase_party_support(self, party_name): + """افزایش حمایت عمومی از یک حزب""" + from ui.console_ui import ConsoleUI + + cost = 3000 + support_increase = 5 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش حمایت از {party_name}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message(f"افزایش حمایت: {support_increase}%", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش حمایت هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.influence_party(party_name, "support", support_increase) + + ConsoleUI.display_success(f"حمایت عمومی از {party_name} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _increase_party_influence(self, party_name): + """افزایش نفوذ سیاسی یک حزب""" + from ui.console_ui import ConsoleUI + + cost = 4000 + influence_increase = 8 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش نفوذ {party_name}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message(f"افزایش نفوذ: {influence_increase}%", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش نفوذ هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.influence_party(party_name, "influence", influence_increase) + + ConsoleUI.display_success(f"نفوذ سیاسی {party_name} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _increase_loyalty(self, party_name): + """افزایش وفاداری یک حزب""" + from ui.console_ui import ConsoleUI + + cost = 5000 + loyalty_increase = 10 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش وفاداری {party_name}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message(f"افزایش وفاداری: {loyalty_increase}%", indent=2) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش وفاداری هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.influence_party(party_name, "loyalty", loyalty_increase) + + ConsoleUI.display_success(f"وفاداری {party_name} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def create_pressure_group(self, name, demands): + """ایجاد یک گروه فشار جدید""" + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + from ui.console_ui import ConsoleUI + ConsoleUI.display_message(f"گروه فشار {name} ایجاد شد.", indent=2) + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم احزاب سیاسی""" + # به‌روزرسانی وفاداری احزاب + self._update_party_loyalty() + + def _update_party_loyalty(self): + """به‌روزرسانی وفاداری احزاب سیاسی""" + for party in self.game_state.political_parties: + # کاهش تدریجی وفاداری به دلیل عدم تعامل + if party["name"] in self.game_state.loyalty_levels: + self.game_state.loyalty_levels[party["name"]] = max(0, + self.game_state.loyalty_levels[party["name"]] - 2) +``` + +### 41. `game/politics/election_system.py` (سیستم انتخابات) +```python +""" +سیستم مدیریت انتخابات و فرآیندهای دموکراتیک +""" + +class ElectionSystem: + """سیستم مدیریت انتخابات و فرآیندهای دموکراتیک""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم انتخابات""" + self.game_state = game_state + self.last_election_year = game_state.current_year + + def initialize(self): + """راه‌اندازی اولیه سیستم انتخابات""" + # تنظیم سال آخرین انتخابات + self.last_election_year = self.game_state.current_year + + def schedule_election(self): + """برنامه‌ریزی انتخابات آینده""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("برنامه‌ریزی انتخابات") + + # تعیین فاصله زمانی انتخابات + election_intervals = [ + "2 سال (انتخابات مقدماتی)", + "4 سال (انتخابات عمومی)", + "6 سال (انتخابات مجلس)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(election_intervals) + + if choice == 4: + return # برگشت + + # محاسبه سال انتخابات + interval = [2, 4, 6][choice-1] + election_year = self.game_state.current_year + interval + + ConsoleUI.display_message(f"انتخابات در سال {election_year} برنامه‌ریزی شد.", indent=2) + ConsoleUI.wait_for_enter() + + # ذخیره اطلاعات + self.last_election_year = self.game_state.current_year + + def conduct_election(self): + """اجرای فرآیند انتخابات""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("اجرای انتخابات") + + # بررسی نوع حکومت + if self.game_state.government_type not in ["Republic", "Democracy"]: + ConsoleUI.display_warning("شما در یک حکومت غیرمردمی هستید و نمی‌توانید انتخابات برگزار کنید.", indent=2) + ConsoleUI.wait_for_enter() + return + + # شبیه‌سازی انتخابات + ConsoleUI.display_message("در حال انجام رای‌گیری...", indent=2) + time.sleep(1) + + # محاسبه نتایج + election_results = self._calculate_election_results() + + # نمایش نتایج + self._display_election_results(election_results) + + # تعیین حزب برنده + winning_party = max(election_results.items(), key=lambda x: x[1])[0] + ConsoleUI.display_success(f"حزب برنده: {winning_party}", indent=2) + + # اعمال تغییرات + self._apply_election_results(winning_party, election_results) + + ConsoleUI.wait_for_enter() + + def _calculate_election_results(self): + """محاسبه نتایج انتخابات بر اساس عوامل مختلف""" + results = {} + + # محاسبه بر اساس حمایت احزاب و ثبات سیاسی + for party in self.game_state.political_parties: + base_support = party["support"] + + # تأثیر ثبات سیاسی + stability_factor = self.game_state.political_stability / 100 + + # تأثیر نارضایتی عمومی + dissatisfaction_factor = 1 - (self.game_state.public_dissatisfaction / 200) + + # تأثیر وفاداری + loyalty_factor = 1.0 + if party["name"] in self.game_state.loyalty_levels: + loyalty_factor = 0.5 + (self.game_state.loyalty_levels[party["name"]] / 200) + + # تأثیر تصادفی + random_factor = self.game_state.random.uniform(0.9, 1.1) + + # محاسبه نتیجه نهایی + votes = base_support * stability_factor * dissatisfaction_factor * loyalty_factor * random_factor + results[party["name"]] = max(5, min(60, int(votes))) + + # نرمال‌سازی نتایج + total_votes = sum(results.values()) + normalized_results = {party: int((votes / total_votes) * 100) for party, votes in results.items()} + + return normalized_results + + def _display_election_results(self, results): + """نمایش نتایج انتخابات""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_section_title("نتایج انتخابات", width=60) + for party, votes in results.items(): + ConsoleUI.display_message(f"{party}: {votes}%", indent=2) + + def _apply_election_results(self, winning_party, results): + """اعمال نتایج انتخابات بر سیستم""" + # تغییر حزب رابین + self.game_state.ruling_party = winning_party + + # به‌روزرسانی حمایت احزاب + for party in self.game_state.political_parties: + if party["name"] == winning_party: + party["support"] = min(60, party["support"] + 5) + else: + party["support"] = max(5, party["support"] - 2) + + # تأثیر بر ثبات سیاسی + self.game_state.political_stability = min(100, + self.game_state.political_stability + 5) + + # تأثیر بر نارضایتی عمومی + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 3) + + def election_crisis_management(self): + """مدیریت بحران‌های انتخاباتی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران انتخاباتی + if random.random() < 0.1: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران انتخاباتی") + + # انتخاب نوع بحران + crisis_types = [ + "تقلب در رای‌گیری", + "اعتراض به نتایج", + "ترس از شرکت در انتخابات", + "تهدید به لغو انتخابات" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "بررسی شفاف نتایج (3000 سکه)", + "تضمین امنیت رای‌گیری (5000 سکه)", + "مذاکره با گروه‌های مخالف (4000 سکه)", + "بی‌تفاوتی" + ] + costs = [3000, 5000, 4000, 0] + effects = [ + {"political_stability": 5, "public_dissatisfaction": -5}, + {"political_stability": 8, "public_dissatisfaction": -3}, + {"political_stability": 3, "public_dissatisfaction": -8}, + {"political_stability": -10, "public_dissatisfaction": 15} + ] + + # نمایش گزینه‌ها + 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_election_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_election_crisis_response(self, 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 in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران انتخاباتی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم انتخابات""" + # بررسی نیاز به انتخابات + if self.game_state.current_year - self.last_election_year >= 4: + self.conduct_election() + self.last_election_year = self.game_state.current_year + + # بررسی بحران‌های انتخاباتی + self.election_crisis_management() +``` + +### 42. `game/society/__init__.py` +```python +""" +پکیج سیستم اجتماعی +""" + +from .happiness_system import HappinessSystem +``` + +### 43. `game/society/social_classes.py` (طبقات اجتماعی) +```python +""" +مدیریت طبقات اجتماعی و توزیع درآمد +""" + +class SocialClasses: + """مدیریت طبقات اجتماعی و توزیع درآمد""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم طبقات اجتماعی""" + self.game_state = game_state + self.social_classes = self._initialize_social_classes() + + def _initialize_social_classes(self): + """راه‌اندازی اولیه طبقات اجتماعی""" + return { + "upper": { + "population": 10, # درصد جمعیت + "income_share": 40, # درصد درآمد + "happiness": 80, + "dissatisfaction": 20 + }, + "middle": { + "population": 40, + "income_share": 40, + "happiness": 60, + "dissatisfaction": 40 + }, + "lower": { + "population": 50, + "income_share": 20, + "happiness": 30, + "dissatisfaction": 70 + } + } + + def display_social_structure(self): + """نمایش ساختار اجتماعی کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("ساختار اجتماعی") + + # نمایش جمعیت کل + ConsoleUI.display_message(f"جمعیت کل: {self.game_state.population:,} نفر", indent=2) + + # نمایش طبقات اجتماعی + ConsoleUI.display_section_title("طبقات اجتماعی", width=60) + for class_name, data in self.social_classes.items(): + class_title = self._get_class_title(class_name) + population = int(self.game_state.population * data["population"] / 100) + + ConsoleUI.display_message(f"{class_title}:", indent=2) + ConsoleUI.display_message(f" جمعیت: {population:,} نفر ({data['population']}%)", indent=4) + ConsoleUI.display_message(f" سهم درآمدی: {data['income_share']}%", indent=4) + ConsoleUI.display_message(f" شادی: {data['happiness']}%", indent=4) + ConsoleUI.display_message(f" نارضایتی: {data['dissatisfaction']}%", indent=4) + + # نمایش نابرابری درآمدی + ConsoleUI.display_section_title("نابرابری درآمدی", width=60) + gini = self.calculate_gini_coefficient() + ConsoleUI.display_message(f"ضریب جینی: {gini:.2f}", indent=2) + + ConsoleUI.wait_for_enter() + + def _get_class_title(self, class_name): + """دریافت عنوان فارسی برای طبقه اجتماعی""" + titles = { + "upper": "طبقة عالی", + "middle": "طبقة متوسط", + "lower": "طبقة پایین" + } + return titles.get(class_name, class_name) + + def calculate_gini_coefficient(self): + """محاسبه ضریب جینی برای اندازه‌گیری نابرابری درآمدی""" + # محاسبه ساده شده ضریب جینی + upper_share = self.social_classes["upper"]["income_share"] + middle_share = self.social_classes["middle"]["income_share"] + lower_share = self.social_classes["lower"]["income_share"] + + # محاسبه مساحت زیر منحنی لورنز + area = (0.1 * upper_share/100) + (0.4 * (upper_share + middle_share)/100) + (0.5 * 1) + + # محاسبه ضریب جینی + gini = 1 - 2 * area + return max(0, min(1, gini)) + + def manage_social_classes(self): + """مدیریت طبقات اجتماعی و کاهش نابرابری""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت طبقات اجتماعی") + + class_options = [ + "طبقة عالی", + "طبقة متوسط", + "طبقة پایین", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(class_options) + + if choice == 4: + return # برگشت + + class_names = ["upper", "middle", "lower"] + selected_class = class_names[choice-1] + self._manage_specific_class(selected_class) + + def _manage_specific_class(self, class_name): + """مدیریت یک طبقه اجتماعی خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت {self._get_class_title(class_name)}") + + class_actions = [ + "سرمایه‌گذاری در آموزش", + "حمایت از درآمدزایی", + "تغییر سیاست‌های مالیاتی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(class_actions) + + if choice == 1: + self._invest_in_education(class_name) + elif choice == 2: + self._support_income_generation(class_name) + elif choice == 3: + self._adjust_tax_policy(class_name) + # choice == 4: برگشت + + def _invest_in_education(self, class_name): + """سرمایه‌گذاری در آموزش یک طبقه اجتماعی""" + from ui.console_ui import ConsoleUI + + cost = 4000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"سرمایه‌گذاری در آموزش {self._get_class_title(class_name)}") + + ConsoleUI.display_message(f"هزینه: {cost} س��ه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش سواد", indent=4) + ConsoleUI.display_message("• افزایش شادی", indent=4) + ConsoleUI.display_message("• کاهش نارضایتی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به سرمایه‌گذاری در آموزش هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.literacy_rate = min(100, + self.game_state.literacy_rate + 3) + + # به‌روزرسانی طبقه اجتماعی + self.social_classes[class_name]["happiness"] = min(100, + self.social_classes[class_name]["happiness"] + 5) + self.social_classes[class_name]["dissatisfaction"] = max(0, + self.social_classes[class_name]["dissatisfaction"] - 5) + + ConsoleUI.display_success(f"سرمایه‌گذاری در آموزش {self._get_class_title(class_name)} انجام شد.") + ConsoleUI.wait_for_enter() + + def _support_income_generation(self, class_name): + """حمایت از درآمدزایی یک طبقه اجتماعی""" + from ui.console_ui import ConsoleUI + + cost = 5000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"حمایت از درآمدزایی {self._get_class_title(class_name)}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش سهم درآمدی", indent=4) + ConsoleUI.display_message("• افزایش شادی", indent=4) + ConsoleUI.display_message("• کاهش نارضایتی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به حمایت از درآمدزایی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # توزیع مجدد درآمد + income_increase = 3 + self.social_classes[class_name]["income_share"] = min(60, + self.social_classes[class_name]["income_share"] + income_increase) + + # کاهش سهم درآمدی سایر طبقات + for cls in self.social_classes: + if cls != class_name: + self.social_classes[cls]["income_share"] = max(5, + self.social_classes[cls]["income_share"] - (income_increase / 2)) + + # به‌روزرسانی شادی و نارضایتی + self.social_classes[class_name]["happiness"] = min(100, + self.social_classes[class_name]["happiness"] + 7) + self.social_classes[class_name]["dissatisfaction"] = max(0, + self.social_classes[class_name]["dissatisfaction"] - 7) + + ConsoleUI.display_success(f"حمایت از درآمدزایی {self._get_class_title(class_name)} انجام شد.") + ConsoleUI.wait_for_enter() + + def _adjust_tax_policy(self, class_name): + """تغییر سیاست‌های مالیاتی برای یک طبقه اجتماعی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"تغییر سیاست‌های مالیاتی برای {self._get_class_title(class_name)}") + + tax_options = [ + "کاهش مالیات (افزایش درآمد خالص)", + "افزایش مالیات (افزایش درآمدهای دولتی)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(tax_options) + + if choice == 3: + return # برگشت + + if choice == 1: + self._reduce_tax(class_name) + elif choice == 2: + self._increase_tax(class_name) + + def _reduce_tax(self, class_name): + """کاهش مالیات برای یک طبقه اجتماعی""" + from ui.console_ui import ConsoleUI + + cost = 0 # کاهش مالیات هزینه‌ای ندارد، اما درآمد دولتی کاهش می‌یابد + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"کاهش مالیات برای {self._get_class_title(class_name)}") + + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش درآمد خالص", indent=4) + ConsoleUI.display_message("• کاهش درآمد دولتی", indent=4) + ConsoleUI.display_message("• افزایش شادی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به کاهش مالیات هستید؟"): + return + + # اعمال تغییرات + income_increase = 5 + self.social_classes[class_name]["income_share"] = min(60, + self.social_classes[class_name]["income_share"] + income_increase) + + # کاهش درآمد دولتی + self.game_state.budget["welfare"] = max(0, + self.game_state.budget["welfare"] - 2) + + # به‌روزرسانی شادی + self.social_classes[class_name]["happiness"] = min(100, + self.social_classes[class_name]["happiness"] + 4) + + ConsoleUI.display_success(f"مالیات {self._get_class_title(class_name)} کاهش یافت.") + ConsoleUI.wait_for_enter() + + def _increase_tax(self, class_name): + """افزایش مالیات برای یک طبقه اجتماعی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش مالیات برای {self._get_class_title(class_name)}") + + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• کاهش درآمد خالص", indent=4) + ConsoleUI.display_message("• افزایش درآمد دولتی", indent=4) + ConsoleUI.display_message("• کاهش شادی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش مالیات هستید؟"): + return + + # اعمال تغییرات + income_decrease = 3 + self.social_classes[class_name]["income_share"] = max(5, + self.social_classes[class_name]["income_share"] - income_decrease) + + # افزایش درآمد دولتی + self.game_state.budget["welfare"] = min(100, + self.game_state.budget["welfare"] + 2) + + # به‌روزرسانی شادی + self.social_classes[class_name]["happiness"] = max(0, + self.social_classes[class_name]["happiness"] - 3) + + ConsoleUI.display_warning(f"مالیات {self._get_class_title(class_name)} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def social_crisis_management(self): + """مدیریت بحران‌های اجتماعی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران اجتماعی + if random.random() < 0.15: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران اجتماعی") + + # انتخاب نوع بحران + crisis_types = [ + "تظاهرات طبقه پایین", + "اختلافات بین طبقات", + "بحران بیکاری", + "بحران مسکن" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "حمایت از طبقه مورد نظر (5000 سکه)", + "اصلاحات ساختاری (7000 سکه)", + "مذاکره با نمایندگان (4000 سکه)", + "بی‌تفاوتی" + ] + costs = [5000, 7000, 4000, 0] + effects = [ + {"public_dissatisfaction": -8, "happiness": 5}, + {"public_dissatisfaction": -12, "political_stability": 3}, + {"public_dissatisfaction": -5, "relations": {"+": 3}}, + {"public_dissatisfaction": 15, "happiness": -10} + ] + + # نمایش گزینه‌ها + 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_social_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_social_crisis_response(self, 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 == "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["+"]) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران اجتماعی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم طبقات اجتماعی""" + # به‌روزرسانی شادی و نارضایتی طبقات + self._update_class_happiness() + + # بررسی بحران‌های اجتماعی + self.social_crisis_management() + + def _update_class_happiness(self): + """به‌روزرسانی شادی و نارضایتی طبقات اجتماعی""" + for class_name in self.social_classes: + # تغییر تصادفی شادی + happiness_change = self.game_state.random.randint(-2, 2) + self.social_classes[class_name]["happiness"] = max(0, min(100, + self.social_classes[class_name]["happiness"] + happiness_change)) + + # به‌روزرسانی نارضایتی بر اساس شادی + self.social_classes[class_name]["dissatisfaction"] = 100 - self.social_classes[class_name]["happiness"] +``` + +### 44. `game/society/social_issues.py` (مسائل اجتماعی) +```python +""" +مدیریت مسائل اجتماعی و چالش‌های فرهنگی +""" + +class SocialIssues: + """مدیریت مسائل اجتماعی و چالش‌های فرهنگی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم مسائل اجتماعی""" + self.game_state = game_state + self.active_issues = [] + + def initialize(self): + """راه‌اندازی اولیه سیستم مسائل اجتماعی""" + # ایجاد برخی مسائل اجتماعی اولیه + self._generate_initial_social_issues() + + def _generate_initial_social_issues(self): + """تولید مسائل اجتماعی اولیه بر اساس کشور انتخابی""" + country = self.game_state.player_country["name"] + + if country == "پادشاهی ایران": + self.active_issues = [ + {"name": "نابرابری جنسیتی", "severity": 40, "trend": "increasing"}, + {"name": "گسترش شهرنشینی", "severity": 30, "trend": "increasing"}, + {"name": "مهاجرت روستایی-شهری", "severity": 50, "trend": "stable"} + ] + elif country == "امپراتوری عثمانی": + self.active_issues = [ + {"name": "اختلافات مذهبی", "severity": 60, "trend": "increasing"}, + {"name": "فقر شهری", "severity": 45, "trend": "stable"}, + {"name": "بیکاری جوانان", "severity": 55, "trend": "increasing"} + ] + else: + # تولید مسائل اجتماعی تصادفی + issue_types = [ + "نابرابری جنسیتی", "اختلافات مذهبی", "فقر شهری", + "بیکاری جوانان", "گسترش شهرنشینی", "مهاجرت روستایی-شهری" + ] + + for _ in range(3): + issue_type = self.game_state.random.choice(issue_types) + issue_types.remove(issue_type) + + severity = self.game_state.random.randint(30, 60) + trend = self.game_state.random.choice(["increasing", "decreasing", "stable"]) + + self.active_issues.append({ + "name": issue_type, + "severity": severity, + "trend": trend + }) + + def display_social_issues(self): + """نمایش مسائل اجتماعی فعال""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مسائل اجتماعی") + + if not self.active_issues: + ConsoleUI.display_message("هیچ مسئله اجتماعی فعالی وجود ندارد.", indent=2) + ConsoleUI.wait_for_enter() + return + + for i, issue in enumerate(self.active_issues, 1): + trend_symbol = self._get_trend_symbol(issue["trend"]) + ConsoleUI.display_message(f"{i}. {issue['name']} {trend_symbol}", indent=2) + ConsoleUI.display_message(f" شدت: {issue['severity']}/100", indent=4) + + ConsoleUI.wait_for_enter() + + def _get_trend_symbol(self, trend): + """دریافت نماد مناسب برای روند مسئله اجتماعی""" + symbols = { + "increasing": "↑", + "decreasing": "↓", + "stable": "→" + } + return symbols.get(trend, "") + + def manage_social_issue(self): + """مدیریت یک مسئله اجتماعی خاص""" + from ui.console_ui import ConsoleUI + + if not self.active_issues: + ConsoleUI.display_warning("هیچ مسئله اجتماعی فعالی وجود ندارد.") + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت مسائل اجتماعی") + + # نمایش مسائل + issue_names = [issue["name"] for issue in self.active_issues] + issue_names.append("برگشت") + + choice = ConsoleUI.get_menu_choice(issue_names) + + if choice == len(issue_names): + return # برگشت + + selected_issue = self.active_issues[choice-1] + self._handle_specific_issue(selected_issue) + + def _handle_specific_issue(self, issue): + """مدیریت یک مسئله اجتماعی خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت {issue['name']}") + + issue_actions = [ + "سیاست‌های اصلاحی", + "آموزش و آگاهی‌بخشی", + "حمایت‌های مالی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(issue_actions) + + if choice == 1: + self._implement_reforms(issue) + elif choice == 2: + self._education_campaign(issue) + elif choice == 3: + self._financial_support(issue) + # choice == 4: برگشت + + def _implement_reforms(self, issue): + """اجرای سیاست‌های اصلاحی برای حل مسئله""" + from ui.console_ui import ConsoleUI + + cost = 6000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"سیاست‌های اصلاحی برای {issue['name']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• کاهش شدت مسئله", indent=4) + ConsoleUI.display_message("• افزایش شادی مردم", indent=4) + ConsoleUI.display_message("• کاهش نارضایتی عمومی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به اجرای سیاست‌های اصلاحی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + issue["severity"] = max(0, issue["severity"] - 15) + self.game_state.happiness = min(100, + self.game_state.happiness + 5) + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 5) + + ConsoleUI.display_success(f"سیاست‌های اصلاحی برای {issue['name']} اعمال شد.") + ConsoleUI.wait_for_enter() + + def _education_campaign(self, issue): + """اجرای کمپین آموزشی برای آگاهی‌بخشی درباره مسئله""" + from ui.console_ui import ConsoleUI + + cost = 4000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"کمپین آموزشی برای {issue['name']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• کاهش شدت مسئله", indent=4) + ConsoleUI.display_message("• افزایش سواد", indent=4) + ConsoleUI.display_message("• افزایش آگاهی عمومی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به اجرای کمپین آموزشی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + issue["severity"] = max(0, issue["severity"] - 10) + self.game_state.literacy_rate = min(100, + self.game_state.literacy_rate + 3) + + ConsoleUI.display_success(f"کمپین آموزشی برای {issue['name']} اجرا شد.") + ConsoleUI.wait_for_enter() + + def _financial_support(self, issue): + """ارائه حمایت‌های مالی برای حل مسئله""" + from ui.console_ui import ConsoleUI + + cost = 7000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"حمایت‌های مالی برای {issue['name']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• کاهش شدت مسئله", indent=4) + ConsoleUI.display_message("• کاهش فقر", indent=4) + ConsoleUI.display_message("• افزایش رفاه عمومی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به ارائه حمایت‌های مالی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + issue["severity"] = max(0, issue["severity"] - 20) + self.game_state.economy["welfare"] = min(100, + self.game_state.economy["welfare"] + 5) + + ConsoleUI.display_success(f"حمایت‌های مالی برای {issue['name']} ارائه شد.") + ConsoleUI.wait_for_enter() + + def social_issue_crisis_management(self): + """مدیریت بحران‌های مرتبط با مسائل اجتماعی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران مرتبط با مسائل اجتماعی + if random.random() < 0.1: + if not self.active_issues: + return # بدون مسئله اجتماعی فعال + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران اجتماعی") + + # انتخاب یک مسئله اجتماعی فعال + issue = random.choice(self.active_issues) + + # افزایش شدت مسئله + issue["severity"] = min(100, issue["severity"] + 10) + + ConsoleUI.display_warning(f"بحران {issue['name']} شدت یافت!", indent=2) + ConsoleUI.display_message(f"شدت فعلی: {issue['severity']}/100", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "اقدام فوری (6000 سکه)", + "برنامه‌ریزی بلندمدت (4000 سکه)", + "درخواست کمک بین‌المللی (5000 سکه)", + "بی‌تفاوتی" + ] + costs = [6000, 4000, 5000, 0] + effects = [ + {"severity": -20, "public_dissatisfaction": -8}, + {"severity": -10, "relations": {"+": 5}}, + {"severity": -15, "relations": {"+": 3}}, + {"severity": 10, "public_dissatisfaction": 12} + ] + + # نمایش گزینه‌ها + 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_social_issue_crisis_response(issue, costs[choice-1], effects[choice-1]) + + def _apply_social_issue_crisis_response(self, issue, cost, effects): + """اعمال پاسخ به بحران مرتبط با مسائل اجتماعی""" + from ui.console_ui import ConsoleUI + + # کسر هزینه + if cost > 0: + self.game_state.gold -= cost + + # اعمال اثرات + issue["severity"] = max(0, issue["severity"] + effects["severity"]) + + if "public_dissatisfaction" in effects: + self.game_state.public_dissatisfaction = max(0, min(100, + self.game_state.public_dissatisfaction + effects["public_dissatisfaction"])) + + if "relations" in effects: + 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] + effects["relations"]["+"]) + + ConsoleUI.display_success("بحران اجتماعی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم مسائل اجتماعی""" + # به‌روزرسانی مسائل اجتماعی + self._update_social_issues() + + # بررسی بحران‌های مرتبط با مسائل اجتماعی + self.social_issue_crisis_management() + + def _update_social_issues(self): + """به‌روزرسانی مسائل اجتماعی""" + for issue in self.active_issues: + # تغییر تصادفی شدت مسئله + change = 0 + if issue["trend"] == "increasing": + change = self.game_state.random.randint(1, 3) + elif issue["trend"] == "decreasing": + change = -self.game_state.random.randint(1, 3) + + issue["severity"] = max(0, min(100, issue["severity"] + change)) +``` + +### 45. `game/society/happiness_system.py` (سیستم شادی) +```python +""" +سیستم مدیریت شادی و رضایت عمومی +""" + +class HappinessSystem: + """سیستم مدیریت شادی و رضایت عمومی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم شادی""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم شادی""" + # محاسبه شادی اولیه بر اساس شرایط کشور + self._calculate_initial_happiness() + + def _calculate_initial_happiness(self): + """محاسبه شادی اولیه بر اساس شرایط کشور""" + # عوامل مؤثر بر شادی + factors = [ + self.game_state.economy["trade"] * 0.2, + self.game_state.economy["agriculture"] * 0.15, + self.game_state.economy["industry"] * 0.1, + self.game_state.literacy_rate * 0.2, + self.game_state.health_index * 0.2, + self.game_state.political_stability * 0.15 + ] + + # محاسبه میانگین وزنی + total = sum(factors) + self.game_state.happiness = min(100, int(total / len(factors))) + + def display_happiness_status(self): + """نمایش وضعیت شادی و عوامل مؤثر بر آن""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت شادی") + + # نمایش شادی کلی + ConsoleUI.display_message(f"شادی عمومی: {self.game_state.happiness}%", indent=2) + + # نمایش عوامل مؤثر + ConsoleUI.display_section_title("عوامل مؤثر", width=60) + self._display_happiness_factors() + + # نمایش تأثیرات شادی + ConsoleUI.display_section_title("تأثیرات شادی", width=60) + self._display_happiness_effects() + + ConsoleUI.wait_for_enter() + + def _display_happiness_factors(self): + """نمایش عوامل مؤثر بر شادی""" + from ui.console_ui import ConsoleUI + + # عوامل اقتصادی + economic_factor = (self.game_state.economy["trade"] * 0.3 + + self.game_state.economy["agriculture"] * 0.2 + + self.game_state.economy["industry"] * 0.2) / 0.7 + ConsoleUI.display_message(f"وضعیت اقتصادی: {int(economic_factor)}%", indent=2) + + # عوامل آموزشی + education_factor = self.game_state.literacy_rate + ConsoleUI.display_message(f"سطح آموزش: {education_factor}%", indent=2) + + # عوامل بهداشتی + health_factor = self.game_state.health_index + ConsoleUI.display_message(f"شاخص سلامت: {health_factor}%", indent=2) + + # عوامل سیاسی + political_factor = self.game_state.political_stability + ConsoleUI.display_message(f"ثبات سیاسی: {political_factor}%", indent=2) + + def _display_happiness_effects(self): + """نمایش تأثیرات شادی بر سایر سیستم‌ها""" + from ui.console_ui import ConsoleUI + + # تأثیر بر نارضایتی عمومی + dissatisfaction = 100 - self.game_state.happiness + ConsoleUI.display_message(f"نارضایتی عمومی: {dissatisfaction}%", indent=2) + + # تأثیر بر رشد جمعیت + population_growth = self.game_state.population_growth * (self.game_state.happiness / 100) + ConsoleUI.display_message(f"رشد جمعیت: {population_growth:.1f}%", indent=2) + + # تأثیر بر ثبات سیاسی + political_stability = min(100, self.game_state.political_stability + (self.game_state.happiness - 50) * 0.2) + ConsoleUI.display_message(f"ثبات سیاسی: {political_stability}%", indent=2) + + def manage_happiness(self): + """مدیریت عوامل مؤثر بر شادی مردم""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت شادی مردم") + + happiness_options = [ + "بهبود وضعیت اقتصادی", + "توسعه آموزش", + "ارتقای سلامت عمومی", + "تقویت ثبات سیاسی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(happiness_options) + + if choice == 1: + self._improve_economic_conditions() + elif choice == 2: + self._develop_education() + elif choice == 3: + self._enhance_public_health() + elif choice == 4: + self._strengthen_political_stability() + # choice == 5: برگشت + + def _improve_economic_conditions(self): + """بهبود وضعیت اقتصادی برای افزایش شادی""" + from ui.console_ui import ConsoleUI + + cost = 7000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بهبود وضعیت اقتصادی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش شادی: +5%", indent=4) + ConsoleUI.display_message("• کاهش نارضایتی: -5%", indent=4) + ConsoleUI.display_message("• افزایش رشد جمعیت: +0.3%", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به بهبود وضعیت اقتصادی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.happiness = min(100, + self.game_state.happiness + 5) + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 5) + self.game_state.population_growth += 0.3 + + ConsoleUI.display_success("وضعیت اقتصادی بهبود یافت.") + ConsoleUI.wait_for_enter() + + def _develop_education(self): + """توسعه سیستم آموزشی برای افزایش شادی""" + from ui.console_ui import ConsoleUI + + cost = 6000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("توسعه آموزش") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش شادی: +4%", indent=4) + ConsoleUI.display_message("• افزایش سواد: +3%", indent=4) + ConsoleUI.display_message("• افزایش ثبات سیاسی: +2%", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به توسعه آموزش هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.happiness = min(100, + self.game_state.happiness + 4) + self.game_state.literacy_rate = min(100, + self.game_state.literacy_rate + 3) + self.game_state.political_stability = min(100, + self.game_state.political_stability + 2) + + ConsoleUI.display_success("سیستم آموزش توسعه یافت.") + ConsoleUI.wait_for_enter() + + def _enhance_public_health(self): + """ارتقای سلامت عمومی برای افزایش شادی""" + from ui.console_ui import ConsoleUI + + cost = 8000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("ارتقای سلامت عمومی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش شادی: +6%", indent=4) + ConsoleUI.display_message("• افزایش شاخص سلامت: +8%", indent=4) + ConsoleUI.display_message("• کاهش مرگ‌ومیر: -2%", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به ارتقای سلامت عمومی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.happiness = min(100, + self.game_state.happiness + 6) + self.game_state.health_index = min(100, + self.game_state.health_index + 8) + + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + ConsoleUI.display_success("سلامت عمومی ارتقا یافت.") + ConsoleUI.wait_for_enter() + + def _strengthen_political_stability(self): + """تقویت ثبات سیاسی برای افزایش شادی""" + from ui.console_ui import ConsoleUI + + cost = 5000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تقویت ثبات سیاسی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش شادی: +3%", indent=4) + ConsoleUI.display_message("• افزایش ثبات سیاسی: +5%", indent=4) + ConsoleUI.display_message("• کاهش نارضایتی: -8%", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به تقویت ثبات سیاسی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.happiness = min(100, + self.game_state.happiness + 3) + self.game_state.political_stability = min(100, + self.game_state.political_stability + 5) + self.game_state.public_dissatisfaction = max(0, + self.game_state.public_dissatisfaction - 8) + + ConsoleUI.display_success("ثبات سیاسی تقویت شد.") + ConsoleUI.wait_for_enter() + + def happiness_crisis_management(self): + """مدیریت بحران‌های مرتبط با شادی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران مرتبط با شادی + if self.game_state.happiness < 40 and random.random() < 0.2: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران شادی") + + ConsoleUI.display_warning("شادی مردم به شدت کاهش یافته است!", indent=2) + ConsoleUI.display_message(f"شادی فعلی: {self.game_state.happiness}%", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "اقدامات فوری اقتصادی (8000 سکه)", + "برنامه‌های اجتماعی (6000 سکه)", + "مذاکره با گروه‌های اجتماعی (5000 سکه)", + "بی‌تفاوتی" + ] + costs = [8000, 6000, 5000, 0] + effects = [ + {"happiness": 10, "public_dissatisfaction": -10}, + {"happiness": 8, "political_stability": 5}, + {"happiness": 5, "relations": {"+": 5}}, + {"happiness": -5, "public_dissatisfaction": 15} + ] + + # نمایش گزینه‌ها + 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_happiness_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_happiness_crisis_response(self, 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 == "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["+"]) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران شادی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم شادی""" + # به‌روزرسانی شادی بر اساس عوامل مختلف + self._update_happiness() + + # بررسی بحران‌های مرتبط با شادی + self.happiness_crisis_management() + + def _update_happiness(self): + """به‌روزرسانی شادی بر اساس عوامل مختلف""" + # محاسبه بر اساس عوامل اصلی + factors = [ + self.game_state.economy["trade"] * 0.2, + self.game_state.economy["agriculture"] * 0.15, + self.game_state.economy["industry"] * 0.1, + self.game_state.literacy_rate * 0.2, + self.game_state.health_index * 0.2, + self.game_state.political_stability * 0.15 + ] + + # محاسبه میانگین وزنی + total = sum(factors) + new_happiness = min(100, int(total / len(factors))) + + # تغییر تدریجی به سمت مقدار جدید + if new_happiness > self.game_state.happiness: + self.game_state.happiness = min(100, self.game_state.happiness + 1) + elif new_happiness < self.game_state.happiness: + self.game_state.happiness = max(0, self.game_state.happiness - 1) +``` + +### 46. `game/culture/__init__.py` +```python +""" +پکیج سیستم فرهنگی +""" + +from .cultural_system import CulturalSystem +``` + +### 47. `game/culture/cultural_system.py` (سیستم فرهنگی) +```python +""" +سیستم مدیریت فرهنگ و گسترش فرهنگی +""" + +class CulturalSystem: + """سیستم مدیریت فرهنگ و گسترش فرهنگی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم فرهنگی""" + self.game_state = game_state + self.cultural_elements = self._initialize_cultural_elements() + + def _initialize_cultural_elements(self): + """راه‌اندازی اولیه عناصر فرهنگی""" + return { + "language": { + "name": "Persian", + "spread": 60, + "influence": 70 + }, + "art": { + "level": 5, + "influence": 65 + }, + "music": { + "level": 4, + "influence": 60 + }, + "literature": { + "level": 6, + "influence": 75 + }, + "cuisine": { + "popularity": 50, + "influence": 55 + } + } + + def initialize(self): + """راه‌اندازی اولیه سیستم فرهنگی""" + # تنظیم اطلاعات فرهنگی اولیه بر اساس کشور انتخابی + country = self.game_state.player_country["name"] + + if country == "پادشاهی ایران": + self.cultural_elements["language"]["name"] = "Persian" + self.cultural_elements["language"]["spread"] = 40 + self.cultural_elements["language"]["influence"] = 60 + elif country == "امپراتوری عثمانی": + self.cultural_elements["language"]["name"] = "Turkish" + self.cultural_elements["language"]["spread"] = 50 + self.cultural_elements["language"]["influence"] = 65 + else: + # تنظیمات پیش‌فرض + self.cultural_elements["language"]["name"] = "National" + self.cultural_elements["language"]["spread"] = 30 + self.cultural_elements["language"]["influence"] = 50 + + def display_culture_status(self): + """نمایش وضعیت فرهنگی کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت فرهنگی") + + # نمایش امتیاز فرهنگی کلی + ConsoleUI.display_message(f"امتیاز فرهنگی: {self.game_state.culture_score}/100", indent=2) + + # نمایش نفوذ فرهنگی + ConsoleUI.display_message(f"نفوذ فرهنگی: {self.game_state.cultural_influence}%", indent=2) + + # نمایش عناصر فرهنگی + ConsoleUI.display_section_title("عناصر فرهنگی", width=60) + for element, data in self.cultural_elements.items(): + element_title = self._get_element_title(element) + if "level" in + ConsoleUI.display_message(f"{element_title}: سطح {data['level']}/10", indent=2) + elif "spread" in + ConsoleUI.display_message(f"{element_title}: گسترش {data['spread']}%", indent=2) + ConsoleUI.display_message(f" نفوذ: {data['influence']}%", indent=4) + + ConsoleUI.wait_for_enter() + + def _get_element_title(self, element): + """دریافت عنوان فارسی برای عنصر فرهنگی""" + titles = { + "language": "زبان", + "art": "هنر", + "music": "موسیقی", + "literature": "ادبیات", + "cuisine": "آشپزی" + } + return titles.get(element, element) + + def invest_in_cultural_spread(self): + """سرمایه‌گذاری در گسترش فرهنگ""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("سرمایه‌گذاری در گسترش فرهنگ") + + investment_options = [ + "گسترش زبان ملی", + "توسعه هنر و معماری", + "ارتقای موسیقی سنتی", + "حمایت از ادبیات", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(investment_options) + + if choice == 5: + return # برگشت + + # تعیین هزینه و تأثیرات + costs = [5000, 6000, 4000, 7000] + effects = [ + {"language": {"spread": 10, "influence": 5}, "cultural_influence": 8}, + {"art": {"level": 1, "influence": 8}, "cultural_influence": 6}, + {"music": {"level": 1, "influence": 6}, "cultural_influence": 5}, + {"literature": {"level": 1, "influence": 10}, "cultural_influence": 7} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"نوع سرمایه‌گذاری: {investment_options[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for element, values in effect.items(): + if element == "cultural_influence": + ConsoleUI.display_message(f"• نفوذ فرهنگی: +{values}%", indent=4) + else: + for attr, value in values.items(): + if attr == "level": + ConsoleUI.display_message(f"• {self._get_element_title(element)}: سطح +{value}", indent=4) + else: + ConsoleUI.display_message(f"• {self._get_element_title(element)}: {attr} +{value}%", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به سرمایه‌گذاری در این حوزه هستید؟"): + self._apply_cultural_investment(cost, effect) + + def _apply_cultural_investment(self, cost, effects): + """اعمال سرمایه‌گذاری فرهنگی و اثرات آن""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # اعمال تأثیرات + for element, values in effects.items(): + if element == "cultural_influence": + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + values) + else: + for attr, value in values.items(): + if attr in self.cultural_elements[element]: + self.cultural_elements[element][attr] = min(100, + self.cultural_elements[element][attr] + value) + + ConsoleUI.display_success("سرمایه‌گذاری فرهنگی انجام شد.") + ConsoleUI.wait_for_enter() + + def cultural_assimilation(self): + """گسترش فرهنگ به کشورهای تحت کنترل""" + from ui.console_ui import ConsoleUI + + if self.game_state.controlled_territories <= 1: + ConsoleUI.display_warning("شما فقط کشور خود را کنترل می‌کنید و نمی‌توانید فرهنگ را گسترش دهید.", indent=2) + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("گسترش فرهنگ به مناطق تحت کنترل") + + assimilation_options = [ + "آموزش زبان ملی", + "تبلیغات فرهنگی", + "تبادل فرهنگی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(assimilation_options) + + if choice == 4: + return # برگشت + + # تعیین هزینه و تأثیرات + costs = [4000, 5000, 3000] + effects = [ + {"cultural_influence": 5, "controlled_territories": 0.5}, + {"cultural_influence": 7, "happiness": 3}, + {"cultural_influence": 4, "relations": {"+": 3}} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"روش گسترش: {assimilation_options[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "relations": + ConsoleUI.display_message(f"• روابط: +{value['+']}", indent=4) + elif effect_type == "controlled_territories": + ConsoleUI.display_message(f"• نفوذ فرهنگی در مناطق تحت کنترل: +{value}%", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به اجرای این روش هستید؟"): + self._apply_cultural_assimilation(cost, effect) + + def _apply_cultural_assimilation(self, cost, effects): + """اعمال گسترش فرهنگ و اثرات آن""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + effects["cultural_influence"]) + + # اعمال سایر تأثیرات + for effect_type, value in effects.items(): + if 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 == "controlled_territories": + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + pass + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + ConsoleUI.display_success("گسترش فرهنگ انجام شد.") + ConsoleUI.wait_for_enter() + + def manage_language_and_art(self): + """مدیریت زبان و هنر""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت زبان و هنر") + + management_options = [ + "تغییر زبان رسمی", + "حمایت از هنرمندان", + "توسعه مراکز فرهنگی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(management_options) + + if choice == 1: + self._change_official_language() + elif choice == 2: + self._support_artists() + elif choice == 3: + self._develop_cultural_centers() + # choice == 4: برگشت + + def _change_official_language(self): + """تغییر زبان رسمی کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تغییر زبان رسمی") + + # گزینه‌های زبان + language_options = [ + "زبان مادری (فارسی)", + "زبان انگلیسی", + "زبان عربی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(language_options) + + if choice == 4: + return # برگشت + + languages = ["Persian", "English", "Arabic"] + new_language = languages[choice-1] + + ConsoleUI.display_message(f"آیا مطمئن هستید که می‌خواهید زبان رسمی را به {new_language} تغییر دهید؟", indent=2) + ConsoleUI.display_warning("هشدار: این تغییر ممکن است تأثیرات فرهنگی و سیاسی داشته باشد!", indent=2) + + if not ConsoleUI.confirm_action("تایید تغییر زبان رسمی"): + return + + # اعمال تغییرات + old_language = self.cultural_elements["language"]["name"] + self.cultural_elements["language"]["name"] = new_language + + # تأثیر بر نفوذ فرهنگی + if new_language == "Persian": + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + 5) + else: + self.game_state.cultural_influence = max(0, + self.game_state.cultural_influence - 3) + + ConsoleUI.display_success(f"زبان رسمی به {new_language} تغییر یافت.") + ConsoleUI.wait_for_enter() + + def _support_artists(self): + """حمایت از هنرمندان و توسعه هنر""" + from ui.console_ui import ConsoleUI + + cost = 4000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("حمایت از هنرمندان") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش سطح هنر: +1", indent=4) + ConsoleUI.display_message("• افزایش نفوذ هنر: +5%", indent=4) + ConsoleUI.display_message("• افزایش امتیاز فرهنگی: +3", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به حمایت از هنرمندان هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.cultural_elements["art"]["level"] = min(10, + self.cultural_elements["art"]["level"] + 1) + self.cultural_elements["art"]["influence"] = min(100, + self.cultural_elements["art"]["influence"] + 5) + self.game_state.culture_score = min(100, + self.game_state.culture_score + 3) + + ConsoleUI.display_success("حمایت از هنرمندان انجام شد.") + ConsoleUI.wait_for_enter() + + def _develop_cultural_centers(self): + """توسعه مراکز فرهنگی""" + from ui.console_ui import ConsoleUI + + cost = 6000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("توسعه مراکز فرهنگی") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش نفوذ فرهنگی: +6%", indent=4) + ConsoleUI.display_message("• افزایش شادی مردم: +4%", indent=4) + ConsoleUI.display_message("• افزایش روابط بین‌المللی: +3", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به توسعه مراکز فرهنگی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + 6) + self.game_state.happiness = min(100, + self.game_state.happiness + 4) + + # افزایش روابط + 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] + 3) + + ConsoleUI.display_success("مراکز فرهنگی توسعه یافتند.") + ConsoleUI.wait_for_enter() + + def cultural_crisis_management(self): + """مدیریت بحران‌های فرهنگی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران فرهنگی + if random.random() < 0.1: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران فرهنگی") + + # انتخاب نوع بحران + crisis_types = [ + "تهدید به یکسان‌سازی فرهنگی", + "اختلافات بین‌الادیانی", + "تضعیف زبان ملی", + "سقوط ارزش‌های سنتی" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "تقویت هویت ملی (5000 سکه)", + "برنامه‌های آموزشی فرهنگی (4000 سکه)", + "مذاکره با گروه‌های فرهنگی (3000 سکه)", + "بی‌تفاوتی" + ] + costs = [5000, 4000, 3000, 0] + effects = [ + {"cultural_influence": 8, "public_dissatisfaction": -5}, + {"culture_score": 6, "happiness": 4}, + {"relations": {"+": 5}, "cultural_influence": 3}, + {"cultural_influence": -10, "culture_score": -5} + ] + + # نمایش گزینه‌ها + 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_cultural_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_cultural_crisis_response(self, 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 == "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 in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران فرهنگی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم فرهنگی""" + # به‌روزرسانی عناصر فرهنگی + self._update_cultural_elements() + + # بررسی بحران‌های فرهنگی + self.cultural_crisis_management() + + def _update_cultural_elements(self): + """به‌روزرسانی عناصر فرهنگی""" + # به‌روزرسانی گسترش زبان + if self.cultural_elements["language"]["spread"] < 100: + self.cultural_elements["language"]["spread"] = min(100, + self.cultural_elements["language"]["spread"] + 1) + + # به‌روزرسانی نفوذ عناصر فرهنگی + for element in ["art", "music", "literature", "cuisine"]: + if self.cultural_elements[element]["influence"] < 100: + self.cultural_elements[element]["influence"] = min(100, + self.cultural_elements[element]["influence"] + 1) +``` + +### 48. `game/culture/language_system.py` (سیستم زبان) +```python +""" +سیستم مدیریت زبان و گسترش زبانی +""" + +class LanguageSystem: + """سیستم مدیریت زبان و گسترش زبانی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم زبان""" + self.game_state = game_state + self.languages = self._initialize_languages() + + def _initialize_languages(self): + """راه‌اندازی اولیه زبان‌ها""" + return { + "Persian": { + "spread": 40, + "influence": 60, + "status": "Official" + }, + "English": { + "spread": 20, + "influence": 40, + "status": "Foreign" + }, + "Arabic": { + "spread": 30, + "influence": 50, + "status": "Religious" + } + } + + def display_language_status(self): + """نمایش وضعیت زبان‌ها""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت زبان‌ها") + + # نمایش زبان رسمی + official_lang = self._get_official_language() + ConsoleUI.display_message(f"زبان رسمی: {official_lang}", indent=2) + + # نمایش سایر زبان‌ها + ConsoleUI.display_section_title("زبان‌های دیگر", width=60) + for lang, data in self.languages.items(): + if lang != official_lang: + ConsoleUI.display_message(f"{lang}:", indent=2) + ConsoleUI.display_message(f" گسترش: {data['spread']}%", indent=4) + ConsoleUI.display_message(f" نفوذ: {data['influence']}%", indent=4) + ConsoleUI.display_message(f" وضعیت: {data['status']}", indent=4) + + ConsoleUI.wait_for_enter() + + def _get_official_language(self): + """دریافت زبان رسمی کشور""" + for lang, data in self.languages.items(): + if data["status"] == "Official": + return lang + return "Persian" # پیش‌فرض + + def change_official_language(self): + """تغییر زبان رسمی کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("تغییر زبان رسمی") + + # فیلتر زبان‌هایی که می‌توانند رسمی باشند + potential_languages = [lang for lang, data in self.languages.items() + if data["spread"] > 20] + + if not potential_languages: + ConsoleUI.display_warning("هیچ زبانی برای تغییر به زبان رسمی کافی گسترده نیست.", indent=2) + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + language_options = [f"{lang} ({self.languages[lang]['spread']}%)" for lang in potential_languages] + language_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(language_options) + + if choice == len(language_options): + return # برگشت + + new_language = potential_languages[choice-1] + + ConsoleUI.display_message(f"آیا مطمئن هستید که می‌خواهید زبان رسمی را به {new_language} تغییر دهید؟", indent=2) + ConsoleUI.display_warning("هشدار: این تغییر ممکن است تأثیرات فرهنگی و سیاسی داشته باشد!", indent=2) + + if not ConsoleUI.confirm_action("تایید تغییر زبان رسمی"): + return + + # اعمال تغییرات + old_language = self._get_official_language() + self.languages[old_language]["status"] = "National" + self.languages[new_language]["status"] = "Official" + + # تأثیر بر نفوذ فرهنگی + if new_language == "Persian": + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + 5) + else: + self.game_state.cultural_influence = max(0, + self.game_state.cultural_influence - 3) + + ConsoleUI.display_success(f"زبان رسمی به {new_language} تغییر یافت.") + ConsoleUI.wait_for_enter() + + def promote_language(self): + """ترویج یک زبان خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("ترویج زبان") + + # نمایش زبان‌ها + language_options = [f"{lang} ({self.languages[lang]['spread']}%)" for lang in self.languages] + language_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(language_options) + + if choice == len(language_options): + return # برگشت + + language = list(self.languages.keys())[choice-1] + self._promote_specific_language(language) + + def _promote_specific_language(self, language): + """ترویج یک زبان خاص""" + from ui.console_ui import ConsoleUI + + cost = 3000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"ترویج زبان {language}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش گسترش زبان: +8%", indent=4) + ConsoleUI.display_message("• افزایش نفوذ فرهنگی: +3%", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به ترویج این زبان هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.languages[language]["spread"] = min(100, + self.languages[language]["spread"] + 8) + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + 3) + + ConsoleUI.display_success(f"زبان {language} ترویج یافت.") + ConsoleUI.wait_for_enter() + + def language_education_programs(self): + """برنامه‌های آموزش زبان""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("برنامه‌های آموزش زبان") + + program_options = [ + "آموزش زبان در مدارس", + "مرکز‌های فرهنگی بین‌المللی", + "تبادل دانشجویی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(program_options) + + if choice == 4: + return # برگشت + + # تعیین هزینه و تأثیرات + costs = [4000, 5000, 6000] + effects = [ + {"language": {"spread": 5}, "literacy_rate": 2}, + {"language": {"influence": 6}, "relations": {"+": 4}}, + {"language": {"spread": 8, "influence": 4}, "culture_score": 3} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"نوع برنامه: {program_options[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for element, values in effect.items(): + if element == "relations": + ConsoleUI.display_message(f"• روابط: +{values['+']}", indent=4) + elif element == "language": + for attr, value in values.items(): + ConsoleUI.display_message(f"• {attr}: +{value}%", indent=4) + else: + ConsoleUI.display_message(f"• {element}: +{value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به اجرای این برنامه هستید؟"): + self._apply_language_program(cost, effect) + + def _apply_language_program(self, cost, effects): + """اعمال برنامه آموزش زبان و اثرات آن""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # اعمال تأثیرات + for element, values in effects.items(): + if element == "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] + values["+"]) + elif element == "language": + for lang in self.languages: + for attr, value in values.items(): + if attr in self.languages[lang]: + self.languages[lang][attr] = min(100, + self.languages[lang][attr] + value) + else: + if element in self.game_state: + self.game_state[element] = min(100, + self.game_state[element] + values) + + ConsoleUI.display_success("برنامه آموزش زبان اجرا شد.") + ConsoleUI.wait_for_enter() + + def language_crisis_management(self): + """مدیریت بحران‌های زبانی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران زبانی + if random.random() < 0.05: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران زبانی") + + # انتخاب نوع بحران + crisis_types = [ + "کاهش گسترش زبان ملی", + "افزایش استفاده از زبان خارجی", + "اختلافات زبانی در مناطق تحت کنترل" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "تقویت آموزش زبان ملی (4000 سکه)", + "محدود کردن استفاده از زبان خارجی (3000 سکه)", + "برنامه‌های فرهنگی (5000 سکه)", + "بی‌تفاوتی" + ] + costs = [4000, 3000, 5000, 0] + effects = [ + {"language": {"spread": 10}, "cultural_influence": 5}, + {"language": {"spread": 5}, "relations": {"-": 3}}, + {"language": {"influence": 8}, "happiness": 4}, + {"language": {"spread": -5}, "cultural_influence": -3} + ] + + # نمایش گزینه‌ها + 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_language_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_language_crisis_response(self, cost, effects): + """اعمال پاسخ به بحران زبانی و اثرات آن""" + from ui.console_ui import ConsoleUI + + # کسر هزینه + if cost > 0: + self.game_state.gold -= cost + + # اعمال اثرات + for element, values in effects.items(): + if element == "relations": + for country in self.game_state.relations: + if country != self.game_state.player_country["name"]: + change = values["+"] + self.game_state.relations[country] = min(100, + self.game_state.relations[country] + change) + elif element == "language": + for lang in self.languages: + for attr, value in values.items(): + if attr in self.languages[lang]: + self.languages[lang][attr] = max(0, min(100, + self.languages[lang][attr] + value)) + else: + if element in self.game_state: + self.game_state[element] = max(0, min(100, + self.game_state[element] + values)) + + ConsoleUI.display_success("بحران زبانی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم زبان""" + # به‌روزرسانی گسترش و نفوذ زبان‌ها + self._update_language_spread() + + # بررسی بحران‌های زبانی + self.language_crisis_management() + + def _update_language_spread(self): + """به‌روزرسانی گسترش زبان‌ها""" + for lang in self.languages: + # تغییر تصادفی گسترش + change = self.game_state.random.randint(-1, 2) + self.languages[lang]["spread"] = max(0, min(100, + self.languages[lang]["spread"] + change)) + + # تغییر تصادفی نفوذ + change = self.game_state.random.randint(-1, 1) + self.languages[lang]["influence"] = max(0, min(100, + self.languages[lang]["influence"] + change)) +``` + +### 49. `game/culture/cultural_influence.py` (نفوذ فرهنگی) +```python +""" +سیستم مدیریت نفوذ فرهنگی و گسترش فرهنگ +""" + +class CulturalInfluence: + """سیستم مدیریت نفوذ فرهنگی و گسترش فرهنگ""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم نفوذ فرهنگی""" + self.game_state = game_state + self.influence_targets = [] + + def initialize(self): + """راه‌اندازی اولیه سیستم نفوذ فرهنگی""" + # تنظیم اهداف اولیه بر اساس روابط + self._setup_initial_influence_targets() + + def _setup_initial_influence_targets(self): + """تنظیم اهداف اولیه برای نفوذ فرهنگی""" + for country, relation in self.game_state.relations.items(): + if country != self.game_state.player_country["name"] and relation > 30: + self.influence_targets.append({ + "country": country, + "level": 1, + "progress": 0 + }) + + def display_influence_status(self): + """نمایش وضعیت نفوذ فرهنگی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت نفوذ فرهنگی") + + # نمایش نفوذ کلی + ConsoleUI.display_message(f"نفوذ فرهنگی کلی: {self.game_state.cultural_influence}%", indent=2) + + # نمایش اهداف نفوذ + ConsoleUI.display_section_title("اهداف نفوذ", width=60) + if not self.influence_targets: + ConsoleUI.display_message("هیچ هدفی برای نفوذ فرهنگی تعریف نشده است.", indent=2) + else: + for target in self.influence_targets: + ConsoleUI.display_message(f"{target['country']}:", indent=2) + ConsoleUI.display_message(f" سطح: {target['level']}", indent=4) + ConsoleUI.display_message(f" پیشرفت: {target['progress']}%", indent=4) + + ConsoleUI.wait_for_enter() + + def select_influence_target(self): + """انتخاب هدف برای نفوذ فرهنگی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("انتخاب هدف نفوذ") + + # فیلتر کشورهایی که می‌توانیم بر آنها نفوذ کنیم + potential_targets = [] + for country, relation in self.game_state.relations.items(): + if relation > 20 and country != self.game_state.player_country["name"]: + potential_targets.append(country) + + if not potential_targets: + ConsoleUI.display_warning("هیچ کشوری برای نفوذ فرهنگی در دسترس نیست.", indent=2) + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_targets.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_targets) + + if choice == len(potential_targets): + return # برگشت + + target_country = potential_targets[choice-1] + + # بررسی اینکه آیا قبلاً انتخاب شده است + if any(t["country"] == target_country for t in self.influence_targets): + ConsoleUI.display_warning(f"{target_country} قبلاً به عنوان هدف نفوذ انتخاب شده است.", indent=2) + ConsoleUI.wait_for_enter() + return + + # اضافه کردن هدف + self.influence_targets.append({ + "country": target_country, + "level": 1, + "progress": 0 + }) + + ConsoleUI.display_success(f"{target_country} به عنوان هدف نفوذ انتخاب شد.") + ConsoleUI.wait_for_enter() + + def manage_influence_target(self): + """مدیریت یک هدف نفوذ فرهنگی خاص""" + from ui.console_ui import ConsoleUI + + if not self.influence_targets: + ConsoleUI.display_warning("هیچ هدفی برای نفوذ فرهنگی تعریف نشده است.", indent=2) + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت اهداف نفوذ") + + # نمایش اهداف + target_options = [target["country"] for target in self.influence_targets] + target_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(target_options) + + if choice == len(target_options): + return # برگشت + + selected_target = self.influence_targets[choice-1] + self._manage_specific_target(selected_target) + + def _manage_specific_target(self, target): + """مدیریت یک هدف نفوذ خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت {target['country']}") + + target_actions = [ + "افزایش سطح نفوذ", + "برنامه‌های فرهنگی", + "تبادل دانش", + "بررسی پیشرفت", + "حذف هدف", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(target_actions) + + if choice == 1: + self._increase_influence_level(target) + elif choice == 2: + self._cultural_programs(target) + elif choice == 3: + self._knowledge_exchange(target) + elif choice == 4: + self._check_progress(target) + elif choice == 5: + self._remove_influence_target(target) + # choice == 6: برگشت + + def _increase_influence_level(self, target): + """افزایش سطح نفوذ بر روی یک هدف""" + from ui.console_ui import ConsoleUI + + cost = 5000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش نفوذ بر {target['country']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش سطح نفوذ", indent=4) + ConsoleUI.display_message("• افزایش نفوذ فرهنگی کلی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش سطح نفوذ هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + target["level"] = min(5, target["level"] + 1) + + ConsoleUI.display_success(f"سطح نفوذ بر {target['country']} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _cultural_programs(self, target): + """اجرای برنامه‌های فرهنگی برای افزایش نفوذ""" + from ui.console_ui import ConsoleUI + + cost = 4000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"برنامه‌های فرهنگی برای {target['country']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش پیشرفت نفوذ", indent=4) + ConsoleUI.display_message("• افزایش روابط", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به اجرای برنامه‌های فرهنگی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + progress_increase = 10 * target["level"] + target["progress"] = min(100, target["progress"] + progress_increase) + + # افزایش روابط + self.game_state.relations[target["country"]] = min(100, + self.game_state.relations[target["country"]] + 3) + + ConsoleUI.display_success(f"برنامه‌های فرهنگی برای {target['country']} اجرا شد.") + ConsoleUI.wait_for_enter() + + def _knowledge_exchange(self, target): + """تبادل دانش برای افزایش نفوذ فرهنگی""" + from ui.console_ui import ConsoleUI + + cost = 6000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"تبادل دانش با {target['country']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش پیشرفت نفوذ", indent=4) + ConsoleUI.display_message("• افزایش نفوذ فرهنگی کلی", indent=4) + ConsoleUI.display_message("• افزایش سطح فناوری", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به تبادل دانش هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + progress_increase = 15 * target["level"] + target["progress"] = min(100, target["progress"] + progress_increase) + + # افزایش نفوذ فرهنگی کلی + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + 5) + + # افزایش فناوری + for tech in ["education", "trade"]: + self.game_state.technology[tech] = min(10, + self.game_state.technology[tech] + 1) + + ConsoleUI.display_success(f"تبادل دانش با {target['country']} انجام شد.") + ConsoleUI.wait_for_enter() + + def _check_progress(self, target): + """بررسی پیشرفت نفوذ فرهنگی بر روی یک هدف""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"پیشرفت نفوذ بر {target['country']}") + + ConsoleUI.display_message(f"سطح نفوذ: {target['level']}", indent=2) + ConsoleUI.display_message(f"پیشرفت: {target['progress']}%", indent=2) + + # محاسبه زمان تخمینی برای تکمیل نفوذ + if target["progress"] < 100: + remaining = 100 - target["progress"] + time_estimate = int(remaining / (10 * target["level"])) + ConsoleUI.display_message(f"زمان تخمینی برای تکمیل: {time_estimate} سال", indent=2) + + ConsoleUI.wait_for_enter() + + def _remove_influence_target(self, target): + """حذف یک هدف نفوذ فرهنگی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"حذف {target['country']} از اهداف نفوذ") + + ConsoleUI.display_warning("هشدار: این عمل غیرقابل بازگشت است!", indent=2) + + if not ConsoleUI.confirm_action("آیا مطمئن هستید که می‌خواهید این هدف را حذف کنید؟"): + return + + # حذف هدف + self.influence_targets.remove(target) + + ConsoleUI.display_warning(f"{target['country']} از اهداف نفوذ حذف شد.") + ConsoleUI.wait_for_enter() + + def influence_crisis_management(self): + """مدیریت بحران‌های نفوذ فرهنگی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران نفوذ فرهنگی + if random.random() < 0.1: + if not self.influence_targets: + return # بدون هدف نفوذ + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران نفوذ فرهنگی") + + # انتخاب یک هدف نفوذ فعال + target = random.choice(self.influence_targets) + + # کاهش پیشرفت نفوذ + target["progress"] = max(0, target["progress"] - 10) + + ConsoleUI.display_warning(f"نفوذ فرهنگی بر {target['country']} کاهش یافت!", indent=2) + ConsoleUI.display_message(f"پیشرفت فعلی: {target['progress']}%", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "تقویت برنامه‌های فرهنگی (5000 سکه)", + "مذاکره با کشور هدف (3000 سکه)", + "تغییر استراتژی نفوذ (4000 سکه)", + "بی‌تفاوتی" + ] + costs = [5000, 3000, 4000, 0] + effects = [ + {"progress": 15, "relations": {"+": 5}}, + {"progress": 10, "relations": {"+": 3}}, + {"progress": 12, "cultural_influence": 3}, + {"progress": -5, "relations": {"-": 5}} + ] + + # نمایش گزینه‌ها + 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_influence_crisis_response(target, costs[choice-1], effects[choice-1]) + + def _apply_influence_crisis_response(self, target, cost, effects): + """اعمال پاسخ به بحران نفوذ فرهنگی""" + from ui.console_ui import ConsoleUI + + # کسر هزینه + if cost > 0: + self.game_state.gold -= cost + + # اعمال اثرات + target["progress"] = min(100, target["progress"] + effects["progress"]) + + if "relations" in effects: + for country in self.game_state.relations: + if country != self.game_state.player_country["name"]: + change = effects["relations"].get("+", 0) - effects["relations"].get("-", 0) + self.game_state.relations[country] = min(100, + self.game_state.relations[country] + change) + + if "cultural_influence" in effects: + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + effects["cultural_influence"]) + + ConsoleUI.display_success("بحران نفوذ فرهنگی مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم نفوذ فرهنگی""" + # به‌روزرسانی پیشرفت نفوذ + self._update_influence_progress() + + # بررسی بحران‌های نفوذ فرهنگی + self.influence_crisis_management() + + def _update_influence_progress(self): + """به‌روزرسانی پیشرفت نفوذ فرهنگی""" + for target in self.influence_targets: + # افزایش پیشرفت بر اساس سطح نفوذ + progress_increase = 5 * target["level"] + target["progress"] = min(100, target["progress"] + progress_increase) + + # اگر نفوذ کامل شد + if target["progress"] >= 100: + # افزایش نفوذ فرهنگی کلی + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + 3) + + # ریست پیشرفت برای سطح بعدی + target["progress"] = 0 + target["level"] = min(5, target["level"] + 1) +``` + +### 50. `game/diplomacy/__init__.py` +```python +""" +پکیج سیستم دیپلماسی +""" + +from .diplomacy_system import DiplomacySystem +``` + +### 51. `game/diplomacy/diplomacy_system.py` (سیستم دیپلماسی) +```python +""" +سیستم مدیریت دیپلماسی و روابط خارجی +""" + +class DiplomacySystem: + """سیستم مدیریت دیپلماسی و روابط خارجی""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم دیپلماسی""" + self.game_state = game_state + + def initialize(self): + """راه‌اندازی اولیه سیستم دیپلماسی""" + # تنظیم روابط اولیه بر اساس کشور انتخابی + self._setup_initial_relations() + + def _setup_initial_relations(self): + """راه‌اندازی روابط اولیه با کشورهای دیگر""" + country = self.game_state.player_country + + # تنظیم روابط پیش‌فرض + for c in country["starting_relations"]: + self.game_state.relations[c] = country["starting_relations"][c] + + # تنظیم روابط برای سایر کشورها + for c in self.game_state.relations: + if c not in country["starting_relations"] and c != country["name"]: + self.game_state.relations[c] = self.game_state.random.randint(-20, 30) + + def display_relations(self): + """نمایش روابط فعلی با سایر کشورها""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("روابط دیپلماتیک") + + # نمایش امتیاز دیپلماسی + ConsoleUI.display_message(f"امتیاز دیپلماسی: {self.game_state.diplomacy_points}", indent=2) + + # نمایش روابط + ConsoleUI.display_section_title("روابط با کشورها", width=60) + for country, relation in self.game_state.relations.items(): + if country == self.game_state.player_country["name"]: + continue + + status = self._get_relation_status(relation) + ConsoleUI.display_message(f"{country}: {relation} ({status})", indent=2) + + ConsoleUI.wait_for_enter() + + def _get_relation_status(self, value): + """دریافت وضعیت رابطه بر اساس مقدار""" + if value > 70: + return "همپیمان" + elif value > 50: + return "دوست" + elif value > 0: + return "خنثی" + elif value > -30: + return "منفی" + else: + return "دشمن" + + def propose_alliance(self): + """پیشنهاد اتحاد یا پیمان به یک کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("پیشنهاد اتحاد") + + # فیلتر کشورهایی که روابط خوبی داریم + potential_allies = [] + for country, relation in self.game_state.relations.items(): + if relation > 30 and country != self.game_state.player_country["name"]: + potential_allies.append(country) + + if not potential_allies: + ConsoleUI.display_warning("هیچ کشوری برای پیشنهاد اتحاد در دسترس نیست.", indent=2) + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_allies.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_allies) + + if choice == len(potential_allies): + return # برگشت + + target_country = potential_allies[choice-1] + self._negotiate_alliance(target_country) + + def _negotiate_alliance(self, target_country): + """مذاکره برای اتحاد با یک کشور خاص""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مذاکره اتحاد با {target_country}") + + # محاسبه شانس موفقیت + base_chance = 0.4 + relation_factor = self.game_state.relations[target_country] / 200 + diplomacy_factor = self.game_state.diplomacy_points / 100 + + success_chance = base_chance + relation_factor + diplomacy_factor + success_chance = max(0.2, min(0.9, success_chance)) + + ConsoleUI.display_message(f"شانس موفقیت: {int(success_chance * 100)}%", indent=2) + + # انتخاب نوع اتحاد + alliance_types = [ + "اتحاد نظامی (دفاع مشترک)", + "پیمان تجاری (تجارت آزاد)", + "اتحاد فرهنگی (تبادل فرهنگی)", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(alliance_types) + + if choice == 4: + return # برگشت + + # انتخاب هزینه و تأثیرات + costs = [7000, 5000, 6000] + effects = [ + {"military_strength": 15, "relations": {"+": 20}}, + {"economy": {"trade": 15}, "relations": {"+": 15}}, + {"cultural_influence": 15, "relations": {"+": 10}} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"نوع اتحاد: {alliance_types[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "relations": + ConsoleUI.display_message(f"• روابط با {target_country}: +{value['+']}", indent=4) + elif effect_type == "economy": + for sector, val in value.items(): + ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به پیشنهاد این اتحاد هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # انجام مذاکره + self.game_state.gold -= cost + + # بررسی موفقیت + if random.random() < success_chance: + self._apply_alliance_success(target_country, effect) + else: + self._apply_alliance_failure(target_country, effect) + + def _apply_alliance_success(self, target_country, effects): + """اعمال اثرات موفقیت در اتحاد""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_success(f"اتحاد با {target_country} موفقیت‌آمیز بود!") + + # اعمال اثرات + for effect_type, value in effects.items(): + if effect_type == "relations": + self.game_state.relations[target_country] = min(100, + self.game_state.relations[target_country] + value["+"]) + elif effect_type == "economy": + for sector, val in value.items(): + self.game_state.economy[sector] = min(100, + self.game_state.economy[sector] + val) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + ConsoleUI.wait_for_enter() + + def _apply_alliance_failure(self, target_country, effects): + """اعمال اثرات شکست در اتحاد""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_error(f"پیشنهاد اتحاد با {target_country} شکست خورد!") + + # کاهش روابط + self.game_state.relations[target_country] = max(-100, + self.game_state.relations[target_country] - 5) + + ConsoleUI.wait_for_enter() + + def negotiate_peace(self): + """مذاکره برای برقراری صلح با کشورهای دشمن""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مذاکره صلح") + + # فیلتر کشورهایی که روابط منفی داریم + potential_peace_partners = [] + for country, relation in self.game_state.relations.items(): + if relation < 0 and country != self.game_state.player_country["name"]: + potential_peace_partners.append(country) + + if not potential_peace_partners: + ConsoleUI.display_warning("هیچ کشوری برای مذاکره صلح در دسترس نیست.", indent=2) + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_peace_partners.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_peace_partners) + + if choice == len(potential_peace_partners): + return # برگشت + + target_country = potential_peace_partners[choice-1] + self._conduct_peace_negotiation(target_country) + + def _conduct_peace_negotiation(self, target_country): + """اجرای مذاکرات صلح با یک کشور خاص""" + from ui.console_ui import ConsoleUI + import random + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مذاکره صلح با {target_country}") + + # محاسبه شانس موفقیت + base_chance = 0.3 + relation_factor = (100 + self.game_state.relations[target_country]) / 200 + diplomacy_factor = self.game_state.diplomacy_points / 100 + + success_chance = base_chance + relation_factor + diplomacy_factor + success_chance = max(0.1, min(0.8, success_chance)) + + ConsoleUI.display_message(f"شانس موفقیت: {int(success_chance * 100)}%", indent=2) + + # انتخاب نوع مذاکره + negotiation_types = [ + "مذاکره مستقیم (بدون واسطه)", + "میانجی‌گری بین‌المللی", + "تغییر سیاست خارجی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(negotiation_types) + + if choice == 4: + return # برگشت + + # انتخاب هزینه و تأثیرات + costs = [5000, 7000, 6000] + effects = [ + {"relations": {"+": 15}, "political_stability": 5}, + {"relations": {"+": 20}, "diplomacy_points": 5}, + {"relations": {"+": 10}, "public_dissatisfaction": -5} + ] + + cost = costs[choice-1] + effect = effects[choice-1] + + ConsoleUI.display_message(f"نوع مذاکره: {negotiation_types[choice-1]}", indent=2) + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "relations": + ConsoleUI.display_message(f"• روابط با {target_country}: +{value['+']}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به انجام این مذاکره هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # انجام مذاکره + self.game_state.gold -= cost + + # بررسی موفقیت + if random.random() < success_chance: + self._apply_peace_success(target_country, effect) + else: + self._apply_peace_failure(target_country, effect) + + def _apply_peace_success(self, target_country, effects): + """اعمال اثرات موفقیت در مذاکرات صلح""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_success(f"مذاکرات صلح با {target_country} موفقیت‌آمیز بود!") + + # اعمال اثرات + for effect_type, value in effects.items(): + if effect_type == "relations": + self.game_state.relations[target_country] = min(100, + self.game_state.relations[target_country] + value["+"]) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + ConsoleUI.wait_for_enter() + + def _apply_peace_failure(self, target_country, effects): + """اعمال اثرات شکست در مذاکرات صلح""" + from ui.console_ui import ConsoleUI + + ConsoleUI.display_error(f"مذاکرات صلح با {target_country} شکست خورد!") + + # کاهش روابط + self.game_state.relations[target_country] = max(-100, + self.game_state.relations[target_country] - 10) + + ConsoleUI.wait_for_enter() + + def send_envoy(self): + """ارسال سفیر و ایجاد سفارتخانه""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("ارسال سفیر") + + # فیلتر کشورهایی که می‌توانیم سفیر ارسال کنیم + potential_destinations = [] + for country, relation in self.game_state.relations.items(): + if country != self.game_state.player_country["name"]: + potential_destinations.append(country) + + if not potential_destinations: + ConsoleUI.display_warning("هیچ کشوری برای ارسال سفیر در دسترس نیست.", indent=2) + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_destinations.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_destinations) + + if choice == len(potential_destinations): + return # برگشت + + destination = potential_destinations[choice-1] + self._establish_embassy(destination) + + def _establish_embassy(self, destination): + """ایجاد سفارتخانه در یک کشور خاص""" + from ui.console_ui import ConsoleUI + + cost = 8000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"ایجاد سفارتخانه در {destination}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش روابط: +10", indent=4) + ConsoleUI.display_message("• افزایش اطلاعات جاسوسی", indent=4) + ConsoleUI.display_message("• افزایش امتیاز دیپلماسی: +5", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به ایجاد سفارتخانه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.relations[destination] = min(100, + self.game_state.relations[destination] + 10) + self.game_state.diplomacy_points += 5 + + ConsoleUI.display_success(f"سفارتخانه در {destination} ایجاد شد.") + ConsoleUI.wait_for_enter() + + def join_international_orgs(self): + """عضویت در سازمان‌های بین‌المللی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("سازمان‌های بین‌المللی") + + # لیست سازمان‌های موجود + orgs = [ + "سازمان ملل متحد (UN)", + "سازمان تجارت جهانی (WTO)", + "سازمان بهداشت جهانی (WHO)", + "سازمان نفت (OPEC)", + "سازمان کشورهای صادرکننده نفت", + "ناتو (NATO)" + ] + + # نمایش گزینه‌ها + orgs.append("برگشت") + choice = ConsoleUI.get_menu_choice(orgs) + + if choice == len(orgs): + return # برگشت + + org = orgs[choice-1] + + # محاسبه هزینه و تأثیرات + costs = { + "سازمان ملل متحد (UN)": 5000, + "سازمان تجارت جهانی (WTO)": 8000, + "سازمان بهداشت جهانی (WHO)": 6000, + "سازمان نفت (OPEC)": 10000, + "سازمان کشورهای صادرکننده نفت": 9000, + "ناتو (NATO)": 12000 + } + + effects = { + "سازمان ملل متحد (UN)": { + "relations": {"+": 10}, + "political_stability": 5, + "diplomacy_points": 10 + }, + "سازمان تجارت جهانی (WTO)": { + "economy": {"trade": 15}, + "gold": -500 # هزینه نگهداری سالانه + }, + "سازمان بهداشت جهانی (WHO)": { + "health_index": 10, + "relations": {"+": 5} + }, + "سازمان نفت (OPEC)": { + "resources": {"oil": 20}, + "economy": {"industry": 10} + }, + "سازمان کشورهای صادرکننده نفت": { + "resources": {"oil": 25}, + "relations": {"+": 15} + }, + "ناتو (NATO)": { + "military_strength": 20, + "relations": {"+": 25} + } + } + + cost = costs[org] + effect = effects[org] + + ConsoleUI.display_message(f"عضویت در {org}") + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in effect.items(): + if effect_type == "relations": + ConsoleUI.display_message(f"• روابط بین‌المللی: +{value['+']}", indent=4) + elif effect_type == "economy": + for sector, val in value.items(): + ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}", indent=4) + elif effect_type == "resources": + for resource, val in value.items(): + ConsoleUI.display_message(f"• منابع {resource}: +{val}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if ConsoleUI.confirm_action("آیا مایل به عضویت در این سازمان هستید؟"): + self._join_organization(org, cost, effect) + + def _join_organization(self, org, cost, effect): + """عضویت در یک سازمان بین‌المللی""" + from ui.console_ui import ConsoleUI + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.international_orgs.append(org) + + # اعمال تأثیرات + for effect_type, value in effect.items(): + if 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] = min(100, self.game_state.economy[sector] + val) + elif effect_type == "resources": + for resource, val in value.items(): + self.game_state.resources[resource] = min(100, self.game_state.resources[resource] + val) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, self.game_state[effect_type] + value) + + ConsoleUI.display_success(f"شما عضو {org} شدید.") + ConsoleUI.wait_for_enter() + + def diplomacy_crisis_management(self): + """مدیریت بحران‌های دیپلماتیک""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران دیپلماتیک + if random.random() < 0.15: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران دیپلماتیک") + + # انتخاب نوع بحران + crisis_types = [ + "اختلافات مرزی", + "جنجال دیپلماتیک", + "تحریم‌های بین‌المللی", + "قطع روابط دیپلماتیک" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "مذاکره فوری (6000 سکه)", + "تغییر سیاست خارجی (5000 سکه)", + "درخواست میانجی‌گری (4000 سکه)", + "بی‌تفاوتی" + ] + costs = [6000, 5000, 4000, 0] + effects = [ + {"relations": {"+": 8}, "diplomacy_points": 5}, + {"relations": {"+": 5}, "political_stability": 3}, + {"relations": {"+": 10}, "diplomacy_points": 3}, + {"relations": {"-": 15}, "political_stability": -5} + ] + + # نمایش گزینه‌ها + 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_diplomacy_crisis_response(costs[choice-1], effects[choice-1]) + + def _apply_diplomacy_crisis_response(self, 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 == "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["+"]) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران دیپلماتیک مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم دیپلماسی""" + # به‌روزرسانی روابط + self._update_relations() + + # بررسی بحران‌های دیپلماتیک + self.diplomacy_crisis_management() + + def _update_relations(self): + """به‌روزرسانی روابط با کشورهای دیگر""" + for country in self.game_state.relations: + if country == self.game_state.player_country["name"]: + continue + + # تغییر تصادفی روابط + change = self.game_state.random.randint(-2, 2) + + # تأثیر سازمان‌های بین‌المللی + if "UN" in self.game_state.international_orgs: + change += 1 + + self.game_state.relations[country] = max(-100, min(100, + self.game_state.relations[country] + change)) +``` + +### 52. `game/diplomacy/embassies.py` (سفارتخانه‌ها) +```python +""" +مدیریت سفارتخانه‌ها و شبکه‌های دیپلماتیک +""" + +class Embassies: + """مدیریت سفارتخانه‌ها و شبکه‌های دیپلماتیک""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم سفارتخانه‌ها""" + self.game_state = game_state + self.embassies = [] + + def initialize(self): + """راه‌اندازی اولیه سیستم سفارتخانه‌ها""" + # ایجاد سفارتخانه اولیه در پایتخت + self.embassies.append({ + "country": self.game_state.player_country["name"], + "city": "Tehran", + "level": 3, + "staff": 50, + "budget": 10000 + }) + + def display_embassy_status(self): + """نمایش وضعیت سفارتخانه‌ها""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("وضعیت سفارتخانه‌ها") + + if not self.embassies: + ConsoleUI.display_message("شما هیچ سفارتخانه‌ای ندارید!", indent=2) + ConsoleUI.wait_for_enter() + return + + for i, embassy in enumerate(self.embassies, 1): + status = self._get_embassy_status(embassy) + ConsoleUI.display_message(f"{i}. {embassy['country']} - {embassy['city']}", indent=2) + ConsoleUI.display_message(f" سطح: {embassy['level']}", indent=4) + ConsoleUI.display_message(f" کادر: {embassy['staff']}", indent=4) + ConsoleUI.display_message(f" وضعیت: {status}", indent=4) + + ConsoleUI.wait_for_enter() + + def _get_embassy_status(self, embassy): + """دریافت وضعیت سفارتخانه بر اساس سطح و بودجه""" + if embassy["level"] >= 4 and embassy["budget"] > 5000: + return "عالی" + elif embassy["level"] >= 3 and embassy["budget"] > 3000: + return "خوب" + elif embassy["level"] >= 2: + return "متوسط" + else: + return "ضعیف" + + def establish_new_embassy(self): + """ایجاد سفارتخانه جدید در یک کشور""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("ایجاد سفارتخانه جدید") + + # فیلتر کشورهایی که می‌توانیم سفارتخانه ایجاد کنیم + potential_countries = [] + for country in self.game_state.relations: + if country != self.game_state.player_country["name"]: + potential_countries.append(country) + + if not potential_countries: + ConsoleUI.display_warning("هیچ کشوری برای ایجاد سفارتخانه در دسترس نیست.", indent=2) + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + potential_countries.append("برگشت") + choice = ConsoleUI.get_menu_choice(potential_countries) + + if choice == len(potential_countries): + return # برگشت + + country = potential_countries[choice-1] + self._create_embassy_in_country(country) + + def _create_embassy_in_country(self, country): + """ایجاد سفارتخانه در یک کشور خاص""" + from ui.console_ui import ConsoleUI + + cost = 10000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"ایجاد سفارتخانه در {country}") + + ConsoleUI.display_message(f"هزینه اولیه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("هزینه نگهداری سالانه: 2000 سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش روابط: +10", indent=4) + ConsoleUI.display_message("• افزایش اطلاعات جاسوسی", indent=4) + ConsoleUI.display_message("• افزایش امتیاز دیپلماسی: +5", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به ایجاد سفارتخانه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.budget["diplomacy"] += 2 # هزینه نگهداری + + # افزودن سفارتخانه جدید + self.embassies.append({ + "country": country, + "city": self._suggest_capital_city(country), + "level": 1, + "staff": 20, + "budget": 2000 + }) + + # افزایش روابط + self.game_state.relations[country] = min(100, + self.game_state.relations[country] + 10) + + # افزایش امتیاز دیپلماسی + self.game_state.diplomacy_points += 5 + + ConsoleUI.display_success(f"سفارتخانه در {country} ایجاد شد.") + ConsoleUI.wait_for_enter() + + def _suggest_capital_city(self, country): + """پیشنهاد پایتخت برای سفارتخانه""" + capitals = { + "پادشاهی ایران": "Tehran", + "امپراتوری عثمانی": "Istanbul", + "پرتغال": "Lisbon", + "اسپانیا": "Madrid", + "انگلستان": "London", + "فرانسه": "Paris", + "آلمان": "Berlin", + "پادشاهی مقدس روم": "Vienna", + "پادشاهی نپال": "Kathmandu", + "پادشاهی ژاپن": "Tokyo", + "پادشاهی هندوستان": "Delhi", + "پادشاهی چین": "Beijing", + "پادشاهی روسیه": "Moscow", + "پادشاهی یونان": "Athens", + "پادشاهی مصر": "Cairo", + "پادشاهی سوئد": "Stockholm", + "پادشاهی دانمارک": "Copenhagen", + "پادشاهی نروژ": "Oslo", + "پادشاهی ونیز": "Venice", + "پادشاهی مجارستان": "Budapest", + "پادشاهی پولند": "Warsaw", + "پادشاهی مالی": "Bamako" + } + + return capitals.get(country, "Capital") + + def manage_embassy(self): + """مدیریت سفارتخانه‌های موجود""" + from ui.console_ui import ConsoleUI + + if not self.embassies: + ConsoleUI.display_warning("شما هیچ سفارتخانه‌ای ندارید!", indent=2) + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت سفارتخانه‌ها") + + # نمایش سفارتخانه‌ها + embassy_options = [] + for embassy in self.embassies: + embassy_options.append(f"{embassy['country']} - {embassy['city']}") + + embassy_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(embassy_options) + + if choice == len(embassy_options): + return # برگشت + + selected_embassy = self.embassies[choice-1] + self._manage_specific_embassy(selected_embassy) + + def _manage_specific_embassy(self, embassy): + """مدیریت یک سفارتخانه خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت {embassy['country']}") + + embassy_actions = [ + "افزایش سطح سفارتخانه", + "افزایش کادر پرسنلی", + "افزایش بودجه", + "برنامه‌های فرهنگی", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(embassy_actions) + + if choice == 1: + self._upgrade_embassy(embassy) + elif choice == 2: + self._increase_staff(embassy) + elif choice == 3: + self._increase_budget(embassy) + elif choice == 4: + self._cultural_programs(embassy) + # choice == 5: برگشت + + def _upgrade_embassy(self, embassy): + """افزایش سطح سفارتخانه""" + from ui.console_ui import ConsoleUI + + cost = 8000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش سطح سفارتخانه {embassy['country']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش سطح سفارتخانه", indent=4) + ConsoleUI.display_message("• افزایش اثرگذاری دیپلماتیک", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش سطح سفارتخانه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + embassy["level"] = min(5, embassy["level"] + 1) + + ConsoleUI.display_success(f"سطح سفارتخانه {embassy['country']} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _increase_staff(self, embassy): + """افزایش کادر پرسنلی سفارتخانه""" + from ui.console_ui import ConsoleUI + + cost = 5000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش کادر {embassy['country']}") + + ConsoleUI.display_message(f"هزینه: {cost} س��ه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش کادر: +10 نفر", indent=4) + ConsoleUI.display_message("• افزایش کارایی سفارتخانه", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش کادر هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + embassy["staff"] += 10 + + ConsoleUI.display_success(f"کادر سفارتخانه {embassy['country']} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _increase_budget(self, embassy): + """افزایش بودجه سفارتخانه""" + from ui.console_ui import ConsoleUI + + cost = 4000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش بودجه {embassy['country']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش بودجه: +2000 سکه", indent=4) + ConsoleUI.display_message("• بهبود خدمات سفارتخانه", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش بودجه هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + embassy["budget"] += 2000 + + ConsoleUI.display_success(f"بودجه سفارتخانه {embassy['country']} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _cultural_programs(self, embassy): + """اجرای برنامه‌های فرهنگی از طریق سفارتخانه""" + from ui.console_ui import ConsoleUI + + cost = 6000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"برنامه‌های فرهنگی {embassy['country']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش نفوذ فرهنگی", indent=4) + ConsoleUI.display_message("• افزایش روابط", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به اجرای برنامه‌های فرهنگی هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.cultural_influence = min(100, + self.game_state.cultural_influence + 5) + + # افزایش روابط + self.game_state.relations[embassy["country"]] = min(100, + self.game_state.relations[embassy["country"]] + 3) + + ConsoleUI.display_success(f"برنامه‌های فرهنگی در {embassy['country']} اجرا شد.") + ConsoleUI.wait_for_enter() + + def embassy_crisis_management(self): + """مدیریت بحران‌های سفارتخانه‌ها""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران در سفارتخانه‌ها + if random.random() < 0.1: + if not self.embassies: + return # بدون سفارتخانه + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران سفارتخانه") + + # انتخاب یک سفارتخانه تصادفی + embassy = random.choice(self.embassies) + + # انتخاب نوع بحران + crisis_types = [ + "حمله به سفارتخانه", + "اخراج دیپلمات", + "اختلال در ارتباطات", + "کمبود بودجه" + ] + crisis_type = random.choice(crisis_types) + + ConsoleUI.display_warning(f"{crisis_type} در {embassy['country']} رخ داده است!", indent=2) + + # گزینه‌های پاسخ به بحران + options = [ + "اقدامات امنیتی (7000 سکه)", + "مذاکره با دولت میزبان (5000 سکه)", + "تغییر استراتژی دیپلماتیک (6000 سکه)", + "بی‌تفاوتی" + ] + costs = [7000, 5000, 6000, 0] + effects = [ + {"relations": {"+": 5}, "embassy": {"security": 10}}, + {"relations": {"+": 8}, "diplomacy_points": 3}, + {"relations": {"+": 3}, "embassy": {"level": 1}}, + {"relations": {"-": 10}, "embassy": {"level": -1}} + ] + + # نمایش گزینه‌ها + 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_embassy_crisis_response(embassy, costs[choice-1], effects[choice-1]) + + def _apply_embassy_crisis_response(self, embassy, 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 == "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 == "embassy": + if "security" in value: + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + pass + if "level" in value: + embassy["level"] = max(1, min(5, embassy["level"] + value["level"])) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = max(0, min(100, self.game_state[effect_type] + value)) + + ConsoleUI.display_success("بحران سفارتخانه مدیریت شد.") + ConsoleUI.wait_for_enter() + + def annual_update(self): + """به‌روزرسانی‌های سالانه سیستم سفارتخانه‌ها""" + # به‌روزرسانی سفارتخانه‌ها + self._update_embassies() + + # بررسی بحران‌های سفارتخانه‌ها + self.embassy_crisis_management() + + def _update_embassies(self): + """به‌روزرسانی سفارتخانه‌ها""" + for embassy in self.embassies: + # کاهش بودجه به دلیل هزینه‌های سالانه + embassy["budget"] = max(0, embassy["budget"] - 500) + + # اگر بودجه خیلی پایین آمد + if embassy["budget"] < 1000 and embassy["level"] > 1: + embassy["level"] -= 1 +``` + +### 53. `game/diplomacy/international_orgs.py` (سازمان‌های بین‌المللی) +```python +""" +مدیریت سازمان‌های بین‌المللی و عضویت در آنها +""" + +class InternationalOrgs: + """مدیریت سازمان‌های بین‌المللی و عضویت در آنها""" + + def __init__(self, game_state): + """ساخت یک نمونه جدید از سیستم سازمان‌های بین‌المللی""" + self.game_state = game_state + self.organizations = self._load_organizations() + + def _load_organizations(self): + """بارگیری سازمان‌های بین‌المللی""" + return { + "UN": { + "name": "سازمان ملل متحد", + "description": "سازمان جهانی برای حفظ صلح و امنیت بین‌المللی", + "cost": 5000, + "effects": { + "relations": {"+": 10}, + "political_stability": 5, + "diplomacy_points": 10 + }, + "requirements": { + "min_relations": 0, + "min_diplomacy": 20 + } + }, + "WTO": { + "name": "سازمان تجا��ت جهانی", + "description": "سازمان برای تنظیم و تسهیل تجارت بین‌المللی", + "cost": 8000, + "effects": { + "economy": {"trade": 15}, + "gold": -500 + }, + "requirements": { + "min_trade": 50, + "min_relations": 30 + } + }, + "WHO": { + "name": "سازمان بهداشت جهانی", + "description": "سازمان جهانی برای بهبود سلامت عمومی", + "cost": 6000, + "effects": { + "health_index": 10, + "relations": {"+": 5} + }, + "requirements": { + "min_health": 50, + "min_diplomacy": 15 + } + }, + "OPEC": { + "name": "سازمان کشورهای صادرکننده نفت", + "description": "سازمان برای هماهنگی سیاست‌های نفتی", + "cost": 10000, + "effects": { + "resources": {"oil": 20}, + "economy": {"industry": 10} + }, + "requirements": { + "has_oil": True, + "min_relations": 40 + } + }, + "NATO": { + "name": "سازمان پیمان آتلانتیک شمالی", + "description": "اتحادیه نظامی برای امنیت مشترک", + "cost": 12000, + "effects": { + "military_strength": 20, + "relations": {"+": 25} + }, + "requirements": { + "min_military": 60, + "min_relations": 50 + } + } + } + + def display_organization_status(self): + """نمایش وضعیت سازمان‌های بین‌المللی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("سازمان‌های بین‌المللی") + + # نمایش سازمان‌های عضو + ConsoleUI.display_section_title("سازمان‌های عضو", width=60) + if not self.game_state.international_orgs: + ConsoleUI.display_message("شما عضو هیچ سازمان بین‌المللی نیستید.", indent=2) + else: + for org in self.game_state.international_orgs: + ConsoleUI.display_message(f"• {org}", indent=2) + + # نمایش سازمان‌های قابل عضویت + ConsoleUI.display_section_title("سازمان‌های قابل عضویت", width=60) + available_orgs = self._get_available_organizations() + + if not available_orgs: + ConsoleUI.display_message("شما شرایط عضویت در هیچ سازمانی را ندارید.", indent=2) + else: + for org_id in available_orgs: + org = self.organizations[org_id] + ConsoleUI.display_message(f"• {org['name']}", indent=2) + ConsoleUI.display_message(f" هزینه: {org['cost']} سکه طلا", indent=4) + ConsoleUI.display_message(f" {org['description']}", indent=4) + + ConsoleUI.wait_for_enter() + + def _get_available_organizations(self): + """دریافت لیست سازمان‌هایی که می‌توان در آنها عضو شد""" + available = [] + + for org_id, org in self.organizations.items(): + if org_id in self.game_state.international_orgs: + continue # اگر قبلاً عضو بود، نادیده بگیر + + if self._check_organization_requirements(org_id): + available.append(org_id) + + return available + + def _check_organization_requirements(self, org_id): + """بررسی شرایط عضویت در یک سازمان""" + org = self.organizations[org_id] + requirements = org["requirements"] + + # بررسی شرایط + if "min_relations" in requirements: + avg_relations = sum(self.game_state.relations.values()) / len(self.game_state.relations) + if avg_relations < requirements["min_relations"]: + return False + + if "min_diplomacy" in requirements: + if self.game_state.diplomacy_points < requirements["min_diplomacy"]: + return False + + if "min_trade" in requirements: + if self.game_state.economy["trade"] < requirements["min_trade"]: + return False + + if "min_health" in requirements: + if self.game_state.health_index < requirements["min_health"]: + return False + + if "min_military" in requirements: + if self.game_state.military_strength < requirements["min_military"]: + return False + + if "has_oil" in requirements and requirements["has_oil"]: + if self.game_state.resources["oil"] < 10: + return False + + return True + + def join_organization(self): + """عضویت در یک سازمان بین‌المللی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("عضویت در سازمان بین‌المللی") + + # دریافت سازمان‌های قابل عضویت + available_orgs = self._get_available_organizations() + + if not available_orgs: + ConsoleUI.display_warning("شما شرایط عضویت در هیچ سازمانی را ندارید.", indent=2) + ConsoleUI.wait_for_enter() + return + + # نمایش گزینه‌ها + org_names = [self.organizations[org_id]["name"] for org_id in available_orgs] + org_names.append("برگشت") + + choice = ConsoleUI.get_menu_choice(org_names) + + if choice == len(org_names): + return # برگشت + + selected_org_id = available_orgs[choice-1] + self._apply_organization_membership(selected_org_id) + + def _apply_organization_membership(self, org_id): + """اعمال عضویت در یک سازمان بین‌المللی""" + from ui.console_ui import ConsoleUI + + org = self.organizations[org_id] + cost = org["cost"] + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"عضویت در {org['name']}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + + # نمایش تأثیرات + for effect_type, value in org["effects"].items(): + if effect_type == "relations": + ConsoleUI.display_message(f"• روابط بین‌المللی: +{value['+']}", indent=4) + elif effect_type == "economy": + for sector, val in value.items(): + ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}", indent=4) + elif effect_type == "resources": + for resource, val in value.items(): + ConsoleUI.display_message(f"• منابع {resource}: +{val}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به عضویت در این سازمان هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + self.game_state.international_orgs.append(org["name"]) + + # اعمال تأثیرات + self._apply_organization_effects(org_id) + + ConsoleUI.display_success(f"شما عضو {org['name']} شدید.") + ConsoleUI.wait_for_enter() + + def _apply_organization_effects(self, org_id): + """اعمال تأثیرات عضویت در سازمان""" + org = self.organizations[org_id] + + # اعمال تأثیرات + for effect_type, value in org["effects"].items(): + if 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] = min(100, + self.game_state.economy[sector] + val) + elif effect_type == "resources": + for resource, val in value.items(): + self.game_state.resources[resource] = min(100, + self.game_state.resources[resource] + val) + else: + if effect_type in self.game_state: + self.game_state[effect_type] = min(100, + self.game_state[effect_type] + value) + + def manage_organization_membership(self): + """مدیریت عضویت در سازمان‌های بین‌الم��لی""" + from ui.console_ui import ConsoleUI + + if not self.game_state.international_orgs: + ConsoleUI.display_warning("شما عضو هیچ سازمان بین‌المللی نیستید.", indent=2) + ConsoleUI.wait_for_enter() + return + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("مدیریت عضویت در سازمان‌ها") + + # نمایش سازمان‌ها + org_options = self.game_state.international_orgs.copy() + org_options.append("برگشت") + + choice = ConsoleUI.get_menu_choice(org_options) + + if choice == len(org_options): + return # برگشت + + selected_org = org_options[choice-1] + self._manage_specific_organization(selected_org) + + def _manage_specific_organization(self, org_name): + """مدیریت یک سازمان بین‌المللی خاص""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مدیریت {org_name}") + + org_actions = [ + "افزایش همکاری", + "درخواست کمک", + "بررسی مزایا", + "خروج از سازمان", + "برگشت" + ] + + choice = ConsoleUI.get_menu_choice(org_actions) + + if choice == 1: + self._increase_cooperation(org_name) + elif choice == 2: + self._request_assistance(org_name) + elif choice == 3: + self._review_benefits(org_name) + elif choice == 4: + self._leave_organization(org_name) + # choice == 5: برگشت + + def _increase_cooperation(self, org_name): + """افزایش همکاری با یک سازمان بین‌المللی""" + from ui.console_ui import ConsoleUI + + cost = 3000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"افزایش همکاری با {org_name}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• افزایش مزایای سازمان", indent=4) + ConsoleUI.display_message("• افزایش روابط بین‌المللی", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به افزایش همکاری هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + ConsoleUI.display_success(f"همکاری با {org_name} افزایش یافت.") + ConsoleUI.wait_for_enter() + + def _request_assistance(self, org_name): + """درخواست کمک از یک سازمان بین‌المللی""" + from ui.console_ui import ConsoleUI + + cost = 2000 + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"درخواست کمک از {org_name}") + + ConsoleUI.display_message(f"هزینه: {cost} سکه طلا", indent=2) + ConsoleUI.display_message("تأثیرات:", indent=2) + ConsoleUI.display_message("• دریافت کمک مالی یا فنی", indent=4) + ConsoleUI.display_message("• افزایش نفوذ در سازمان", indent=4) + + if not ConsoleUI.confirm_action("آیا مایل به درخواست کمک هستید؟"): + return + + # بررسی موجودی + if self.game_state.gold < cost: + ConsoleUI.display_error("موجودی طلا کافی نیست!") + ConsoleUI.wait_for_enter() + return + + # اعمال تغییرات + self.game_state.gold -= cost + + # در نسخه ساده، فقط یک پیام نمایش می‌دهیم + ConsoleUI.display_success(f"کمک از {org_name} درخواست شد.") + ConsoleUI.wait_for_enter() + + def _review_benefits(self, org_name): + """بررسی مزایای عضویت در یک سازمان بین‌المللی""" + from ui.console_ui import ConsoleUI + + # پیدا کردن سازمان + org_id = None + for oid, org in self.organizations.items(): + if org["name"] == org_name: + org_id = oid + break + + if not org_id: + ConsoleUI.display_error("سازمان مورد نظر یافت نشد!") + ConsoleUI.wait_for_enter() + return + + org = self.organizations[org_id] + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"مزایای {org_name}") + + ConsoleUI.display_message(f"توضیحات: {org['description']}", indent=2) + ConsoleUI.display_message("مزایا:", indent=2) + + # نمایش مزایا + for effect_type, value in org["effects"].items(): + if effect_type == "relations": + ConsoleUI.display_message(f"• روابط بین‌المللی: +{value['+']}", indent=4) + elif effect_type == "economy": + for sector, val in value.items(): + ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}", indent=4) + elif effect_type == "resources": + for resource, val in value.items(): + ConsoleUI.display_message(f"• منابع {resource}: +{val}", indent=4) + else: + ConsoleUI.display_message(f"• {effect_type}: +{value}", indent=4) + + ConsoleUI.wait_for_enter() + + def _leave_organization(self, org_name): + """خروج از یک سازمان بین‌المللی""" + from ui.console_ui import ConsoleUI + + ConsoleUI.clear_screen() + ConsoleUI.display_section_title(f"خروج از {org_name}") + + ConsoleUI.display_warning("هشدار: خروج از سازمان ممکن است تأثیرات منفی داشته باشد!", indent=2) + + if not ConsoleUI.confirm_action("آیا مطمئن هستید که می‌خواهید از این سازمان خارج شوید؟"): + return + + # حذف سازمان از لیست عضویت + if org_name in self.game_state.international_orgs: + self.game_state.international_orgs.remove(org_name) + + # کاهش روابط + for country in self.game_state.relations: + if country != self.game_state.player_country["name"]: + self.game_state.relations[country] = max(-100, + self.game_state.relations[country] - 5) + + ConsoleUI.display_warning(f"شما از {org_name} خارج شدید.") + ConsoleUI.wait_for_enter() + + def organization_crisis_management(self): + """مدیریت بحران‌های سازمان‌های بین‌المللی""" + from ui.console_ui import ConsoleUI + import random + + # احتمال وقوع بحران در سازمان‌ها + if random.random() < 0.1 and self.game_state.international_orgs: + ConsoleUI.clear_screen() + ConsoleUI.display_section_title("بحران سازمان بین‌المللی") + + # انتخاب یک سازمان تصادفی + org_name = random.choice(self.game_state.international_orgs) + + # انتخاب نوع بحران + crisis_types = [ + "اختلاف نظر در سازمان", + "کاهش مزای