Unit Display: When the recruiting or recruited units is invisible, don't scroll to it.

When the enemy leader and the unit it recruits are both invisible,
scrolling to them would leak their location to the player.

(cherry-picked from commit 4db974431dfdc2c5fc75a97536cc4edc24163404)
This commit is contained in:
josteph 2018-09-16 16:24:11 +00:00 committed by Jyrki Vesterinen
parent 9514298858
commit 50c85f4691

View File

@ -719,19 +719,34 @@ void unit_recruited(const map_location& loc,const map_location& leader_loc)
return;
}
const display_context& dc = disp->get_disp_context();
const team& viewing_team = dc.get_team(disp->viewing_side());
unit_map::const_iterator u = disp->get_units().find(loc);
if(u == disp->get_units().end()) return;
const bool unit_visible = u->is_visible_to_team(viewing_team, false);
unit_map::const_iterator leader = disp->get_units().find(leader_loc); // may be null_location
const bool leader_visible = (leader != disp->get_units().end()) && leader->is_visible_to_team(viewing_team, false);
u->set_hidden(true);
unit_animator animator;
if(leader_loc != map_location::null_location()) {
unit_map::const_iterator leader = disp->get_units().find(leader_loc);
if(leader == disp->get_units().end()) return;
if (leader_visible && unit_visible) {
disp->scroll_to_tiles(loc,leader_loc,game_display::ONSCREEN,true,0.0,false);
leader->set_facing(leader_loc.get_relative_dir(loc));
animator.add_animation(&*leader, "recruiting", leader_loc, loc, 0, true);
} else {
} else if (leader_visible) {
disp->scroll_to_tile(leader_loc,game_display::ONSCREEN,true,false);
} else if (unit_visible) {
disp->scroll_to_tile(loc,game_display::ONSCREEN,true,false);
} else {
return;
}
if (leader != disp->get_units().end()) {
leader->set_facing(leader_loc.get_relative_dir(loc));
if (leader_visible) {
animator.add_animation(&*leader, "recruiting", leader_loc, loc, 0, true);
}
}
disp->draw();