diff --git a/src/game_events.cpp b/src/game_events.cpp index d4d80c8833b..ea532209ed1 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -59,6 +59,7 @@ game_state* state_of_game = NULL; const game_data* game_data_ptr = NULL; gamestatus* status_ptr = NULL; int floating_label = 0; + typedef Uint32 msecs; const msecs prevent_misclick_duration = 10; const msecs average_frame_time = 30; @@ -2468,6 +2469,10 @@ bool pump() snprintf(buf,sizeof(buf),"%d",ev.loc2.y+1); state_of_game->set_variable("y2", buf); + + if(event_name == "select") { + state_of_game->last_selected = ev.loc1; + } } while(i.first != i.second) { diff --git a/src/gamestatus.cpp b/src/gamestatus.cpp index 679fcb712e1..7f2eaaea8ed 100644 --- a/src/gamestatus.cpp +++ b/src/gamestatus.cpp @@ -420,7 +420,8 @@ player_info read_player(const game_data& data, const config* cfg) return res; } -game_state::game_state(const game_data& data, const config& cfg) : difficulty("NORMAL"), recursive_(false) +game_state::game_state(const game_data& data, const config& cfg) +: difficulty("NORMAL"), last_selected(gamemap::location::null_location), recursive_(false) { log_scope("read_game"); label = cfg["label"]; @@ -1371,6 +1372,7 @@ game_state& game_state::operator=(const game_state& state) replay_data = state.replay_data; starting_pos = state.starting_pos; snapshot = state.snapshot; + last_selected = state.last_selected; set_variables(state.get_variables()); recursive_ = state.recursive_; diff --git a/src/gamestatus.hpp b/src/gamestatus.hpp index 83156339e01..03406e4a123 100644 --- a/src/gamestatus.hpp +++ b/src/gamestatus.hpp @@ -78,7 +78,8 @@ struct player_info class game_state : public variable_set { public: - game_state() : difficulty("NORMAL"), recursive_(false) {} + game_state() : difficulty("NORMAL"), last_selected(gamemap::location::null_location), + recursive_(false) {} game_state(const game_state& state); game_state(const game_data& data, const config& cfg); @@ -137,6 +138,8 @@ public: //to view a replay, the game's settings are read in from this object config snapshot; + //the last location where a select event fired. + gamemap::location last_selected; private: void get_variable_internal(const std::string& key, config& cfg, t_string** varout, config** cfgout); diff --git a/src/play_controller.cpp b/src/play_controller.cpp index c14f7310194..ee2f7527a48 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -464,7 +464,12 @@ bool play_controller::execute_command(hotkey::HOTKEY_COMMAND command, int index) throw game::load_game_exception(savenames_[i],false); } else if (i < wml_commands_.size() && wml_commands_[i] != NULL) { - game_events::fire(wml_commands_[i]->name, mouse_handler_.get_last_hex()); + if(gamestate_.last_selected.valid()) { + recorder.add_event("select", gamestate_.last_selected); + } + gamemap::location const& menu_hex = mouse_handler_.get_last_hex(); + recorder.add_event(wml_commands_[i]->name, menu_hex); + game_events::fire(wml_commands_[i]->name, menu_hex); return true; } } diff --git a/src/replay.cpp b/src/replay.cpp index bf890e045a8..42df3471b55 100644 --- a/src/replay.cpp +++ b/src/replay.cpp @@ -405,11 +405,12 @@ void replay::end_turn() config* const cmd = add_command(); cmd->add_child("end_turn"); } -void replay::add_event(const std::string& name) +void replay::add_event(const std::string& name, const gamemap::location& loc) { config* const cmd = add_command(); config& ev = cmd->add_child("fire_event"); ev["raise"] = name; + loc.write(ev); (*cmd)["undo"] = "no"; } void replay::add_checksum_check(const gamemap::location& loc) @@ -1058,7 +1059,10 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo, //exclude these events here, because in a replay proper time of execution can't be //established and therefore we fire those events inside play_controller::init_side if ((event != "side turn") && (event != "turn 1") && (event != "new_turn")){ - game_events::fire(event); + gamemap::location ev1; + ev1.x = lexical_cast_default((*child)["x"].value(), -1); + ev1.y = lexical_cast_default((*child)["y"].value(), -1); + game_events::fire(event, ev1); } } else { if(! cfg->child("checksum")) { diff --git a/src/replay.hpp b/src/replay.hpp index 98fde9c0406..e0d7907249d 100644 --- a/src/replay.hpp +++ b/src/replay.hpp @@ -60,7 +60,8 @@ public: void clear_labels(const std::string&); void add_rename(const std::string& name, const gamemap::location& loc); void end_turn(); - void add_event(const std::string& name); + void add_event(const std::string& name, + const gamemap::location& loc=gamemap::location::null_location); void add_unit_checksum(const gamemap::location& loc,config* const cfg); void add_checksum_check(const gamemap::location& loc);