Whiteboard execution now halts if a unit is sighted on...

...the last hex of a move.
This commit is contained in:
Tommy Schmitz 2011-07-24 21:41:27 +00:00
parent 184c170f65
commit 0229f94913
5 changed files with 24 additions and 8 deletions

View File

@ -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) {

View File

@ -401,13 +401,15 @@ typedef std::vector<undo_action> 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<map_location> &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);

View File

@ -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<map_location> 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();

View File

@ -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:
/**

View File

@ -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<map_location>(1,route_->steps.back());
result = action::PARTIAL;
}
else // Everything went smoothly
result = action::SUCCESS;
}
else // Move was interrupted, probably by enemy unit sighted
{