First cut at new end-of-turn logic.

Currently works only for single-player.  Issues: Needs some kind of
visible indication on the display.  Also, saves made during the
post-victory-or-defeat linger could be reloaded and abused for
experience farming.
This commit is contained in:
Eric S. Raymond 2007-07-31 22:56:06 +00:00
parent e635a5a51d
commit 31ccad0752
5 changed files with 32 additions and 6 deletions

View File

@ -40,7 +40,7 @@ play_controller::play_controller(const config& level, const game_data& gameinfo,
loading_game_(level["playing_team"].empty() == false),
first_human_team_(-1), player_number_(1),
first_player_ (lexical_cast_default<unsigned int,std::string>(level_["playing_team"], 0) + 1),
start_turn_(status_.turn()), skip_replay_(skip_replay), browse_(false), scrolling_(false)
start_turn_(status_.turn()), skip_replay_(skip_replay), browse_(false), linger_(false), scrolling_(false)
{
status_.teams = &teams_;
game_config::add_color_info(level);

View File

@ -145,6 +145,7 @@ protected:
unsigned int start_turn_;
bool skip_replay_;
bool browse_;
bool linger_;
bool scrolling_;
bool first_turn_;

View File

@ -281,6 +281,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
const int ticks = SDL_GetTicks();
const int num_turns = atoi((*scenario)["turns"].c_str());
// FIXME: make this an auto_ptr
playsingle_controller *pcontroller;
LOG_NG << "creating objects... " << (SDL_GetTicks() - ticks) << "\n";
@ -294,12 +295,10 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
case IO_CLIENT:
pcontroller = new playmp_controller(*scenario,units_data,gamestate,ticks,num_turns,game_config,video,skip_replay);
LOG_NG << "created objects... " << (SDL_GetTicks() - pcontroller->get_ticks()) << "\n";
res = reinterpret_cast<playmp_controller *>(pcontroller)->play_scenario(story, log, skip_replay);
res = dynamic_cast<playmp_controller *>(pcontroller)->play_scenario(story, log, skip_replay);
break;
}
// tell all clients that the campaign won't continue
// why isn't this done on VICTORY as well?
if(io_type==IO_SERVER && (res==QUIT || res==DEFEAT)) {
@ -316,6 +315,12 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
_("You have been defeated!")
).show();
}
// FIXME: Support this for MP as well.
if (io_type == IO_NONE && (res == VICTORY || res == DEFEAT)) {
pcontroller->linger(log);
}
// Temporary fix:
// Only apply preferences for replays and autosave
// deletes on victory. We need to rethink what this

View File

@ -75,7 +75,9 @@ void playsingle_controller::update_shroud_now(){
}
void playsingle_controller::end_turn(){
if (!browse_){
if (linger_)
end_turn_ = true;
else if (!browse_){
end_turn_ = menu_handler_.end_turn(player_number_);
}
}
@ -114,6 +116,22 @@ void playsingle_controller::user_command(){
menu_handler_.user_command();
}
void playsingle_controller::linger(upload_log& log)
{
LOG_NG << "beginning post-turn linger";
browse_ = true;
linger_ = true;
try {
play_human_turn();
} catch(game::load_game_exception&) {
// Loading a new game is effectively a quit.
log.quit(status_.turn());
throw;
} catch(end_level_exception& end_level) {
}
LOG_NG << "ending post-turn linger";
}
LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& story, upload_log& log,
bool skip_replay)
{
@ -455,6 +473,7 @@ void playsingle_controller::before_human_turn(bool save)
{
log_scope("player turn");
browse_ = false;
linger_ = false;
gui_->set_team(player_number_ - 1);
gui_->recalculate_minimap();
@ -572,7 +591,7 @@ bool playsingle_controller::can_execute_command(hotkey::HOTKEY_COMMAND command,
case hotkey::HOTKEY_REPEAT_RECRUIT:
case hotkey::HOTKEY_RECALL:
case hotkey::HOTKEY_ENDTURN:
return !browse_ && !events::commands_disabled;
return (!browse_ || linger_) && !events::commands_disabled;
case hotkey::HOTKEY_DELAY_SHROUD:
return !browse_ && (current_team().uses_fog() || current_team().uses_shroud());

View File

@ -52,6 +52,7 @@ public:
virtual void unit_hold_position();
virtual void end_unit_turn();
virtual void user_command();
void linger(upload_log& log);
protected:
virtual void play_turn(bool no_save);