Make "viewing_team" a non-optional arg to paths() constructor.

Callers must understand the difference between asking for paths to
draw them (ie. viewing_player()) and to actually move something
(ie. current_player()).  Most importantly, this fixes #5362 where you
can detect hidden enemy units by mousing over your own players during
an enemy move.
This commit is contained in:
Rusty Russell 2006-02-22 10:42:13 +00:00
parent a7a46a1eac
commit bb4ba16e96
7 changed files with 29 additions and 32 deletions

View file

@ -1862,7 +1862,7 @@ bool clear_shroud_unit(const gamemap& map,
unit_map temp_units;
temp_units.insert(*u);
paths p(map,status,gamedata,temp_units,loc,teams,true,false);
paths p(map,status,gamedata,temp_units,loc,teams,true,false,teams[team]);
for(paths::routes_map::const_iterator i = p.routes.begin();
i != p.routes.end(); ++i) {
clear_shroud_loc(map,teams[team],i->first,&cleared_locations);

View file

@ -416,7 +416,7 @@ gamemap::location ai_interface::move_unit_partial(location from, location to, st
const bool ignore_zocs = u_it->second.type().is_skirmisher();
const bool teleport = u_it->second.type().teleports();
paths current_paths(info_.map,info_.state,info_.gameinfo,info_.units,from,info_.teams,ignore_zocs,teleport);
paths current_paths(info_.map,info_.state,info_.gameinfo,info_.units,from,info_.teams,ignore_zocs,teleport,current_team());
const std::map<location,paths>::iterator p_it = possible_moves.find(from);
@ -537,7 +537,7 @@ bool ai::multistep_move_possible(location from, location to, location via, std::
unit temp_unit(i->second);
temp_unit.set_movement(move_left);
const temporary_unit_placer unit_placer(units_,via,temp_unit);
const paths unit_paths(map_,state_,gameinfo_,units_,via,teams_,false,false);
const paths unit_paths(map_,state_,gameinfo_,units_,via,teams_,false,false,current_team());
LOG_AI << "found " << unit_paths.routes.size() << " moves for temp leader\n";
@ -666,7 +666,7 @@ void ai_interface::calculate_possible_moves(std::map<location,paths>& res, move_
const bool teleports = un_it->second.type().teleports();
res.insert(std::pair<gamemap::location,paths>(
un_it->first,paths(info_.map,info_.state,info_.gameinfo,info_.units,
un_it->first,info_.teams,ignore_zocs,teleports)));
un_it->first,info_.teams,ignore_zocs,teleports,current_team())));
}
for(std::map<location,paths>::iterator m = res.begin(); m != res.end(); ++m) {
@ -1752,7 +1752,7 @@ void ai::move_leader_to_goals( const move_map& enemy_dstsrc)
return;
}
const paths leader_paths(map_,state_,gameinfo_,units_,leader->first,teams_,false,false);
const paths leader_paths(map_,state_,gameinfo_,units_,leader->first,teams_,false,false,current_team());
std::map<gamemap::location,paths> possible_moves;
possible_moves.insert(std::pair<gamemap::location,paths>(leader->first,leader_paths));
@ -1778,7 +1778,7 @@ void ai::move_leader_to_keep(const move_map& enemy_dstsrc)
}
//find where the leader can move
const paths leader_paths(map_,state_,gameinfo_,units_,leader->first,teams_,false,false);
const paths leader_paths(map_,state_,gameinfo_,units_,leader->first,teams_,false,false,current_team());
const gamemap::location& start_pos = nearest_keep(leader->first);
std::map<gamemap::location,paths> possible_moves;
@ -1826,7 +1826,7 @@ void ai::move_leader_after_recruit(const move_map& enemy_dstsrc)
return;
}
const paths leader_paths(map_,state_,gameinfo_,units_,leader->first,teams_,false,false);
const paths leader_paths(map_,state_,gameinfo_,units_,leader->first,teams_,false,false,current_team());
std::map<gamemap::location,paths> possible_moves;
possible_moves.insert(std::pair<gamemap::location,paths>(leader->first,leader_paths));
@ -1857,7 +1857,7 @@ void ai::move_leader_after_recruit(const move_map& enemy_dstsrc)
<< "," << str_cast(current_loc.y+1);
unit_map temp_units;
temp_units.insert(std::pair<location,unit>(current_loc,leader->second));
const paths p(map_,state_,gameinfo_,temp_units,current_loc,teams_,false,false);
const paths p(map_,state_,gameinfo_,temp_units,current_loc,teams_,false,false,current_team());
if(p.routes.count(i->first)) {
move_unit(leader->first,current_loc,possible_moves);
@ -1924,7 +1924,7 @@ bool ai::leader_can_reach_keep() const
}
//find where the leader can move
const paths leader_paths(map_,state_,gameinfo_,units_,leader->first,teams_,false,false);
const paths leader_paths(map_,state_,gameinfo_,units_,leader->first,teams_,false,false,current_team());
return leader_paths.routes.count(start_pos) > 0;

View file

@ -149,7 +149,7 @@ void mouse_handler::mouse_motion(int x, int y)
const bool ignore_zocs = un->second.type().is_skirmisher();
const bool teleport = un->second.type().teleports();
current_paths_ = paths(map_,status_,gameinfo_,units_,new_hex,teams_,
ignore_zocs,teleport,NULL,path_turns_);
ignore_zocs,teleport,viewing_team(),path_turns_);
gui_->highlight_reach(current_paths_);
enemy_paths_ = true;
}
@ -367,7 +367,7 @@ void mouse_handler::left_click(const SDL_MouseButtonEvent& event)
const bool ignore_zocs = it->second.type().is_skirmisher();
const bool teleport = it->second.type().teleports();
current_paths_ = paths(map_,status_,gameinfo_,units_,hex,teams_,
ignore_zocs,teleport,NULL,path_turns_);
ignore_zocs,teleport,viewing_team(),path_turns_);
next_unit_ = it->first;

View file

@ -360,15 +360,13 @@ namespace {
std::map<gamemap::location,paths::route>& routes,
std::vector<team> const &teams,
bool ignore_zocs, bool allow_teleport, int turns_left,
bool starting_pos, const team *viewing_team)
bool starting_pos, const team &viewing_team)
{
if(size_t(u.side()-1) >= teams.size()) {
return;
}
team const &current_team = teams[u.side()-1];
if (!viewing_team)
viewing_team = &current_team;
//find adjacent tiles
std::vector<gamemap::location> locs(6);
@ -380,7 +378,7 @@ namespace {
current_team.owns_village(loc) &&
(starting_pos || find_visible_unit(units, loc, map,
status.get_time_of_day().lawful_bonus,
teams, *viewing_team) == units.end())) {
teams, viewing_team) == units.end())) {
const std::vector<gamemap::location>& villages = map.villages();
//if we are on a village, see all friendly villages that we can
@ -407,7 +405,7 @@ namespace {
const std::map<gamemap::location,unit>::const_iterator unit_it =
find_visible_unit(units, locs[i], map,
status.get_time_of_day().lawful_bonus,
teams, *viewing_team);
teams, viewing_team);
if (unit_it != units.end() &&
current_team.is_enemy(unit_it->second.side()))
@ -437,7 +435,7 @@ namespace {
continue;
const bool zoc = !ignore_zocs && enemy_zoc(map,status,units,teams,currentloc,
*viewing_team,u.side());
viewing_team,u.side());
paths::route new_route = routes[loc];
new_route.steps.push_back(loc);
@ -461,7 +459,7 @@ paths::paths(gamemap const &map, gamestatus const &status,
std::map<gamemap::location, unit> const &units,
gamemap::location const &loc,
std::vector<team> const &teams,
bool ignore_zocs, bool allow_teleport, const team *viewing_team,
bool ignore_zocs, bool allow_teleport, const team &viewing_team,
int additional_turns)
{
const std::map<gamemap::location,unit>::const_iterator i = units.find(loc);

View file

@ -81,7 +81,7 @@ struct paths
std::map<gamemap::location, unit> const &units,
gamemap::location const &loc, std::vector<team> const &teams,
bool ignore_zocs, bool allow_teleport,
const team *viewing_team = NULL, int additional_turns = 0);
const team &viewing_team, int additional_turns = 0);
//structure which holds a single route between one location and another.
struct route

View file

@ -306,8 +306,8 @@ void turn_info::handle_event(const SDL_Event& event)
const bool ignore_zocs = u->second.type().is_skirmisher();
const bool teleport = u->second.type().teleports();
current_paths_ = paths(map_,status_,gameinfo_,units_,u->first,
teams_,ignore_zocs,teleport,NULL,
path_turns_);
teams_,ignore_zocs,teleport,
viewing_team(),path_turns_);
gui_.highlight_reach(current_paths_);
}
}
@ -365,7 +365,6 @@ void turn_info::mouse_motion(int x, int y)
gamemap::location::DIRECTION nearest_hex = gamemap::location::NDIRECTIONS;
gamemap::location::DIRECTION second_nearest_hex = gamemap::location::NDIRECTIONS;
const team& current_team = teams_[team_num_-1];
const gamemap::location new_hex = gui_.hex_clicked_on(x,y,&nearest_hex,&second_nearest_hex);
if(new_hex != last_hex_ || nearest_hex != last_nearest_ || second_nearest_hex != last_second_nearest_) {
@ -392,7 +391,7 @@ void turn_info::mouse_motion(int x, int y)
attack_from.valid())) {
if(mouseover_unit == units_.end()) {
cursor::set(cursor::MOVE);
} else if(current_team.is_enemy(mouseover_unit->second.side()) && !mouseover_unit->second.stone()) {
} else if(viewing_team().is_enemy(mouseover_unit->second.side()) && !mouseover_unit->second.stone()) {
cursor::set(cursor::ATTACK);
} else {
cursor::set(cursor::NORMAL);
@ -418,7 +417,7 @@ void turn_info::mouse_motion(int x, int y)
unit_map::const_iterator un = find_unit(selected_hex_);
if((new_hex != last_hex_ || attack_from.valid()) && un != units_.end() && !un->second.stone()) {
const shortest_path_calculator calc(un->second,current_team,
const shortest_path_calculator calc(un->second,viewing_team(),
visible_units(),teams_,map_,status_);
const bool can_teleport = un->second.type().teleports();
@ -426,9 +425,9 @@ void turn_info::mouse_motion(int x, int y)
std::set<gamemap::location> allowed_teleports;
if(can_teleport) {
allowed_teleports = vacant_villages(current_team.villages(),units_);
allowed_teleports = vacant_villages(viewing_team().villages(),units_);
teleports = &allowed_teleports;
if(current_team.villages().count(un->first))
if(viewing_team().villages().count(un->first))
allowed_teleports.insert(un->first);
}
@ -451,7 +450,7 @@ void turn_info::mouse_motion(int x, int y)
const bool ignore_zocs = un->second.type().is_skirmisher();
const bool teleport = un->second.type().teleports();
current_paths_ = paths(map_,status_,gameinfo_,units_,new_hex,teams_,
ignore_zocs,teleport,&current_team,path_turns_);
ignore_zocs,teleport,viewing_team(),path_turns_);
gui_.highlight_reach(current_paths_);
enemy_paths_ = true;
}
@ -949,7 +948,7 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
const bool ignore_zocs = it->second.type().is_skirmisher();
const bool teleport = it->second.type().teleports();
current_paths_ = paths(map_,status_,gameinfo_,units_,hex,teams_,
ignore_zocs,teleport,NULL,path_turns_);
ignore_zocs,teleport,viewing_team(),path_turns_);
next_unit_ = it->first;
@ -1275,7 +1274,7 @@ void turn_info::cycle_units()
if(it != units_.end() && !gui_.fogged(it->first.x,it->first.y)) {
const bool ignore_zocs = it->second.type().is_skirmisher();
const bool teleport = it->second.type().teleports();
current_paths_ = paths(map_,status_,gameinfo_,units_,it->first,teams_,ignore_zocs,teleport,NULL,path_turns_);
current_paths_ = paths(map_,status_,gameinfo_,units_,it->first,teams_,ignore_zocs,teleport,viewing_team(),path_turns_);
gui_.highlight_reach(current_paths_);
gui_.scroll_to_tile(it->first.x,it->first.y,display::WARP);
@ -1321,7 +1320,7 @@ void turn_info::cycle_back_units()
if(it != units_.begin() && !gui_.fogged(it->first.x,it->first.y)) {
const bool ignore_zocs = it->second.type().is_skirmisher();
const bool teleport = it->second.type().teleports();
current_paths_ = paths(map_,status_,gameinfo_,units_,it->first,teams_,ignore_zocs,teleport,NULL,path_turns_);
current_paths_ = paths(map_,status_,gameinfo_,units_,it->first,teams_,ignore_zocs,teleport,viewing_team(),path_turns_);
gui_.highlight_reach(current_paths_);
gui_.scroll_to_tile(it->first.x,it->first.y,display::WARP);
@ -2745,7 +2744,7 @@ void turn_info::show_enemy_moves(bool ignore_units)
unit_map units;
units.insert(*u);
const paths& path = paths(map_,status_,gameinfo_,ignore_units?units:units_,
u->first,teams_,is_skirmisher,teleports,&current_team());
u->first,teams_,is_skirmisher,teleports,viewing_team());
gui_.highlight_another_reach(path);
}

View file

@ -802,7 +802,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
const bool ignore_zocs = u->second.type().is_skirmisher();
const bool teleport = u->second.type().teleports();
paths paths_list(map,state,gameinfo,units,src,teams,ignore_zocs,teleport);
paths paths_list(map,state,gameinfo,units,src,teams,ignore_zocs,teleport,current_team);
unit current_unit = u->second;