text-dataset-tiny-code-script-py-format / Shadows_of_Empires /game /demographics /population_system.py
| """ | |
| سیستم جمعیتشناسی پیشرفته با رشد جمعیت، مهاجرت و ساختار سنی | |
| """ | |
| 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) |