Skip to content

Commit

Permalink
add variants of "find visible unit" to game_board
Browse files Browse the repository at this point in the history
Allow size_t instead of reference to a team, also possibility to
query for presence of a visible unit instead of returning an
iterator to it.
  • Loading branch information
cbeck88 committed Jun 8, 2014
1 parent 358531e commit 39c8aab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/game_board.cpp
Expand Up @@ -61,6 +61,15 @@ unit_map::iterator game_board::find_visible_unit(const map_location &loc,
return u;
}

bool game_board::has_visible_unit(const map_location & loc, const team& current_team, bool see_all)
{
if (!map_.on_board(loc)) return false;
unit_map::iterator u = units_.find(loc);
if (!u.valid() || !u->is_visible_to_team(current_team, see_all))
return false;
return true;
}

unit* game_board::get_visible_unit(const map_location &loc,
const team &current_team, bool see_all)
{
Expand Down
4 changes: 4 additions & 0 deletions src/game_board.hpp
Expand Up @@ -117,6 +117,10 @@ class game_board {
// Global accessor from unit.hpp

unit_map::iterator find_visible_unit(const map_location &loc, const team& current_team, bool see_all = false);
unit_map::iterator find_visible_unit(const map_location & loc, size_t team, bool see_all = false) { return find_visible_unit(loc, teams_[team], see_all); }
bool has_visible_unit (const map_location & loc, const team & team, bool see_all = false);
bool has_visible_unit (const map_location & loc, size_t team, bool see_all = false) { return has_visible_unit(loc, teams_[team], see_all); }

unit* get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false); //TODO: can this not return a pointer?
};

Expand Down

0 comments on commit 39c8aab

Please sign in to comment.