The Battle for Wesnoth  1.15.12+dev
game_launcher.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "editor/editor_main.hpp" // for EXIT_STATUS
18 #include "events.hpp" // for event_context
19 #include "font/font_config.hpp" // for manager
20 #include "game_end_exceptions.hpp" // for LEVEL_RESULT, etc
21 #include "hotkey/hotkey_manager.hpp" // for manager
22 #include "picture.hpp" // for manager
23 #include "preferences/game.hpp" // for manager
24 #include "saved_game.hpp" // for saved_game
25 #include "savegame.hpp" // for clean_saves, etc
26 #include "sound.hpp" // for music_thinker
27 #include <optional>
28 
29 #include <string> // for string
30 #include <vector> // for vector
31 
33 class config;
34 class CVideo;
35 
37 {
38  /** Whether the game should immediately start a campaign. */
39  bool jump = false;
40 
41  /** Whether the story screen should be skipped. */
42  bool skip_story = false;
43 
44  /** The difficulty at which to launch the campaign. */
45  int difficulty = -1;
46 
47  /** The ID of the campaign to launch. */
48  std::string campaign_id = "";
49 
50  /** The ID of the scenario within the campaign to jump to. */
51  std::string scenario_id = "";
52 };
53 
55 {
56 public:
57  game_launcher(const commandline_options& cmdline_opts);
58  ~game_launcher();
59 
60  enum class mp_mode { CONNECT, HOST, LOCAL };
61  enum class reload_mode { RELOAD_DATA, NO_RELOAD_DATA };
62 
63  /**
64  * Status code after running a unit test, should match the run_wml_tests
65  * script and the documentation for the --unit_test command-line option.
66  */
67  enum class unit_test_result : int {
68  TEST_PASS = 0,
69  TEST_FAIL = 1,
70  // 2 is reserved for timeouts
71  TEST_FAIL_LOADING_REPLAY = 3,
72  TEST_FAIL_PLAYING_REPLAY = 4,
73  TEST_FAIL_BROKE_STRICT = 5,
74  TEST_FAIL_WML_EXCEPTION = 6,
75  TEST_FAIL_BY_DEFEAT = 7,
76  TEST_PASS_BY_VICTORY = 8,
77  };
78 
79  bool init_video();
80  bool init_language();
81  bool init_lua_script();
82 
83  bool play_test();
84  bool play_screenshot_mode();
85  bool play_render_image_mode();
86  /** Runs unit tests specified on the command line */
87  unit_test_result unit_test();
88 
89  bool has_load_data() const;
90  bool load_game();
91  void set_test(const std::string& id);
92 
93  /** Return the ID of the campaign to jump to (skipping the main menu). */
94  std::string jump_to_campaign_id() const;
95  bool new_campaign();
96  bool goto_campaign();
97  bool goto_multiplayer();
98  bool goto_editor();
99 
100  void select_mp_server(const std::string& server) { multiplayer_server_ = server; }
101  bool play_multiplayer(mp_mode mode);
102  bool play_multiplayer_commandline();
103  bool change_language();
104 
105  void launch_game(reload_mode reload = reload_mode::RELOAD_DATA);
106  void play_replay();
107 
109 
110  const commandline_options & opts() const { return cmdline_opts_; }
111 
112 private:
113  game_launcher(const game_launcher&) = delete;
114  game_launcher& operator=(const game_launcher&) = delete;
115 
116  void clear_loaded_game();
117  void start_wesnothd();
118 
119  editor::EXIT_STATUS start_editor(const std::string& filename);
120  unit_test_result pass_victory_or_defeat(LEVEL_RESULT res);
121 
122  /**
123  * Internal to the implementation of unit_test(). If a single instance of
124  * Wesnoth is running multiple unit tests, this gets called once per test.
125  */
126  unit_test_result single_unit_test();
127 
129  //Never null.
130  const std::unique_ptr<CVideo> video_;
131 
139 
140  std::vector<std::string> test_scenarios_;
141 
142  std::string screenshot_map_, screenshot_filename_;
143 
146 
147  std::string multiplayer_server_;
150 
152  std::optional<savegame::load_game_metadata> load_data_;
153 };
sound::music_muter music_muter_
const hotkey::manager hotkey_manager_
std::string scenario_id
The ID of the scenario within the campaign to jump to.
const std::unique_ptr< CVideo > video_
this class is initialized once at game start put all initialization and wipe code in the methods here...
Definition: video.hpp:31
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
jump_to_campaign_info jump_to_campaign_
std::vector< std::string > test_scenarios_
const commandline_options & opts() const
unit_test_result
Status code after running a unit test, should match the run_wml_tests script and the documentation fo...
font::manager font_manager_
bool skip_story
Whether the story screen should be skipped.
std::optional< savegame::load_game_metadata > load_data_
std::string multiplayer_server_
editor::EXIT_STATUS start_editor()
void select_mp_server(const std::string &server)
std::string screenshot_map_
const preferences::manager prefs_manager_
Image cache manager.
Definition: picture.hpp:201
const commandline_options & cmdline_opts_
sound::music_thinker music_thinker_
saved_game state_
const events::event_context main_event_context_
bool jump
Whether the game should immediately start a campaign.
int difficulty
The difficulty at which to launch the campaign.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
const image::manager image_manager_
std::string campaign_id
The ID of the campaign to launch.