From 0f129f2d102205145b231dafde396f0e94ad8624 Mon Sep 17 00:00:00 2001 From: josteph Date: Sun, 14 Oct 2018 17:38:42 +0000 Subject: [PATCH] Units: Add is_visible_to_team() overload and use it to improve the previous commit. --- src/units/udisplay.cpp | 13 ++++--------- src/units/unit.cpp | 5 +++++ src/units/unit.hpp | 2 ++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/units/udisplay.cpp b/src/units/udisplay.cpp index 803ff361a162..8452fd769518 100644 --- a/src/units/udisplay.cpp +++ b/src/units/udisplay.cpp @@ -77,13 +77,8 @@ void teleport_unit_between(const map_location& a, const map_location& b, unit& t const display_context& dc = disp.get_disp_context(); const team& viewing_team = dc.get_team(disp.viewing_side()); - // Temporarily change the unit's location to check if it's visible - // before and after the teleport. - assert(temp_unit.get_location() == a); - const bool a_visible = temp_unit.is_visible_to_team(viewing_team, false); - temp_unit.set_location(b); - const bool b_visible = temp_unit.is_visible_to_team(viewing_team, false); - temp_unit.set_location(a); + const bool a_visible = temp_unit.is_visible_to_team(a, viewing_team, false); + const bool b_visible = temp_unit.is_visible_to_team(b, viewing_team, false); if ( a_visible ) { // teleport disp.invalidate(a); @@ -342,8 +337,8 @@ void unit_mover::proceed_to(unit_ptr u, std::size_t path_index, bool update, boo path_index = std::min(path_index, path_.size()-1); for ( ; current_ < path_index; ++current_ ) { - // It is possible for paths_[current_] and paths_[current_+1] not to be adjacent. - // When that is the case, and the unit is invisible at paths_[current_], we shouldn't + // It is possible for path_[current_] and path_[current_+1] not to be adjacent. + // When that is the case, and the unit is invisible at path_[current_], we shouldn't // scroll to that hex. std::vector locs; if (!temp_unit_ptr_->invisible(path_[current_])) diff --git a/src/units/unit.cpp b/src/units/unit.cpp index 3db489c9f422..09158498305b 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -2359,6 +2359,11 @@ bool unit::invisible(const map_location& loc, bool see_all) const bool unit::is_visible_to_team(const team& team, bool const see_all) const { const map_location& loc = get_location(); + return is_visible_to_team(loc, team, see_all); +} + +bool unit::is_visible_to_team(const map_location& loc, const team& team, bool const see_all) const +{ if(!display::get_singleton()->get_map().on_board(loc)) { return false; } diff --git a/src/units/unit.hpp b/src/units/unit.hpp index 67806e50f127..653fefa84dcc 100644 --- a/src/units/unit.hpp +++ b/src/units/unit.hpp @@ -1570,6 +1570,8 @@ class unit bool invisible(const map_location& loc, bool see_all = true) const; bool is_visible_to_team(const team& team, bool const see_all = true) const; + /// Return true if the unit would be visible to team if its location were loc. + bool is_visible_to_team(const map_location& loc, const team& team, bool const see_all = true) const; /** * Serializes the current unit metadata values.