Hexes with invisible enemy units are treated as empty hexes to calculate paths
This commit is contained in:
parent
f48cd4f5d9
commit
c1e997d1a6
3 changed files with 25 additions and 9 deletions
|
@ -281,8 +281,11 @@ int route_turns_to_complete(const unit& u, const gamemap& map,
|
|||
|
||||
shortest_path_calculator::shortest_path_calculator(const unit& u, const team& t,
|
||||
const unit_map& units,
|
||||
const gamemap& map)
|
||||
: unit_(u), team_(t), units_(units), map_(map)
|
||||
const std::vector<team>& teams,
|
||||
const gamemap& map,
|
||||
const gamestatus& status)
|
||||
: unit_(u), team_(t), units_(units), teams_(teams),
|
||||
status_(status), map_(map)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -292,7 +295,10 @@ double shortest_path_calculator::cost(const gamemap::location& loc,
|
|||
if(!map_.on_board(loc) || team_.shrouded(loc.x,loc.y))
|
||||
return 100000.0;
|
||||
|
||||
const unit_map::const_iterator enemy_unit = units_.find(loc);
|
||||
const unit_map::const_iterator enemy_unit = find_visible_unit(units_,
|
||||
loc,map_,
|
||||
status_.get_time_of_day().lawful_bonus,teams_,team_);
|
||||
|
||||
if(enemy_unit != units_.end() && team_.is_enemy(enemy_unit->second.side()))
|
||||
return 100000.0;
|
||||
|
||||
|
@ -301,7 +307,10 @@ double shortest_path_calculator::cost(const gamemap::location& loc,
|
|||
get_adjacent_tiles(loc,adj);
|
||||
|
||||
for(size_t i = 0; i != 6; ++i) {
|
||||
const unit_map::const_iterator u = units_.find(adj[i]);
|
||||
const unit_map::const_iterator u = find_visible_unit(units_,
|
||||
adj[i],map_,
|
||||
status_.get_time_of_day().lawful_bonus,teams_,team_);
|
||||
|
||||
if(u != units_.end() && team_.is_enemy(u->second.side()) && !team_.fogged(adj[i].x,adj[i].y)) {
|
||||
return 100000.0;
|
||||
}
|
||||
|
|
|
@ -94,14 +94,19 @@ int route_turns_to_complete(const unit& u, const gamemap& map,
|
|||
struct shortest_path_calculator
|
||||
{
|
||||
shortest_path_calculator(const unit& u, const team& t,
|
||||
const unit_map& units, const gamemap& map);
|
||||
const unit_map& units,
|
||||
const std::vector<team>& teams,
|
||||
const gamemap& map,
|
||||
const gamestatus& status);
|
||||
double cost(const gamemap::location& loc, double so_far) const;
|
||||
|
||||
private:
|
||||
const unit& unit_;
|
||||
const team& team_;
|
||||
const unit_map& units_;
|
||||
const std::vector<team>& teams_;
|
||||
const gamemap& map_;
|
||||
const gamestatus& status_;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
|
|
@ -90,7 +90,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
assert(ui != units.end());
|
||||
|
||||
unit u = ui->second;
|
||||
const shortest_path_calculator calc(u,current_team,units,map);
|
||||
const shortest_path_calculator calc(u,current_team,units,teams,map,status);
|
||||
|
||||
const std::set<gamemap::location>* teleports = NULL;
|
||||
|
||||
|
@ -313,7 +313,7 @@ void turn_info::mouse_motion(const SDL_MouseMotionEvent& event)
|
|||
|
||||
if(un != units_.end()) {
|
||||
const shortest_path_calculator calc(un->second,current_team,
|
||||
units_,map_);
|
||||
units_,teams_,map_,status_);
|
||||
const bool can_teleport = un->second.type().teleports();
|
||||
|
||||
const std::set<gamemap::location>* teleports = NULL;
|
||||
|
@ -426,7 +426,9 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
|
|||
|
||||
gamemap::location hex = gui_.hex_clicked_on(event.x,event.y);
|
||||
|
||||
unit_map::iterator u = units_.find(selected_hex_);
|
||||
unit_map::iterator u = find_visible_unit(units_,
|
||||
selected_hex_, map_,
|
||||
status_.get_time_of_day().lawful_bonus,teams_,current_team);
|
||||
|
||||
//if the unit is selected and then itself clicked on,
|
||||
//any goto command is cancelled
|
||||
|
@ -658,7 +660,7 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
|
|||
const gamemap::location go_to = u.get_goto();
|
||||
if(map_.on_board(go_to)) {
|
||||
const shortest_path_calculator calc(u,current_team,
|
||||
units_,map_);
|
||||
units_,teams_,map_,status_);
|
||||
|
||||
const std::set<gamemap::location>* teleports = NULL;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue