68 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS 75 #define WIN32_LEAN_AND_MEAN 83 #define ERR_CONFIG LOG_STREAM(err, log_config) 84 #define WRN_CONFIG LOG_STREAM(warn, log_config) 85 #define LOG_CONFIG LOG_STREAM(info, log_config) 87 #define ERR_GENERAL LOG_STREAM(err, lg::general()) 88 #define LOG_GENERAL LOG_STREAM(info, lg::general()) 89 #define WRN_GENERAL LOG_STREAM(warn, lg::general()) 90 #define DBG_GENERAL LOG_STREAM(debug, lg::general()) 92 #define LOG_TEST FORCE_LOG_TO(lg::general(), log_config) 95 #define DBG_MP LOG_STREAM(debug, log_mp_create) 98 #define ERR_NET LOG_STREAM(err, log_network) 101 #define LOG_RG LOG_STREAM(info, log_enginerefac) 104 : cmdline_opts_(cmdline_opts)
108 , main_event_context_()
112 , test_scenarios_{
"test"}
123 bool no_music =
false;
124 bool no_sound =
false;
173 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS 175 gui2::debug_layout_graph::set_domain(*
cmdline_opts_.debug_dot_domain);
197 if(1000 % fps != 0) {
217 if(xres > 0 && yres > 0) {
266 if(!cmdline_opts.nobanner) {
283 }
else if(no_music) {
328 PLAIN_LOG <<
"--nogui flag is only valid with --multiplayer or --screenshot or --plugin flags";
342 #if !(defined(__APPLE__)) 344 if(icon !=
nullptr) {
374 std::string full_script((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
388 PLAIN_LOG <<
"Loading a plugin file'" << filename <<
"'...";
394 throw std::runtime_error(
"failed to open plugin file");
402 std::string full_plugin((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
406 std::size_t
i = pm.
add_plugin(filename, full_plugin);
408 for(std::size_t j = 0; j < pm.
size(); ++j) {
415 for(std::size_t j = 0; j < pm.
size(); ++j) {
421 for(std::size_t repeat = 0; repeat < 5; ++repeat) {
425 for(std::size_t j = 0; j < pm.
size(); ++j) {
431 }
catch(
const std::exception&
e) {
459 static bool first_time =
true;
473 PLAIN_LOG <<
"Error in the test handling code";
478 PLAIN_LOG <<
"You can't run more than one unit test in interactive mode";
516 const char* describe_result;
519 describe_result =
"PASS TEST";
522 describe_result =
"FAIL TEST (INVALID REPLAY)";
525 describe_result =
"FAIL TEST (ERRORED REPLAY)";
528 describe_result =
"FAIL TEST (WML EXCEPTION)";
531 describe_result =
"FAIL TEST (DEFEAT)";
534 describe_result =
"PASS TEST (VICTORY)";
537 describe_result =
"BROKE STRICT (PASS)";
540 describe_result =
"BROKE STRICT (FAIL)";
543 describe_result =
"BROKE STRICT (DEFEAT)";
546 describe_result =
"BROKE STRICT (VICTORY)";
549 describe_result =
"FAIL TEST (UNKNOWN)";
553 PLAIN_LOG << describe_result <<
" (" << int(ret) <<
"): " << scenario;
570 if(game_res == level_result::type::fail) {
595 PLAIN_LOG <<
"Failed to load the replay!";
604 PLAIN_LOG <<
"Observed failure on replay";
617 if(res == level_result::type::defeat) {
623 }
else if(res == level_result::type::victory) {
669 std::string outfile =
"wesnoth_image.png";
701 if(!load.load_game()) {
705 load.set_gamestate();
756 if(load.data().cancel_orders) {
836 std::string command =
"\"" + wesnothd_program +
"\" -c \"" + config +
"\" -d -t 2 -T 5";
839 std::string command =
"cmd /C start \"wesnoth server\" /B \"" + wesnothd_program +
"\" -c \"" + config +
"\" -t 2 -T 5";
844 SetEnvironmentVariableA(
"SDL_STDIO_REDIRECT",
"0");
847 if (std::system(command.c_str()) == 0) {
855 WRN_GENERAL <<
"Failed to run server start script";
878 if(!gui2::dialogs::mp_connect::execute()) {
918 std::string user_msg;
928 ? conn_err->user_message
929 :
_(
"Connection failed: ") + e.
message;
938 ERR_NET <<
"caught network error";
968 DBG_MP <<
"starting multiplayer game from the commandline";
982 if(!gui2::dialogs::language_selection::execute()) {
1076 }
catch(std::exception&
e) {
1077 ERR_GENERAL <<
"Suppressing exception thrown during ~game_launcher: " << e.what();
bool start_in_fullscreen_
void init(fake type)
Initialize the video subsystem.
bool has_load_data() const
An error occurred inside the underlying network communication code (boost asio) TODO: find a short na...
An error occurred during when trying to communicate with the wesnothd server.
bool new_widgets
Do we wish to use the new library or not.
bool set_sound(bool ison)
game_launcher(const commandline_options &cmdline_opts)
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...
static lg::log_domain log_mp_create("mp/create")
std::optional< std::string > core_id
Non-empty if –core was given on the command line.
void discard_input()
Discards all input events.
static void reset_translations()
Error used when the client is rejected by the MP server.
bool is_mid_game_save() const
bool nogui
True if –nogui was given on the command line.
bool play_multiplayer(mp_mode mode)
std::string scenario_id
The ID of the scenario within the campaign to jump to.
The class for loading a savefile.
bool script_unsafe_mode
Whether to load the "package" package for the scripting environment.
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
void _set_maximized(bool ison)
std::string label
Name of the game (e.g.
void disable_preferences_save()
std::optional< std::string > test
Non-empty if –test was given on the command line.
void set_window_title(const std::string &title)
Sets the title of the main window.
bool jump_to_multiplayer_
std::vector< game_tip > load(const config &cfg)
Loads the tips from a config.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
std::optional< std::string > password
Non-empty if –password was given on the command line.
const std::string & filename() const
level_result::type play_game()
Error used when game loading fails.
std::optional< unsigned int > translation_percent
Non-empty if –all-translations or –translations-over is given on the command line.
void show_wesnothd_server_search()
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
static bool file_exists(const bfs::path &fpath)
surface get_surface(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image surface suitable for software manipulation.
std::string network_host()
static void progress(loading_stage stage=loading_stage::none)
Report what is being loaded to the loading screen.
const language_def & get_locale()
filesystem::scoped_istream istream_file(const std::string &fname, bool treat_failure_as_error)
void load_game_config_for_game(const game_classification &classification, const std::string &scenario_id)
void _set_resolution(const point &res)
void deinit()
Deinitialize the video subsystem.
void set_language(const std::string &language, const std::vector< std::string > *)
save_result save_image(const locator &i_locator, const std::string &filename)
std::string get_default_title_string()
void set_min_translation_percent(int percent)
bool fps
True if –fps was given on the command line.
std::vector< std::string > unit_test
Non-empty if –unit was given on the command line.
unit_test_result unit_test()
Runs unit tests specified on the command line.
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
void set_network_host(const std::string &host)
std::string normalize_path(const std::string &fpath, bool normalize_separators, bool resolve_dot_entries)
Returns the absolute path of a file.
bool noreplaycheck
True if –noreplaycheck was given on the command line.
std::optional< std::string > load
Non-empty if –load was given on the command line.
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
std::optional< int > max_fps
Max FPS specified by –max-fps option.
static std::string _(const char *str)
std::string jump_to_campaign_id() const
Return the ID of the campaign to jump to (skipping the main menu).
Definitions for the interface to Wesnoth Markup Language (WML).
std::string user_message
User-friendly and potentially translated message for use in the UI.
jump_to_campaign_info jump_to_campaign_
void flush_cache()
Purges all image caches.
std::string get_scenario_id() const
static lg::log_domain log_config("config")
std::vector< std::string > test_scenarios_
bool with_replay
True if –with-replay was given on the command line.
void set_mp_server_program_name(const std::string &path)
void load_game_config_for_editor()
void show() const
Shows the error in a dialog.
bool play_render_image_mode()
bool headless_unit_test
True if –unit is used and –showgui is not present.
static game_config_manager * get()
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_
bool skip_story
Whether the story screen should be skipped.
std::optional< std::string > render_image_dst
Output file to put rendered image path in.
const std::vector< game_config::server_info > & builtin_servers_list()
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
static lg::log_domain log_enginerefac("enginerefac")
void start_plugin(std::size_t idx)
std::optional< savegame::load_game_metadata > load_data_
level_result::type play_replay()
std::string get_name(std::size_t idx)
This file contains the settings handling of the widget library.
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 start_local_game_commandline(const commandline_options &cmdline_opts)
Starts a multiplayer game in single-user mode using command line settings.
bool nodelay
True if –nodelay was given on the command line.
std::string get_user_data_dir()
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.
static lg::log_domain log_network("network")
std::string multiplayer_server_
std::string campaign_define
If there is a define the campaign uses to customize data.
editor::EXIT_STATUS start_editor()
void set_login(const std::string &login)
std::optional< int > campaign_difficulty
Non-empty if –campaign-difficulty was given on the command line.
language_list get_languages(bool all)
Return a list of available translations.
void load_package()
Loads the package library into lua environment.
bool windowed
True if –windowed was given on the command line.
void set_show_fps(bool value)
std::unique_ptr< std::istream > scoped_istream
void set_test(const std::string &id)
void set_password(const std::string &server, const std::string &login, const std::string &key)
void set_core_id(const std::string &core_id)
bool multiplayer
True if –multiplayer was given on the command line.
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands...
const char * what() const noexcept
bool clock
True if –clock was given on the command line.
Error used for any general game error, e.g.
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
bool is_multiplayer() const
bool nobanner
True if –nobanner was given on the command line.
std::string screenshot_map_
void set_window_icon(surface &icon)
Sets the icon of the main window.
void set_draw_delay(int value)
void set_level(const std::string &value)
std::optional< std::string > render_image
Image path to render.
Helper class, don't construct this directly.
bool nomusic
True if –nomusic was given on the command line.
std::string dev_message
The message for developers telling which problem was triggered, this shouldn't be translated...
std::optional< std::string > campaign
Non-empty if –campaign was given on the command line.
std::string get_cache_dir()
Exception used to signal that the user has decided to abortt a game, and to load another game instead...
void run(char const *prog, const std::string &name, int nArgs=0)
Runs a plain script.
void write_file(const std::string &fname, const std::string &data, std::ios_base::openmode mode)
Throws io_exception if an error occurs.
static std::string gettext(const char *str)
bool debug
True if –debug was given on the command line.
std::size_t add_plugin(const std::string &name, const std::string &prog)
std::string get_mp_server_program_name()
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...
void clean_saves(const std::string &label)
Delete all autosaves of a certain scenario from the default save directory.
void load_game_config_for_create(bool is_mp, bool is_test=false)
Game configuration data as global variables.
bool new_widgets
True if –new-widgets was given on the command line.
std::optional< std::string > screenshot_output_file
Output file to put screenshot in.
An exception object used when an IO error occurs.
bool load_language_list()
bool set_UI_sound(bool ison)
Declarations for File-IO.
std::optional< std::string > script_file
File to load lua script from.
std::optional< std::string > username
Non-empty if –username was given on the command line.
unit_test_result pass_victory_or_defeat(level_result::type res)
Class for replay saves (either manually or automatically).
bool campaign_skip_story
True if –skip-story was given on the command line.
unit_test_result single_unit_test()
Internal to the implementation of unit_test().
static manager * singleton_
std::optional< std::string > server
Non-empty if –server was given on the command line.
std::string get_user_config_dir()
bool screenshot
True if –screenshot was given on the command line.
std::string get_detailed_status(std::size_t idx)
static void display(std::function< void()> f)
const commandline_options & cmdline_opts_
bool select_campaign(saved_game &state, jump_to_campaign_info jump_to_campaign)
Base class for all the errors encountered by the engine.
game_classification & classification()
std::string screenshot_filename_
void set_carryover_sides_start(config carryover_sides_start)
std::optional< std::string > screenshot_map_file
Map file to make a screenshot of.
bool set_music(bool ison)
Standard logging facilities (interface).
void set_skip_story(bool skip_story)
bool set_turn_bell(bool ison)
bool fullscreen
True if –fullscreen was given on the command line.
bool jump
Whether the game should immediately start a campaign.
std::optional< std::string > editor
Non-empty if –editor was given on the command line.
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
void point(int x, int y)
Draw a single point.
void launch_game(reload_mode reload=reload_mode::RELOAD_DATA)
int difficulty
The difficulty at which to launch the campaign.
void reload_changed_game_config()
bool nosound
True if –nosound was given on the command line.
bool play_screenshot_mode()
lua_kernel_base * get_kernel_base()
A config object defines a single node in a WML file, with access to child nodes.
std::optional< std::string > campaign_scenario
Non-empty if –campaign-scenario was given on the command line.
void clear_current_scenario()
Delete the current scenario from the stats.
Unmodified original-size image.
void start_client(const std::string &host)
Pubic entry points for the MP workflow.
std::optional< std::pair< int, int > > resolution
Pair of AxB values specified after –resolution.
std::vector< server_info > server_list
std::optional< std::string > plugin_file
File to load a lua plugin (similar to a script) from.
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...
bool play_multiplayer_commandline()
void set_debug(bool new_debug)
static plugins_manager * get()
bool show_debug_clock_button
Do we wish to show the button for the debug clock.
std::string campaign_id
The ID of the campaign to launch.
void start_local_game()
Starts a multiplayer game in single-user mode.
std::optional< std::string > language
Non-empty if –language was given on the command line.
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.