Implemented dropout to observer on surrender

This commit is contained in:
kallaballa 2017-12-14 19:54:39 +01:00 committed by Gunter Labes
parent 4f1a7a9faa
commit 78dff47bd3
6 changed files with 53 additions and 8 deletions

View file

@ -85,7 +85,7 @@
id=menu-main
title= _ "Menu"
image=classic/lite
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,AUTOSAVES,help,stopnetwork,startnetwork,quit,quit-to-desktop
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,AUTOSAVES,help,stopnetwork,startnetwork,surrender,quit,quit-to-desktop
ref=top-panel
rect="=+3,=+1,+100,=-4"
xanchor=fixed

View file

@ -79,7 +79,7 @@
id=menu-main
title= _ "Menu"
image=button_menu/menu_button_copper_H20
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,menu-autosaves,help,stopnetwork,startnetwork,quit,quit-to-desktop
items=objectives,statistics,unitlist,statustable,save,savereplay,savemap,load,preferences,chatlog,menu-autosaves,help,stopnetwork,startnetwork,surrender,quit,quit-to-desktop
ref=top-panel
rect="=,=+1,+100,=-4"
xanchor=fixed

View file

@ -29,6 +29,8 @@
#include "display.hpp"
#include "quit_confirmation.hpp"
#include "show_dialog.hpp"
#include "../resources.hpp"
#include "../playmp_controller.hpp"
#include "utils/functional.hpp"
@ -352,7 +354,7 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/
quit_confirmation::quit_to_title();
break;
case HOTKEY_SURRENDER:
surrender_game();
break;
default:
return false;
@ -362,9 +364,10 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/
void command_executor::surrender_game() {
if(gui2::show_message(_("Surrender"), _("Do you really want to surrender the game?"), gui2::dialogs::message::yes_no_buttons) != gui2::window::CANCEL) {
} else {
playmp_controller* pmc = dynamic_cast<playmp_controller*>(resources::controller);
if(pmc && !pmc->is_linger_mode() && !pmc->is_observer()) {
pmc->surrender(display::get_singleton()->viewing_team());
}
}
}

View file

@ -296,7 +296,6 @@ bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_c
case hotkey::HOTKEY_OBJECTIVES:
case hotkey::HOTKEY_UNIT_LIST:
case hotkey::HOTKEY_STATISTICS:
case hotkey::HOTKEY_SURRENDER:
case hotkey::HOTKEY_QUIT_GAME:
case hotkey::HOTKEY_QUIT_TO_DESKTOP:
case hotkey::HOTKEY_SEARCH:
@ -324,6 +323,16 @@ bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_c
case hotkey::HOTKEY_SCROLL_RIGHT:
return true;
case hotkey::HOTKEY_SURRENDER: {
size_t humans_notme_cnt = 0;
for(const auto& t : play_controller_.get_teams_const()) {
if(t.is_network_human()) {
++humans_notme_cnt;
}
}
return !(humans_notme_cnt < 1 || play_controller_.is_linger_mode() || play_controller_.is_observer());
}
// Commands that have some preconditions:
case hotkey::HOTKEY_SAVE_GAME:
return !events::commands_disabled;

View file

@ -63,8 +63,17 @@ bool quit_confirmation::show_prompt(const std::string& message)
bool quit_confirmation::default_prompt()
{
playmp_controller* pmc = dynamic_cast<playmp_controller*>(resources::controller);
size_t humans_notme_cnt = 0;
if(!(pmc == nullptr || pmc->is_linger_mode() || pmc->is_observer())) {
if(pmc != nullptr) {
for(const auto& t : pmc->get_teams_const()) {
if(t.is_network_human()) {
++humans_notme_cnt;
}
}
}
if(!(pmc == nullptr || humans_notme_cnt < 1 || pmc->is_linger_mode() || pmc->is_observer())) {
gui2::dialogs::surrender_quit sq;
sq.show();
int retval = sq.get_retval();

View file

@ -1071,6 +1071,30 @@ bool game::process_turn(simple_wml::document& data, const socket_ptr& user)
}
}
} else if (command->child("surrender")) {
size_t side_index = 0;
for(auto s : sides_) {
if(s == user) {
break;
}
++side_index;
}
if(side_index < sides_.size()) {
simple_wml::document cfg;
std::string playername;
cfg.root().set_attr("side", std::to_string(side_index + 1).c_str());
// figure out who gets the surrendered side
if(owner_ == user) {
playername = username(sides_[(side_index + 1) % sides_.size()]);
} else {
playername = username(owner_);
}
cfg.root().set_attr("player", playername.c_str());
transfer_side_control(user, cfg.root());
}
send_and_record_server_message(username(user) + " has surrendered.");
} else if(is_current_player(user) && (*command).child("end_turn")) {
turn_ended = end_turn();