bug #12227: Added the carryover_report, save and linger_mode attributes to the endlevel tag, added a deprecated message for result=continue and result=continue_no_saves

This commit is contained in:
Christian Bielert 2008-12-23 02:44:00 +00:00
parent 670dd7075e
commit 8fed71047b
9 changed files with 54 additions and 46 deletions

View file

@ -105,6 +105,9 @@ Version 1.5.6+svn:
* If there is a file called _initial.cfg in an included directory, and
no _main.cfg, _initial.cfg is guaranteed to be processed before other
files in the directory.
* [endlevel] has been expanded by the carryover_report=, save= and
linger_mode= attribute. result=continue and continue_no_saves are
now deprecated.
* Miscellaneous and bug fixes:
* Compressed start-of-scenario saves are properly recognized by the
load-game dialog again.

View file

@ -1603,7 +1603,7 @@ void game_controller::launch_game(RELOAD_GAME_DATA reload)
const LEVEL_RESULT result = play_game(disp(),state_,game_config_, log);
// don't show The End for multiplayer scenario
// change this if MP campaigns are implemented
if((result == VICTORY || result == LEVEL_CONTINUE_NO_SAVE) && (state_.campaign_type.empty() || state_.campaign_type != "multiplayer")) {
if(result == VICTORY && (state_.campaign_type.empty() || state_.campaign_type != "multiplayer")) {
the_end(disp(), state_.end_text, state_.end_text_duration);
about::show_about(disp(),state_.campaign);
}

View file

@ -28,8 +28,6 @@ enum LEVEL_RESULT {
VICTORY,
DEFEAT,
QUIT,
LEVEL_CONTINUE,
LEVEL_CONTINUE_NO_SAVE,
OBSERVER_END,
SKIP_TO_LINGER
};
@ -63,9 +61,15 @@ struct end_level_exception {
const std::string& endlevel_music_list="",
const int percentage = -1,
const bool add = false,
const bool bonus=true
const bool bonus=true,
const bool report=true,
const bool prescenario_save=true,
const bool linger=true
)
: result(res)
, carryover_report(report)
, save(prescenario_save)
, linger_mode(linger)
, gold_bonus(bonus)
, carryover_percentage(percentage)
, carryover_add(add)
@ -73,6 +77,9 @@ struct end_level_exception {
{}
LEVEL_RESULT result; /**< Game outcome. */
bool carryover_report; /**< Should a summary of the scenario outcome be displayed?*/
bool save; /**< Should a prescenario be created the next game?*/
bool linger_mode; /**< Should linger mode be invoked?*/
bool gold_bonus; /**< Should early-finish bonus be applied? */
int carryover_percentage; /**< How much gold is carried over to next scenario. */
bool carryover_add; /**< Add or replace next scenario's minimum starting gold. */

View file

@ -2512,6 +2512,10 @@ namespace {
const std::string result = cfg["result"].base_str(); //do not translate
const std::string endlevel_music = cfg["music"];
const bool carryover_report = utils::string_bool(cfg["carryover_report"],true);
const bool save = utils::string_bool(cfg["save"],true);
const bool linger_mode = utils::string_bool(cfg["linger_mode"],true);
if(result.empty() || result == "victory") {
const bool bonus = utils::string_bool(cfg["bonus"],true);
@ -2521,14 +2525,18 @@ namespace {
const bool gold_add = utils::string_bool(cfg["carryover_add"],
game_config::gold_carryover_add);
throw end_level_exception(VICTORY, endlevel_music, carry_over, gold_add, bonus);
throw end_level_exception(VICTORY, endlevel_music, carry_over, gold_add, bonus, carryover_report, save, linger_mode);
} else if(result == "continue") {
throw end_level_exception(LEVEL_CONTINUE, endlevel_music);
lg::wml_error << "continue is deprecated as result in [endlevel],"
<< " use the new attributes instead.\n";
throw end_level_exception(VICTORY, endlevel_music, 100, false, false, false, true, false);
} else if(result == "continue_no_save") {
throw end_level_exception(LEVEL_CONTINUE_NO_SAVE);
lg::wml_error << "continue_no_save is deprecated as result in [endlevel],"
<< " use the new attributes instead.\n";
throw end_level_exception(VICTORY, endlevel_music, 100, false, false, false, false, false);
} else {
LOG_NG << "throwing event defeat...\n";
throw end_level_exception(DEFEAT, endlevel_music);
throw end_level_exception(DEFEAT, endlevel_music, -1, false, true, carryover_report, save, linger_mode);
}
}

View file

@ -2803,7 +2803,7 @@ private:
void console_handler::do_next_level() {
if (!get_data().empty())
menu_handler_.gamestate_.next_scenario = get_data();
throw end_level_exception(LEVEL_CONTINUE_NO_SAVE);
throw end_level_exception(VICTORY, "", 100, false, false, false, true, false);
}
void console_handler::do_choose_level() {
std::vector<std::string> options;
@ -2827,7 +2827,7 @@ private:
if (size_t(choice) < options.size()) {
menu_handler_.gamestate_.next_scenario = options[choice];
throw end_level_exception(LEVEL_CONTINUE_NO_SAVE);
throw end_level_exception(VICTORY, "", 100, false, false, false, true, false);
}
}
void console_handler::do_debug() {

View file

@ -118,15 +118,15 @@ static void clean_saves(const std::string &label)
static LEVEL_RESULT playsingle_scenario(const config& game_config,
const config* level, display& disp, game_state& state_of_game,
const std::vector<config*>& story, upload_log& log, bool skip_replay)
const std::vector<config*>& story, upload_log& log, bool skip_replay, end_level_exception *end_level)
{
const int ticks = SDL_GetTicks();
const int num_turns = atoi((*level)["turns"].c_str());
LOG_NG << "creating objects... " << (SDL_GetTicks() - ticks) << "\n";
playsingle_controller playcontroller(*level, state_of_game, ticks, num_turns, game_config, disp.video(), skip_replay);
LOG_NG << "created objects... " << (SDL_GetTicks() - playcontroller.get_ticks()) << "\n";
const LEVEL_RESULT res = playcontroller.play_scenario(story, log, skip_replay);
const LEVEL_RESULT res = playcontroller.play_scenario(story, log, skip_replay, end_level);
if (res == DEFEAT) {
gui::message_dialog(disp,
@ -135,7 +135,7 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,
).show();
}
if (!disp.video().faked() && res != QUIT && res != LEVEL_CONTINUE && res != LEVEL_CONTINUE_NO_SAVE)
if (!disp.video().faked() && res != QUIT && end_level->linger_mode)
try {
playcontroller.linger(log);
} catch(end_level_exception& e) {
@ -151,14 +151,14 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,
static LEVEL_RESULT playmp_scenario(const config& game_config,
config const* level, display& disp, game_state& state_of_game,
const config::child_list& story, upload_log& log, bool skip_replay,
io_type_t& io_type)
io_type_t& io_type, end_level_exception *end_level)
{
const int ticks = SDL_GetTicks();
const int num_turns = atoi((*level)["turns"].c_str());
playmp_controller playcontroller(*level, state_of_game, ticks, num_turns,
game_config, disp.video(), skip_replay, io_type == IO_SERVER);
const LEVEL_RESULT res = playcontroller.play_scenario(story, log, skip_replay);
const LEVEL_RESULT res = playcontroller.play_scenario(story, log, skip_replay, end_level);
//Check if the player started as mp client and changed to host
if (io_type == IO_CLIENT && playcontroller.is_host())
io_type = IO_SERVER;
@ -171,7 +171,7 @@ static LEVEL_RESULT playmp_scenario(const config& game_config,
}
if (!disp.video().faked() && res != QUIT) {
if(res == LEVEL_CONTINUE || res == LEVEL_CONTINUE_NO_SAVE) {
if(!end_level->linger_mode) {
if(!playcontroller.is_host()) {
// If we continue without lingering we need to
// make sure the host uploads the next scenario
@ -318,7 +318,8 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
bool save_game_after_scenario = true;
LEVEL_RESULT res = LEVEL_CONTINUE;
LEVEL_RESULT res = VICTORY;
end_level_exception *end_level = new end_level_exception(VICTORY);
try {
// Preserve old label eg. replay
@ -370,11 +371,11 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
switch (io_type){
case IO_NONE:
res = playsingle_scenario(game_config,scenario,disp,gamestate,story,log, skip_replay);
res = playsingle_scenario(game_config,scenario,disp,gamestate,story,log, skip_replay, end_level);
break;
case IO_SERVER:
case IO_CLIENT:
res = playmp_scenario(game_config,scenario,disp,gamestate,story,log, skip_replay, io_type);
res = playmp_scenario(game_config,scenario,disp,gamestate,story,log, skip_replay, io_type, end_level);
break;
}
} catch(game::load_game_failed& e) {
@ -436,8 +437,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
gamestate.replay_data.clear();
// On DEFEAT, QUIT, or OBSERVER_END, we're done now
if (res != VICTORY && res != LEVEL_CONTINUE_NO_SAVE
&& res != LEVEL_CONTINUE)
if (res != VICTORY)
{
if (res != OBSERVER_END || gamestate.next_scenario.empty())
return res;
@ -451,7 +451,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// Continue without saving is like a victory,
// but the save game dialog isn't displayed
if(res == LEVEL_CONTINUE_NO_SAVE)
if(!end_level->save)
save_game_after_scenario = false;
// Switch to the next scenario.

View file

@ -231,7 +231,7 @@ void playsingle_controller::report_victory(
}
LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& story, upload_log& log,
bool skip_replay)
bool skip_replay, end_level_exception* end_level_result)
{
LOG_NG << "in playsingle_controller::play_scenario()...\n";
@ -319,6 +319,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
log.quit(status_.turn());
throw;
} catch(end_level_exception& end_level) {
*end_level_result = end_level;
if(!end_level.custom_endlevel_music.empty()) {
switch(end_level.result) {
case DEFEAT:
@ -373,10 +374,9 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
} else {
return QUIT;
}
} else if (end_level.result == VICTORY
|| end_level.result == LEVEL_CONTINUE
|| end_level.result == LEVEL_CONTINUE_NO_SAVE) {
gamestate_.completion = (end_level.result == LEVEL_CONTINUE_NO_SAVE ?
} else if (end_level.result == VICTORY)
{
gamestate_.completion = (!end_level.linger_mode ?
"running" : "victory");
recorder.set_save_info_completion(gamestate_.completion);
try {
@ -425,19 +425,6 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
}
}
// 'continue' is like a victory, except it doesn't announce victory,
// and the player retains 100% of gold.
if(end_level.result == LEVEL_CONTINUE || end_level.result == LEVEL_CONTINUE_NO_SAVE) {
for(i=teams_.begin(); i!=teams_.end(); ++i) {
player_info *player=gamestate_.get_player(i->save_id());
if(player) {
player->gold = i->gold();
}
}
return end_level.result == LEVEL_CONTINUE_NO_SAVE ? LEVEL_CONTINUE_NO_SAVE : VICTORY;
}
std::stringstream report;
std::string title;
@ -482,8 +469,11 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
}
}
}
gui::message_dialog(*gui_, title, report.str()).show();
if(end_level.carryover_report)
{
gui::message_dialog(*gui_, title, report.str()).show();
}
return VICTORY;
} else if (end_level.result == SKIP_TO_LINGER) {

View file

@ -33,7 +33,7 @@ public:
const int ticks, const int num_turns, const config& game_config, CVideo& video, bool skip_replay);
virtual ~playsingle_controller() ;
LEVEL_RESULT play_scenario(const std::vector<config*>& story, upload_log& log, bool skip_replay);
LEVEL_RESULT play_scenario(const std::vector<config*>& story, upload_log& log, bool skip_replay, end_level_exception* end_level = NULL);
virtual void handle_generic_event(const std::string& name);

View file

@ -48,7 +48,7 @@ LEVEL_RESULT play_replay_level(const config& game_config,
} catch (replay::error&) {
}
return LEVEL_CONTINUE;
return VICTORY;
}
replay_controller::replay_controller(const config& level,