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