| """
|
| مدیریت وضعیت فعلی بازی و اطلاعات کشور بازیکن
|
| """
|
|
|
| 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 |