The Battle for Wesnoth  1.15.3+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 "preferences/game.hpp" // for manager
21 #include "hotkey/hotkey_manager.hpp" // for manager
22 #include "picture.hpp" // for manager
23 #include "saved_game.hpp" // for saved_game
24 #include "sound.hpp" // for music_thinker
25 
26 #include <string> // for string
27 #include <vector> // for vector
28 
30 class config;
31 class CVideo;
32 namespace savegame { struct load_game_metadata; }
34 {
35 public:
36  jump_to_campaign_info(bool jump, bool skip_story, int difficulty, const std::string& campaign_id,const std::string& scenario_id)
37  : jump_(jump)
38  , skip_story_(skip_story)
39  , difficulty_(difficulty)
40  , campaign_id_(campaign_id)
41  , scenario_id_(scenario_id)
42  {
43  }
44  bool jump_;
47  std::string campaign_id_,scenario_id_;
48 };
49 
51 {
52 public:
53  game_launcher(const commandline_options& cmdline_opts, const char* appname);
54  ~game_launcher();
55 
56  CVideo& video() { return *video_; }
57 
58  enum mp_selection {MP_CONNECT, MP_HOST, MP_LOCAL};
59 
60  /**
61  * Status code after running a unit test, should match the run_wml_tests
62  * script and the documentation for the --unit_test command-line option.
63  */
64  enum class unit_test_result : int {
65  TEST_PASS = 0,
66  TEST_FAIL = 1,
67  // 2 is reserved for timeouts
68  TEST_FAIL_LOADING_REPLAY = 3,
69  TEST_FAIL_PLAYING_REPLAY = 4,
70  TEST_FAIL_BROKE_STRICT = 5,
71  TEST_FAIL_WML_EXCEPTION = 6,
72  };
73 
74  bool init_video();
75  bool init_language();
76  bool init_lua_script();
77 
78  bool play_test();
79  bool play_screenshot_mode();
80  bool play_render_image_mode();
81  /// Runs unit tests specified on the command line
82  unit_test_result unit_test();
83 
84  bool is_loading() const;
85  void clear_loaded_game();
86  bool load_game();
87  void set_tutorial();
88  void set_test(const std::string& id);
89 
90  /// Return the ID of the campaign to jump to (skipping the main menu).
91  std::string jump_to_campaign_id() const;
92  bool new_campaign();
93  bool goto_campaign();
94  bool goto_multiplayer();
95  bool goto_editor();
96 
97  bool jump_to_editor() const { return jump_to_editor_; }
98 
99  void select_mp_server(const std::string& server) { multiplayer_server_ = server; }
100  bool play_multiplayer(mp_selection res);
101  bool play_multiplayer_commandline();
102  bool change_language();
103 
104  void show_preferences();
105 
106  enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
107  void launch_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
108  void play_replay();
109 
111 
112  void start_wesnothd();
113 
114  const commandline_options & opts() const { return cmdline_opts_; }
115 private:
117  void operator=(const game_launcher&);
118 
119  void mark_completed_campaigns(std::vector<config>& campaigns);
120 
121  editor::EXIT_STATUS start_editor(const std::string& filename);
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  unit_test_result single_unit_test();
126 
128  //Never null.
129  const std::unique_ptr<CVideo> video_;
130 
138 
139  std::vector<std::string> test_scenarios_;
140 
141  std::string screenshot_map_, screenshot_filename_;
142 
145 
146  std::string multiplayer_server_;
149 
151  std::unique_ptr<savegame::load_game_metadata> load_data_;
152 };
sound::music_muter music_muter_
CVideo & video()
const hotkey::manager hotkey_manager_
const std::unique_ptr< CVideo > video_
this class is initialized once at game start put all initialization and wipe code in the methods here...
jump_to_campaign_info(bool jump, bool skip_story, int difficulty, const std::string &campaign_id, const std::string &scenario_id)
Definition: video.hpp:31
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_
std::string multiplayer_server_
editor::EXIT_STATUS start_editor()
void select_mp_server(const std::string &server)
bool jump_to_editor() const
std::string screenshot_map_
std::unique_ptr< savegame::load_game_metadata > load_data_
const preferences::manager prefs_manager_
the image manager is responsible for setting up images, and destroying all images when the program ex...
Definition: picture.hpp:157
const commandline_options & cmdline_opts_
std::string jump(const unsigned amount)
Definition: help_impl.hpp:356
sound::music_thinker music_thinker_
saved_game state_
const events::event_context main_event_context_
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
const image::manager image_manager_