The Battle for Wesnoth  1.19.0-dev
game_launcher.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 
36 {
37  /** Whether the game should immediately start a campaign. */
38  bool jump = false;
39 
40  /** Whether the story screen should be skipped. */
41  bool skip_story = false;
42 
43  /** The difficulty at which to launch the campaign. */
44  int difficulty = -1;
45 
46  /** The ID of the campaign to launch. */
47  std::string campaign_id = "";
48 
49  /** The ID of the scenario within the campaign to jump to. */
50  std::string scenario_id = "";
51 };
52 
54 {
55 public:
56  game_launcher(const commandline_options& cmdline_opts);
58 
59  enum class mp_mode { CONNECT, HOST, LOCAL };
61 
62  /**
63  * Status code after running a unit test, should match the run_wml_tests
64  * script and the documentation for the --unit_test command-line option.
65  */
66  enum class unit_test_result : int {
67  TEST_PASS = 0,
68  TEST_FAIL = 1,
69  // 2 is reserved for timeouts
72  //TEST_FAIL_BROKE_STRICT = 5,
80  };
81 
82  bool init_video();
83  bool init_language();
84  bool init_lua_script();
85 
86  bool play_test();
87  bool play_screenshot_mode();
89  /** Runs unit tests specified on the command line */
91 
92  bool has_load_data() const;
93  bool load_game();
94  void set_test(const std::string& id);
95 
96  /** Return the ID of the campaign to jump to (skipping the main menu). */
97  std::string jump_to_campaign_id() const;
98  bool new_campaign();
99  bool goto_campaign();
100  bool goto_multiplayer();
101  bool goto_editor();
102 
103  void select_mp_server(const std::string& server) { multiplayer_server_ = server; }
104  bool play_multiplayer(mp_mode mode);
106  bool change_language();
107 
109  void play_replay();
110 
112 
113  const commandline_options & opts() const { return cmdline_opts_; }
114 
115 private:
116  game_launcher(const game_launcher&) = delete;
118 
119  void clear_loaded_game();
120  void start_wesnothd();
121 
122  editor::EXIT_STATUS start_editor(const std::string& filename);
124 
125  /**
126  * Internal to the implementation of unit_test(). If a single instance of
127  * Wesnoth is running multiple unit tests, this gets called once per test.
128  */
130 
132  bool start_in_fullscreen_ = false;
133 
141 
142  std::vector<std::string> test_scenarios_;
143 
145 
148 
149  std::string multiplayer_server_;
152 
154  std::optional<savegame::load_game_metadata> load_data_;
155 };
game_launcher(const commandline_options &cmdline_opts)
const events::event_context main_event_context_
game_launcher & operator=(const game_launcher &)=delete
unit_test_result single_unit_test()
Internal to the implementation of unit_test().
std::string multiplayer_server_
std::string jump_to_campaign_id() const
Return the ID of the campaign to jump to (skipping the main menu).
std::optional< savegame::load_game_metadata > load_data_
bool play_screenshot_mode()
jump_to_campaign_info jump_to_campaign_
std::string screenshot_filename_
void launch_game(reload_mode reload=reload_mode::RELOAD_DATA)
sound::music_thinker music_thinker_
bool goto_multiplayer()
game_launcher(const game_launcher &)=delete
bool change_language()
saved_game state_
unit_test_result pass_victory_or_defeat(level_result::type res)
bool has_load_data() const
bool play_render_image_mode()
void clear_loaded_game()
bool init_lua_script()
std::vector< std::string > test_scenarios_
unit_test_result
Status code after running a unit test, should match the run_wml_tests script and the documentation fo...
std::string screenshot_map_
const commandline_options & cmdline_opts_
font::manager font_manager_
const hotkey::manager hotkey_manager_
void select_mp_server(const std::string &server)
const image::manager image_manager_
void set_test(const std::string &id)
bool play_multiplayer_commandline()
unit_test_result unit_test()
Runs unit tests specified on the command line.
sound::music_muter music_muter_
const preferences::manager prefs_manager_
const commandline_options & opts() const
bool play_multiplayer(mp_mode mode)
editor::EXIT_STATUS start_editor()
this class is initialized once at game start put all initialization and wipe code in the methods here...
Contains the exception interfaces used to signal completion of a scenario, campaign or turn.
Image cache manager.
Definition: picture.hpp:206
std::string campaign_id
The ID of the campaign to launch.
bool jump
Whether the game should immediately start a campaign.
std::string scenario_id
The ID of the scenario within the campaign to jump to.
bool skip_story
Whether the story screen should be skipped.
int difficulty
The difficulty at which to launch the campaign.