Пример #1
0
 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()
Пример #2
0
 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()
Пример #3
0
 def run_on(self):
     if self.record_replay:
         self._replay_file = open(
             os.path.join(REPLAYS_PATH, "%s.txt" % int(time.time())), "w")
         self._replay_file.write(self._replay_file_content)
     sounds.enter_map(self.map.mapfile)
     self.world.restore_links_for_savegame()
     rules.copy(self._rules)
     definitions._ai = self._ai
     style.copy(self._style)
     update_orders_list()  # when style has changed
     self.interface.set_self_as_listener()
     t = threading.Thread(target=self.world.loop)
     t.daemon = True
     t.start()
     # Because the simulation is in a different thread,
     # sometimes the interface "forgets" to ask for an
     # update. Maybe a better communication protocol
     # between interface and simulation would solve
     # this problem ("update" and "no_end_of_update_yet"
     # should contain the simulation time, maybe). Maybe
     # some data in a queue has been lost.
     self.interface.asked_to_update = False
     self.interface.loop()
     self._record_stats(self.world)
     self.post_run()
     self.world.clean()
Пример #4
0
 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()
Пример #5
0
 def run_on(self):
     if self.record_replay:
         self._replay_file = open(os.path.join(REPLAYS_PATH, "%s.txt" % int(time.time())), "w")
         self._replay_file.write(self._replay_file_content)
     try:
         self.map.load_resources()
         self.world.restore_links_for_savegame()
         rules.copy(self._rules)
         definitions._ai = self._ai
         style.copy(self._style)
         update_orders_list() # when style has changed
         self.interface.set_self_as_listener()
         t = threading.Thread(target=self.world.loop)
         t.daemon = True
         t.start()
         # Because the simulation is in a different thread,
         # sometimes the interface "forgets" to ask for an
         # update. Maybe a better communication protocol
         # between interface and simulation would solve
         # this problem ("update" and "no_end_of_update_yet"
         # should contain the simulation time, maybe). Maybe
         # some data in a queue has been lost.
         self.interface.asked_to_update = False
         self.interface.loop()
         self._record_stats(self.world)
         self.post_run()
         self.world.clean()
     finally:
         self.map.unload_resources()
Пример #6
0
 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()
Пример #7
0
 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()
Пример #8
0
 def run_on(self):
     if self.record_replay:
         self._replay_file = open(os.path.join(REPLAYS_PATH, "%s.txt" % int(time.time())), "w")
         self._replay_file.write(self._replay_file_content)
     sounds.enter_map(self.map.mapfile)
     self.world.restore_links_for_savegame()
     rules.copy(self._rules)
     definitions._ai = self._ai
     style.copy(self._style)
     update_orders_list() # when style has changed
     self.interface.set_self_as_listener()
     t = threading.Thread(target=self.world.loop)
     t.daemon = True
     t.start()
     self.interface.loop()
     self._record_stats(self.world)
     self.post_run()
     self.world.clean()
Пример #9
0
 def run_on(self):
     if self.record_replay:
         self._replay_file = open(
             os.path.join(REPLAYS_PATH, "%s.txt" % int(time.time())), "w")
         self._replay_file.write(self._replay_file_content)
     try:
         self.map.load_resources()
         self.world.restore_links_for_savegame()
         rules.copy(self._rules)
         definitions._ai = self._ai
         style.copy(self._style)
         update_orders_list()  # when style has changed
         self.interface.set_self_as_listener()
         t = threading.Thread(target=self.world.loop)
         t.daemon = True
         t.start()
         self.interface.loop()
         self._record_stats(self.world)
         self.post_run()
         self.world.stop()
     finally:
         self.map.unload_resources()