committed patch #1024:

..."Optionally cancel unit orders (goto location) on load game" by ilor
This commit is contained in:
Gunter Labes 2008-03-29 11:18:09 +00:00
parent b37dbb0a98
commit 211cc1506c
8 changed files with 51 additions and 10 deletions

View file

@ -652,6 +652,10 @@
comment = "Test and final implementation of female leaders in multiplayer games, minor WML engine features"
wikiuser = "ShikadiLord"
[/entry]
[entry]
name = "ilor"
comment = "option to cancel goto orders on load"
[/entry]
[entry]
name = "J.R. Blain (Cowboy)"
[/entry]

View file

@ -628,7 +628,7 @@ std::string format_time_summary(time_t t)
} // end anon namespace
std::string load_game_dialog(display& disp, const config& game_config, const game_data& data, bool* show_replay)
std::string load_game_dialog(display& disp, const config& game_config, const game_data& data, bool* show_replay, bool* cancel_orders)
{
std::vector<save_info> games;
{
@ -689,6 +689,13 @@ std::string load_game_dialog(display& disp, const config& game_config, const gam
lmenu.add_option(_("Show replay"), false);
#endif
}
if(cancel_orders != NULL) {
#ifdef USE_SMALL_GUI
lmenu.add_option(_("Cancel orders"), false, gui::dialog::BUTTON_STANDARD);
#else
lmenu.add_option(_("Cancel orders"), false);
#endif
}
lmenu.add_button(new gui::standard_dialog_button(disp.video(),_("OK"),0,false), gui::dialog::BUTTON_STANDARD);
lmenu.add_button(new gui::standard_dialog_button(disp.video(),_("Cancel"),1,true), gui::dialog::BUTTON_STANDARD);
@ -711,13 +718,16 @@ std::string load_game_dialog(display& disp, const config& game_config, const gam
res = filter->get_save_index(res);
if(show_replay != NULL) {
*show_replay = lmenu.option_checked();
*show_replay = lmenu.option_checked(0);
const config& summary = *summaries[res];
if(utils::string_bool(summary["replay"], false) && !utils::string_bool(summary["snapshot"], true)) {
*show_replay = true;
}
}
if (cancel_orders != NULL) {
*cancel_orders = lmenu.option_checked(1);
}
return games[res].name;
}

View file

@ -64,7 +64,7 @@ int get_save_name(display & disp,const std::string& message, const std::string&
//of the save they want to load. Stores whether the user wants to show
//a replay of the game in show_replay. If show_replay is NULL, then
//the user will not be asked if they want to show a replay.
std::string load_game_dialog(display& disp, const config& terrain_config, const game_data& data, bool* show_replay);
std::string load_game_dialog(display& disp, const config& terrain_config, const game_data& data, bool* show_replay, bool* cancel_orders);
class unit_preview_pane : public gui::preview_pane
{

View file

@ -179,6 +179,7 @@ private:
std::string loaded_game_;
bool loaded_game_show_replay_;
bool loaded_game_cancel_orders_;
preproc_map defines_map_, old_defines_map_;
};
@ -187,7 +188,8 @@ game_controller::game_controller(int argc, char** argv)
: argc_(argc), arg_(1), argv_(argv), thread_manager(),
test_scenario_("test"), test_mode_(false), multiplayer_mode_(false),
no_gui_(false), use_caching_(true), force_valid_cache_(false),
force_bpp_(-1), disp_(NULL), loaded_game_show_replay_(false)
force_bpp_(-1), disp_(NULL), loaded_game_show_replay_(false),
loaded_game_cancel_orders_(false)
{
bool no_sound = false;
for(arg_ = 1; arg_ != argc_; ++arg_) {
@ -502,6 +504,7 @@ bool game_controller::play_test()
} catch(game::load_game_exception& e) {
loaded_game_ = e.game;
loaded_game_show_replay_ = e.show_replay;
loaded_game_cancel_orders_ = e.cancel_orders;
test_mode_ = false;
return true;
}
@ -701,6 +704,7 @@ bool game_controller::play_multiplayer_mode()
//the user's trying to load a game, so go into the normal title screen loop and load one
loaded_game_ = e.game;
loaded_game_show_replay_ = e.show_replay;
loaded_game_cancel_orders_ = e.cancel_orders;
return true;
} catch(twml_exception& e) {
e.show(disp());
@ -722,8 +726,9 @@ bool game_controller::load_game()
state_ = game_state();
bool show_replay = loaded_game_show_replay_;
bool cancel_orders = loaded_game_cancel_orders_;
const std::string game = loaded_game_.empty() ? dialogs::load_game_dialog(disp(),game_config_,units_data_,&show_replay) : loaded_game_;
const std::string game = loaded_game_.empty() ? dialogs::load_game_dialog(disp(),game_config_,units_data_,&show_replay,&cancel_orders) : loaded_game_;
loaded_game_ = "";
@ -860,6 +865,19 @@ bool game_controller::load_game()
(**sides.first)["controller"] = "human";
}
}
if (cancel_orders) {
for(config::child_itors sides = state_.snapshot.child_range("side");
sides.first != sides.second; ++sides.first) {
if((**sides.first)["controller"] == "human") {
for (config::child_itors units = (**sides.first).child_range("unit");
units.first != units.second; ++units.first) {
(**units.first)["goto_x"] = "-999";
(**units.first)["goto_y"] = "-999";
}
}
}
}
return true;
}
@ -1571,6 +1589,7 @@ bool game_controller::play_multiplayer()
//this will make it so next time through the title screen loop, this game is loaded
loaded_game_ = e.game;
loaded_game_show_replay_ = e.show_replay;
loaded_game_cancel_orders_ = e.cancel_orders;
} catch(twml_exception& e) {
e.show(disp());
}
@ -1935,6 +1954,7 @@ void game_controller::play_game(RELOAD_GAME_DATA reload)
//this will make it so next time through the title screen loop, this game is loaded
loaded_game_ = e.game;
loaded_game_show_replay_ = e.show_replay;
loaded_game_cancel_orders_ = e.cancel_orders;
} catch(twml_exception& e) {
e.show(disp());
@ -1955,6 +1975,7 @@ void game_controller::play_replay()
//this will make it so next time through the title screen loop, this game is loaded
loaded_game_ = e.game;
loaded_game_show_replay_ = e.show_replay;
loaded_game_cancel_orders_ = e.cancel_orders;
} catch(twml_exception& e) {
e.show(disp());

View file

@ -49,9 +49,11 @@ struct game_error : public error {
//an exception object used to signal that the user has decided to abort
//a game, and load another game instead
struct load_game_exception {
load_game_exception(const std::string& game, bool show_replay) : game(game), show_replay(show_replay) {}
load_game_exception(const std::string& game, bool show_replay, bool cancel_orders)
: game(game), show_replay(show_replay), cancel_orders(cancel_orders) {}
std::string game;
bool show_replay;
bool cancel_orders;
};
}

View file

@ -889,9 +889,10 @@ private:
void menu_handler::load_game(){
bool show_replay = false;
const std::string game = dialogs::load_game_dialog(*gui_, game_config_, gameinfo_, &show_replay);
bool cancel_orders = false;
const std::string game = dialogs::load_game_dialog(*gui_, game_config_, gameinfo_, &show_replay, &cancel_orders);
if(game != "") {
throw game::load_game_exception(game,show_replay);
throw game::load_game_exception(game,show_replay,cancel_orders);
}
}

View file

@ -1409,8 +1409,11 @@ void connect::load_game()
{
if(params_.saved_game) {
bool show_replay = false;
//bool cancel_orders = false;
const std::string game = dialogs::load_game_dialog(disp(),
game_config(), game_data_, &show_replay);
game_config(), game_data_, &show_replay,
NULL);
if(game.empty()) {
set_result(CREATE);
return;

View file

@ -472,7 +472,7 @@ bool play_controller::execute_command(hotkey::HOTKEY_COMMAND command, int index)
unsigned i = static_cast<unsigned>(index);
if(i < savenames_.size() && !savenames_[i].empty()) {
// Load the game by throwing load_game_exception
throw game::load_game_exception(savenames_[i],false);
throw game::load_game_exception(savenames_[i],false,false);
} else if (i < wml_commands_.size() && wml_commands_[i] != NULL) {
if(gamestate_.last_selected.valid() && wml_commands_[i]->needs_select) {