Moved end_level to the same mechanism as end_turn.

This commit is contained in:
Guillaume Melquiond 2009-08-03 12:39:32 +00:00
parent 16c460a27d
commit 39a8620156
6 changed files with 53 additions and 8 deletions

View File

@ -23,7 +23,6 @@
#include "ai/manager.hpp"
#include "dialogs.hpp"
#include "foreach.hpp"
#include "game_end_exceptions.hpp"
#include "game_display.hpp"
#include "game_events.hpp"
#include "game_preferences.hpp"
@ -2761,18 +2760,22 @@ WML_HANDLER_FUNCTION(endlevel, /*event_info*/, cfg)
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, carryover_report, save, linger_mode);
resources::controller->force_end_level(VICTORY, endlevel_music,
carry_over, gold_add, bonus, carryover_report, save, linger_mode);
} else if(result == "continue") {
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);
resources::controller->force_end_level(VICTORY, endlevel_music,
100, false, false, false, true, false);
} else if(result == "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);
resources::controller->force_end_level(VICTORY, endlevel_music,
100, false, false, false, false, false);
} else {
LOG_NG << "throwing event defeat...\n";
throw end_level_exception(DEFEAT, endlevel_music, -1, false, true, carryover_report, save, linger_mode);
resources::controller->force_end_level(DEFEAT, endlevel_music,
-1, false, true, carryover_report, save, linger_mode);
}
}

View File

@ -18,6 +18,7 @@
#include "global.hpp"
#include "controller_base.hpp"
#include "game_end_exceptions.hpp"
#include "game_events.hpp"
#include "gamestatus.hpp"
#include "generic_event.hpp"
@ -79,7 +80,12 @@ public:
virtual void do_init_side(const unsigned int team_index);
virtual void play_side(const unsigned int team_num, bool save) = 0;
virtual void force_end_turn(){}
virtual void force_end_turn() = 0;
virtual void force_end_level(LEVEL_RESULT res,
const std::string &endlevel_music_list = std::string(),
int percentage = -1, bool add = false, bool bonus = true,
bool report = true, bool prescenario_save = true,
bool linger = true) = 0;
//turn functions
size_t turn() const {return tod_manager_.turn();}

View File

@ -248,6 +248,7 @@ void playmp_controller::play_human_turn(){
}
play_slice();
check_end_level();
} catch(end_level_exception& e) {
turn_data_->send_data();
throw e;

View File

@ -53,6 +53,7 @@ playsingle_controller::playsingle_controller(const config& level,
textbox_info_(),
replay_sender_(recorder),
end_turn_(false),
end_level_(NULL),
player_type_changed_(false),
replaying_(false),
turn_over_(false),
@ -77,6 +78,7 @@ playsingle_controller::~playsingle_controller()
{
ai::manager::remove_observer(this) ;
ai::manager::clear_ais() ;
delete end_level_;
}
@ -135,6 +137,28 @@ void playsingle_controller::force_end_turn(){
end_turn_ = true;
}
void playsingle_controller::force_end_level(LEVEL_RESULT res,
const std::string &endlevel_music_list, int percentage, bool add,
bool bonus, bool report, bool prescenario_save, bool linger)
{
if (end_level_) {
// Or should we merge them instead?
return;
}
end_level_ = new end_level_exception(res, endlevel_music_list, percentage,
add, bonus, report, prescenario_save, linger);
force_end_turn();
}
void playsingle_controller::check_end_level()
{
if (!end_level_) return;
end_level_exception exn(*end_level_);
delete end_level_;
end_level_ = NULL;
throw exn;
}
void playsingle_controller::rename_unit(){
menu_handler_.rename_unit(mouse_handler_);
}
@ -680,6 +704,7 @@ void playsingle_controller::play_human_turn() {
gui_->enable_menu("endturn", true);
while(!end_turn_) {
play_slice();
check_end_level();
gui_->draw();
}
}
@ -730,7 +755,7 @@ void playsingle_controller::linger(upload_log& log)
// Reset the team number to make sure we're the right team.
player_number_ = first_player_;
play_slice();
check_end_level();
gui_->draw();
}
} catch(game::load_game_exception&) {

View File

@ -19,7 +19,6 @@
#include "global.hpp"
#include "cursor.hpp"
#include "game_end_exceptions.hpp"
#include "play_controller.hpp"
struct upload_log;
@ -63,6 +62,11 @@ public:
#endif
void linger(upload_log& log);
virtual void force_end_level(LEVEL_RESULT res, const std::string &endlevel_music_list,
int percentage, bool add, bool bonus, bool report, bool prescenario_save,
bool linger);
void check_end_level();
protected:
virtual void play_turn(bool no_save);
virtual void play_side(const unsigned int team_index, bool save);
@ -85,6 +89,7 @@ protected:
replay_network_sender replay_sender_;
bool end_turn_;
end_level_exception *end_level_;
bool player_type_changed_;
bool replaying_;
bool turn_over_;

View File

@ -45,6 +45,11 @@ public:
void replay_show_team1();
void replay_skip_animation();
virtual void force_end_turn() {}
virtual void force_end_level(LEVEL_RESULT res, const std::string &endlevel_music_list,
int percentage, bool add, bool bonus, bool report, bool prescenario_save,
bool linger) {}
std::vector<team> teams_start_;
protected: