55 #include <boost/process/windows.hpp>
57 #include <boost/process.hpp>
63 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
68 #define ERR_CONFIG LOG_STREAM(err, log_config)
69 #define WRN_CONFIG LOG_STREAM(warn, log_config)
70 #define LOG_CONFIG LOG_STREAM(info, log_config)
72 #define ERR_GENERAL LOG_STREAM(err, lg::general())
73 #define LOG_GENERAL LOG_STREAM(info, lg::general())
74 #define WRN_GENERAL LOG_STREAM(warn, lg::general())
75 #define DBG_GENERAL LOG_STREAM(debug, lg::general())
77 #define LOG_TEST FORCE_LOG_TO(lg::general(), log_config)
80 #define DBG_MP LOG_STREAM(debug, log_mp_create)
83 #define ERR_NET LOG_STREAM(err, log_network)
86 #define LOG_RG LOG_STREAM(info, log_enginerefac)
91 : cmdline_opts_(cmdline_opts)
94 , main_event_context_()
98 , test_scenarios_{
"test"}
100 , screenshot_filename_()
102 , play_replay_(false)
103 , multiplayer_server_()
104 , jump_to_multiplayer_(false)
105 , jump_to_campaign_{}
106 , jump_to_editor_(false)
109 bool no_music =
false;
110 bool no_sound =
false;
142 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
144 gui2::debug_layout_graph::set_domain(*
cmdline_opts_.debug_dot_domain);
146 gui2::debug_layout_graph::set_level(*
cmdline_opts_.debug_dot_level);
178 if(xres > 0 && yres > 0) {
243 }
else if(no_music) {
289 PLAIN_LOG <<
"--nogui flag is only valid with --multiplayer or --screenshot or --plugin flags";
309 #if !(defined(__APPLE__))
311 if(icon !=
nullptr) {
341 std::string full_script((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
361 throw std::runtime_error(
"failed to open plugin file");
369 std::string full_plugin((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
375 for(std::size_t j = 0; j < pm.
size(); ++j) {
382 for(std::size_t j = 0; j < pm.
size(); ++j) {
388 for(std::size_t repeat = 0; repeat < 5; ++repeat) {
392 for(std::size_t j = 0; j < pm.
size(); ++j) {
398 }
catch(
const std::exception&
e) {
426 static bool first_time =
true;
440 PLAIN_LOG <<
"Error in the test handling code";
445 PLAIN_LOG <<
"You can't run more than one unit test in interactive mode";
483 const char* describe_result;
486 describe_result =
"PASS TEST";
489 describe_result =
"FAIL TEST (INVALID REPLAY)";
492 describe_result =
"FAIL TEST (ERRORED REPLAY)";
495 describe_result =
"FAIL TEST (WML EXCEPTION)";
498 describe_result =
"FAIL TEST (DEFEAT)";
501 describe_result =
"PASS TEST (VICTORY)";
504 describe_result =
"BROKE STRICT (PASS)";
507 describe_result =
"BROKE STRICT (FAIL)";
510 describe_result =
"BROKE STRICT (DEFEAT)";
513 describe_result =
"BROKE STRICT (VICTORY)";
516 describe_result =
"FAIL TEST (UNKNOWN)";
520 PLAIN_LOG << describe_result <<
" (" << int(ret) <<
"): " << scenario;
537 if(game_res == level_result::type::fail) {
545 PLAIN_LOG <<
"Caught WML Exception:" <<
e.dev_message;
562 PLAIN_LOG <<
"Failed to load the replay!";
571 PLAIN_LOG <<
"Observed failure on replay";
575 PLAIN_LOG <<
"WML Exception while playing replay: " <<
e.dev_message;
584 if(res == level_result::type::defeat) {
590 }
else if(res == level_result::type::victory) {
631 PLAIN_LOG <<
"Error loading game config: " <<
e.what();
636 std::string outfile =
"wesnoth_image.png";
668 if(!
load.load_game()) {
672 load.set_gamestate();
680 if(
e.message.empty()) {
691 if(
e.message.empty()) {
699 if(
e.message.empty()) {
723 if(
load.data().cancel_orders) {
787 std::string wesnothd_program =
"";
788 if(!
prefs::get().get_mp_server_program_name().empty()) {
804 bp::child
c(wesnothd_program,
"-c",
config);
806 bp::child
c(wesnothd_program,
"-c",
config, bp::windows::create_no_window);
810 using namespace std::chrono_literals;
811 std::this_thread::sleep_for(50ms);
814 catch(
const bp::process_error&
e)
819 WRN_GENERAL <<
"Failed to start server " << wesnothd_program <<
":\n" <<
e.what();
843 if(!gui2::dialogs::mp_connect::execute()) {
880 if(!
e.message.empty()) {
881 ERR_NET <<
"caught network error: " <<
e.message;
883 std::string user_msg;
893 ? conn_err->user_message
894 :
_(
"Connection failed: ") +
e.message;
903 ERR_NET <<
"caught network error";
906 if(!
e.message.empty()) {
907 ERR_CONFIG <<
"caught config::error: " <<
e.message;
933 DBG_MP <<
"starting multiplayer game from the commandline";
952 if(!gui2::dialogs::language_selection::execute()) {
1047 }
catch(std::exception&
e) {
1048 ERR_GENERAL <<
"Suppressing exception thrown during ~game_launcher: " <<
e.what();
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands.
static manager * singleton_
level_result::type play_game()
level_result::type play_replay()
bool nogui
True if –nogui was given on the command line.
utils::optional< std::pair< int, int > > resolution
Pair of AxB values specified after –resolution.
bool headless_unit_test
True if –unit is used and –showgui is not present.
utils::optional< std::string > screenshot_map_file
Map file to make a screenshot of.
utils::optional< std::string > test
Non-empty if –test was given on the command line.
bool windowed
True if –windowed was given on the command line.
utils::optional< std::string > language
Non-empty if –language was given on the command line.
bool noreplaycheck
True if –noreplaycheck was given on the command line.
utils::optional< std::string > screenshot_output_file
Output file to put screenshot in.
utils::optional< int > max_fps
Max FPS specified by –max-fps option.
utils::optional< std::string > core_id
Non-empty if –core was given on the command line.
utils::optional< int > campaign_difficulty
Non-empty if –campaign-difficulty was given on the command line.
bool debug
True if –debug was given on the command line.
bool nosound
True if –nosound was given on the command line.
bool multiplayer
True if –multiplayer was given on the command line.
utils::optional< std::string > server
Non-empty if –server was given on the command line.
bool script_unsafe_mode
Whether to load the "package" package for the scripting environment.
utils::optional< unsigned int > translation_percent
Non-empty if –all-translations or –translations-over is given on the command line.
utils::optional< std::string > plugin_file
File to load a lua plugin (similar to a script) from.
bool nobanner
True if –nobanner was given on the command line.
bool nomusic
True if –nomusic was given on the command line.
bool clock
True if –clock was given on the command line.
utils::optional< std::string > render_image_dst
Output file to put rendered image path in.
utils::optional< std::string > render_image
Image path to render.
utils::optional< std::string > script_file
File to load lua script from.
utils::optional< std::string > campaign
Non-empty if –campaign was given on the command line.
bool new_widgets
True if –new-widgets was given on the command line.
bool fps
True if –fps was given on the command line.
utils::optional< std::string > username
Non-empty if –username was given on the command line.
bool campaign_skip_story
True if –skip-story was given on the command line.
bool with_replay
True if –with-replay was given on the command line.
bool screenshot
True if –screenshot was given on the command line.
std::vector< std::string > unit_test
Non-empty if –unit was given on the command line.
utils::optional< std::string > editor
Non-empty if –editor was given on the command line.
utils::optional< std::string > password
Non-empty if –password was given on the command line.
bool fullscreen
True if –fullscreen was given on the command line.
utils::optional< std::string > campaign_scenario
Non-empty if –campaign-scenario was given on the command line.
utils::optional< std::string > load
Non-empty if –load was given on the command line.
A config object defines a single node in a WML file, with access to child nodes.
std::string label
Name of the game (e.g.
std::string campaign_define
If there is a define the campaign uses to customize data.
bool is_multiplayer() const
static game_config_manager * get()
void load_game_config_for_game(const game_classification &classification, const std::string &scenario_id)
void load_game_config_for_create(bool is_mp, bool is_test=false)
void reload_changed_game_config()
void load_game_config_for_editor()
game_launcher(const commandline_options &cmdline_opts)
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).
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)
bool jump_to_multiplayer_
bool start_in_fullscreen_
unit_test_result pass_victory_or_defeat(level_result::type res)
bool has_load_data() const
bool play_render_image_mode()
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...
@ BROKE_STRICT_TEST_FAIL_BY_DEFEAT
@ TEST_FAIL_LOADING_REPLAY
@ TEST_FAIL_PLAYING_REPLAY
@ TEST_FAIL_WML_EXCEPTION
@ BROKE_STRICT_TEST_PASS_BY_VICTORY
std::string screenshot_map_
const commandline_options & cmdline_opts_
utils::optional< savegame::load_game_metadata > load_data_
void set_test(const std::string &id)
bool play_multiplayer_commandline()
unit_test_result unit_test()
Runs unit tests specified on the command line.
bool play_multiplayer(mp_mode mode)
editor::EXIT_STATUS start_editor()
static void progress(loading_stage stage=loading_stage::none)
Report what is being loaded to the loading screen.
static void display(const std::function< void()> &f)
Generic locator abstracting the location of an image.
void run(char const *prog, const std::string &name, int nArgs=0)
Runs a plain script.
void load_package()
Loads the package library into lua environment.
std::string get_name(std::size_t idx)
static plugins_manager * get()
void start_plugin(std::size_t idx)
std::string get_detailed_status(std::size_t idx)
lua_kernel_base * get_kernel_base()
std::size_t add_plugin(const std::string &name, const std::string &prog)
void set_network_host(const std::string &host)
bool set_music(bool ison)
std::string network_host()
bool set_ui_sound(bool ison)
void set_login(const std::string &login)
void show_wesnothd_server_search()
void set_password(const std::string &server, const std::string &login, const std::string &key)
bool set_turn_bell(bool ison)
void set_show_fps(bool value)
bool set_sound(bool ison)
void set_resolution(const point &res)
static void disable_preferences_save()
std::string get_mp_server_program_name()
void set_mp_server_program_name(const std::string &)
game_classification & classification()
void set_skip_story(bool skip_story)
bool is_mid_game_save() const
bool is_start_of_scenario() const
void set_carryover_sides_start(config carryover_sides_start)
std::string get_scenario_id() const
statistics_record::campaign_stats_t & statistics()
Exception used to signal that the user has decided to abortt a game, and to load another game instead...
The class for loading a savefile.
Class for replay saves (either manually or automatically).
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
bool save_game_automatic(bool ask_for_overwrite=false, const std::string &filename="")
Saves a game without user interaction, unless the file exists and it should be asked to overwrite it.
const std::string & filename() const
static void reset_translations()
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
static lg::log_domain log_enginerefac("enginerefac")
static lg::log_domain log_network("network")
static lg::log_domain log_mp_create("mp/create")
static lg::log_domain log_config("config")
static std::string _(const char *str)
const language_def & get_locale()
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
bool load_language_list()
language_list get_languages(bool all)
Return a list of available translations.
void set_min_translation_percent(int percent)
Standard logging facilities (interface).
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
void point(int x, int y)
Draw a single point.
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
void discard_input()
Discards all input events.
std::string get_cache_dir()
filesystem::scoped_istream istream_file(const std::string &fname, bool treat_failure_as_error)
std::string get_user_data_dir()
static bool file_exists(const bfs::path &fpath)
utils::optional< std::string > get_wml_location(const std::string &path, const utils::optional< std::string > ¤t_dir)
Returns a translated path to the actual file or directory, if it exists.
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
std::unique_ptr< std::istream > scoped_istream
void write_file(const std::string &fname, const std::string &data, std::ios_base::openmode mode)
Throws io_exception if an error occurs.
std::string get_wesnothd_name()
std::string normalize_path(const std::string &fpath, bool normalize_separators, bool resolve_dot_entries)
Returns the absolute path of a file.
Game configuration data as global variables.
std::string get_default_title_string()
std::vector< server_info > server_list
void set_debug(bool new_debug)
bool show_debug_clock_button
Do we wish to show the button for the debug clock.
static bool ui_sound_on()
std::vector< game_tip > load(const config &cfg)
Loads the tips from a config.
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
bool new_widgets
Do we wish to use the new library or not.
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
void flush_cache()
Purges all image caches.
surface get_surface(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image surface suitable for software manipulation.
save_result save_image(const locator &i_locator, const std::string &filename)
@ UNSCALED
Unmodified original-size image.
void start_local_game()
Starts a multiplayer game in single-user mode.
void start_local_game_commandline(const commandline_options &cmdline_opts)
Starts a multiplayer game in single-user mode using command line settings.
void start_client(const std::string &host)
Pubic entry points for the MP workflow.
void clean_saves(const std::string &label)
Delete all autosaves of a certain scenario from the default save directory.
bool select_campaign(saved_game &state, jump_to_campaign_info jump_to_campaign)
void set_language(const std::string &language, const std::vector< std::string > *)
static std::string gettext(const char *str)
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
void set_window_title(const std::string &title)
Sets the title of the main window.
void set_window_icon(surface &icon)
Sets the icon of the main window.
void init(fake type)
Initialize the video subsystem.
void deinit()
Deinitialize the video subsystem.
This file contains the settings handling of the widget library.
std::string filename
Filename.
An exception object used when an IO error occurs.
Base class for all the errors encountered by the engine.
Error used for any general game error, e.g.
Error used when game loading fails.
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.
void clear_current_scenario()
Delete the current scenario from the stats.
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
An error occurred inside the underlying network communication code (boost asio) TODO: find a short na...
std::string user_message
User-friendly and potentially translated message for use in the UI.
An error occurred during when trying to communicate with the wesnothd server.
Error used when the client is rejected by the MP server.
Helper class, don't construct this directly.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...