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.
This commit is contained in:
josteph 2018-09-16 16:24:11 +00:00 committed by Jyrki Vesterinen
parent 68dbd928ca
commit 83ba09a5a9

View file

@ -698,20 +698,34 @@ void reset_helpers(const unit *attacker,const unit *defender)
void unit_recruited(const map_location& loc,const map_location& leader_loc)
{
game_display* disp = game_display::get_singleton();
const display_context& dc = disp->get_disp_context();
const team& viewing_team = dc.get_team(disp->viewing_side());
if(!disp || disp->video().update_locked() || disp->video().faked() ||disp->fogged(loc)) return;
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, dc, 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, dc, 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();