File size: 11,734 Bytes
89dc309 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | """
مدیریت وضعیت فعلی بازی و اطلاعات کشور بازیکن
"""
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 |