The Battle for Wesnoth  1.15.2+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  TEST_FAIL_LOADING_REPLAY = 3,
68  TEST_FAIL_PLAYING_REPLAY = 4,
69  };
70 
71  bool init_video();
72  bool init_language();
73  bool init_lua_script();
74 
75  bool play_test();
76  bool play_screenshot_mode();
77  bool play_render_image_mode();
78  /// Runs unit tests specified on the command line
79  unit_test_result unit_test();
80 
81  bool is_loading() const;
82  void clear_loaded_game();
83  bool load_game();
84  void set_tutorial();
85  void set_test(const std::string& id);
86 
87  /// Return the ID of the campaign to jump to (skipping the main menu).
88  std::string jump_to_campaign_id() const;
89  bool new_campaign();
90  bool goto_campaign();
91  bool goto_multiplayer();
92  bool goto_editor();
93 
94  bool jump_to_editor() const { return jump_to_editor_; }
95 
96  void select_mp_server(const std::string& server) { multiplayer_server_ = server; }
97  bool play_multiplayer(mp_selection res);
98  bool play_multiplayer_commandline();
99  bool change_language();
100 
101  void show_preferences();
102 
103  enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
104  void launch_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
105  void play_replay();
106 
108 
109  void start_wesnothd();
110 
111  const commandline_options & opts() const { return cmdline_opts_; }
112 private:
114  void operator=(const game_launcher&);
115 
116  void mark_completed_campaigns(std::vector<config>& campaigns);
117 
118  editor::EXIT_STATUS start_editor(const std::string& filename);
119 
120  /// Internal to the implementation of unit_test(). If a single instance of
121  /// Wesnoth is running multiple unit tests, this gets called once per test.
122  unit_test_result single_unit_test();
123 
125  //Never null.
126  const std::unique_ptr<CVideo> video_;
127 
135 
136  std::vector<std::string> test_scenarios_;
137 
138  std::string screenshot_map_, screenshot_filename_;
139 
142 
143  std::string multiplayer_server_;
146 
148  std::unique_ptr<savegame::load_game_metadata> load_data_;
149 };
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_