Skip to content

Commit

Permalink
Commandline: Add --campaign-skip-story option
Browse files Browse the repository at this point in the history
Fixes #3472

(cherry-picked from commit f7be872)
  • Loading branch information
jostephd authored and loonycyborg committed Oct 7, 2018
1 parent 2053901 commit d443df9
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions doc/man/wesnoth.6
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/commandline_options.cpp
Expand Up @@ -65,6 +65,7 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
campaign(),
campaign_difficulty(),
campaign_scenario(),
campaign_skip_story(false),
clock(false),
data_path(false),
data_dir(),
Expand Down Expand Up @@ -215,6 +216,7 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
("campaign,c", po::value<std::string>()->implicit_value(std::string()), "goes directly to the campaign with id <arg>. A selection menu will appear if no id was specified.")
("campaign-difficulty", po::value<int>(), "The difficulty of the specified campaign (1 to max). If none specified, the campaign difficulty selection widget will appear.")
("campaign-scenario", po::value<std::string>(),"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");
Expand Down Expand Up @@ -312,6 +314,8 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
campaign_difficulty = vm["campaign-difficulty"].as<int>();
if (vm.count("campaign-scenario"))
campaign_scenario = vm["campaign-scenario"].as<std::string>();
if (vm.count("campaign-skip-story"))
campaign_skip_story = true;
if (vm.count("clock"))
clock = true;
if (vm.count("core"))
Expand Down
2 changes: 2 additions & 0 deletions src/commandline_options.hpp
Expand Up @@ -56,6 +56,8 @@ friend std::ostream& operator<<(std::ostream &os, const commandline_options& cmd
boost::optional<int> 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<std::string> 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.
Expand Down
7 changes: 6 additions & 1 deletion src/game_launcher.cpp
Expand Up @@ -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_()
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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{
Expand Down
5 changes: 4 additions & 1 deletion src/game_launcher.hpp
Expand Up @@ -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_;
};
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/playsingle_controller.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/saved_game.cpp
Expand Up @@ -94,6 +94,7 @@ saved_game::saved_game()
, starting_point_type_(STARTING_POINT_NONE)
, starting_point_()
, replay_data_()
, skip_story_(false)
{
}

Expand All @@ -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);
Expand All @@ -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_)
{
}

Expand Down
6 changes: 6 additions & 0 deletions src/saved_game.hpp
Expand Up @@ -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_;
/**
Expand All @@ -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). */
Expand Down
5 changes: 5 additions & 0 deletions src/tests/test_commandline_options.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d443df9

Please sign in to comment.