diff --git a/projectfiles/CodeBlocks-SCons/wesnoth.cbp b/projectfiles/CodeBlocks-SCons/wesnoth.cbp
index 9c67a61ebedd..dd932d6e191d 100644
--- a/projectfiles/CodeBlocks-SCons/wesnoth.cbp
+++ b/projectfiles/CodeBlocks-SCons/wesnoth.cbp
@@ -191,6 +191,7 @@
+
diff --git a/projectfiles/CodeBlocks/wesnoth.cbp b/projectfiles/CodeBlocks/wesnoth.cbp
index 080f8019b5c0..9c838988872b 100644
--- a/projectfiles/CodeBlocks/wesnoth.cbp
+++ b/projectfiles/CodeBlocks/wesnoth.cbp
@@ -229,6 +229,7 @@
+
diff --git a/projectfiles/VC9/wesnoth.vcproj b/projectfiles/VC9/wesnoth.vcproj
index 7a37ccebd599..ae780cd12065 100644
--- a/projectfiles/VC9/wesnoth.vcproj
+++ b/projectfiles/VC9/wesnoth.vcproj
@@ -20052,6 +20052,10 @@
RelativePath="..\..\src\display.hpp"
>
+
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2c732407cc52..88cbe2083b7c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -916,6 +916,7 @@ set(libwesnoth-game_STAT_SRC
construct_dialog.cpp
cursor.cpp
display.cpp
+ display_context.cpp
events.cpp
font.cpp
format_time_summary.cpp
diff --git a/src/SConscript b/src/SConscript
index 0a0b5a66bd64..63475bf64f95 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -75,6 +75,7 @@ libwesnoth_sources = Split("""
construct_dialog.cpp
cursor.cpp
display.cpp
+ display_context.cpp
events.cpp
format_time_summary.cpp
generic_event.cpp
diff --git a/src/display_context.cpp b/src/display_context.cpp
new file mode 100644
index 000000000000..0b3690e10ce5
--- /dev/null
+++ b/src/display_context.cpp
@@ -0,0 +1,31 @@
+/*
+ Copyright (C) 2014 by Chris Beck
+ Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY.
+
+ See the COPYING file for more details.
+*/
+
+#include "display_context.hpp"
+
+#include "map.hpp"
+#include "map_location.hpp"
+#include "team.hpp"
+#include "unit.hpp"
+#include "unit_map.hpp"
+
+const unit * display_context::get_visible_unit(const map_location & loc, const team ¤t_team, bool see_all) const
+{
+ if (!map().on_board(loc)) return NULL;
+ const unit_map::const_iterator u = units().find(loc);
+ if (!u.valid() || !u->is_visible_to_team(current_team, map(), see_all)) {
+ return NULL;
+ }
+ return &*u;
+}
diff --git a/src/display_context.hpp b/src/display_context.hpp
index b25079d46094..b506fff6e473 100644
--- a/src/display_context.hpp
+++ b/src/display_context.hpp
@@ -28,12 +28,17 @@ class team;
class gamemap;
class unit_map;
+class unit;
+struct map_location;
+
class display_context {
public:
virtual const std::vector & teams() const = 0;
virtual const gamemap & map() const = 0;
virtual const unit_map & units() const = 0;
+ const unit * get_visible_unit(const map_location &loc, const team ¤t_team, bool see_all = false) const;
+
virtual ~display_context() {}
};
diff --git a/src/map_location.cpp b/src/map_location.cpp
index d89e08f2756f..56eebd9b49ba 100644
--- a/src/map_location.cpp
+++ b/src/map_location.cpp
@@ -24,8 +24,8 @@
#include "map_location.hpp"
#include "config.hpp"
+#include "display_context.hpp"
#include "formula_string_utils.hpp"
-#include "game_board.hpp"
#include "map.hpp"
#include "resources.hpp"
#include "gettext.hpp"
@@ -318,7 +318,7 @@ std::vector parse_location_range(const std::string &x, const std::
std::vector res;
const std::vector xvals = utils::split(x);
const std::vector yvals = utils::split(y);
- const gamemap *map = & resources::gameboard->map();
+ const gamemap *map = & resources::disp_context->map();
assert(map);
int xmin = 1, xmax = map->w(), ymin = 1, ymax = map->h();
if (with_border) {
diff --git a/src/reports.cpp b/src/reports.cpp
index c679f968deaa..2572f79d0706 100644
--- a/src/reports.cpp
+++ b/src/reports.cpp
@@ -16,6 +16,7 @@
#include "actions/attack.hpp"
#include "attack_prediction.hpp"
+#include "display_context.hpp"
#include "editor/editor_controller.hpp"
#include "editor/palette/terrain_palettes.hpp"
#include "font.hpp"
@@ -123,14 +124,14 @@ namespace reports {
static const unit *get_visible_unit()
{
- return resources::gameboard->get_visible_unit(resources::screen->displayed_unit_hex(),
+ return resources::disp_context->get_visible_unit(resources::screen->displayed_unit_hex(),
(*resources::teams)[resources::screen->viewing_team()],
resources::screen->show_everything());
}
static const unit *get_selected_unit()
{
- return resources::gameboard->get_visible_unit(resources::screen->selected_hex(),
+ return resources::disp_context->get_visible_unit(resources::screen->selected_hex(),
(*resources::teams)[resources::screen->viewing_team()],
resources::screen->show_everything());
}
@@ -318,7 +319,7 @@ static config unit_status(const unit* u)
if (!u) return report();
config res;
map_location displayed_unit_hex = resources::screen->displayed_unit_hex();
- if (resources::gameboard->map().on_board(displayed_unit_hex) && u->invisible(displayed_unit_hex)) {
+ if (resources::disp_context->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."));
}
@@ -528,8 +529,8 @@ static config unit_defense(const unit* u, const map_location& displayed_unit_hex
}
std::ostringstream str, tooltip;
- const gamemap &map = resources::gameboard->map();
- if(!resources::gameboard->map().on_board(displayed_unit_hex)) {
+ const gamemap &map = resources::disp_context->map();
+ if(!resources::disp_context->map().on_board(displayed_unit_hex)) {
return report();
}
@@ -617,7 +618,7 @@ static config unit_moves(const unit* u)
if (terrain == t_translation::FOGGED || terrain == t_translation::VOID_TERRAIN || terrain == t_translation::OFF_MAP_USER)
continue;
- const terrain_type& info = resources::gameboard->map().get_terrain_info(terrain);
+ const terrain_type& info = resources::disp_context->map().get_terrain_info(terrain);
if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
@@ -1199,7 +1200,7 @@ static config unit_box_at(const map_location& mouseover_hex)
else if (local_tod.bonus_modified < 0) local_tod_image += "~DARKEN()";
if (preferences::flip_time()) local_tod_image += "~FL(horiz)";
- const gamemap &map = resources::gameboard->map();
+ const gamemap &map = resources::disp_context->map();
t_translation::t_terrain terrain = map.get_terrain(mouseover_hex);
//if (terrain == t_translation::OFF_MAP_USER)
@@ -1278,13 +1279,13 @@ REPORT_GENERATOR(villages)
str << td.villages << '/';
if (viewing_team.uses_shroud()) {
int unshrouded_villages = 0;
- BOOST_FOREACH(const map_location &loc, resources::gameboard->map().villages()) {
+ BOOST_FOREACH(const map_location &loc, resources::disp_context->map().villages()) {
if (!viewing_team.shrouded(loc))
++unshrouded_villages;
}
str << unshrouded_villages;
} else {
- str << resources::gameboard->map().villages().size();
+ str << resources::disp_context->map().villages().size();
}
return gray_inactive(str.str());
}
@@ -1351,7 +1352,7 @@ void blit_tced_icon(config &cfg, const std::string &terrain_id, const std::strin
REPORT_GENERATOR(terrain_info)
{
- const gamemap &map = resources::gameboard->map();
+ const gamemap &map = resources::disp_context->map();
map_location mouseover_hex = display::get_singleton()->mouseover_hex();
if (!map.on_board(mouseover_hex))
@@ -1397,7 +1398,7 @@ REPORT_GENERATOR(terrain_info)
REPORT_GENERATOR(terrain)
{
- const gamemap &map = resources::gameboard->map();
+ const gamemap &map = resources::disp_context->map();
int viewing_side = resources::screen->viewing_side();
const team &viewing_team = (*resources::teams)[viewing_side - 1];
map_location mouseover_hex = resources::screen->mouseover_hex();
@@ -1446,7 +1447,7 @@ REPORT_GENERATOR(zoom_level)
REPORT_GENERATOR(position)
{
- const gamemap &map = resources::gameboard->map();
+ const gamemap &map = resources::disp_context->map();
map_location mouseover_hex = resources::screen->mouseover_hex(),
displayed_unit_hex = resources::screen->displayed_unit_hex(),
selected_hex = resources::screen->selected_hex();
diff --git a/src/tod_manager.cpp b/src/tod_manager.cpp
index 1ce5408c18d1..74bd456b3bb4 100644
--- a/src/tod_manager.cpp
+++ b/src/tod_manager.cpp
@@ -15,6 +15,7 @@
#include "tod_manager.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
+#include "display_context.hpp"
#include "formula_string_utils.hpp"
#include "gamestatus.hpp"
#include "log.hpp"
@@ -194,7 +195,7 @@ const time_of_day& tod_manager::get_time_of_day(const map_location& loc, int n_t
const time_of_day tod_manager::get_illuminated_time_of_day(const map_location& loc, int for_turn) const
{
- const gamemap& map = resources::gameboard->map();
+ const gamemap& map = resources::disp_context->map();
const unit_map& units = *resources::units;
// get ToD ignoring illumination