From d443df9be13ade6fe8d20627b79f0172157dea9b Mon Sep 17 00:00:00 2001 From: josteph Date: Fri, 7 Sep 2018 14:45:00 +0000 Subject: [PATCH] Commandline: Add --campaign-skip-story option Fixes #3472 (cherry-picked from commit f7be872da24474a47894becd7c6d5f013c495a2f) --- doc/man/wesnoth.6 | 5 +++++ src/commandline_options.cpp | 4 ++++ src/commandline_options.hpp | 2 ++ src/game_launcher.cpp | 7 ++++++- src/game_launcher.hpp | 5 ++++- src/playsingle_controller.cpp | 2 +- src/saved_game.cpp | 3 +++ src/saved_game.hpp | 6 ++++++ src/tests/test_commandline_options.cpp | 5 +++++ 9 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doc/man/wesnoth.6 b/doc/man/wesnoth.6 index 089bcdd64c33..f78d6416ec73 100644 --- a/doc/man/wesnoth.6 +++ b/doc/man/wesnoth.6 @@ -71,6 +71,11 @@ the campaign difficulty selection widget will appear. .BI --campaign-scenario \ id_scenario The id of the scenario from the specified campaign. The default is the first scenario. .TP +.B --campaign-skip-story +Skip story screens and dialog through the end of the +.B start +event. +.TP .BI --core \ id_core overrides the loaded core with the one whose id is specified. .TP diff --git a/src/commandline_options.cpp b/src/commandline_options.cpp index a5680bec1bb0..07d103e0a5f2 100644 --- a/src/commandline_options.cpp +++ b/src/commandline_options.cpp @@ -65,6 +65,7 @@ commandline_options::commandline_options (const std::vector& args) campaign(), campaign_difficulty(), campaign_scenario(), + campaign_skip_story(false), clock(false), data_path(false), data_dir(), @@ -215,6 +216,7 @@ commandline_options::commandline_options (const std::vector& args) ("campaign,c", po::value()->implicit_value(std::string()), "goes directly to the campaign with id . A selection menu will appear if no id was specified.") ("campaign-difficulty", po::value(), "The difficulty of the specified campaign (1 to max). If none specified, the campaign difficulty selection widget will appear.") ("campaign-scenario", po::value(),"The id of the scenario from the specified campaign. The default is the first scenario.") + ("campaign-skip-story", "Skip [story] tags of the specified campaign.") ; po::options_description display_opts("Display options"); @@ -312,6 +314,8 @@ commandline_options::commandline_options (const std::vector& args) campaign_difficulty = vm["campaign-difficulty"].as(); if (vm.count("campaign-scenario")) campaign_scenario = vm["campaign-scenario"].as(); + if (vm.count("campaign-skip-story")) + campaign_skip_story = true; if (vm.count("clock")) clock = true; if (vm.count("core")) diff --git a/src/commandline_options.hpp b/src/commandline_options.hpp index ed1128979cce..e217f207d0f5 100644 --- a/src/commandline_options.hpp +++ b/src/commandline_options.hpp @@ -56,6 +56,8 @@ friend std::ostream& operator<<(std::ostream &os, const commandline_options& cmd boost::optional campaign_difficulty; /// Non-empty if --campaign-scenario was given on the command line. Chooses starting scenario in the campaign to be played. Dependent on --campaign. boost::optional campaign_scenario; + /// True if --skip-story was given on the command line. Skips [story] and [message]s through the end of the "start" event. Dependent on --campaign. + bool campaign_skip_story; /// True if --clock was given on the command line. Enables bool clock; /// Non-empty if --core was given on the command line. Chooses the core to be loaded. diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index d82a460986d7..495bcca43868 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.cpp @@ -118,7 +118,7 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char play_replay_(false), multiplayer_server_(), jump_to_multiplayer_(false), - jump_to_campaign_(false, -1, "", ""), + jump_to_campaign_(false, false, -1, "", ""), jump_to_editor_(false), load_data_() { @@ -164,6 +164,10 @@ game_launcher::game_launcher(const commandline_options& cmdline_opts, const char jump_to_campaign_.scenario_id_ = *cmdline_opts_.campaign_scenario; std::cerr << "selected scenario id: [" << jump_to_campaign_.scenario_id_ << "]\n"; } + + if (cmdline_opts_.campaign_skip_story) { + jump_to_campaign_.skip_story_ = true; + } } if (cmdline_opts_.clock) gui2::dialogs::show_debug_clock_button = true; @@ -728,6 +732,7 @@ bool game_launcher::goto_campaign() { if(jump_to_campaign_.jump_){ if(new_campaign()) { + state_.set_skip_story(jump_to_campaign_.skip_story_); jump_to_campaign_.jump_ = false; launch_game(NO_RELOAD_DATA); }else{ diff --git a/src/game_launcher.hpp b/src/game_launcher.hpp index c4cc4f14f5d7..586c71ba95b2 100644 --- a/src/game_launcher.hpp +++ b/src/game_launcher.hpp @@ -33,14 +33,16 @@ namespace savegame { struct load_game_metadata; } struct jump_to_campaign_info { public: - jump_to_campaign_info(bool jump,int difficulty, const std::string& campaign_id,const std::string& scenario_id) + jump_to_campaign_info(bool jump, bool skip_story, int difficulty, const std::string& campaign_id,const std::string& scenario_id) : jump_(jump) + , skip_story_(skip_story) , difficulty_(difficulty) , campaign_id_(campaign_id) , scenario_id_(scenario_id) { } bool jump_; + bool skip_story_; int difficulty_; std::string campaign_id_,scenario_id_; }; @@ -71,6 +73,7 @@ class game_launcher void set_tutorial(); void set_test(const std::string& id); + /// Return the ID of the campaign to jump to (skipping the main menu). std::string jump_to_campaign_id() const; bool new_campaign(); bool goto_campaign(); diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index 4599d418e11b..910ed85b8e8c 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -228,7 +228,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level) } sound::commit_music_changes(); - if(!this->is_skipping_replay()) { + if(!this->is_skipping_replay() && !saved_game_.skip_story()) { // Combine all the [story] tags into a single config. Handle this here since // storyscreen::controller doesn't have a default constructor. config cfg; diff --git a/src/saved_game.cpp b/src/saved_game.cpp index c2ec2c2654d7..dbdf0fa62409 100644 --- a/src/saved_game.cpp +++ b/src/saved_game.cpp @@ -94,6 +94,7 @@ saved_game::saved_game() , starting_point_type_(STARTING_POINT_NONE) , starting_point_() , replay_data_() + , skip_story_(false) { } @@ -106,6 +107,7 @@ saved_game::saved_game(config cfg) , starting_point_type_(STARTING_POINT_NONE) , starting_point_() , replay_data_() + , skip_story_(false) { set_data(cfg); @@ -120,6 +122,7 @@ saved_game::saved_game(const saved_game& state) , starting_point_type_(state.starting_point_type_) , starting_point_(state.starting_point_) , replay_data_(state.replay_data_) + , skip_story_(state.skip_story_) { } diff --git a/src/saved_game.hpp b/src/saved_game.hpp index 974ad8cb16d0..b04babd7de7a 100644 --- a/src/saved_game.hpp +++ b/src/saved_game.hpp @@ -121,6 +121,10 @@ class saved_game replay_recorder_base& get_replay() { return replay_data_; } const replay_recorder_base& get_replay() const { return replay_data_; } + /// Whether to play [story] tags + bool skip_story() const { return skip_story_; } + void set_skip_story(bool skip_story) { skip_story_ = skip_story; } + private: bool has_carryover_expanded_; /** @@ -143,6 +147,8 @@ class saved_game config starting_point_; replay_recorder_base replay_data_; + + bool skip_story_; }; /** Implement non-member swap function for std::swap (calls @ref saved_game::swap). */ diff --git a/src/tests/test_commandline_options.cpp b/src/tests/test_commandline_options.cpp index 7536a6539478..d9a2abdc47ef 100644 --- a/src/tests/test_commandline_options.cpp +++ b/src/tests/test_commandline_options.cpp @@ -29,6 +29,7 @@ BOOST_AUTO_TEST_CASE (test_empty_options) BOOST_CHECK(!co.campaign); BOOST_CHECK(!co.campaign_difficulty); BOOST_CHECK(!co.campaign_scenario); + BOOST_CHECK(!co.campaign_skip_story); BOOST_CHECK(!co.clock); BOOST_CHECK(!co.data_dir); BOOST_CHECK(!co.data_path); @@ -104,6 +105,7 @@ BOOST_AUTO_TEST_CASE (test_default_options) BOOST_CHECK(co.campaign && co.campaign->empty()); BOOST_CHECK(!co.campaign_difficulty); BOOST_CHECK(!co.campaign_scenario); + BOOST_CHECK(!co.campaign_skip_story); BOOST_CHECK(!co.clock); BOOST_CHECK(!co.data_dir); BOOST_CHECK(!co.data_path); @@ -175,6 +177,7 @@ BOOST_AUTO_TEST_CASE (test_full_options) "--campaign=campfoo", "--campaign-difficulty=16", "--campaign-scenario=scenfoo", + "--campaign-skip-story", "--clock", "--controller=5:confoo", "--controller=6:conbar", @@ -239,6 +242,7 @@ BOOST_AUTO_TEST_CASE (test_full_options) BOOST_CHECK(co.campaign && *co.campaign == "campfoo"); BOOST_CHECK(co.campaign_difficulty && *co.campaign_difficulty == 16); BOOST_CHECK(co.campaign_scenario && *co.campaign_scenario == "scenfoo"); + BOOST_CHECK(co.campaign_skip_story); BOOST_CHECK(co.clock); BOOST_CHECK(co.data_dir && *co.data_dir == "datadirfoo"); BOOST_CHECK(co.data_path); @@ -331,6 +335,7 @@ BOOST_AUTO_TEST_CASE (test_positional_options) BOOST_CHECK(!co.campaign); BOOST_CHECK(!co.campaign_difficulty); BOOST_CHECK(!co.campaign_scenario); + BOOST_CHECK(!co.campaign_skip_story); BOOST_CHECK(!co.clock); BOOST_CHECK(co.data_dir && *co.data_dir == "datadirfoo"); BOOST_CHECK(!co.data_path);