Eliminate a parameter that was always *resources::teams.
This made the two implementations of village_owner() identical modulo an error check, so I merged them.
This commit is contained in:
parent
e3b1f228ae
commit
b08206f291
14 changed files with 23 additions and 38 deletions
|
@ -1925,16 +1925,6 @@ void attack::perform()
|
|||
}
|
||||
|
||||
|
||||
int village_owner(const map_location& loc, const std::vector<team>& teams)
|
||||
{
|
||||
for(size_t i = 0; i != teams.size(); ++i) {
|
||||
if(teams[i].owns_village(loc))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool get_village(const map_location& loc, int side, int *action_timebonus)
|
||||
{
|
||||
std::vector<team> &teams = *resources::teams;
|
||||
|
@ -3401,7 +3391,7 @@ namespace { // Private helpers for move_unit()
|
|||
// Village capturing.
|
||||
if ( resources::game_map->is_village(final_loc) ) {
|
||||
// Is this a capture?
|
||||
orig_village_owner = village_owner(final_loc, *resources::teams);
|
||||
orig_village_owner = village_owner(final_loc);
|
||||
if ( orig_village_owner != current_side_-1 ) {
|
||||
// Captured. Zap movement and take over the village.
|
||||
move_it_->set_movement(0);
|
||||
|
|
|
@ -299,12 +299,6 @@ private:
|
|||
unit_map::const_iterator unit_;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 std::vector<team>& teams);
|
||||
|
||||
/**
|
||||
* Makes it so the village at the given location is owned by the given side.
|
||||
* Returns true if getting the village triggered a mutating event.
|
||||
|
|
|
@ -830,7 +830,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::game_map->villages();
|
||||
for(std::vector<map_location>::const_iterator v = villages.begin(); v != villages.end(); ++v) {
|
||||
const int owner = village_owner(*v,*resources::teams);
|
||||
const int owner = village_owner(*v);
|
||||
if(owner == -1) {
|
||||
const size_t distance = distance_between(start_pos,*v);
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "contexts.hpp"
|
||||
|
||||
#include "../../actions.hpp"
|
||||
#include "../../log.hpp"
|
||||
#include "../../map.hpp"
|
||||
#include "../../resources.hpp"
|
||||
|
@ -118,7 +117,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, *resources::teams) + 1;
|
||||
int owner = village_owner(loc) + 1;
|
||||
|
||||
if(owner == get_side()) {
|
||||
rating += friendly_village_value;
|
||||
|
|
|
@ -374,7 +374,7 @@ int aspect_attacks::rate_terrain(const unit& u, const map_location& loc)
|
|||
}
|
||||
|
||||
if(map_.is_village(terrain)) {
|
||||
int owner = village_owner(loc, *resources::teams) + 1;
|
||||
int owner = village_owner(loc) + 1;
|
||||
|
||||
if(owner == u.side()) {
|
||||
rating += friendly_village_value;
|
||||
|
|
|
@ -223,7 +223,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,teams_);
|
||||
const int owner = village_owner(*v);
|
||||
if(owner == -1) {
|
||||
const size_t distance = distance_between(start_pos,*v);
|
||||
|
||||
|
|
|
@ -2758,7 +2758,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 = player_teams::village_owner(loc);
|
||||
const int owner = village_owner(loc);
|
||||
if (owner >= 0 && flags_[owner].need_update()
|
||||
&& (!fogged(loc) || !(*teams_)[currentTeam_].is_enemy(owner+1))) {
|
||||
invalidate(loc);
|
||||
|
|
|
@ -1782,7 +1782,7 @@ void change_terrain(const map_location &loc, const t_translation::t_terrain &t,
|
|||
preferences::encountered_terrains().insert(new_t);
|
||||
|
||||
if (game_map->is_village(old_t) && !game_map->is_village(new_t)) {
|
||||
int owner = village_owner(loc, *resources::teams);
|
||||
int owner = village_owner(loc);
|
||||
if (owner != -1)
|
||||
(*resources::teams)[owner].lose_village(loc);
|
||||
}
|
||||
|
|
|
@ -1630,7 +1630,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, teams_) + 1;
|
||||
int team = 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()) {
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "actions.hpp"
|
||||
#include "attack_prediction.hpp"
|
||||
#include "editor/editor_controller.hpp"
|
||||
#include "editor/palette/terrain_palettes.hpp"
|
||||
|
@ -1101,7 +1100,7 @@ REPORT_GENERATOR(terrain)
|
|||
std::ostringstream str;
|
||||
if (map.is_village(mouseover_hex))
|
||||
{
|
||||
int owner = village_owner(mouseover_hex, *resources::teams) + 1;
|
||||
int owner = 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) {
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "scripting/lua.hpp"
|
||||
#include "scripting/lua_api.hpp"
|
||||
|
||||
#include "actions.hpp"
|
||||
#include "ai/manager.hpp"
|
||||
#include "ai/composite/component.hpp"
|
||||
#include "ai/composite/engine_lua.hpp"
|
||||
|
@ -1809,7 +1808,7 @@ static int intf_get_village_owner(lua_State *L)
|
|||
if (!resources::game_map->is_village(loc))
|
||||
return 0;
|
||||
|
||||
int side = village_owner(loc, *resources::teams) + 1;
|
||||
int side = village_owner(loc) + 1;
|
||||
if (!side) return 0;
|
||||
lua_pushinteger(L, side);
|
||||
return 1;
|
||||
|
@ -1831,7 +1830,7 @@ static int intf_set_village_owner(lua_State *L)
|
|||
if (!resources::game_map->is_village(loc))
|
||||
return 0;
|
||||
|
||||
int old_side = village_owner(loc, teams) + 1;
|
||||
int old_side = village_owner(loc) + 1;
|
||||
if (new_side == old_side
|
||||
|| new_side < 0
|
||||
|| new_side > static_cast<int>(teams.size())
|
||||
|
|
|
@ -875,7 +875,10 @@ config team::to_config() const
|
|||
return result;
|
||||
}
|
||||
|
||||
namespace player_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)
|
||||
{
|
||||
if(! teams) {
|
||||
|
@ -887,4 +890,4 @@ int village_owner(const map_location& loc)
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -323,9 +323,11 @@ namespace teams_manager {
|
|||
const std::vector<team> &get_teams();
|
||||
}
|
||||
|
||||
namespace player_teams {
|
||||
int village_owner(const map_location& loc);
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "actions.hpp"
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "map.hpp"
|
||||
|
@ -284,7 +283,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, *resources::teams) == -1)
|
||||
if(sides.empty() && village_owner(loc) == -1)
|
||||
found = true;
|
||||
BOOST_FOREACH(const int side, sides) {
|
||||
if(resources::teams->at(side - 1).owns_village(loc)) {
|
||||
|
@ -297,7 +296,7 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
|
|||
}
|
||||
else if(!owner_side.empty()) {
|
||||
const int side_index = lexical_cast_default<int>(owner_side,0) - 1;
|
||||
if(village_owner(loc, *resources::teams) != side_index) {
|
||||
if(village_owner(loc) != side_index) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue