diff --git a/client/control.cpp b/client/control.cpp index 3ae3e63445..a2996a51fd 100644 --- a/client/control.cpp +++ b/client/control.cpp @@ -357,7 +357,7 @@ static void ask_server_for_actions(struct unit *punit) } /** - Return TRUE iff this unit is in focus. + Return TRUE if this unit is in focus. */ bool unit_is_in_focus(const struct unit *punit) { @@ -365,6 +365,26 @@ bool unit_is_in_focus(const struct unit *punit) return std::find(focus.begin(), focus.end(), punit) != focus.end(); } +/** + Returns TRUE if this unit is on stand by. + + A unit is on stand by, if it is idle or sentried and not busy + building anything. +*/ +bool unit_is_on_stand_by(const struct unit *punit) +{ + if (ACTIVITY_IDLE != punit->activity + && ACTIVITY_SENTRY != punit->activity) { + return false; + } + + if (!can_unit_do_activity(punit, ACTIVITY_IDLE)) { + return false; + } + + return true; +} + /** Return TRUE iff a unit on this tile is in focus. */ diff --git a/client/control.h b/client/control.h index 8e61eb9dd0..004d78ac11 100644 --- a/client/control.h +++ b/client/control.h @@ -141,6 +141,7 @@ void wakeup_sentried_units(struct tile *ptile); void clear_unit_orders(struct unit *punit); bool unit_is_in_focus(const struct unit *punit); +bool unit_is_on_stand_by(const struct unit *punit); struct unit *get_focus_unit_on_tile(const struct tile *ptile); struct unit *head_of_units_in_focus(); std::vector &get_units_in_focus(); diff --git a/client/hudwidget.cpp b/client/hudwidget.cpp index 28d8301dde..623b0ff4b5 100644 --- a/client/hudwidget.cpp +++ b/client/hudwidget.cpp @@ -1787,16 +1787,7 @@ static bool cycle_units_predicate(const struct unit *current_unit, return false; } - if (ACTIVITY_IDLE != candidate->activity - && ACTIVITY_SENTRY != candidate->activity) { - return false; - } - - if (!can_unit_do_activity(candidate, ACTIVITY_IDLE)) { - return false; - } - - return true; + return unit_is_on_stand_by(candidate); } /** diff --git a/client/views/view_units.cpp b/client/views/view_units.cpp index c9fa048c76..fa51ecfa7a 100644 --- a/client/views/view_units.cpp +++ b/client/views/view_units.cpp @@ -550,11 +550,8 @@ void units_view::find_nearest() if ((punit = find_nearest_unit(utype, ptile))) { queen()->mapview_wdg->center_on_tile(punit->tile); - if (ACTIVITY_IDLE == punit->activity - || ACTIVITY_SENTRY == punit->activity) { - if (can_unit_do_activity(punit, ACTIVITY_IDLE)) { - unit_focus_set_and_select(punit); - } + if (unit_is_on_stand_by(punit)) { + unit_focus_set_and_select(punit); } }