From 28eef7cfdd7f73ea39580c60b8399bcb64dd124a Mon Sep 17 00:00:00 2001 From: "J. Tyne" Date: Tue, 5 Feb 2013 21:22:34 +0000 Subject: [PATCH] A tweak to the way fog/shroud is cleared during a [teleport] action: Clear the destination hex before the teleport animation (so it can be seen), and clear the remaining hexes after the animation (when it looks like the unit can see them). --- src/actions/vision.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/actions/vision.hpp | 3 +++ src/game_events.cpp | 14 ++++++++++---- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/actions/vision.cpp b/src/actions/vision.cpp index 8c599212504..cf00c92e962 100644 --- a/src/actions/vision.cpp +++ b/src/actions/vision.cpp @@ -374,6 +374,45 @@ bool shroud_clearer::clear_unit(const map_location &view_loc, const unit &viewer } +/** + * Clears shroud (and fog) at the provided location and it immediate neighbors. + * This is an aid for the [teleport] action, allowing the destination to be + * cleared before teleporting, while the unit's full visual range gets cleared + * after. + * The @a viewer is needed for correct firing of sighted events. + * + * @return whether or not information was uncovered (i.e. returns true if the + * locations in question were fogged/shrouded under shared vision/maps). + */ +bool shroud_clearer::clear_dest(const map_location &dest, const unit &viewer) +{ + team & viewing_team = (*resources::teams)[viewer.side()-1]; + // A pair of dummy variables needed to simplify some logic. + size_t enemies, friends; + + // Abort if there is nothing to clear. + if ( !viewing_team.fog_or_shroud() ) + return false; + + // Clear the destination. + bool cleared_something = clear_loc(viewing_team, dest, viewer, dest, true, + enemies, friends); + + // Clear the adjacent hexes (will be seen even if vision is 0, and the + // graphics do not work so well for an isolated cleared hex). + map_location adjacent[6]; + get_adjacent_tiles(dest, adjacent); + for ( int i = 0; i != 6; ++i ) + cleared_something = clear_loc(viewing_team, adjacent[i], viewer, dest, + true, enemies, friends); + + if ( cleared_something ) + invalidate_after_clear(); + + return cleared_something; +} + + /** * Clears the record of sighted events from earlier fog/shroud clearing. * This should be called if the events are to be ignored and not fired. diff --git a/src/actions/vision.hpp b/src/actions/vision.hpp index 4d100f04cef..858fe3e9ac7 100644 --- a/src/actions/vision.hpp +++ b/src/actions/vision.hpp @@ -74,6 +74,9 @@ public: bool can_delay = false, bool invalidate = true, bool instant = false); + /// Clears shroud (and fog) at the provided location and it immediate neighbors. + bool clear_dest(const map_location &dest, const unit &viewer); + /// Erases the record of sighted events from earlier fog/shroud clearing. void drop_events(); diff --git a/src/game_events.cpp b/src/game_events.cpp index 0edccae0b3e..89085fb2cb2 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -878,9 +878,11 @@ WML_HANDLER_FUNCTION(teleport, event_info, cfg) const map_location vacant_dst = find_vacant_tile(dst, pathfind::VACANT_ANY, pass_check); if (!resources::game_map->on_board(vacant_dst)) return; + // Clear the destination hex before the move (so the animation can be seen). + bool clear_shroud = cfg["clear_shroud"].to_bool(true); actions::shroud_clearer clearer; - if (cfg["clear_shroud"].to_bool(true)) { - clearer.clear_unit(vacant_dst, *u); + if ( clear_shroud ) { + clearer.clear_dest(vacant_dst, *u); } map_location src_loc = u->get_location(); @@ -897,12 +899,16 @@ WML_HANDLER_FUNCTION(teleport, event_info, cfg) u = resources::units->find(vacant_dst); u->set_standing(); + if ( clear_shroud ) { + // Now that the unit is visibly in position, clear the shroud. + clearer.clear_unit(vacant_dst, *u); + } + if (resources::game_map->is_village(vacant_dst)) { actions::get_village(vacant_dst, u->side()); } - resources::screen->invalidate_unit_after_move(src_loc, dst); - + resources::screen->invalidate_unit_after_move(src_loc, vacant_dst); resources::screen->draw(); // Sighted events.