From 0229f94913fcb6547d1eb4a32de16666d63081a0 Mon Sep 17 00:00:00 2001 From: Tommy Schmitz Date: Sun, 24 Jul 2011 21:41:27 +0000 Subject: [PATCH] Whiteboard execution now halts if a unit is sighted on... ...the last hex of a move. --- src/actions.cpp | 6 +++++- src/actions.hpp | 4 +++- src/mouse_events.cpp | 4 ++-- src/mouse_events.hpp | 3 ++- src/whiteboard/move.cpp | 15 ++++++++++++--- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 2ed72fc0c08..62f02b4c571 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -2344,7 +2344,8 @@ size_t move_unit(move_unit_spectator *move_spectator, replay* move_recorder, undo_list* undo_stack, bool show_move, map_location *next_unit, bool continue_move, - bool should_clear_shroud, bool is_replay) + bool should_clear_shroud, bool is_replay, + bool* units_sighted_result) { assert(route.empty() == false); @@ -2549,6 +2550,9 @@ size_t move_unit(move_unit_spectator *move_spectator, assert(steps.size() <= route.size()); + if(units_sighted_result) + *units_sighted_result = !seen_units.empty(); + // If we can't get all the way there and have to set a go-to. if(steps.size() != route.size() && discovered_unit == false) { if(seen_units.empty() == false) { diff --git a/src/actions.hpp b/src/actions.hpp index 82106205de1..4b5913b58eb 100644 --- a/src/actions.hpp +++ b/src/actions.hpp @@ -401,13 +401,15 @@ typedef std::vector undo_list; * a goto order will be set. * If move_recorder is not NULL, the move will be recorded in it. * If undos is not NULL, undo information will be added. + * If units_sighted_result is not NULL, it will indicate whether a sighting occurred. */ size_t move_unit(move_unit_spectator* move_spectator, const std::vector &steps, replay* move_recorder, undo_list* undos, bool show_move, map_location *next_unit = NULL, - bool continue_move = false, bool should_clear_shroud=true, bool is_replay=false); + bool continue_move = false, bool should_clear_shroud=true, bool is_replay=false, + bool* units_sighted_result = NULL); /** Function which recalculates the fog. */ void recalculate_fog(int side); diff --git a/src/mouse_events.cpp b/src/mouse_events.cpp index 0b80aed40d9..18851d723e4 100644 --- a/src/mouse_events.cpp +++ b/src/mouse_events.cpp @@ -716,7 +716,7 @@ bool mouse_handler::move_unit_along_current_route(bool check_shroud) return finished_moves; } -bool mouse_handler::move_unit_along_route(pathfind::marked_route const& route, map_location* next_unit, bool check_shroud) +bool mouse_handler::move_unit_along_route(pathfind::marked_route const& route, map_location* next_unit, bool check_shroud, bool* sighted_result) { const std::vector steps = route.steps; if(steps.empty()) { @@ -725,7 +725,7 @@ bool mouse_handler::move_unit_along_route(pathfind::marked_route const& route, m size_t moves = 0; try { - moves = ::move_unit(NULL, steps, &recorder, resources::undo_stack, true, next_unit, false, check_shroud); + moves = ::move_unit(NULL, steps, &recorder, resources::undo_stack, true, next_unit, false, check_shroud, false, sighted_result); } catch(end_turn_exception&) { cursor::set(cursor::NORMAL); gui().invalidate_game_status(); diff --git a/src/mouse_events.hpp b/src/mouse_events.hpp index 48d55c3eed9..c588c8f017a 100644 --- a/src/mouse_events.hpp +++ b/src/mouse_events.hpp @@ -70,7 +70,8 @@ public: // wrapper to catch bad_alloc so this should be called void attack_enemy(const map_location& attacker_loc, const map_location& defender_loc, int choice); - bool move_unit_along_route(pathfind::marked_route const& route, map_location* next_unit, bool check_shroud); + // output arg: sighted_result: if not NULL, indicates whether a "unit sighted" occurred + bool move_unit_along_route(pathfind::marked_route const& route, map_location* next_unit, bool check_shroud, bool* sighted_result = NULL); protected: /** diff --git a/src/whiteboard/move.cpp b/src/whiteboard/move.cpp index 5cc03d203a6..736cc10afca 100644 --- a/src/whiteboard/move.cpp +++ b/src/whiteboard/move.cpp @@ -230,11 +230,12 @@ action::EXEC_RESULT move::execute() map_location final_location; bool steps_finished; + bool enemy_sighted; { events::mouse_handler& mouse_handler = resources::controller->get_mouse_handler_base(); team const& owner_team = resources::teams->at(team_index()); try { - steps_finished = mouse_handler.move_unit_along_route(*route_, &final_location, owner_team.auto_shroud_updates()); + steps_finished = mouse_handler.move_unit_along_route(*route_, &final_location, owner_team.auto_shroud_updates(), &enemy_sighted); } catch (end_turn_exception&) { set_arrow_brightness(ARROW_BRIGHTNESS_STANDARD); throw; // we rely on the caller to delete this action @@ -255,8 +256,16 @@ action::EXEC_RESULT move::execute() { if (steps_finished && route_->steps.back() == final_location) //reached destination { - // Everything went smoothly - result = action::SUCCESS; + if(enemy_sighted) + { + LOG_WB << "Move completed, but interrupted on final hex. Halting.\n"; + //reset to a single-hex path, just in case *this is a wb::attack + arrow_.reset(); + route_->steps = std::vector(1,route_->steps.back()); + result = action::PARTIAL; + } + else // Everything went smoothly + result = action::SUCCESS; } else // Move was interrupted, probably by enemy unit sighted {