73 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS 80 #define WIN32_LEAN_AND_MEAN 88 #define ERR_CONFIG LOG_STREAM(err, log_config) 89 #define WRN_CONFIG LOG_STREAM(warn, log_config) 90 #define LOG_CONFIG LOG_STREAM(info, log_config) 92 #define LOG_GENERAL LOG_STREAM(info, lg::general()) 93 #define WRN_GENERAL LOG_STREAM(warn, lg::general()) 94 #define DBG_GENERAL LOG_STREAM(debug, lg::general()) 97 #define DBG_MP LOG_STREAM(debug, log_mp_create) 100 #define ERR_NET LOG_STREAM(err, log_network) 103 #define LOG_RG LOG_STREAM(info, log_enginerefac) 106 cmdline_opts_(cmdline_opts),
111 main_event_context_(),
115 test_scenarios_{
"test"},
126 bool no_music =
false;
127 bool no_sound =
false;
179 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS 181 gui2::debug_layout_graph::set_domain (*
cmdline_opts_.debug_dot_domain);
201 if(1000 % fps != 0) {
221 if(xres > 0 && yres > 0) {
323 std::cerr <<
"--nogui flag is only valid with --multiplayer or --screenshot or --plugin flags\n";
337 #if !(defined(__APPLE__)) 339 if(icon !=
nullptr) {
351 std::cerr <<
"Checking lua scripts... ";
368 std::string full_script((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
383 std::cerr <<
"Loading a plugin file'" << filename <<
"'...\n";
389 throw std::runtime_error(
"failed to open plugin file");
397 std::string full_plugin((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
401 std::size_t
i = pm.
add_plugin(filename, full_plugin);
403 for (std::size_t j = 0 ; j < pm.size(); ++j) {
407 std::cerr <<
"Starting a plugin...\n";
410 for (std::size_t j = 0 ; j < pm.size(); ++j) {
416 for (std::size_t repeat = 0; repeat < 5; ++repeat) {
417 std::cerr <<
"Playing a slice...\n";
420 for (std::size_t j = 0 ; j < pm.size(); ++j) {
426 }
catch (
const std::exception &
e) {
448 config {
"next_scenario",
id}
457 static bool first_time =
true;
469 std::cerr <<
"Error in the test handling code" << std::endl;
473 std::cerr <<
"You can't run more than one unit test in interactive mode" << std::endl;
511 const char* describe_result;
514 describe_result =
"PASS TEST";
517 describe_result =
"FAIL TEST (INVALID REPLAY)";
520 describe_result =
"FAIL TEST (ERRORED REPLAY)";
523 describe_result =
"FAIL TEST";
526 std::cerr << describe_result <<
": " << scenario << std::endl;
541 LEVEL_RESULT res = ccontroller.
play_game();
546 std::cerr <<
"Caught WML Exception:" << e.
dev_message << std::endl;
561 std::cerr <<
"Failed to load the replay!" << std::endl;
569 std::cerr <<
"Observed failure on replay" << std::endl;
573 std::cerr <<
"WML Exception while playing replay: " << e.
dev_message << std::endl;
607 std::cerr <<
"Error loading game config: " << e.
what() << std::endl;
612 std::string outfile =
"wesnoth_image.bmp";
640 load.
data() = std::move(*load_data);
716 config {
"next_scenario",
"tutorial"}
723 for (
config &campaign : campaigns) {
786 const std::string wesnothd_program =
797 std::string command =
"\"" + wesnothd_program +
"\" -c \"" + config +
"\" -d -t 2 -T 5";
800 std::string command =
"cmd /C start \"wesnoth server\" /B \"" + wesnothd_program +
"\" -c \"" + config +
"\" -t 2 -T 5";
805 SetEnvironmentVariableA(
"SDL_STDIO_REDIRECT",
"0");
807 LOG_GENERAL <<
"Starting wesnothd: "<< command <<
"\n";
808 if (std::system(command.c_str()) == 0) {
816 WRN_GENERAL <<
"Failed to run server start script" << std::endl;
847 if(!gui2::dialogs::mp_connect::execute()) {
888 std::string user_msg;
898 ? conn_err->user_message
899 :
_(
"Connection failed: ") + e.
message;
908 ERR_NET <<
"caught network error" << std::endl;
915 ERR_CONFIG <<
"caught config::error" << std::endl;
925 std::cerr <<
"caught game::error...\n";
938 DBG_MP <<
"starting multiplayer game from the commandline" << std::endl;
958 if(!gui2::dialogs::language_selection::execute()) {
998 LEVEL_RESULT result = ccontroller.
play_game();
boost::optional< std::string > core_id
Non-empty if –core was given on the command line. Chooses the core to be loaded. ...
constexpr const T & clamp(const T &value, const T &min, const T &max)
an error occurred inside the underlying network communication code (boost asio) TODO: find a short na...
boost::optional< std::string > script_file
File to load lua script from.
An error occurred during when trying to coommunicate with the wesnothd server.
bool new_widgets
Do we wish to use the new library or not.
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
unsigned int end_text_duration
for how long the end-of-campaign text is shown
void set_window_icon(surface &icon)
Sets the icon of the main window.
bool set_sound(bool ison)
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...
LEVEL_RESULT play_replay()
bool load_game()
Load a game with pre-setting information for the load-game dialog.
static lg::log_domain log_mp_create("mp/create")
void discard_input()
Discards all input events.
bool end_credits
whether to show the standard credits at the end
void start_local_game_commandline(const config &game_config, saved_game &state, const commandline_options &cmdline_opts)
Starts a multiplayer game in single-user mode.
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. Disables GUI.
The class for loading a savefile.
bool script_unsafe_mode
Whether to load the "package" package for the scripting environment. (This allows to load arbitrary l...
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()
void set_gamestate()
Generate the gamestate out of the loaded game config.
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...
static l_noret error(LoadState *S, const char *why)
Error used when game loading fails.
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)
bool is_campaign_completed(const std::string &campaign_id)
std::string network_host()
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, const bool restore_background)
Shows a transient message to the user.
static void progress(loading_stage stage=loading_stage::none)
const language_def & get_locale()
filesystem::scoped_istream istream_file(const std::string &fname, bool treat_failure_as_error)
void _set_resolution(const point &res)
void set_language(const std::string &language, const std::vector< std::string > *)
boost::optional< std::string > username
Non-empty if –username was given on the command line. Forces Wesnoth to use this network username...
bool is_normal_mp_game() const
void mark_completed_campaigns(std::vector< config > &campaigns)
save_result save_image(const locator &i_locator, const std::string &filename)
boost::optional< std::string > campaign_scenario
Non-empty if –campaign-scenario was given on the command line. Chooses starting scenario in the camp...
std::string get_default_title_string()
void set_min_translation_percent(int percent)
boost::optional< int > max_fps
Max FPS specified by –max-fps option.
bool fps
True if –fps was given on the command line. Shows number of fps.
std::vector< std::string > unit_test
Non-empty if –unit was given on the command line. Goes directly into unit test mode, into a scenario, if specified.
unit_test_result unit_test()
Runs unit tests specified on the command line.
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. Dependent on –unit.
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
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).
load_game_metadata & data()
boost::optional< std::string > plugin_file
File to load a lua plugin (similar to a script) from. Experimental / may replace script.
std::string user_message
User-friendly and potentially translated message for use in the UI.
jump_to_campaign_info jump_to_campaign_
boost::optional< std::string > load
Non-empty if –load was given on the command line. Savegame specified to load after start...
static lg::log_domain log_config("config")
bool play_multiplayer(mp_selection res)
std::vector< std::string > test_scenarios_
bool with_replay
True if –with-replay was given on the command line. Shows replay of the loaded file.
void set_mp_server_program_name(const std::string &path)
void set_window_title(const std::string &title)
Sets the title of the main window.
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()
static UNUSEDNOWARN std::string _(const char *str)
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_
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::string get_name(std::size_t idx)
This file contains the settings handling of the widget library.
bool nodelay
True if –nodelay was given on the command line.
std::string get_user_data_dir()
void write_file(const std::string &fname, const std::string &data)
Throws io_exception if an error occurs.
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)
boost::optional< unsigned int > translation_percent
Non-empty if –all-translations or –translations-over is given on the command line.
void load_package()
Loads the package library into lua environment.
bool windowed
True if –windowed was given on the command line. Starts Wesnoth in windowed mode.
boost::optional< std::string > editor
Non-empty if –editor was given on the command line. Goes directly into editor. If string is longer t...
void set_show_fps(bool value)
std::unique_ptr< std::istream > scoped_istream
void set_test(const std::string &id)
std::string end_text
end-of-campaign text
void set_password(const std::string &server, const std::string &login, const std::string &key)
void set_core_id(const std::string &core_id)
boost::optional< std::string > test
Non-empty if –test was given on the command line. Goes directly into test mode, into a scenario...
void init_textdomains(const config &cfg)
Initializes the list of textdomains from a configuration object.
bool multiplayer
True if –multiplayer was given on the command line. Goes directly into multiplayer mode...
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands...
std::string sanitize_path(const std::string &path)
Sanitizes a path to remove references to the user's name.
if(win_locale=="af") win_locale
game_launcher(const commandline_options &cmdline_opts, const char *appname)
std::string campaign
The id of the campaign being played.
const char * what() const noexcept
bool clock
True if –clock was given on the command line. Enables.
static UNUSEDNOWARN std::string gettext(const char *str)
Error used for any general game error, e.g.
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
std::string screenshot_map_
std::unique_ptr< savegame::load_game_metadata > load_data_
void set_draw_delay(int value)
boost::optional< std::string > render_image
Image path to render. First parameter after –render-image.
void start_client(const config &game_config, saved_game &state, const std::string &host)
Starts a multiplayer game in client mode.
void set_level(const std::string &value)
boost::optional< int > campaign_difficulty
Non-empty if –campaign-difficulty was given on the command line. Numerical difficulty of the campaig...
Helper class, don't construct this directly.
bool nomusic
True if –nomusic was given on the command line. Disables music.
std::string dev_message
The message for developers telling which problem was triggered, this shouldn't be translated...
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.
static void display(const config &game_cfg, const preferences::PREFERENCE_VIEW initial_view=preferences::VIEW_DEFAULT)
The display function – see modal_dialog for more information.
boost::optional< std::string > password
Non-empty if –password was given on the command line. Forces Wesnoth to use this network password...
bool debug
True if –debug was given on the command line. Enables debug mode.
void start_local_game(const config &game_config, saved_game &state)
Starts a multiplayer game in single-user mode.
std::size_t add_plugin(const std::string &name, const std::string &prog)
std::string get_mp_server_program_name()
boost::optional< std::string > screenshot_map_file
Map file to make a screenshot of. First parameter given after –screenshot.
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. Hidden option to enable the new widget toolkit...
void init_window()
Initializes a new SDL window instance, taking into account any preiously saved states.
An exception object used when an IO error occurs.
void add_completed_campaign(const std::string &campaign_id, const std::string &difficulty_level)
bool load_language_list()
language_list get_languages()
void set_fullscreen(bool ison)
bool set_UI_sound(bool ison)
Declarations for File-IO.
static void save(LexState *ls, int c)
void launch_game(RELOAD_GAME_DATA reload=RELOAD_DATA)
Class for replay saves (either manually or automatically).
bool campaign_skip_story
True if –skip-story was given on the command line. Skips [story] and [message]s through the end of t...
std::string difficulty
The difficulty level the game is being played on.
unit_test_result single_unit_test()
Internal to the implementation of unit_test().
boost::optional< std::string > render_image_dst
Output file to put rendered image path in. Optional second parameter after –render-image.
std::string base_name(const std::string &file, const bool remove_extension)
Returns the base filename of a file, with directory name stripped.
static manager * singleton_
std::string get_user_config_dir()
bool screenshot
True if –screenshot was given on the command line. Starts Wesnoth in screenshot mode.
std::string get_detailed_status(std::size_t idx)
static void display(std::function< void()> f)
const commandline_options & cmdline_opts_
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)
bool set_music(bool ison)
Standard logging facilities (interface).
void set_skip_story(bool skip_story)
boost::optional< std::string > screenshot_output_file
Output file to put screenshot in. Second parameter given after –screenshot.
bool set_turn_bell(bool ison)
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.
bool fullscreen
True if –fullscreen was given on the command line. Starts Wesnoth in fullscreen mode.
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
boost::optional< std::string > language
Non-empty if –language was given on the command line. Sets the language for this session...
void reload_changed_game_config()
bool nosound
True if –nosound was given on the command line. Disables sound.
boost::optional< std::pair< int, int > > resolution
Pair of AxB values specified after –resolution. Changes Wesnoth resolution.
bool play_screenshot_mode()
lua_kernel_base * get_kernel_base()
boost::optional< std::string > campaign
Non-empty if –campaign was given on the command line. ID of the campaign we want to start...
A config object defines a single node in a WML file, with access to child nodes.
void clear_current_scenario()
Delete the current scenario from the stats.
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
bool enter_create_mode(saved_game &state, jump_to_campaign_info jump_to_campaign)
std::vector< server_info > server_list
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...
boost::optional< std::string > server
Non-empty if –server was given on the command line. Connects Wesnoth to specified server...
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.