void playsingle_controller::play_ai_turn() { LOG_NG << "is ai...\n"; end_turn_enable(false); gui_->recalculate_minimap(); const cursor::setter cursor_setter(cursor::WAIT); // Correct an oddball case where a human could have left delayed shroud // updates on before giving control to the AI. (The AI does not bother // with the undo stack, so it cannot delay shroud updates.) team & cur_team = current_team(); if ( !cur_team.auto_shroud_updates() ) { // We just took control, so the undo stack is empty. We still need // to record this change for the replay though. synced_context::run_and_store("auto_shroud", replay_helper::get_auto_shroud(true)); } undo_stack().clear(); turn_data_.send_data(); try { try { if (!should_return_to_play_side()) { ai::manager::play_turn(current_side()); } } catch (return_to_play_side_exception&) { } catch (fallback_ai_to_human_exception&) { current_team().make_human(); player_type_changed_ = true; } } catch(...) { turn_data_.sync_network(); throw; } if(!should_return_to_play_side()) { end_turn_ = END_TURN_REQUIRED; } turn_data_.sync_network(); gui_->recalculate_minimap(); gui_->invalidate_unit(); gui_->invalidate_game_status(); gui_->invalidate_all(); gui_->draw(); }
void playsingle_controller::play_idle_loop() { while(!should_return_to_play_side()) { play_slice_catch(); gui_->draw(); SDL_Delay(10); } }
void playsingle_controller::execute_gotos() { if(should_return_to_play_side()) { return; } try { menu_handler_.execute_gotos(mouse_handler_, current_side()); } catch (const return_to_play_side_exception&) { } }
void playsingle_controller::play_human_turn() { show_turn_dialog(); if (!preferences::disable_auto_moves()) { execute_gotos(); } end_turn_enable(true); while(!should_return_to_play_side()) { play_slice_catch(); gui_->draw(); } }
void playmp_controller::play_idle_loop() { LOG_NG << "playmp::play_human_turn...\n"; remove_blindfold(); while (!should_return_to_play_side()) { try { process_network_data(); play_slice_catch(); SDL_Delay(1); } catch(...) { turn_data_.send_data(); throw; } turn_data_.send_data(); } }
void playmp_controller::play_human_turn() { LOG_NG << "playmp::play_human_turn...\n"; assert(!linger_); assert(gamestate_->init_side_done()); assert(gamestate().gamedata_.phase() == game_data::PLAY); mp_ui_alerts::turn_changed(current_team().current_player()); LOG_NG << "events::commands_disabled=" << events::commands_disabled <<"\n"; remove_blindfold(); const std::unique_ptr<countdown_clock> timer(saved_game_.mp_settings().mp_countdown ? new countdown_clock(current_team()) : nullptr); show_turn_dialog(); if(undo_stack().can_undo()) { // If we reload a networked mp game we cannot undo moves made before the save // because other players already received them if(!current_team().auto_shroud_updates()) { synced_context::run_and_store("update_shroud", replay_helper::get_update_shroud()); } undo_stack().clear(); } if (!preferences::disable_auto_moves()) { execute_gotos(); } end_turn_enable(true); while(!should_return_to_play_side()) { try { process_network_data(); check_objectives(); play_slice_catch(); if (player_type_changed_) { // Clean undo stack if turn has to be restarted (losing control) if ( undo_stack().can_undo() ) { font::floating_label flabel(_("Undoing moves not yet transmitted to the server.")); color_t color {255,255,255,SDL_ALPHA_OPAQUE}; flabel.set_color(color); SDL_Rect rect = gui_->map_area(); flabel.set_position(rect.w/2, rect.h/2); flabel.set_lifetime(150); flabel.set_clip_rect(rect); font::add_floating_label(flabel); } while( undo_stack().can_undo() ) undo_stack().undo(); } if(timer) { bool time_left = timer->update(); if(!time_left) { end_turn_ = END_TURN_REQUIRED; } } } catch(...) { turn_data_.send_data(); throw; } turn_data_.send_data(); } }
void playmp_controller::play_human_turn() { LOG_NG << "playmp::play_human_turn...\n"; assert(!linger_); remove_blindfold(); boost::scoped_ptr<countdown_clock> timer; if(saved_game_.mp_settings().mp_countdown) { timer.reset(new countdown_clock(current_team())); } show_turn_dialog(); if(undo_stack_->can_undo()) { // If we reload a networked mp game we cannot undo moves made before the save // Becasue other players already received them if(!current_team().auto_shroud_updates()) { synced_context::run_and_store("update_shroud", replay_helper::get_update_shroud()); } undo_stack_->clear(); } if (!preferences::disable_auto_moves()) { execute_gotos(); } end_turn_enable(true); while(!should_return_to_play_side()) { try { process_network_data(); if (player_type_changed_) { // Clean undo stack if turn has to be restarted (losing control) if ( undo_stack_->can_undo() ) { font::floating_label flabel(_("Undoing moves not yet transmitted to the server.")); SDL_Color color = {255,255,255,255}; flabel.set_color(color); SDL_Rect rect = gui_->map_area(); flabel.set_position(rect.w/2, rect.h/2); flabel.set_lifetime(150); flabel.set_clip_rect(rect); font::add_floating_label(flabel); } while( undo_stack_->can_undo() ) undo_stack_->undo(); } check_objectives(); play_slice_catch(); if(timer) { bool time_left = timer->update(); if(!time_left) { end_turn_ = END_TURN_REQUIRED; } } } catch(...) { turn_data_.send_data(); throw; } turn_data_.send_data(); gui_->draw(); } }
void maybe_throw_return_to_play_side() { if(should_return_to_play_side()) { throw return_to_play_side_exception(); } }