67 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
74 #define WIN32_LEAN_AND_MEAN
82 #define ERR_CONFIG LOG_STREAM(err, log_config)
83 #define WRN_CONFIG LOG_STREAM(warn, log_config)
84 #define LOG_CONFIG LOG_STREAM(info, log_config)
86 #define ERR_GENERAL LOG_STREAM(err, lg::general())
87 #define LOG_GENERAL LOG_STREAM(info, lg::general())
88 #define WRN_GENERAL LOG_STREAM(warn, lg::general())
89 #define DBG_GENERAL LOG_STREAM(debug, lg::general())
91 #define LOG_TEST FORCE_LOG_TO(lg::general(), log_config)
94 #define DBG_MP LOG_STREAM(debug, log_mp_create)
97 #define ERR_NET LOG_STREAM(err, log_network)
100 #define LOG_RG LOG_STREAM(info, log_enginerefac)
103 : cmdline_opts_(cmdline_opts)
107 , main_event_context_()
111 , test_scenarios_{
"test"}
113 , screenshot_filename_()
115 , play_replay_(false)
116 , multiplayer_server_()
117 , jump_to_multiplayer_(false)
118 , jump_to_campaign_{}
119 , jump_to_editor_(false)
122 bool no_music =
false;
123 bool no_sound =
false;
172 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
174 gui2::debug_layout_graph::set_domain(*
cmdline_opts_.debug_dot_domain);
196 if(1000 % fps != 0) {
216 if(xres > 0 && yres > 0) {
282 }
else if(no_music) {
327 PLAIN_LOG <<
"--nogui flag is only valid with --multiplayer or --screenshot or --plugin flags";
341 #if !(defined(__APPLE__))
343 if(icon !=
nullptr) {
373 std::string full_script((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
387 PLAIN_LOG <<
"Loading a plugin file'" << filename <<
"'...";
393 throw std::runtime_error(
"failed to open plugin file");
401 std::string full_plugin((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
405 std::size_t
i = pm.
add_plugin(filename, full_plugin);
407 for(std::size_t j = 0; j < pm.
size(); ++j) {
414 for(std::size_t j = 0; j < pm.
size(); ++j) {
420 for(std::size_t repeat = 0; repeat < 5; ++repeat) {
424 for(std::size_t j = 0; j < pm.
size(); ++j) {
430 }
catch(
const std::exception&
e) {
458 static bool first_time =
true;
472 PLAIN_LOG <<
"Error in the test handling code";
477 PLAIN_LOG <<
"You can't run more than one unit test in interactive mode";
515 const char* describe_result;
518 describe_result =
"PASS TEST";
521 describe_result =
"FAIL TEST (INVALID REPLAY)";
524 describe_result =
"FAIL TEST (ERRORED REPLAY)";
527 describe_result =
"FAIL TEST (WML EXCEPTION)";
530 describe_result =
"FAIL TEST (DEFEAT)";
533 describe_result =
"PASS TEST (VICTORY)";
536 describe_result =
"BROKE STRICT (PASS)";
539 describe_result =
"BROKE STRICT (FAIL)";
542 describe_result =
"BROKE STRICT (DEFEAT)";
545 describe_result =
"BROKE STRICT (VICTORY)";
548 describe_result =
"FAIL TEST (UNKNOWN)";
552 PLAIN_LOG << describe_result <<
" (" << int(ret) <<
"): " << scenario;
569 if(game_res == level_result::type::fail) {
577 PLAIN_LOG <<
"Caught WML Exception:" <<
e.dev_message;
594 PLAIN_LOG <<
"Failed to load the replay!";
603 PLAIN_LOG <<
"Observed failure on replay";
607 PLAIN_LOG <<
"WML Exception while playing replay: " <<
e.dev_message;
616 if(res == level_result::type::defeat) {
622 }
else if(res == level_result::type::victory) {
663 PLAIN_LOG <<
"Error loading game config: " <<
e.what();
668 std::string outfile =
"wesnoth_image.png";
700 if(!
load.load_game()) {
704 load.set_gamestate();
712 if(
e.message.empty()) {
723 if(
e.message.empty()) {
731 if(
e.message.empty()) {
755 if(
load.data().cancel_orders) {
835 std::string command =
"\"" + wesnothd_program +
"\" -c \"" +
config +
"\" -d -t 2 -T 5";
838 std::string command =
"cmd /C start \"wesnoth server\" /B \"" + wesnothd_program +
"\" -c \"" +
config +
"\" -t 2 -T 5";
843 SetEnvironmentVariableA(
"SDL_STDIO_REDIRECT",
"0");
846 if (std::system(command.c_str()) == 0) {
854 WRN_GENERAL <<
"Failed to run server start script";
877 if(!gui2::dialogs::mp_connect::execute()) {
914 if(!
e.message.empty()) {
915 ERR_NET <<
"caught network error: " <<
e.message;
917 std::string user_msg;
927 ? conn_err->user_message
928 :
_(
"Connection failed: ") +
e.message;
937 ERR_NET <<
"caught network error";
940 if(!
e.message.empty()) {
941 ERR_CONFIG <<
"caught config::error: " <<
e.message;
967 DBG_MP <<
"starting multiplayer game from the commandline";
981 if(!gui2::dialogs::language_selection::execute()) {
1075 }
catch(std::exception&
e) {
1076 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()
std::optional< std::string > render_image_dst
Output file to put rendered image path in.
bool nogui
True if –nogui was given on the command line.
std::optional< std::string > server
Non-empty if –server was given on the command line.
std::optional< std::string > plugin_file
File to load a lua plugin (similar to a script) from.
bool headless_unit_test
True if –unit is used and –showgui is not present.
bool windowed
True if –windowed was given on the command line.
bool noreplaycheck
True if –noreplaycheck was given on the command line.
std::optional< std::string > render_image
Image path to render.
std::optional< int > campaign_difficulty
Non-empty if –campaign-difficulty was given on the command line.
std::optional< unsigned int > translation_percent
Non-empty if –all-translations or –translations-over is given on the command line.
std::optional< std::string > campaign_scenario
Non-empty if –campaign-scenario was given on the command line.
std::optional< std::string > password
Non-empty if –password 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.
bool script_unsafe_mode
Whether to load the "package" package for the scripting environment.
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.
bool nodelay
True if –nodelay was given on the command line.
std::optional< std::string > username
Non-empty if –username was given on the command line.
bool new_widgets
True if –new-widgets was given on the command line.
std::optional< std::string > load
Non-empty if –load was given on the command line.
std::optional< std::string > campaign
Non-empty if –campaign was given on the command line.
bool fps
True if –fps was given on the command line.
std::optional< std::string > script_file
File to load lua script from.
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.
std::optional< std::string > core_id
Non-empty if –core 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.
bool fullscreen
True if –fullscreen was given on the command line.
std::optional< std::string > test
Non-empty if –test was given on the command line.
std::optional< std::string > language
Non-empty if –language was given on the command line.
std::optional< int > max_fps
Max FPS specified by –max-fps option.
std::optional< std::pair< int, int > > resolution
Pair of AxB values specified after –resolution.
std::optional< std::string > screenshot_map_file
Map file to make a screenshot of.
std::optional< std::string > screenshot_output_file
Output file to put screenshot in.
std::optional< std::string > editor
Non-empty if –editor 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).
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)
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_
font::manager font_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.
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(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)
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()
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(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_config_dir()
std::string get_user_data_dir()
static bool file_exists(const bfs::path &fpath)
std::string get_wml_location(const std::string &filename, const std::string ¤t_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
std::string get_program_invocation(const std::string &program_name)
Returns the appropriate invocation for a Wesnoth-related binary, assuming that it is located in the s...
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 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.
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 disable_preferences_save()
std::string get_mp_server_program_name()
void set_core_id(const std::string &core_id)
void set_mp_server_program_name(const std::string &path)
bool set_turn_bell(bool ison)
bool set_sound(bool ison)
void set_draw_delay(int value)
void set_show_fps(bool value)
std::string network_host()
bool set_music(bool ison)
void set_network_host(const std::string &host)
void _set_maximized(bool ison)
const std::vector< game_config::server_info > & builtin_servers_list()
bool set_UI_sound(bool ison)
void set_level(const std::string &value)
void set_login(const std::string &login)
void set_password(const std::string &server, const std::string &login, const std::string &key)
void _set_resolution(const point &res)
void show_wesnothd_server_search()
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(const std::string &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.
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...