Units: Add is_visible_to_team() overload and use it to improve the previous commit.

This commit is contained in:
josteph 2018-10-14 17:38:42 +00:00
parent 180971da2b
commit 0f129f2d10
3 changed files with 11 additions and 9 deletions

View file

@ -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<map_location> locs;
if (!temp_unit_ptr_->invisible(path_[current_]))

View file

@ -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;
}

View file

@ -1570,6 +1570,8 @@ public:
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.