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): style.load(res.get_text("ui/style", append=True, locale=True), self.map.campaign_style, self.map.additional_style) sounds.enter_map(self.map.mapfile) 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("ui/bindings", append=True, locale=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() self.interface.loop() self._record_stats(self.world) self.post_run() sounds.exit_map() self.world.clean() else: voice.alert([1029]) # hostile sound voice.alert([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) if self.world.load_and_build_map(self.map): style.load(res.get_text("ui/style", append=True, locale=True), self.map.campaign_style, self.map.additional_style) sounds.enter_map(self.map.mapfile) 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("ui/bindings", append=True, locale=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.races) self.nb_human_players = self.world.current_nb_human_players() t = threading.Thread(target=self.world.loop) t.daemon = True t.start() self.interface.loop() self._record_stats(self.world) self.post_run() sounds.exit_map() self.world.clean() else: voice.alert([1029]) # hostile sound voice.alert([self.world.map_error]) if self.record_replay: self._replay_file.close()
def reload_all(): update_display_caption() res.update_mods_list() sounds.load_default() rules.load(res.get_text("rules", append=True)) load_ai(res.get_text("ai", append=True)) # just in case style.load(res.get_text("ui/style", append=True, locale=True)) while (res.alerts): voice.alert(res.alerts.pop(0))
def compatibility_version(): # Includes a hash of rules.txt. # (about the choice of MD5, check the comments in mapfile.py, line 45) # Don't check *.pyc (or library.zip, soundrts.exe and server.exe) # because it would require to add an internal version for every file. # (a bit complicated for the moment, and not as useful as checking rules.txt) # TODO: use Git to include a version in every *.pyc? (check other projects) return _remove_dev(VERSION) + "-" + md5(res.get_text("rules", append=True) + res.get_text("ai", append=True)).hexdigest()
def reload_all(): update_display_caption() res.update_mods_list() sounds.load_default() rules.load(res.get_text("rules", append=True)) load_ai(res.get_text("ai", append=True)) # just in case style.load(res.get_text("ui/style", append=True, locale=True)) while(res.alerts): voice.alert(res.alerts.pop(0))
def compatibility_version(): # Include a hash of rules.txt in COMPATIBILITY_VERSION. # (about the choice of MD5, check the comments in mapfile.py, line 45) # Don't check *.pyc (or library.zip, soundrts.exe and server.exe) # because it would require to add an internal version for every file. # (a bit complicated for the moment, and not as useful as checking rules.txt; # commun.py already contains a small check, wrong only if individual # *.pyc files have been changed) # TODO: use SVN to include a version in every *.pyc? (check other projects) return _remove_dev(VERSION) + "-" + md5(res.get_text("rules", append=True) + res.get_text("ai", append=True)).hexdigest()
def set_race(self, player_index, race): player = self.players[int(player_index)] player.race = race style = Style() style.load(res.get_text("ui/style", append=True, locale=True)) race_name = style.get(player.race, 'title') self.broadcast([player.login, ] + race_name)
def training_menu_after_map(self, m): style.load(res.get_text("ui/style", append=True, locale=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 set_faction(self, player_index, faction): player = self.players[int(player_index)] player.faction = faction style = Style() style.load(res.get_text("ui/style", append=True, locale=True)) faction_name = style.get(player.faction, 'title') self.broadcast([player.login, ] + faction_name)
def _move_recommended_maps(w): style = Style() style.load(res.get_text("ui/style", append=True, locale=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 set_faction(self, player_index, faction): player = self.players[int(player_index)] player.faction = faction style = Style() style.load(res.get_text("ui/style", append=True, locale=True)) faction_name = style.get(player.faction, 'title') self.broadcast([ player.login, ] + faction_name)
def _move_recommended_maps(w): style = Style() style.load(res.get_text("ui/style", append=True, locale=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("rules", append=True), map.campaign_rules, map.additional_rules) load_ai(res.get_text("ai", append=True), map.campaign_ai, map.additional_ai) self._load_map(map) self.map = map self.square_width = int(self.square_width * 1000) # XXX 1000=PRECISION? self._build_map() if self.objective: self.introduction = [4020] + self.objective else: self.introduction = [] except MapError, msg: warning("map error: %s", msg) self.map_error = "map error: %s" % msg return False
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("rules", append=True), map.campaign_rules, map.additional_rules) load_ai(res.get_text("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() if self.objective: self.introduction = [4020] + self.objective else: self.introduction = [] except MapError, msg: warning("map error: %s", msg) self.map_error = "map error: %s" % msg return False
def srv_map_factions(self, args): self.map_factions = args style.load(res.get_text("ui/style", append=True, locale=True)) # XXX: won't work with factions defined in the map
def srv_map_factions(self, args): self.map_factions = args style.load(res.get_text( "ui/style", append=True, locale=True)) # XXX: won't work with factions defined in the map
def _read_table_from_file(name): return [x.split() for x in res.get_text(name).split("\n") if x.strip()]