Skip to content

Commit

Permalink
go to next scenario if there is at least one human
Browse files Browse the repository at this point in the history
defeated sides in mp now also advance to the next scenario if there is
at least one networked human side that got a victory.
  • Loading branch information
gfgtdf committed May 31, 2014
1 parent e50a778 commit 1443713
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/game_end_exceptions.cpp
Expand Up @@ -24,6 +24,7 @@ transient_end_level::transient_end_level()
, custom_endlevel_music()
, reveal_map(true)
, disabled(false)
, proceed_to_next_level(false)
{}

end_level_data::end_level_data()
Expand Down
1 change: 1 addition & 0 deletions src/game_end_exceptions.hpp
Expand Up @@ -91,6 +91,7 @@ struct transient_end_level{
std::string custom_endlevel_music; /**< Custom short music played at the end. */
bool reveal_map; /**< Should we reveal map when game is ended? (Multiplayer only) */
bool disabled; /**< Limits execution of tag [endlevel] to a single time > */
bool proceed_to_next_level; /**< whether to proceed to the next scenario, equals (res == VICTORY) in sp. > */
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/play_controller.cpp
Expand Up @@ -1490,6 +1490,8 @@ void play_controller::check_victory()
}

DBG_NG << "throwing end level exception..." << std::endl;
//Also proceed to the next scenario when another player survived.
end_level_data_.transient.proceed_to_next_level = found_player || found_network_player;
throw end_level_exception(found_player ? VICTORY : DEFEAT);
}

Expand Down
95 changes: 46 additions & 49 deletions src/playcampaign.cpp
Expand Up @@ -97,10 +97,10 @@ static void clear_carryover_WML (game_state & gamestate) {
}
}

static void store_carryover(game_state& gamestate, playsingle_controller& playcontroller, display& disp, const end_level_data& end_level){
static void store_carryover(game_state& gamestate, playsingle_controller& playcontroller, display& disp, const end_level_data& end_level, const LEVEL_RESULT res){
bool has_next_scenario = !resources::gamedata->next_scenario().empty() &&
resources::gamedata->next_scenario() != "null";

//explain me: when could this be the case??
if(resources::teams->size() < 1){
gamestate.carryover_sides_start["next_scenario"] = resources::gamedata->next_scenario();
return;
Expand All @@ -117,9 +117,12 @@ static void store_carryover(game_state& gamestate, playsingle_controller& playco

if (obs) {
title = _("Scenario Report");
} else {
} else if (res == VICTORY) {
title = _("Victory");
report << "<b>" << _("You have emerged victorious!") << "</b>\n\n";
} else {
title = _("Defeat");
report << _("You have been defeated!") << "\n";
}

std::vector<team> teams = playcontroller.get_teams_const();
Expand All @@ -130,7 +133,7 @@ static void store_carryover(game_state& gamestate, playsingle_controller& playco
}
}

if (persistent_teams > 0 && (has_next_scenario ||
if (persistent_teams > 0 && ((has_next_scenario && end_level.transient.proceed_to_next_level)||
gamestate.classification().campaign_type == game_classification::TEST))
{
gamemap map = playcontroller.get_map_const();
Expand Down Expand Up @@ -296,25 +299,17 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,
config& cfg_end_level = state_of_game.carryover_sides.child_or_add("end_level_data");
end_level.write(cfg_end_level);

if (res == DEFEAT) {
if (resources::persist != NULL)
resources::persist->end_transaction();
gui2::show_transient_message(disp.video(),
_("Defeat"),
_("You have been defeated!")
);
}
else if(res == VICTORY){
store_carryover(state_of_game, playcontroller, disp, end_level);
}

if (!disp.video().faked() && res != QUIT)
if (res != QUIT)
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
store_carryover(state_of_game, playcontroller, disp, end_level, res);
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
}
}
}
}
Expand Down Expand Up @@ -347,27 +342,26 @@ static LEVEL_RESULT playmp_scenario(const config& game_config,
if (io_type == IO_CLIENT && playcontroller.is_host())
io_type = IO_SERVER;

if (res == DEFEAT) {
if (resources::persist != NULL)
resources::persist->end_transaction();
gui2::show_transient_message(disp.video(),
_("Defeat"),
_("You have been defeated!")
);
}
else if(res == VICTORY){
store_carryover(state_of_game, playcontroller, disp, end_level);
}
else if(res == OBSERVER_END){
state_of_game.carryover_sides_start["next_scenario"] = resources::gamedata->next_scenario();
}

if (!disp.video().faked() && res != QUIT) {
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
if (res != QUIT)
{
if(res != OBSERVER_END)
{
//We need to call this before linger because it also prints the defeated/victory message.
//(we want to see that message before entering the linger mode)
store_carryover(state_of_game, playcontroller, disp, end_level, res);
}
else
{
state_of_game.carryover_sides_start["next_scenario"] = resources::gamedata->next_scenario();
}
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
}
}
}
}
Expand Down Expand Up @@ -535,13 +529,16 @@ LEVEL_RESULT play_game(game_display& disp, game_state& gamestate,
gamestate.replay_start().clear();

// On DEFEAT, QUIT, or OBSERVER_END, we're done now
if (res != VICTORY)
//if(res == QUIT || ((res != VICTORY) && gamestate.carryover_sides_start["next_scenario"].empty()))

//If there is no next scenario we're done now.
if(res == QUIT || !end_level.transient.proceed_to_next_level || gamestate.carryover_sides_start["next_scenario"].empty())
{
gamestate.snapshot = config();
return res;
}
else if(res == OBSERVER_END)
{
if (res != OBSERVER_END || gamestate.carryover_sides_start["next_scenario"].empty()) {
gamestate.snapshot = config();
return res;
}

const int dlg_res = gui2::show_message(disp.video(), _("Game Over"),
_("This scenario has ended. Do you want to continue the campaign?"),
gui2::tmessage::yes_no_buttons);
Expand Down
4 changes: 4 additions & 0 deletions src/playsingle_controller.cpp
Expand Up @@ -165,6 +165,7 @@ void playsingle_controller::check_end_level()
}
return;
}
get_end_level_data().transient.proceed_to_next_level = (level_result_ == VICTORY);
throw end_level_exception(level_result_);
}

Expand Down Expand Up @@ -524,6 +525,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
if(defeat_music.empty() != true)
sound::play_music_once(defeat_music);

persist_.end_transaction();
return DEFEAT;
} else {
return QUIT;
Expand Down Expand Up @@ -1001,6 +1003,8 @@ void playsingle_controller::check_time_over(){
}

check_victory();

get_end_level_data().transient.proceed_to_next_level = false;
throw end_level_exception(DEFEAT);
}
}
Expand Down

0 comments on commit 1443713

Please sign in to comment.