63 #include <boost/optional.hpp>
64 #include <boost/tuple/tuple.hpp>
69 #include <SDL_events.h>
70 #include <SDL_joystick.h>
71 #include <SDL_timer.h>
72 #include <SDL_video.h>
74 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
81 #define WIN32_LEAN_AND_MEAN
89 #define ERR_CONFIG LOG_STREAM(err, log_config)
90 #define WRN_CONFIG LOG_STREAM(warn, log_config)
91 #define LOG_CONFIG LOG_STREAM(info, log_config)
93 #define LOG_GENERAL LOG_STREAM(info, lg::general())
94 #define WRN_GENERAL LOG_STREAM(warn, lg::general())
95 #define DBG_GENERAL LOG_STREAM(debug, lg::general())
98 #define DBG_MP LOG_STREAM(debug, log_mp_create)
101 #define ERR_NET LOG_STREAM(err, log_network)
104 #define LOG_RG LOG_STREAM(info, log_enginerefac)
107 cmdline_opts_(cmdline_opts),
112 main_event_context_(),
115 test_scenario_(
"test"),
117 screenshot_filename_(),
120 multiplayer_server_(),
121 jump_to_multiplayer_(false),
122 jump_to_campaign_(false, -1,
"",
""),
123 jump_to_editor_(false)
125 bool no_music =
false;
126 bool no_sound =
false;
171 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
173 gui2::tdebug_layout_graph::set_domain (*
cmdline_opts_.debug_dot_domain);
192 fps = lexical_cast_default<int>(
"", 50);
194 fps = std::min<int>(fps, 1000);
195 fps = std::max<int>(fps, 1);
198 if(1000 % fps != 0) {
218 if(xres > 0 && yres > 0) {
243 if (cmdline_opts_.username) {
247 if (cmdline_opts_.password) {
251 if (cmdline_opts_.test)
253 if (!cmdline_opts_.test->empty())
254 test_scenario_ = *cmdline_opts_.test;
256 if (cmdline_opts_.unit_test)
258 if (!cmdline_opts_.unit_test->empty()) {
259 test_scenario_ = *cmdline_opts_.unit_test;
263 if (cmdline_opts_.windowed)
264 video().set_fullscreen(
false);
265 if (cmdline_opts_.with_replay)
295 if(SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
296 if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
299 int joysticks = SDL_NumJoysticks();
300 if (joysticks == 0)
return false;
302 SDL_JoystickEventState(SDL_ENABLE);
304 bool joystick_found =
false;
305 for (
int i = 0;
i<joysticks;
i++) {
307 if (SDL_JoystickOpen(
i))
308 joystick_found =
true;
310 return joystick_found;
344 std::cerr <<
"--nogui flag is only valid with --multiplayer or --screenshot or --plugin flags\n";
358 #if !(defined(__APPLE__))
360 if(icon !=
nullptr) {
372 std::cerr <<
"Checking lua scripts... ";
389 std::string full_script((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
404 std::cerr <<
"Loading a plugin file'" << filename <<
"'...\n";
410 throw std::runtime_error(
"failed to open plugin file");
418 std::string full_plugin((std::istreambuf_iterator<char>(*sf)), std::istreambuf_iterator<char>());
424 for (
size_t j = 0 ; j < pm.size(); ++j) {
428 std::cerr <<
"Starting a plugin...\n";
431 for (
size_t j = 0 ; j < pm.size(); ++j) {
437 for (
size_t repeat = 0; repeat < 5; ++repeat) {
438 std::cerr <<
"Playing a slice...\n";
441 for (
size_t j = 0 ; j < pm.size(); ++j) {
447 }
catch (std::exception &
e) {
462 static bool first_time =
true;
500 static bool first_time_unit =
true;
508 first_time_unit =
false;
527 std::cerr <<
"Load_game_exception encountered while loading the unit test!" << std::endl;
530 std::cerr <<
"Caught WML Exception:" << e.
dev_message << std::endl;
552 std::cerr <<
"Failed to load the replay!" << std::endl;
559 if (!(res == LEVEL_RESULT::VICTORY)) {
560 std::cerr <<
"Observed failure on replay" << std::endl;
565 std::cerr <<
"Load_game_exception encountered during play_replay!" << std::endl;
568 std::cerr <<
"WML Exception while playing replay: " << e.
dev_message << std::endl;
603 std::cerr <<
"Error loading game config: " << e.
what() << std::endl;
717 for (
config &campaign : campaigns) {
792 std::string command =
"\"" + wesnothd_program +
"\" -c \"" + config +
"\" -d -t 2 -T 5";
795 std::string command =
"cmd /C start \"wesnoth server\" /B \"" + wesnothd_program +
"\" -c \"" + config +
"\" -t 2 -T 5";
800 SetEnvironmentVariableA(
"SDL_STDIO_REDIRECT",
"0");
802 LOG_GENERAL <<
"Starting wesnothd: "<< command <<
"\n";
803 if (std::system(command.c_str()) == 0) {
811 WRN_GENERAL <<
"Failed to run server start script" << std::endl;
843 }
while (start_server);
880 }
else if((res >= 0 && res <= 2) || res == 4) {
909 ERR_NET <<
"caught network error" << std::endl;
916 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;
boost::optional< std::string > core_id
Non-empty if –core was given on the command line. Chooses the core to be loaded. ...
void show_about(CVideo &video, const std::string &campaign)
Show credits with list of contributors.
boost::optional< std::string > script_file
File to load lua script from.
An error occured 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.
void set_password(const std::string &password)
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 without providing any information.
static lg::log_domain log_mp_create("mp/create")
void show_error_message(CVideo &video, const std::string &message, bool message_use_markup)
Shows an error message to the user.
void discard_input()
Discards all input events.
void _set_resolution(const std::pair< int, int > &res)
void show_wesnothd_server_search(CVideo &video)
bool end_credits
whether to show the standard credits at the end
bool nogui
True if –nogui was given on the command line. Disables GUI.
bool cancel_orders() const
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()
size_t add_plugin(const std::string &name, const std::string &prog)
const char * what() const
void set_gamestate()
Generate the gamestate out of the loaded game config.
void start_client(CVideo &video, const config &game_config, saved_game &state, const std::string &host)
Starts a multiplayer game in client mode.
bool jump_to_multiplayer_
static bool skip_version_check
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
static l_noret error(LoadState *S, const char *why)
Error used when game loading fails.
bool is_campaign_completed(const std::string &campaign_id)
std::string network_host()
const language_def & get_locale()
void show(CVideo &video)
Shows the error in a dialog.
void set_login(const std::string &username)
void mark_completed_campaigns(std::vector< config > &campaigns)
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()
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.
void show_transient_message(CVideo &video, 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 bool execute(CVideo &video)
The execute function see tdialog for more information.
bool noreplaycheck
True if –noreplaycheck was given on the comand line. Dependent on –unit.
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
void the_end(CVideo &video, std::string text, unsigned int duration)
Displays a simple fading screen with any user-provided text.
Definitions for the interface to Wesnoth Markup Language (WML).
void set_language(const std::string &slocale, const std::vector< std::string > *alternates)
boost::optional< std::string > plugin_file
File to load a lua plugin (similar to a script) from. Experimental / may replace script.
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...
bool save_image(const locator &i_locator, const std::string &filename)
static lg::log_domain log_config("config")
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()
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)
bool joystick_support_enabled()
Dialog is closed with ok button.
static lg::log_domain log_enginerefac("enginerefac")
bool nodelay
True if –nodelay was given on the command line.
std::string get_user_data_dir()
std::string normalize_path(const std::string &path)
Returns the absolute path of a file.
void write_file(const std::string &fname, const std::string &data)
Throws io_exception if an error occurs.
void show_preferences_dialog(CVideo &video, const config &game_cfg, const DIALOG_OPEN_TO initial_view)
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.
std::string base_name(const std::string &file)
Returns the base filename of a file, with directory name stripped.
editor::EXIT_STATUS start_editor()
std::istream * istream_file(const std::string &fname, bool treat_failure_as_error=true)
bool init_window()
Initializes a new window, taking into account any preiously saved states.
void load_package()
Loads the "package" package into the Lua environment.
std::string dev_message
The message for developers telling which problem was triggered, this shouldn't be translated...
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)
const std::vector< game_config::server_info > & server_list()
std::string end_text
end-of-campaign text
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...
game_launcher(const commandline_options &cmdline_opts, const char *appname)
std::string campaign
the campaign being played
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.
Templates and utility-routines for strings and numbers.
static void display(CVideo &video, std::function< void()> f)
bool enter_create_mode(CVideo &video, const config &game_config, saved_game &state, jump_to_campaign_info jump_to_campaign, bool local_players_only)
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
std::string screenshot_map_
void set_draw_delay(int value)
boost::optional< std::string > render_image
Image path to render. First parameter after –render-image.
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...
void load_game_config_for_create(bool is_mp)
bool nomusic
True if –nomusic was given on the command line. Disables music.
void run(char const *prog, int nArgs=0)
Runs a plain script.
static bool select_difficulty
std::string get_detailed_status(size_t idx)
void update_font_path() const
Updates the font path, when initialized it sets the fontpath to game_config::path.
std::string get_cache_dir()
static void progress(const char *stage_name=nullptr)
int mp_server_warning_disabled()
std::string jump_to_campaign_id() const
bool debug
True if –debug was given on the command line. Enables debug mode.
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=std::string())
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.
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...
An exception object used when an IO error occurs.
Exception used to signal that the user has decided to abort a game, and to load another game instead...
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).
std::string get_name(size_t idx)
std::string difficulty
The difficulty level the game is being played on.
boost::optional< std::string > render_image_dst
Output file to put rendered image path in. Optional second parameter after –render-image.
std::string get_user_config_dir()
bool screenshot
True if –screenshot was given on the command line. Starts Wesnoth in screenshot mode.
boost::optional< 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.
const commandline_options & cmdline_opts_
void start_local_game_commandline(CVideo &video, const config &game_config, saved_game &state, const commandline_options &cmdline_opts)
Starts a multiplayer game in single-user mode.
Base class for all the errors encountered by the engine.
void start_plugin(size_t idx)
game_classification & classification()
std::string screenshot_filename_
void set_carryover_sides_start(config carryover_sides_start)
bool is_normal_mp_game() const
bool show_debug_clock_button
Do we wish to show the button for the debug clock.
bool set_music(bool ison)
Standard logging facilities (interface).
boost::optional< std::string > screenshot_output_file
Output file to put screenshot in. Second parameter given after –screenshot.
bool set_turn_bell(bool ison)
bool fullscreen
True if –fullscreen was given on the command line. Starts Wesnoth in fullscreen mode.
boost::optional< std::string > language
Non-empty if –language was given on the command line. Sets the language for this session...
std::string test_scenario_
void reload_changed_game_config()
bool nosound
True if –nosound was given on the command line. Disables sound.
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.
Helper class, don't construct this directly.
void clear_current_scenario()
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
bool file_exists(const std::string &name)
Returns true if a file or directory with such name already exists.
static bool cancel_orders
GLsizei const GLcharARB ** string
bool save_game_automatic(CVideo &video, 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 font::manager font_manager_
std::vector< server_info > server_list
boost::optional< std::string > server
Non-empty if –server was given on the command line. Connects Wesnoth to specified server...
bool play_multiplayer_commandline()
static std::string difficulty
boost::optional< boost::tuple< int, int > > resolution
Pair of AxB values specified after –resolution. Changes Wesnoth resolution.
static plugins_manager * get()
EXIT_STATUS start(const config &game_conf, CVideo &video, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
static void delete_empty_menu()
Explicit freeing of class static resources.
void start_local_game(CVideo &video, const config &game_config, saved_game &state)
Starts a multiplayer game in single-user mode.