diff --git a/src/actions.cpp b/src/actions.cpp index 33039aacc74..3e78373ae61 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -2513,9 +2513,8 @@ std::vector::const_iterator known_movement_end( // Alias some resources. const gamemap &map = *resources::game_map; const unit_map &units = *resources::units; - const std::vector &teams = *resources::teams; const int current_side = mover_it->side(); - const team ¤t_team = teams[current_side-1]; + const team ¤t_team = (*resources::teams)[current_side-1]; // This loop will end with step pointing one element beyond // where the unit thinks it will stop. @@ -2538,7 +2537,7 @@ std::vector::const_iterator known_movement_end( // Check for being unable to leave this hex. if ( !mover_it->get_ability_bool("skirmisher", *step) && - pathfind::enemy_zoc(teams, *step, current_team, current_side) ) { + pathfind::enemy_zoc(current_team, *step, current_team) ) { zoc_stop = *step; } } diff --git a/src/pathfind/pathfind.cpp b/src/pathfind/pathfind.cpp index 6008f88b024..f3c50448cc0 100644 --- a/src/pathfind/pathfind.cpp +++ b/src/pathfind/pathfind.cpp @@ -93,22 +93,30 @@ map_location pathfind::find_vacant_tile(const gamemap& map, return map_location(); } -bool pathfind::enemy_zoc(std::vector const &teams, - map_location const &loc, team const &viewing_team, int side, bool see_all) +/** + * Determines if a given location is in an enemy zone of control. + * + * @param current_team The moving team (only ZoC of enemies of this team are considered). + * @param loc The location to check. + * @param viewing_team Only units visible to this team are considered. + * @param see_all If true, all units are considered (and viewing_team is ignored). + * + * @return true iff a visible enemy exerts zone of control over loc. + */ +bool pathfind::enemy_zoc(team const ¤t_team, map_location const &loc, + team const &viewing_team, bool see_all) { + // Check the adjacent tiles. map_location locs[6]; - const team ¤t_team = teams[side-1]; get_adjacent_tiles(loc,locs); for (int i = 0; i != 6; ++i) { const unit *u = get_visible_unit(locs[i], viewing_team, see_all); - if (u && u->side() != side && current_team.is_enemy(u->side()) && - u->emits_zoc()) - { + if ( u && current_team.is_enemy(u->side()) && u->emits_zoc() ) return true; - } } + // No adjacent tiles had an enemy exerting ZoC over loc. return false; } @@ -169,16 +177,14 @@ struct comp { }; } -static void find_routes(const gamemap& map, const unit_map& /*units*/, - const unit& u, +static void find_routes(const gamemap& map, const unit& u, int move_left, pathfind::paths::dest_vect &destinations, - std::vector const &teams, + const team ¤t_team, bool force_ignore_zocs, bool allow_teleport, int turns_left, const team &viewing_team, bool see_all, bool ignore_units) { const map_location loc = u.get_location(); - const team& current_team = teams[u.side() - 1]; pathfind::teleport_map teleports; if (allow_teleport) { teleports = pathfind::get_teleport_locations(u, viewing_team, see_all, ignore_units); @@ -250,7 +256,7 @@ static void find_routes(const gamemap& map, const unit_map& /*units*/, continue; if (!force_ignore_zocs && t.movement_left > 0 - && pathfind::enemy_zoc(teams, locs[i], viewing_team, u.side(), see_all) + && pathfind::enemy_zoc(current_team, locs[i], viewing_team, see_all) && !u.get_ability_bool("skirmisher", locs[i])) { t.movement_left = 0; } @@ -347,7 +353,7 @@ bool pathfind::paths::dest_vect::contains(const map_location &loc) const return find(loc) != end(); } -pathfind::paths::paths(gamemap const &map, unit_map const &units, +pathfind::paths::paths(gamemap const &map, unit_map const &/*units*/, const unit& u, std::vector const &teams, bool force_ignore_zoc, bool allow_teleport, const team &viewing_team, int additional_turns, bool see_all, bool ignore_units) @@ -357,10 +363,9 @@ pathfind::paths::paths(gamemap const &map, unit_map const &units, return; } - find_routes(map, units, u, - u.movement_left(), destinations, teams, force_ignore_zoc, - allow_teleport,additional_turns,viewing_team, - see_all, ignore_units); + find_routes(map, u, u.movement_left(), destinations, teams[u.side()-1], + force_ignore_zoc, allow_teleport, additional_turns, + viewing_team, see_all, ignore_units); } pathfind::marked_route pathfind::mark_route(const plain_route &rt) @@ -412,7 +417,7 @@ pathfind::marked_route pathfind::mark_route(const plain_route &rt) } } - zoc = enemy_zoc((*resources::teams), *(i + 1), viewing_team,u.side()) + zoc = enemy_zoc(unit_team, *(i + 1), viewing_team) && !u.get_ability_bool("skirmisher", *(i+1)); if (zoc) { @@ -495,7 +500,7 @@ double pathfind::shortest_path_calculator::cost(const map_location& loc, const d // check ZoC if (!ignore_unit_ && remaining_movement != terrain_cost - && enemy_zoc(teams_, loc, viewing_team_, unit_.side(), see_all_) + && enemy_zoc(teams_[unit_.side()-1], loc, viewing_team_, see_all_) && !unit_.get_ability_bool("skirmisher", loc)) { // entering ZoC cost all remaining MP move_cost += remaining_movement; diff --git a/src/pathfind/pathfind.hpp b/src/pathfind/pathfind.hpp index 1fc8153a031..da647d8d199 100644 --- a/src/pathfind/pathfind.hpp +++ b/src/pathfind/pathfind.hpp @@ -50,9 +50,9 @@ map_location find_vacant_tile(const gamemap& map, VACANT_TILE_TYPE vacancy=VACANT_ANY, const unit* pass_check=NULL); -/** Function which determines if a given location is in an enemy zone of control. */ -bool enemy_zoc(std::vector const &teams, map_location const &loc, - team const &viewing_team, int side, bool see_all=false); +/** Determines if a given location is in an enemy zone of control. */ +bool enemy_zoc(team const ¤t_team, map_location const &loc, + team const &viewing_team, bool see_all=false); struct cost_calculator @@ -85,7 +85,7 @@ struct paths // will be calculated, and so forth. // viewing_team is usually current team, except for Show Enemy Moves etc. paths(gamemap const &map, - unit_map const &units, + unit_map const &/*units*/, // Not used const unit& u, std::vector const &teams, bool force_ignore_zocs, bool allow_teleport, const team &viewing_team, int additional_turns = 0, diff --git a/src/whiteboard/utility.cpp b/src/whiteboard/utility.cpp index d37975c9b11..5d762294e91 100644 --- a/src/whiteboard/utility.cpp +++ b/src/whiteboard/utility.cpp @@ -117,9 +117,10 @@ int path_cost(std::vector const& path, unit const& u) if(path.size() < 2) return 0; + team const& u_team = resources::teams->at(u.side()-1); map_location const& dest = path.back(); - if((resources::game_map->is_village(dest) && !resources::teams->at(u.side()-1).owns_village(dest)) - || pathfind::enemy_zoc(*resources::teams,dest,resources::teams->at(u.side()-1),u.side())) + if ( (resources::game_map->is_village(dest) && !u_team.owns_village(dest)) + || pathfind::enemy_zoc(u_team, dest, u_team) ) return u.total_movement(); int result = 0;