Esempio n. 1
0
 def load(self, savegame, players, is_ai_test, is_map):
     # keep a reference on the savegame, so we can cleanup in `end`
     self.savegame = savegame
     self.started_from_map = is_map
     if is_ai_test:
         # enable trader, pirate and natural resources in AI tests.
         options = StartGameOptions.create_ai_test(savegame, players)
     else:
         # disable the above in usual game tests for simplicity.
         options = StartGameOptions.create_game_test(savegame, players)
         options.is_map = is_map
     super(SPTestSession, self).load(options)
Esempio n. 2
0
	def load(self, savegame, players, is_ai_test, is_map):
		# keep a reference on the savegame, so we can cleanup in `end`
		self.savegame = savegame
		self.started_from_map = is_map
		if is_ai_test:
			# enable trader, pirate and natural resources in AI tests.
			options = StartGameOptions.create_ai_test(savegame, players)
		else:
			# disable the above in usual game tests for simplicity.
			options = StartGameOptions.create_game_test(savegame, players)
			options.is_map = is_map
		super(SPTestSession, self).load(options)
Esempio n. 3
0
def prepare_multiplayer(game, trader_enabled=True, pirate_enabled=True, natural_resource_multiplier=1):
	"""Starts a multiplayer game server
	TODO: actual game data parameter passing
	"""
	_modules.gui.show_loading_screen()

	global preloading
	preload_game_join(preloading)

	# remove cursor while loading
	horizons.globals.fife.cursor.set(fife_module.CURSOR_NONE)
	horizons.globals.fife.engine.pump()
	horizons.globals.fife.set_cursor_image('default')

	# destruct old session (right now, without waiting for gc)
	if _modules.session is not None and _modules.session.is_alive:
		_modules.session.end()
	# start new session
	from horizons.mpsession import MPSession
	# get random seed for game
	uuid = game.uuid
	random = sum([ int(uuid[i : i + 2], 16) for i in range(0, len(uuid), 2) ])
	_modules.session = MPSession(horizons.globals.db, NetworkInterface(), rng_seed=random)

	# NOTE: this data passing is only temporary, maybe use a player class/struct
	if game.is_savegame:
		map_file = SavegameManager.get_multiplayersave_map(game.map_name)
	else:
		map_file = SavegameManager.get_map(game.map_name)

	options = StartGameOptions.create_start_multiplayer(map_file, game.get_player_list(), not game.is_savegame)
	_modules.session.load(options)
Esempio n. 4
0
def _start_map(
    map_name,
    ai_players=0,
    is_scenario=False,
    pirate_enabled=True,
    trader_enabled=True,
    force_player_id=None,
    is_map=False,
):
    """Start a map specified by user
	@param map_name: name of map or path to map
	@return: bool, whether loading succeeded"""
    if is_scenario:
        savegames = SavegameManager.get_available_scenarios(locales=True)
    else:
        savegames = SavegameManager.get_maps()
    map_file = _find_matching_map(map_name, savegames)
    if not map_file:
        return False

    options = StartGameOptions.create_start_singleplayer(
        map_file, is_scenario, ai_players, trader_enabled, pirate_enabled, force_player_id, is_map
    )
    start_singleplayer(options)
    return True
Esempio n. 5
0
def test_save_load_ticket_1421(gui):
	"""
	Boatbuilder crashes when saving/loading while a ship is being produced.
	"""

	# Select boat builder
	gui.cursor_click(64, 10, 'left')

	# Select trade ships tab
	gui.trigger('tab_base', '1')

	# Build huker
	gui.trigger('boatbuilder_showcase', 'ok_0')

	# Select war ships tab
	gui.trigger('tab_base', '2')

	# Build frigate
	gui.trigger('boatbuilder_showcase', 'ok_0')

	fd, filename = tempfile.mkstemp()
	os.close(fd)

	assert gui.session.save(savegamename=filename)

	options = StartGameOptions.create_load_game(filename, None)
	horizons.main.start_singleplayer(options)
Esempio n. 6
0
def prepare_multiplayer(game, trader_enabled=True, pirate_enabled=True, natural_resource_multiplier=1):
	"""Starts a multiplayer game server
	TODO: actual game data parameter passing
	"""
	_modules.gui.show_loading_screen()

	preloader.wait_for_finish()

	# remove cursor while loading
	horizons.globals.fife.cursor.set(fife_module.CURSOR_NONE)
	horizons.globals.fife.engine.pump()
	horizons.globals.fife.set_cursor_image('default')

	# destruct old session (right now, without waiting for gc)
	if _modules.session is not None and _modules.session.is_alive:
		_modules.session.end()
	# start new session
	from horizons.mpsession import MPSession
	# get random seed for game
	uuid = game.uuid
	random = sum([int(uuid[i : i + 2], 16) for i in range(0, len(uuid), 2)])
	_modules.session = MPSession(horizons.globals.db, NetworkInterface(), rng_seed=random)

	# NOTE: this data passing is only temporary, maybe use a player class/struct
	if game.is_savegame:
		map_file = SavegameManager.get_multiplayersave_map(game.map_name)
	else:
		map_file = SavegameManager.get_map(game.map_name)

	options = StartGameOptions.create_start_multiplayer(map_file, game.get_player_list(), not game.is_savegame)
	_modules.session.load(options)
    def start_single(self):
        """ Starts a single player horizons. """
        assert self.current is self.widgets['singleplayermenu']
        playername = self.current.playerdata.get_player_name()
        if not playername:
            self.show_popup(_("Invalid player name"),
                            _("You entered an invalid playername."))
            return
        playercolor = self.current.playerdata.get_player_color()
        self._save_player_name()

        if self.current.collectData('random'):
            map_file = self._get_random_map_file()
        else:
            assert self.active_right_side.collectData('maplist') != -1
            map_file = self._get_selected_map()

        is_scenario = bool(self.current.collectData('scenario'))
        if not is_scenario:
            ai_players = int(self.current.aidata.get_ai_players())
            horizons.globals.fife.set_uh_setting("AIPlayers", ai_players)
        horizons.globals.fife.save_settings()

        self.show_loading_screen()
        if is_scenario:
            try:
                options = StartGameOptions.create_start_scenario(map_file)
                options.set_human_data(playername, playercolor)
                horizons.main.start_singleplayer(options)
            except InvalidScenarioFileFormat as e:
                self._show_invalid_scenario_file_popup(e)
                self._select_single(show='scenario')
        else:  # free play/random map
            options = StartGameOptions.create_start_map(map_file)
            options.set_human_data(playername, playercolor)
            options.ai_players = ai_players
            options.trader_enabled = self.widgets['game_settings'].findChild(
                name='free_trader').marked
            options.pirate_enabled = self.widgets['game_settings'].findChild(
                name='pirates').marked
            options.disasters_enabled = self.widgets[
                'game_settings'].findChild(name='disasters').marked
            options.natural_resource_multiplier = self._get_natural_resource_multiplier(
            )
            horizons.main.start_singleplayer(options)

        ExtScheduler().rem_all_classinst_calls(self)
Esempio n. 8
0
	def load_game(self):
		saved_game = self.show_select_savegame(mode='load')
		if saved_game is None:
			return False # user aborted dialog

		options = StartGameOptions(saved_game)
		horizons.main.start_singleplayer(options)
		return True
	def act(self, player_name, player_color):
		map_file = self._get_selected_map()

		try:
			options = StartGameOptions.create_start_scenario(map_file)
			options.set_human_data(player_name, player_color)
			horizons.main.start_singleplayer(options)
		except InvalidScenarioFileFormat as e:
			self._show_invalid_scenario_file_popup(e)
    def act(self, player_name, player_color):
        map_file = self._get_selected_map()

        try:
            options = StartGameOptions.create_start_scenario(map_file)
            options.set_human_data(player_name, player_color)
            horizons.main.start_singleplayer(options)
        except InvalidScenarioFileFormat as e:
            self._show_invalid_scenario_file_popup(e)
	def start_single(self):
		""" Starts a single player horizons. """
		assert self.current is self.widgets['singleplayermenu']
		playername = self.current.playerdata.get_player_name()
		if not playername:
			self.show_popup(_("Invalid player name"), _("You entered an invalid playername."))
			return
		playercolor = self.current.playerdata.get_player_color()
		self._save_player_name()

		if self.current.collectData('random'):
			map_file = self._get_random_map_file()
		else:
			assert self.active_right_side.collectData('maplist') != -1
			map_file = self._get_selected_map()

		is_scenario = bool(self.current.collectData('scenario'))
		if not is_scenario:
			ai_players = int(self.current.aidata.get_ai_players())
			horizons.globals.fife.set_uh_setting("AIPlayers", ai_players)
		horizons.globals.fife.save_settings()

		self.mainmenu.show_loading_screen()
		if is_scenario:
			try:
				options = StartGameOptions.create_start_scenario(map_file)
				options.set_human_data(playername, playercolor)
				horizons.main.start_singleplayer(options)
			except InvalidScenarioFileFormat as e:
				self._show_invalid_scenario_file_popup(e)
				self._select_single(show='scenario')
		else: # free play/random map
			options = StartGameOptions.create_start_map(map_file)
			options.set_human_data(playername, playercolor)
			options.ai_players = ai_players
			options.trader_enabled = self.widgets['game_settings'].findChild(name='free_trader').marked
			options.pirate_enabled = self.widgets['game_settings'].findChild(name='pirates').marked
			options.disasters_enabled = self.widgets['game_settings'].findChild(name='disasters').marked
			options.natural_resource_multiplier = self._get_natural_resource_multiplier()
			horizons.main.start_singleplayer(options)

		ExtScheduler().rem_all_classinst_calls(self)
Esempio n. 12
0
	def act(self):
		for size in self.sizes:
			option_name = 'size_%d' % size
			if self._gui.findChild(name=option_name).marked:
				self._windows.close()

				# the empty list is interpreted as the empty list of random map island strings
				options = StartGameOptions.create_editor_load([])
				options.map_padding = size // 2
				horizons.main.start_singleplayer(options)
				return
    def act(self, player_name, player_color):
        map_file = self._get_selected_map()

        options = StartGameOptions.create_start_map(map_file)
        options.set_human_data(player_name, player_color)
        options.ai_players = self._aidata.get_ai_players()
        options.trader_enabled = self._game_settings.free_trader
        options.pirate_enabled = self._game_settings.pirates
        options.disasters_enabled = self._game_settings.disasters
        options.natural_resource_multiplier = self._game_settings.natural_resource_multiplier
        horizons.main.start_singleplayer(options)
Esempio n. 14
0
    def act(self):
        for size in self.sizes:
            option_name = 'size_{:d}'.format(size)
            if self._gui.findChild(name=option_name).marked:
                self._windows.close()

                # the empty list is interpreted as the empty list of random map island strings
                options = StartGameOptions.create_editor_load([])
                options.map_padding = size // 2
                horizons.main.start_singleplayer(options)
                return
Esempio n. 15
0
	def act(self, player_name, player_color):
		map_file = self._get_selected_map()

		options = StartGameOptions.create_start_map(map_file)
		options.set_human_data(player_name, player_color)
		options.ai_players = self._aidata.get_ai_players()
		options.trader_enabled = self._game_settings.free_trader
		options.pirate_enabled = self._game_settings.pirates
		options.disasters_enabled = self._game_settings.disasters
		options.natural_resource_multiplier = self._game_settings.natural_resource_multiplier
		horizons.main.start_singleplayer(options)
	def act(self):
		for size in self.sizes:
			option_name = 'size_%d' % size
			if self._gui.findChild(name=option_name).marked:
				self.parent.hide()
				self.parent.parent.show_loading_screen()

				# the empty list is interpreted as the empty list of random map island strings
				options = StartGameOptions.create_editor_load([])
				options.map_padding = size // 2
				session = horizons.main.start_singleplayer(options)
				session.world_editor = WorldEditor(session.world)
				return
Esempio n. 17
0
def _load_cmd_map(savegame, ai_players, force_player_id=None):
	"""Load a map specified by user.
	@param savegame: either the displayname of a savegame or a path to a savegame
	@return: bool, whether loading succeeded"""
	# first check for partial or exact matches in the normal savegame list
	savegames = SavegameManager.get_saves()
	map_file = _find_map(savegame, savegames)
	if not map_file:
		return False

	options = StartGameOptions.create_load_game(map_file, force_player_id)
	start_singleplayer(options)
	return True
Esempio n. 18
0
    def _load_game(self):
        if self._in_editor_mode:
            editor_start_menu = EditorStartMenu(self._windows)
            self._windows.show(editor_start_menu)
        else:
            window = SelectSavegameDialog('load', self._windows)
            saved_game = self._windows.show(window)
            if saved_game is None:
                return

            options = StartGameOptions(saved_game)
            horizons.main.start_singleplayer(options)
            return True
Esempio n. 19
0
def _edit_map(map_file):
	"""
	Start editing the specified map file.

	@param map_file: path to the map file or a list of random island strings
	@return: bool, whether loading succeeded
	"""
	if not map_file:
		return False

	options = StartGameOptions.create_editor_load(map_file)
	start_singleplayer(options)
	return True
Esempio n. 20
0
def _load_cmd_map(savegame, ai_players, force_player_id=None):
	"""Load a map specified by user.
	@param savegame: either the displayname of a savegame or a path to a savegame
	@return: bool, whether loading succeeded"""
	# first check for partial or exact matches in the normal savegame list
	savegames = SavegameManager.get_saves()
	map_file = _find_matching_map(savegame, savegames)
	if not map_file:
		return False

	options = StartGameOptions.create_load_game(map_file, force_player_id)
	start_singleplayer(options)
	return True
Esempio n. 21
0
def _edit_map(map_file):
	"""
	Start editing the specified map file.

	@param map_file: path to the map file or a list of random island strings
	@return: bool, whether loading succeeded
	"""
	if not map_file:
		return False

	options = StartGameOptions.create_editor_load(map_file)
	start_singleplayer(options)
	return True
	def act(self, player_name, player_color):
		self.end()
		self._mainmenu.show_loading_screen()

		map_file = generate_random_map(*self._get_map_parameters())

		options = StartGameOptions.create_start_map(map_file)
		options.set_human_data(player_name, player_color)
		options.ai_players = self._aidata.get_ai_players()
		options.trader_enabled = self._game_settings.free_trader
		options.pirate_enabled = self._game_settings.pirates
		options.disasters_enabled = self._game_settings.disasters
		options.natural_resource_multiplier = self._game_settings.natural_resource_multiplier
		horizons.main.start_singleplayer(options)
Esempio n. 23
0
def saveload(gui):
	"""Save and load the game (gui test version). Use like this:

	# For gui tests
	saveload(gui)
	"""
	fd, filename = tempfile.mkstemp()
	os.close(fd)
	assert gui.session.save(savegamename=filename)
	options = StartGameOptions.create_load_game(filename, None)
	# This hands out a new session, but `gui.session` is a property.
	horizons.main.start_singleplayer(options)
	# Restore some properties that were changed for tests:
	# Set game speed to maximum, and disable autoscroll.
	gui.setup()
Esempio n. 24
0
def _edit_map(map_file):
	"""
	Start editing the specified map file.

	@param map_file: path to the map file or a list of random island strings
	@return: bool, whether loading succeeded
	"""
	if not map_file:
		return False

	options = StartGameOptions.create_editor_load(map_file)
	start_singleplayer(options)

	from horizons.editor.worldeditor import WorldEditor
	_modules.session.world_editor = WorldEditor(_modules.session.world)
	return True
Esempio n. 25
0
def _edit_map(map_file):
    """
	Start editing the specified map file.

	@param map_file: path to the map file or a list of random island strings
	@return: bool, whether loading succeeded
	"""
    if not map_file:
        return False

    options = StartGameOptions.create_editor_load(map_file)
    start_singleplayer(options)

    from horizons.editor.worldeditor import WorldEditor
    _modules.session.world_editor = WorldEditor(_modules.session.world)
    return True
Esempio n. 26
0
def _start_map(map_name, ai_players=0, is_scenario=False,
               pirate_enabled=True, trader_enabled=True, force_player_id=None, is_map=False):
	"""Start a map specified by user
	@param map_name: name of map or path to map
	@return: bool, whether loading succeeded"""
	if is_scenario:
		map_file = _find_scenario(map_name, SavegameManager.get_available_scenarios(locales=True))
	else:
		map_file = _find_map(map_name, SavegameManager.get_maps())

	if not map_file:
		return False

	options = StartGameOptions.create_start_singleplayer(map_file, is_scenario,
		ai_players, trader_enabled, pirate_enabled, force_player_id, is_map)
	start_singleplayer(options)
	return True
Esempio n. 27
0
def _load_last_quicksave(session=None, force_player_id=None):
	"""Load last quicksave
	@param session: value of session
	@return: bool, whether loading succeeded"""
	save_files = SavegameManager.get_quicksaves()[0]
	if _modules.session is not None:
		if not save_files:
			_modules.session.ingame_gui.open_popup(_("No quicksaves found"),
			                                       _("You need to quicksave before you can quickload."))
			return False
	else:
		if not save_files:
			print "Error: No quicksave found."
			return False

	save = max(save_files)
	options = StartGameOptions.create_load_game(save, force_player_id)
	start_singleplayer(options)
	return True
Esempio n. 28
0
def _load_last_quicksave(session=None, force_player_id=None):
	"""Load last quicksave
	@param session: value of session
	@return: bool, whether loading succeeded"""
	save_files = SavegameManager.get_quicksaves()[0]
	if _modules.session is not None:
		if not save_files:
			_modules.session.ingame_gui.open_popup(T("No quicksaves found"),
			                                       T("You need to quicksave before you can quickload."))
			return False
	else:
		if not save_files:
			print("Error: No quicksave found.")
			return False

	save = max(save_files)
	options = StartGameOptions.create_load_game(save, force_player_id)
	start_singleplayer(options)
	return True
Esempio n. 29
0
def _load_last_quicksave(session=None, force_player_id=None):
    """Load last quicksave
	@param session: value of session
	@return: bool, whether loading succeded"""
    save_files = SavegameManager.get_quicksaves()[0]
    if session is not None:
        if not save_files:
            session.gui.show_popup(
                _("No quicksaves found"),
                _("You need to quicksave before you can quickload."))
            return False
        else:
            session.ingame_gui.on_escape()  # close widgets that might be open
    else:
        if not save_files:
            print "Error: No quicksave found."
            return False

    save = max(save_files)
    _modules.gui.show_loading_screen()
    options = StartGameOptions.create_load_game(save, force_player_id)
    start_singleplayer(options)
    return True
Esempio n. 30
0
def _start_random_map(ai_players, seed=None, force_player_id=None):
	options = StartGameOptions.create_start_random_map(ai_players, seed, force_player_id)
	start_singleplayer(options)
	return True
Esempio n. 31
0
def _start_random_map(ai_players, seed=None, force_player_id=None):
	options = StartGameOptions.create_start_random_map(ai_players, seed, force_player_id)
	start_singleplayer(options)
	return True