diff --git a/src/actions/move.cpp b/src/actions/move.cpp index 09732341df2e..3eedcbd60c9a 100644 --- a/src/actions/move.cpp +++ b/src/actions/move.cpp @@ -1051,7 +1051,7 @@ namespace { // Private helpers for move_unit() // Village capturing. if ( resources::gameboard->map().is_village(final_loc) ) { // Is this a capture? - orig_village_owner = village_owner(final_loc); + orig_village_owner = resources::gameboard->village_owner(final_loc); if ( orig_village_owner != current_side_-1 ) { // Captured. Zap movement and take over the village. move_it_->set_movement(0, true); diff --git a/src/ai/default/ai.cpp b/src/ai/default/ai.cpp index f04a5e2b2ceb..297d46356ee6 100644 --- a/src/ai/default/ai.cpp +++ b/src/ai/default/ai.cpp @@ -831,7 +831,7 @@ bool ai_default_recruitment_stage::do_play_stage() // that are closer to us than to other keeps. const std::vector& villages = resources::gameboard->map().villages(); for(std::vector::const_iterator v = villages.begin(); v != villages.end(); ++v) { - const int owner = village_owner(*v); + const int owner = resources::gameboard->village_owner(*v); if(owner == -1) { const size_t distance = distance_between(start_pos,*v); diff --git a/src/ai/default/contexts.cpp b/src/ai/default/contexts.cpp index 20dfcafadc55..25c6144a5e1d 100644 --- a/src/ai/default/contexts.cpp +++ b/src/ai/default/contexts.cpp @@ -114,7 +114,7 @@ int default_ai_context_impl::rate_terrain(const unit& u, const map_location& loc } if(map_.is_village(terrain)) { - int owner = village_owner(loc) + 1; + int owner = resources::gameboard->village_owner(loc) + 1; if(owner == get_side()) { rating += friendly_village_value; diff --git a/src/ai/recruitment/recruitment.cpp b/src/ai/recruitment/recruitment.cpp index f141a18c09d4..ad15f86ceabf 100644 --- a/src/ai/recruitment/recruitment.cpp +++ b/src/ai/recruitment/recruitment.cpp @@ -1445,7 +1445,7 @@ double recruitment::get_estimated_village_gain() const { const gamemap& map = resources::gameboard->map(); int neutral_villages = 0; BOOST_FOREACH(const map_location& village, map.villages()) { - if (village_owner(village) == -1) { + if (resources::gameboard->village_owner(village) == -1) { ++neutral_villages; } } @@ -1710,7 +1710,7 @@ void recruitment::update_scouts_wanted() { // We recruit the initial allocation of scouts // based on how many neutral villages there are. BOOST_FOREACH(const map_location& village, resources::gameboard->map().villages()) { - if (village_owner(village) == -1) { + if (resources::gameboard->village_owner(village) == -1) { ++neutral_villages; } } diff --git a/src/ai/testing/aspect_attacks.cpp b/src/ai/testing/aspect_attacks.cpp index d29d6d12c2db..404c84bcab24 100644 --- a/src/ai/testing/aspect_attacks.cpp +++ b/src/ai/testing/aspect_attacks.cpp @@ -375,7 +375,7 @@ int aspect_attacks::rate_terrain(const unit& u, const map_location& loc) } if(map_.is_village(terrain)) { - int owner = village_owner(loc) + 1; + int owner = resources::gameboard->village_owner(loc) + 1; if(owner == u.side()) { rating += friendly_village_value; diff --git a/src/ai/testing/ca.cpp b/src/ai/testing/ca.cpp index 1d10d45fbefe..c434e0084a16 100644 --- a/src/ai/testing/ca.cpp +++ b/src/ai/testing/ca.cpp @@ -246,7 +246,7 @@ void recruitment_phase::execute() // that are closer to us than to other keeps. const std::vector& villages = map_.villages(); for(std::vector::const_iterator v = villages.begin(); v != villages.end(); ++v) { - const int owner = village_owner(*v); + const int owner = resources::gameboard->village_owner(*v); if(owner == -1) { const size_t distance = distance_between(start_pos,*v); diff --git a/src/display.cpp b/src/display.cpp index e5a6593bf845..92bd23490e23 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -3058,7 +3058,7 @@ bool display::invalidate_locations_in_rect(const SDL_Rect& rect) void display::invalidate_animations_location(const map_location& loc) { if (get_map().is_village(loc)) { - const int owner = village_owner(loc); + const int owner = dc_->village_owner(loc); if (owner >= 0 && flags_[owner].need_update() && (!fogged(loc) || !dc_->teams()[currentTeam_].is_enemy(owner+1))) { invalidate(loc); diff --git a/src/display_context.cpp b/src/display_context.cpp index 221cd80f7b0b..591fd89db109 100644 --- a/src/display_context.cpp +++ b/src/display_context.cpp @@ -67,3 +67,18 @@ bool display_context::unit_can_move(const unit &u) const return false; } + +/** + * Given the location of a village, will return the 0-based index + * of the team that currently owns it, and -1 if it is unowned. + */ +int display_context::village_owner(const map_location& loc) const +{ + const std::vector & t = teams(); + for(size_t i = 0; i != t.size(); ++i) { + if(t[i].owns_village(loc)) + return i; + } + return -1; +} + diff --git a/src/display_context.hpp b/src/display_context.hpp index f2a3d56b6612..b30b29e23588 100644 --- a/src/display_context.hpp +++ b/src/display_context.hpp @@ -45,6 +45,14 @@ class display_context { bool unit_can_move(const unit & u) const; + // From class team + + /** + * Given the location of a village, will return the 0-based index + * of the team that currently owns it, and -1 if it is unowned. + */ + int village_owner(const map_location & loc) const; + // Dtor virtual ~display_context() {} diff --git a/src/menu_events.cpp b/src/menu_events.cpp index 11fc811b110a..17ac710f1d2d 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -1130,7 +1130,7 @@ void menu_handler::change_side(mouse_handler& mousehandler) return; // village_owner returns -1 for free village, so team 0 will get it - int team = village_owner(loc) + 1; + int team = resources::gameboard->village_owner(loc) + 1; // team is 0-based so team=team::nteams() is not a team // but this will make get_village free it if(team > team::nteams()) { diff --git a/src/minimap.cpp b/src/minimap.cpp index 6c776defd7ed..a18c86dafdb8 100644 --- a/src/minimap.cpp +++ b/src/minimap.cpp @@ -17,6 +17,7 @@ #include "global.hpp" #include "minimap.hpp" +#include "game_board.hpp" #include "gettext.hpp" #include "image.hpp" #include "log.hpp" @@ -233,7 +234,7 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std:: if (terrain_info.is_village() && preferences_minimap_draw_villages) { - int side = village_owner(loc); + int side = resources::gameboard->village_owner(loc); SDL_Color col = int_to_color(game_config::team_rgb_range.find("white")->second.min()); diff --git a/src/reports.cpp b/src/reports.cpp index ebbe1c3d49c7..de9cd3adb50f 100644 --- a/src/reports.cpp +++ b/src/reports.cpp @@ -1407,7 +1407,7 @@ REPORT_GENERATOR(terrain, rc) std::ostringstream str; if (map.is_village(mouseover_hex)) { - int owner = village_owner(mouseover_hex) + 1; + int owner = rc.dc().village_owner(mouseover_hex) + 1; if (owner == 0 || viewing_team.fogged(mouseover_hex)) { str << map.get_terrain_info(terrain).income_description(); } else if (owner == viewing_side) { diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index ec459cef2972..00834674e1a1 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1440,7 +1440,7 @@ static int intf_get_village_owner(lua_State *L) if (!resources::gameboard->map().is_village(loc)) return 0; - int side = village_owner(loc) + 1; + int side = resources::gameboard->village_owner(loc) + 1; if (!side) return 0; lua_pushinteger(L, side); return 1; @@ -1462,7 +1462,7 @@ static int intf_set_village_owner(lua_State *L) if (!resources::gameboard->map().is_village(loc)) return 0; - int old_side = village_owner(loc) + 1; + int old_side = resources::gameboard->village_owner(loc) + 1; if (new_side == old_side || new_side < 0 || new_side > static_cast(teams.size()) diff --git a/src/team.cpp b/src/team.cpp index 1dcab52b58ab..47469841d054 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -842,20 +842,3 @@ config team::to_config() const write(result); return result; } - -/** - * Given the location of a village, will return the 0-based index - * of the team that currently owns it, and -1 if it is unowned. - */ -int village_owner(const map_location& loc) -{ - if(! teams) { - return -1; - } - for(size_t i = 0; i != teams->size(); ++i) { - if((*teams)[i].owns_village(loc)) - return i; - } - return -1; -} - diff --git a/src/team.hpp b/src/team.hpp index 8bf34d01e01e..76c9d116cdd8 100644 --- a/src/team.hpp +++ b/src/team.hpp @@ -381,12 +381,6 @@ namespace teams_manager { const std::vector &get_teams(); } -/** - * Given the location of a village, will return the 0-based index - * of the team that currently owns it, and -1 if it is unowned. - */ -int village_owner(const map_location& loc); - //FIXME: this global method really needs to be moved into play_controller, //or somewhere else that makes sense. bool is_observer(); diff --git a/src/terrain_filter.cpp b/src/terrain_filter.cpp index 270d36b758b8..663498e3890d 100644 --- a/src/terrain_filter.cpp +++ b/src/terrain_filter.cpp @@ -289,7 +289,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x side_filter ssf(filter_owner); const std::vector& sides = ssf.get_teams(); bool found = false; - if(sides.empty() && village_owner(loc) == -1) + if(sides.empty() && resources::gameboard->village_owner(loc) == -1) found = true; BOOST_FOREACH(const int side, sides) { if(resources::teams->at(side - 1).owns_village(loc)) { @@ -302,7 +302,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x } else if(!owner_side.empty()) { const int side_index = owner_side.to_int(0) - 1; - if(village_owner(loc) != side_index) { + if(resources::gameboard->village_owner(loc) != side_index) { return false; } }