Units: refactor display_context parameter out of ability functions

This was essentially only needed for the affects_side() helper. THAT'S IT. All this code just for
one single line... Anyway...

Utilized the display singleton's display_context getter instead. This also means fewer explicit
uses of resources::gameboard as the display_context object, meaning more compatibility with the
editor (not that that's relevant for most of the changed usecases, such as the AI, but it does
affect unit::get_abilities, which might be useful there in the future).

This also removes the display_context parameter from unit::invisible() since it was only passed to
unit::get_ability_bool().

unit::is_visible_to_team() also had its display_context parameter removed. It was used once as an
argument for invisible() and the other case was replaced with display::get_map().

(cherry-picked from commit 7e442cbb54)
This commit is contained in:
Charles Dang 2018-04-20 16:06:19 +11:00
parent baf02ebf1d
commit 2b65a8c5c8
30 changed files with 71 additions and 77 deletions

View file

@ -83,7 +83,7 @@ const std::set<std::string> get_recruits(int side, const map_location &recruit_l
local_result.insert(find_it->recruits().begin(),
find_it->recruits().end());
}
else if ( find_it->is_visible_to_team(current_team, *resources::gameboard, false) )
else if ( find_it->is_visible_to_team(current_team, false) )
{
// This hex is visibly occupied, so we cannot recruit here.
allow_local = false;
@ -184,7 +184,7 @@ std::vector<unit_const_ptr > get_recalls(int side, const map_location &recall_lo
add_leader_filtered_recalls(find_it.get_shared_ptr(), result);
return result;
}
else if ( find_it->is_visible_to_team(resources::gameboard->get_team(side), *resources::gameboard, false) )
else if ( find_it->is_visible_to_team(resources::gameboard->get_team(side), false) )
{
// This hex is visibly occupied, so we cannot recall here.
allow_local = false;
@ -585,7 +585,7 @@ namespace { // Helpers for place_recruit()
for ( unit_itor = units.begin(); unit_itor != units.end(); ++unit_itor ) {
if (resources::gameboard->get_team(unit_itor->side()).is_enemy(new_unit.side()) &&
unit_itor->is_visible_to_team(resources::gameboard->get_team(new_unit.side()), *resources::gameboard, false)) {
unit_itor->is_visible_to_team(resources::gameboard->get_team(new_unit.side()), false)) {
int dist = distance_between(unit_itor->get_location(),recruit_loc) - unit_itor->level();
if (dist < min_dist) {
min_dist = dist;

View file

@ -349,7 +349,7 @@ void calculate_healing(int side, bool update_display)
const team & viewing_team =
resources::gameboard->teams()[display::get_singleton()->viewing_team()];
if (!resources::controller->is_skipping_replay() && update_display &&
patient.is_visible_to_team(viewing_team, *resources::gameboard, false) )
patient.is_visible_to_team(viewing_team, false) )
{
unit_list.emplace_front(patient, healers, healing, curing == POISON_CURE);
}

View file

@ -428,7 +428,7 @@ namespace { // Private helpers for move_unit()
if ( neighbor_it != units.end() &&
current_team_->is_enemy(neighbor_it->side()) &&
neighbor_it->invisible(adjacent[i], *resources::gameboard) )
neighbor_it->invisible(adjacent[i]) )
{
// Ambushed!
ambushed_ = true;
@ -751,7 +751,7 @@ namespace { // Private helpers for move_unit()
if ( start != begin_ ) {
// Check for being unable to leave the current hex.
if ( !move_it_->get_ability_bool("skirmisher", *start, *resources::gameboard) &&
if ( !move_it_->get_ability_bool("skirmisher", *start) &&
pathfind::enemy_zoc(*current_team_, *start, *current_team_) )
zoc_stop_ = *start;
}
@ -774,7 +774,7 @@ namespace { // Private helpers for move_unit()
moves_left_.push_back(remaining_moves);
// Check for being unable to leave this hex.
if (!move_it_->get_ability_bool("skirmisher", *end, *resources::gameboard) &&
if (!move_it_->get_ability_bool("skirmisher", *end) &&
pathfind::enemy_zoc(*current_team_, *end, *current_team_))
{
zoc_stop_ = *end;

View file

@ -599,7 +599,7 @@ std::vector<int> get_sides_not_seeing(const unit & target)
std::size_t team_size = teams.size();
for ( std::size_t i = 0; i != team_size; ++i)
if ( !target.is_visible_to_team(teams[i], *resources::gameboard, false) )
if ( !target.is_visible_to_team(teams[i], false) )
// not_see contains side numbers; i is a team index, so add 1.
not_seeing.push_back(i+1);
@ -646,7 +646,7 @@ game_events::pump_result_t actor_sighted(const unit & target, const std::vector<
needs_event[target.side()-1] = false;
// Exclude those teams that cannot see the target.
for ( std::size_t i = 0; i != teams_size; ++i )
needs_event[i] = needs_event[i] && target.is_visible_to_team(teams[i], *resources::gameboard, false);
needs_event[i] = needs_event[i] && target.is_visible_to_team(teams[i], false);
// Cache "jamming".
std::vector< std::map<map_location, int>> jamming_cache(teams_size);

View file

@ -280,7 +280,7 @@ void protect_goal::add_targets(std::back_insert_iterator< std::vector< target >>
{
int distance = distance_between(u.get_location(), loc);
if (current_team().is_enemy(u.side()) && distance < radius_ &&
!u.invisible(u.get_location(), *resources::gameboard))
!u.invisible(u.get_location()))
{
DBG_AI_GOAL << "side " << get_side() << ": in " << goal_type << ": found threat target. " << u.get_location() << " is a threat to "<< loc << '\n';
*target_list = target(u.get_location(),

View file

@ -376,7 +376,7 @@ void readonly_context_impl::calculate_moves(const unit_map& units, std::map<map_
}
// We can't see where invisible enemy units might move.
if (enemy && un_it->invisible(un_it->get_location(), *resources::gameboard) && !see_all) {
if (enemy && un_it->invisible(un_it->get_location()) && !see_all) {
continue;
}
// If it's an enemy unit, reset its moves while we do the calculations.

View file

@ -104,7 +104,7 @@ std::shared_ptr<attacks_vector> aspect_attacks_base::analyze_targets() const
// Attack anyone who is on the enemy side,
// and who is not invisible or petrified.
if (current_team().is_enemy(j->side()) && !j->incapacitated() &&
!j->invisible(j->get_location(), *resources::gameboard))
!j->invisible(j->get_location()))
{
if (!is_allowed_enemy(*j)) {
continue;
@ -288,7 +288,7 @@ void aspect_attacks_base::do_attack_analysis(
}
// No surround bonus if target is skirmisher
if (!itor->get_ability_bool("skirmisher", *resources::gameboard))
if (!itor->get_ability_bool("skirmisher"))
surround_bonus = 1.2;
}
@ -360,7 +360,7 @@ int aspect_attacks_base::rate_terrain(const unit& u, const map_location& loc)
const int neutral_village_value = 10;
const int enemy_village_value = 15;
if(map_.gives_healing(terrain) && u.get_ability_bool("regenerate", loc, *resources::gameboard) == false) {
if(map_.gives_healing(terrain) && u.get_ability_bool("regenerate", loc) == false) {
rating += healing_value;
}

View file

@ -1332,7 +1332,7 @@ double get_healing_phase::evaluate()
if(u.side() == get_side() &&
(u.max_hitpoints() - u.hitpoints() >= game_config::poison_amount/2
|| u.get_state(unit::STATE_POISONED)) &&
!u.get_ability_bool("regenerate", *resources::gameboard))
!u.get_ability_bool("regenerate"))
{
// Look for the village which is the least vulnerable to enemy attack.
typedef std::multimap<map_location,map_location>::const_iterator Itor;

View file

@ -81,7 +81,7 @@ int default_ai_context_impl::count_free_hexes_in_castle(const map_location &loc,
ret += count_free_hexes_in_castle(adj[n], checked_hexes);
if (u == units_.end()
|| (current_team().is_enemy(u->side())
&& u->invisible(adj[n], *resources::gameboard))
&& u->invisible(adj[n]))
|| ((&resources::gameboard->get_team(u->side()) == &current_team())
&& u->movement_left() > 0)) {
ret += 1;
@ -109,7 +109,7 @@ int default_ai_context_impl::rate_terrain(const unit& u, const map_location& loc
const int neutral_village_value = 10;
const int enemy_village_value = 15;
if(map_.gives_healing(terrain) && u.get_ability_bool("regenerate", loc, *resources::gameboard) == false) {
if(map_.gives_healing(terrain) && u.get_ability_bool("regenerate", loc) == false) {
rating += healing_value;
}
@ -228,7 +228,7 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
for(u = units_.begin(); u != units_.end(); ++u) {
//is a visible enemy leader
if (u->can_recruit() && current_team().is_enemy(u->side())
&& !u->invisible(u->get_location(), *resources::gameboard)) {
&& !u->invisible(u->get_location())) {
assert(map_.on_board(u->get_location()));
LOG_AI << "found enemy leader (side: " << u->side() << ") target... " << u->get_location() << " with value: " << get_leader_value() << "\n";
targets.emplace_back(u->get_location(), get_leader_value(), target::TYPE::LEADER);

View file

@ -285,7 +285,7 @@ void attack_map_callable::collect_possible_attacks(std::vector<variant>& vars, m
/* if tile is occupied by friendly or petrified/invisible unit */
if (!ai_.current_team().is_enemy(unit->side()) ||
unit->incapacitated() ||
unit->invisible(unit->get_location(), *resources::gameboard))
unit->invisible(unit->get_location()))
continue;
/* add attacks with default weapon */
auto item = std::make_shared<attack_callable>(attacker_location, attack_position, adj[n], -1);

View file

@ -21,7 +21,6 @@
#include "ai/formula/candidates.hpp"
#include "game_board.hpp"
#include "log.hpp"
#include "resources.hpp"
#include "units/unit.hpp"
static lg::log_domain log_formula_ai("ai/engine/fai");
@ -166,7 +165,7 @@ void attack_candidate_action::evaluate(ai::formula_ai* ai, unit_map& units)
}
} else
{
if (ai->current_team().is_enemy(i->side()) && !i->incapacitated() && !i->invisible(i->get_location(), *resources::gameboard)) {
if (ai->current_team().is_enemy(i->side()) && !i->incapacitated() && !i->invisible(i->get_location())) {
enemy_res.emplace_back(std::make_shared<unit_callable>(*i));
}
}

View file

@ -1845,7 +1845,7 @@ void display::draw_minimap_units()
for(const auto& u : dc_->units()) {
if (fogged(u.get_location()) ||
(dc_->teams()[currentTeam_].is_enemy(u.side()) &&
u.invisible(u.get_location(), *dc_)) ||
u.invisible(u.get_location())) ||
u.get_hidden()) {
continue;
}

View file

@ -47,7 +47,7 @@ bool display_context::would_be_discovered(const map_location & loc, int side_num
if(see_all) {
return true;
} else if (!get_team(side_num).fogged(u_loc)
&& !u.invisible(u_loc, *this, true)) {
&& !u.invisible(u_loc, true)) {
return true;
}
}
@ -59,7 +59,7 @@ const unit * display_context::get_visible_unit(const map_location & loc, const t
{
if (!map().on_board(loc)) return nullptr;
const unit_map::const_iterator u = units().find(loc);
if (!u.valid() || !u->is_visible_to_team(current_team, *this, see_all)) {
if (!u.valid() || !u->is_visible_to_team(current_team, see_all)) {
return nullptr;
}
return &*u;

View file

@ -170,7 +170,7 @@ unit_map::iterator game_board::find_visible_unit(const map_location &loc,
{
if (!map_->on_board(loc)) return units_.end();
unit_map::iterator u = units_.find(loc);
if (!u.valid() || !u->is_visible_to_team(current_team, *this, see_all))
if (!u.valid() || !u->is_visible_to_team(current_team, see_all))
return units_.end();
return u;
}
@ -179,7 +179,7 @@ bool game_board::has_visible_unit(const map_location & loc, const team& current_
{
if (!map_->on_board(loc)) return false;
unit_map::const_iterator u = units_.find(loc);
if (!u.valid() || !u->is_visible_to_team(current_team, *this, see_all))
if (!u.valid() || !u->is_visible_to_team(current_team, see_all))
return false;
return true;
}

View file

@ -33,8 +33,6 @@
#include "display.hpp"
#include "font/text_formatting.hpp"
#include "formatter.hpp"
#include "game_board.hpp"
#include "resources.hpp"
#include "units/map.hpp"
#include "units/ptr.hpp"
#include "units/unit.hpp"
@ -155,7 +153,7 @@ void unit_list::pre_show(window& window)
find_widget<image>(row_grid, "unit_status_slowed", false).set_visible(widget::visibility::invisible);
}
if(!unit->invisible(unit->get_location(), *resources::gameboard, false)) {
if(!unit->invisible(unit->get_location(), false)) {
find_widget<image>(row_grid, "unit_status_invisible", false).set_visible(widget::visibility::invisible);
}
}

View file

@ -440,7 +440,7 @@ void menu_handler::show_enemy_moves(bool ignore_units, int side_num)
// Compute enemy movement positions
for(auto& u : units()) {
bool invisible = u.invisible(u.get_location(), gui_->get_disp_context());
bool invisible = u.invisible(u.get_location());
if(board().get_team(side_num).is_enemy(u.side()) && !gui_->fogged(u.get_location()) && !u.incapacitated()
&& !invisible) {
@ -1351,7 +1351,7 @@ void menu_handler::do_search(const std::string& new_search)
name.begin(), name.end(), last_search_.begin(), last_search_.end(), chars_equal_insensitive)
!= name.end()) {
if(!teams()[gui_->viewing_team()].is_enemy(ui->side())
|| !ui->invisible(ui->get_location(), gui_->get_disp_context())) {
|| !ui->invisible(ui->get_location())) {
found = true;
}
}

View file

@ -793,7 +793,7 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
for(unit_map::iterator u = pc_.gamestate().board_.units_.begin(); u != pc_.gamestate().board_.units_.end();
++u) {
bool invisible = u->invisible(u->get_location(), gui_->get_disp_context());
bool invisible = u->invisible(u->get_location());
if(!gui_->fogged(u->get_location()) && !u->incapacitated() && !invisible) {
const pathfind::paths& path =
@ -1126,7 +1126,7 @@ void mouse_handler::show_attack_options(const unit_map::const_iterator& u)
}
unit_map::const_iterator i = pc_.gamestate().board_.units().find(loc);
if(!i || !i->is_visible_to_team(cur_team, gui_->get_disp_context(), false)) {
if(!i || !i->is_visible_to_team(cur_team, false)) {
continue;
}
@ -1151,7 +1151,7 @@ bool mouse_handler::unit_in_cycle(unit_map::const_iterator it)
return false;
}
if(current_team().is_enemy(int(gui().viewing_team() + 1)) && it->invisible(it->get_location(), gui().get_disp_context())) {
if(current_team().is_enemy(int(gui().viewing_team() + 1)) && it->invisible(it->get_location())) {
return false;
}

View file

@ -416,7 +416,7 @@ static void find_routes(
if ( skirmisher && next.moves_left > 0 &&
enemy_zoc(*current_team, next_hex, *viewing_team, see_all) &&
!skirmisher->get_ability_bool("skirmisher", next_hex, *resources::gameboard) ) {
!skirmisher->get_ability_bool("skirmisher", next_hex) ) {
next.moves_left = 0;
}
}
@ -685,7 +685,7 @@ marked_route mark_route(const plain_route &rt)
++turns;
bool invisible = u.invisible(*i, *resources::gameboard, false);
bool invisible = u.invisible(*i, false);
res.marks[*i] = marked_route::mark(turns, zoc, capture, invisible);
@ -698,7 +698,7 @@ marked_route mark_route(const plain_route &rt)
}
zoc = enemy_zoc(unit_team, *(i + 1), viewing_team)
&& !u.get_ability_bool("skirmisher", *(i+1), *resources::gameboard);
&& !u.get_ability_bool("skirmisher", *(i+1));
if (zoc) {
movement = 0;
@ -782,7 +782,7 @@ double shortest_path_calculator::cost(const map_location& loc, const double so_f
// check ZoC
if (!ignore_unit_ && remaining_movement != terrain_cost
&& enemy_zoc(teams_[unit_.side()-1], loc, viewing_team_, see_all_)
&& !unit_.get_ability_bool("skirmisher", loc, *resources::gameboard)) {
&& !unit_.get_ability_bool("skirmisher", loc)) {
// entering ZoC cost all remaining MP
move_cost += remaining_movement;
} else {

View file

@ -262,7 +262,7 @@ const teleport_map get_teleport_locations(const unit &u,
{
std::vector<teleport_group> groups;
if (u.get_ability_bool("teleport", *resources::gameboard)) {
if (u.get_ability_bool("teleport")) {
for (const unit_ability & teleport : u.get_abilities("teleport")) {
const int tunnel_count = (teleport.first)->child_count("tunnel");
for(int i = 0; i < tunnel_count; ++i) {

View file

@ -626,7 +626,7 @@ void play_controller::tab()
for (const unit& u : gamestate().board_.units()){
const map_location& loc = u.get_location();
if(!gui_->fogged(loc) &&
!(gamestate().board_.teams()[gui_->viewing_team()].is_enemy(u.side()) && u.invisible(loc, gui_->get_disp_context())))
!(gamestate().board_.teams()[gui_->viewing_team()].is_enemy(u.side()) && u.invisible(loc)))
dictionary.insert(u.name());
}
//TODO List map labels

View file

@ -297,7 +297,7 @@ static config unit_status(reports::context & rc, const unit* u)
if (!u) return config();
config res;
map_location displayed_unit_hex = rc.screen().displayed_unit_hex();
if (rc.map().on_board(displayed_unit_hex) && u->invisible(displayed_unit_hex, rc.dc())) {
if (rc.map().on_board(displayed_unit_hex) && u->invisible(displayed_unit_hex)) {
add_status(res, "misc/invisible.png", N_("invisible: "),
N_("This unit is invisible. It cannot be seen or attacked by enemy units."));
}
@ -772,7 +772,7 @@ static int attack_info(reports::context & rc, const attack_type &at, config &res
continue;
const map_location &loc = enemy.get_location();
if (viewing_team.fogged(loc) ||
(viewing_team.is_enemy(enemy.side()) && enemy.invisible(loc, rc.dc())))
(viewing_team.is_enemy(enemy.side()) && enemy.invisible(loc)))
continue;
bool new_type = seen_types.insert(enemy.type_id()).second;
if (new_type) {

View file

@ -2410,7 +2410,7 @@ int game_lua_kernel::intf_unit_ability(lua_State *L)
{
const unit& u = luaW_checkunit(L, 1);
char const *m = luaL_checkstring(L, 2);
lua_pushboolean(L, u.get_ability_bool(m, board()));
lua_pushboolean(L, u.get_ability_bool(m));
return 1;
}

View file

@ -239,7 +239,7 @@ const time_of_day tod_manager::get_illuminated_time_of_day(const unit_map & unit
for ( std::size_t i = 0; i < locs.size(); ++i ) {
const unit_map::const_iterator itor = units.find(locs[i]);
if (itor != units.end() &&
itor->get_ability_bool("illuminates", *resources::gameboard) &&
itor->get_ability_bool("illuminates") &&
!itor->incapacitated())
{
unit_ability_list illum = itor->get_abilities("illuminates");

View file

@ -124,20 +124,21 @@ A poisoned unit cannot be cured of its poison by a healer, and must seek the car
namespace {
bool affects_side(const config& cfg, const std::vector<team>& teams, std::size_t side, std::size_t other_side)
bool affects_side(const config& cfg, std::size_t side, std::size_t other_side)
{
if (side == other_side)
// display::get_singleton() has already been confirmed valid by both callers.
const team& side_team = display::get_singleton()->get_disp_context().get_team(side);
if(side == other_side || !side_team.is_enemy(other_side)) {
return cfg["affect_allies"].to_bool(true);
if (teams[side - 1].is_enemy(other_side))
} else {
return cfg["affect_enemies"].to_bool();
else
return cfg["affect_allies"].to_bool();
}
}
}
bool unit::get_ability_bool(const std::string& tag_name, const map_location& loc, const display_context& dc) const
bool unit::get_ability_bool(const std::string& tag_name, const map_location& loc) const
{
for (const config &i : this->abilities_.child_range(tag_name)) {
if (ability_active(tag_name, i, loc) &&
@ -164,7 +165,7 @@ bool unit::get_ability_bool(const std::string& tag_name, const map_location& loc
if ( &*it == this )
continue;
for (const config &j : it->abilities_.child_range(tag_name)) {
if (affects_side(j, dc.teams(), side(), it->side()) &&
if (affects_side(j, side(), it->side()) &&
it->ability_active(tag_name, j, adjacent[i]) &&
ability_affects_adjacent(tag_name, j, i, loc, *it))
{
@ -208,7 +209,7 @@ unit_ability_list unit::get_abilities(const std::string& tag_name, const map_loc
if ( &*it == this )
continue;
for (const config &j : it->abilities_.child_range(tag_name)) {
if (affects_side(j, resources::gameboard->teams(), side(), it->side()) &&
if (affects_side(j, side(), it->side()) &&
it->ability_active(tag_name, j, adjacent[i]) &&
ability_affects_adjacent(tag_name, j, i, loc, *it) &&
ability_affects_weapon(j, weapon, false) &&

View file

@ -79,8 +79,7 @@ void unit_drawer::redraw_unit (const unit & u) const
std::string ellipse=u.image_ellipse();
if ( hidden || is_blindfolded || !u.is_visible_to_team(viewing_team_ref, dc, show_everything) )
{
if(hidden || is_blindfolded || !u.is_visible_to_team(viewing_team_ref, show_everything)) {
ac.clear_haloes();
if(ac.anim_) {
ac.anim_->update_last_draw_time();
@ -105,8 +104,7 @@ void unit_drawer::redraw_unit (const unit & u) const
// instead use -1.0 (as in "negative depth", it will be ignored by rendering)
params.submerge= is_flying ? -1.0 : terrain_info.unit_submerge();
if (u.invisible(loc, dc) &&
params.highlight_ratio > 0.6) {
if(u.invisible(loc) && params.highlight_ratio > 0.6) {
params.highlight_ratio = 0.6;
}
if (loc == sel_hex && params.highlight_ratio == 1.0) {

View file

@ -702,7 +702,7 @@ void unit_filter_compound::fill(vconfig cfg)
for (const int viewer : viewers) {
bool fogged = args.fc->get_disp_context().get_team(viewer).fogged(args.loc);
bool hiding = args.u.invisible(args.loc, args.fc->get_disp_context()) && args.fc->get_disp_context().get_team(viewer).is_enemy(args.u.side());
bool hiding = args.u.invisible(args.loc) && args.fc->get_disp_context().get_team(viewer).is_enemy(args.u.side());
bool unit_hidden = fogged || hiding;
if (c["visible"].to_bool(true) != unit_hidden) {
return true;

View file

@ -274,7 +274,7 @@ void unit_mover::start(unit_ptr u)
disp_->invalidate(path_[0]);
// If the unit can be seen here by the viewing side:
if ( !is_enemy_ || !temp_unit_ptr_->invisible(path_[0], disp_->get_disp_context()) ) {
if(!is_enemy_ || !temp_unit_ptr_->invisible(path_[0])) {
// Scroll to the path, but only if it fully fits on screen.
// If it does not fit we might be able to do a better scroll later.
disp_->scroll_to_tiles(path_, game_display::ONSCREEN, true, true, 0.0, false);
@ -329,9 +329,10 @@ void unit_mover::proceed_to(unit_ptr u, std::size_t path_index, bool update, boo
for ( ; current_ < path_index; ++current_ )
// If the unit can be seen by the viewing side while making this step:
if ( !is_enemy_ || !temp_unit_ptr_->invisible(path_[current_], disp_->get_disp_context()) ||
!temp_unit_ptr_->invisible(path_[current_+1], disp_->get_disp_context()) )
{
if(!is_enemy_
|| !temp_unit_ptr_->invisible(path_[current_])
|| !temp_unit_ptr_->invisible(path_[current_ + 1])
) {
// Wait for the previous step to complete before drawing the next one.
wait_for_anims();

View file

@ -21,7 +21,7 @@
#include "color.hpp"
#include "deprecation.hpp"
#include "display_context.hpp"
#include "display.hpp"
#include "formatter.hpp"
#include "formula/string_utils.hpp" // for VGETTEXT
#include "game_board.hpp" // for game_board
@ -2322,7 +2322,7 @@ void unit::apply_modifications()
max_experience_ = std::max<int>(1, (max_experience_ * exp_accel + 50)/100);
}
bool unit::invisible(const map_location& loc, const display_context& dc, bool see_all) const
bool unit::invisible(const map_location& loc, bool see_all) const
{
if(loc != get_location()) {
DBG_UT << "unit::invisible called: id = " << id() << " loc = " << loc << " get_loc = " << get_location() << std::endl;
@ -2348,7 +2348,7 @@ bool unit::invisible(const map_location& loc, const display_context& dc, bool se
// Test hidden status
static const std::string hides("hides");
bool is_inv = get_ability_bool(hides, loc, dc);
bool is_inv = get_ability_bool(hides, loc);
if(is_inv){
is_inv = (resources::gameboard ? !resources::gameboard->would_be_discovered(loc, side_,see_all) : true);
}
@ -2365,10 +2365,10 @@ bool unit::invisible(const map_location& loc, const display_context& dc, bool se
return is_inv;
}
bool unit::is_visible_to_team(const team& team,const display_context& dc, bool const see_all) const
bool unit::is_visible_to_team(const team& team, bool const see_all) const
{
const map_location& loc = get_location();
if(!dc.map().on_board(loc)) {
if(!display::get_singleton()->get_map().on_board(loc)) {
return false;
}
@ -2376,7 +2376,7 @@ bool unit::is_visible_to_team(const team& team,const display_context& dc, bool
return true;
}
if(team.is_enemy(side()) && invisible(loc, dc)) {
if(team.is_enemy(side()) && invisible(loc)) {
return false;
}

View file

@ -24,7 +24,6 @@
#include <boost/variant.hpp>
class display;
class display_context;
class team;
class unit_animation_component;
class unit_formula_manager;
@ -1442,9 +1441,8 @@ public:
* @param tag_name The name of the ability to check for.
* @param loc The location around which to check for affected units. This may or
* may not be the location of this unit.
* @param dc A display_context object, used in calculations.
*/
bool get_ability_bool(const std::string& tag_name, const map_location& loc, const display_context& dc) const;
bool get_ability_bool(const std::string& tag_name, const map_location& loc) const;
/**
* Checks whether this unit currently possesses or is affected by a given ability.
@ -1455,11 +1453,10 @@ public:
* This overload uses the location of this unit for calculations.
*
* @param tag_name The name of the ability to check for.
* @param dc A display_context object, used in calculations.
*/
bool get_ability_bool(const std::string& tag_name, const display_context& dc) const
bool get_ability_bool(const std::string& tag_name) const
{
return get_ability_bool(tag_name, loc_, dc);
return get_ability_bool(tag_name, loc_);
}
/**
@ -1556,9 +1553,9 @@ public:
void generate_name();
// Only see_all = true use caching
bool invisible(const map_location& loc, const display_context& dc, bool see_all = true) const;
bool invisible(const map_location& loc, bool see_all = true) const;
bool is_visible_to_team(const team& team, const display_context& dc, bool const see_all = true) const;
bool is_visible_to_team(const team& team, bool const see_all = true) const;
/**
* Serializes the current unit metadata values.

View file

@ -68,7 +68,7 @@ void mapbuilder::pre_build()
//Remove any unit the current side cannot see to avoid their detection by planning
//Units will be restored to the unit map by destruction of removers_
if(!on_current_side && !u.is_visible_to_team(resources::gameboard->teams()[viewer_team()], *resources::gameboard, false)) {
if(!on_current_side && !u.is_visible_to_team(resources::gameboard->teams()[viewer_team()], false)) {
removers_.push_back(new temporary_unit_remover(resources::gameboard->units(), u.get_location()));
//Don't do anything else to the removed unit!