def set_faction(self, player_index, faction): player = self.players[int(player_index)] player.faction = faction style = Style() style.load(res.get_text_file("ui/style", append=True, localize=True)) faction_name = style.get(player.faction, 'title') self.broadcast([player.login, ] + faction_name)
def run(self, speed=config.speed): if self.record_replay: self.create_replay() self.world = World(self.default_triggers, self.seed) if self.world.load_and_build_map(self.map): self.map.load_style(res) try: self.map.load_resources() update_orders_list() # when style has changed self.pre_run() self.interface = clientgame.GameInterface(self.me, speed=speed) self.interface.load_bindings( res.get_text_file("ui/bindings", append=True, localize=True) + "\n" + self.map.get_campaign("ui/bindings.txt") + "\n" + self.map.get_additional("ui/bindings.txt")) self.world.populate_map(self.players, self.alliances, self.factions) self.nb_human_players = self.world.current_nb_human_players() t = threading.Thread(target=self.world.loop) t.daemon = True t.start() if PROFILE: import cProfile cProfile.runctx("self.interface.loop()", globals(), locals(), "interface_profile.tmp") else: self.interface.loop() self._record_stats(self.world) self.post_run() finally: self.map.unload_resources() self.world.clean() else: voice.alert([1029]) # hostile sound voice.alert([self.world.map_error]) if self.record_replay: self._replay_file.close()
def training_menu_after_map(self, m): style.load(res.get_text_file("ui/style", append=True, localize=True)) # XXX: won't work with factions defined in the map self.players = [config.login] self.factions = ["random_faction"] self.map = m self.menu = self.build_training_menu_after_map() self.menu.loop()
def _open_players_menu(self, m): # note: won't work with factions defined in the map style.load(res.get_text_file("ui/style", append=True, localize=True)) self._players = [config.login] self._factions = ["random_faction"] self._map = m self._players_menu = self._build_players_menu() self._players_menu.loop()
def _move_recommended_maps(w): style = Style() style.load(res.get_text_file("ui/style", append=True, localize=True)) for n in reversed(style.get("parameters", "recommended_maps")): for m in reversed(w[:]): # reversed so the custom map is after the official map if m.get_name()[:-4] == n: w.remove(m) w.insert(0, m)
def load_and_build_map(self, map): if os.path.exists(MAPERROR_PATH): try: os.remove(MAPERROR_PATH) except: warning("cannot remove map error file") try: rules.load(res.get_text_file("rules", append=True), map.campaign_rules, map.additional_rules) load_ai(res.get_text_file("ai", append=True), map.campaign_ai, map.additional_ai) self._load_map(map) self.map = map self.square_width = int(self.square_width * PRECISION) self._build_map() except MapError, msg: warning("map error: %s", msg) self.map_error = "map error: %s" % msg return False
def set_faction(self, player_index, faction): player = self.players[int(player_index)] player.faction = faction style = Style() style.load(res.get_text_file("ui/style", append=True, localize=True)) faction_name = style.get(player.faction, 'title') self.broadcast([ player.login, ] + faction_name)
def training_menu_after_map(self, m): style.load(res.get_text_file( "ui/style", append=True, localize=True)) # XXX: won't work with factions defined in the map self.players = [config.login] self.factions = ["random_faction"] self.map = m self.menu = self.build_training_menu_after_map() self.menu.loop()
def run(self, speed=config.speed): if self.record_replay: self.create_replay() self.world = World( self.default_triggers, self.seed, must_apply_equivalent_type=self.must_apply_equivalent_type) if self.world.load_and_build_map(self.map): self.map.load_style(res) try: self.map.load_resources() update_orders_list() # when style has changed self.pre_run() if self.world.objective: voice.confirmation(mp.OBJECTIVE + self.world.objective) self.interface = clientgame.GameInterface(self.me, speed=speed) b = res.get_text_file("ui/bindings", append=True, localize=True) b += "\n" + self.map.get_campaign("ui/bindings.txt") b += "\n" + self.map.get_additional("ui/bindings.txt") try: b += "\n" + open(CUSTOM_BINDINGS_PATH, "U").read() except IOError: pass self.interface.load_bindings(b) self.world.populate_map(self.players) self.nb_human_players = self.world.current_nb_human_players() t = threading.Thread(target=self.world.loop) t.daemon = True t.start() if PROFILE: import cProfile cProfile.runctx("self.interface.loop()", globals(), locals(), "interface_profile.tmp") import pstats for n in ("interface_profile.tmp", ): p = pstats.Stats(n) p.strip_dirs() p.sort_stats('time', 'cumulative').print_stats(30) p.print_callers(30) p.print_callees(20) p.sort_stats('cumulative').print_stats(50) else: self.interface.loop() self._record_stats(self.world) self.post_run() finally: self.map.unload_resources() self.world.stop() else: voice.alert(mp.BEEP + [self.world.map_error]) if self.record_replay: self._replay_file.close()
def run(self, speed=config.speed): if self.record_replay: self.create_replay() self.world = World(self.default_triggers, self.seed, must_apply_equivalent_type=self.must_apply_equivalent_type) if self.world.load_and_build_map(self.map): self.map.load_style(res) try: self.map.load_resources() update_orders_list() # when style has changed self.pre_run() if self.world.objective: voice.confirmation(mp.OBJECTIVE + self.world.objective) self.interface = clientgame.GameInterface(self.me, speed=speed) b = res.get_text_file("ui/bindings", append=True, localize=True) b += "\n" + self.map.get_campaign("ui/bindings.txt") b += "\n" + self.map.get_additional("ui/bindings.txt") try: b += "\n" + open(CUSTOM_BINDINGS_PATH, "U").read() except IOError: pass self.interface.load_bindings(b) self.world.populate_map(self.players) self.nb_human_players = self.world.current_nb_human_players() t = threading.Thread(target=self.world.loop) t.daemon = True t.start() if PROFILE: import cProfile cProfile.runctx("self.interface.loop()", globals(), locals(), "interface_profile.tmp") import pstats for n in ("interface_profile.tmp", ): p = pstats.Stats(n) p.strip_dirs() p.sort_stats('time', 'cumulative').print_stats(30) p.print_callers(30) p.print_callees(20) p.sort_stats('cumulative').print_stats(50) else: self.interface.loop() self._record_stats(self.world) self.post_run() finally: self.map.unload_resources() self.world.stop() else: voice.alert(mp.BEEP + [self.world.map_error]) if self.record_replay: self._replay_file.close()
def rules_hash(): rules_and_ai = res.get_text_file("rules", append=True) + res.get_text_file("ai", append=True) return md5(rules_and_ai).hexdigest()
def load_rules_and_ai(self, res): from definitions import rules, load_ai rules.load(res.get_text_file("rules", append=True), self.campaign_rules, self.additional_rules) load_ai(res.get_text_file("ai", append=True), self.campaign_ai, self.additional_ai)
def load_style(self, res): from definitions import style style.load(res.get_text_file("ui/style", append=True, localize=True), self.campaign_style, self.additional_style)
def _read_table_from_file(name): return [x.split() for x in res.get_text_file(name).split("\n") if x.strip()]
def rules_hash(): rules_and_ai = res.get_text_file("rules", append=True) + res.get_text_file( "ai", append=True) return md5(rules_and_ai).hexdigest()
def _read_table_from_file(name): return [ x.split() for x in res.get_text_file(name).split("\n") if x.strip() ]