The Battle for Wesnoth  1.15.5+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 #include "game_end_exceptions.hpp" // for LEVEL_RESULT, etc
26 
27 #include <string> // for string
28 #include <vector> // for vector
29 
31 class config;
32 class CVideo;
33 namespace savegame { struct load_game_metadata; }
35 {
36 public:
37  jump_to_campaign_info(bool jump, bool skip_story, int difficulty, const std::string& campaign_id,const std::string& scenario_id)
38  : jump_(jump)
39  , skip_story_(skip_story)
40  , difficulty_(difficulty)
41  , campaign_id_(campaign_id)
42  , scenario_id_(scenario_id)
43  {
44  }
45  bool jump_;
48  std::string campaign_id_,scenario_id_;
49 };
50 
52 {
53 public:
54  game_launcher(const commandline_options& cmdline_opts, const char* appname);
55  ~game_launcher();
56 
57  CVideo& video() { return *video_; }
58 
59  enum mp_selection {MP_CONNECT, MP_HOST, MP_LOCAL};
60 
61  /**
62  * Status code after running a unit test, should match the run_wml_tests
63  * script and the documentation for the --unit_test command-line option.
64  */
65  enum class unit_test_result : int {
66  TEST_PASS = 0,
67  TEST_FAIL = 1,
68  // 2 is reserved for timeouts
69  TEST_FAIL_LOADING_REPLAY = 3,
70  TEST_FAIL_PLAYING_REPLAY = 4,
71  TEST_FAIL_BROKE_STRICT = 5,
72  TEST_FAIL_WML_EXCEPTION = 6,
73  TEST_FAIL_BY_DEFEAT = 7,
74  TEST_PASS_BY_VICTORY = 8,
75  };
76 
77  bool init_video();
78  bool init_language();
79  bool init_lua_script();
80 
81  bool play_test();
82  bool play_screenshot_mode();
83  bool play_render_image_mode();
84  /// Runs unit tests specified on the command line
85  unit_test_result unit_test();
86 
87  bool is_loading() const;
88  void clear_loaded_game();
89  bool load_game();
90  void set_tutorial();
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  bool jump_to_editor() const { return jump_to_editor_; }
101 
102  void select_mp_server(const std::string& server) { multiplayer_server_ = server; }
103  bool play_multiplayer(mp_selection res);
104  bool play_multiplayer_commandline();
105  bool change_language();
106 
107  void show_preferences();
108 
109  enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
110  void launch_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
111  void play_replay();
112 
114 
115  void start_wesnothd();
116 
117  const commandline_options & opts() const { return cmdline_opts_; }
118 private:
120  void operator=(const game_launcher&);
121 
122  void mark_completed_campaigns(std::vector<config>& campaigns);
123 
124  editor::EXIT_STATUS start_editor(const std::string& filename);
125  unit_test_result pass_victory_or_defeat(LEVEL_RESULT res);
126 
127  /// Internal to the implementation of unit_test(). If a single instance of
128  /// Wesnoth is running multiple unit tests, this gets called once per test.
129  unit_test_result single_unit_test();
130 
132  //Never null.
133  const std::unique_ptr<CVideo> video_;
134 
142 
143  std::vector<std::string> test_scenarios_;
144 
145  std::string screenshot_map_, screenshot_filename_;
146 
149 
153 
155  std::unique_ptr<savegame::load_game_metadata> load_data_;
156 };
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
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_
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:369
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_