Skip to content

Commit

Permalink
Units: Add is_visible_to_team() overload and use it to improve the pr…
Browse files Browse the repository at this point in the history
…evious commit.
  • Loading branch information
jostephd committed Oct 14, 2018
1 parent 180971d commit 0f129f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/units/udisplay.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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_]))
Expand Down
5 changes: 5 additions & 0 deletions src/units/unit.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/units/unit.hpp
Expand Up @@ -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.
Expand Down

0 comments on commit 0f129f2

Please sign in to comment.