move village_owner function to display_context

I would have liked to put it in game_board, but it is needed for
reports so it can't go there
This commit is contained in:
Chris Beck 2014-06-25 22:22:07 -04:00
parent 221863b893
commit f5a9de40d5
16 changed files with 39 additions and 38 deletions

View File

@ -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);

View File

@ -831,7 +831,7 @@ bool ai_default_recruitment_stage::do_play_stage()
// that are closer to us than to other keeps.
const std::vector<map_location>& villages = resources::gameboard->map().villages();
for(std::vector<map_location>::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);

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -246,7 +246,7 @@ void recruitment_phase::execute()
// that are closer to us than to other keeps.
const std::vector<map_location>& villages = map_.villages();
for(std::vector<map_location>::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);

View File

@ -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);

View File

@ -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<team> & t = teams();
for(size_t i = 0; i != t.size(); ++i) {
if(t[i].owns_village(loc))
return i;
}
return -1;
}

View File

@ -45,6 +45,14 @@ public:
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() {}

View File

@ -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()) {

View File

@ -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());

View File

@ -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) {

View File

@ -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<int>(teams.size())

View File

@ -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;
}

View File

@ -381,12 +381,6 @@ namespace teams_manager {
const std::vector<team> &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();

View File

@ -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<int>& 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;
}
}