From 059e64071b9c5f0a2172b55023fa35d9efbb7ff5 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Tue, 9 Mar 2021 12:24:27 +0100 Subject: [PATCH 4/8] Introduce units_can_do_action_with_result(). It works like units_can_do_action() but is for any action with the specified result rather than just for the specified action. See osdn #41718 --- common/unitlist.c | 19 +++++++++++++++++++ common/unitlist.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/common/unitlist.c b/common/unitlist.c index 224c2b265b..f484965c54 100644 --- a/common/unitlist.c +++ b/common/unitlist.c @@ -230,6 +230,25 @@ bool units_can_do_action(const struct unit_list *punits, return FALSE; } +/************************************************************************//** + If has_flag is true, returns true iff any of the units are able to do + any action with the specified result. + + If has_flag is false, returns true iff any of the units are unable do + any action with the specified result. +****************************************************************************/ +bool units_can_do_action_with_result(const struct unit_list *punits, + enum action_result result, bool can_do) +{ + unit_list_iterate(punits, punit) { + if (EQ(can_do, unit_can_do_action_result(punit, result))) { + return TRUE; + } + } unit_list_iterate_end; + + return FALSE; +} + /************************************************************************//** Return TRUE iff any of the units is a transporter that is occupied. ****************************************************************************/ diff --git a/common/unitlist.h b/common/unitlist.h index b6e1a63621..6273a1d908 100644 --- a/common/unitlist.h +++ b/common/unitlist.h @@ -81,6 +81,9 @@ bool units_have_type_flag(const struct unit_list *punits, bool units_contain_cityfounder(const struct unit_list *punits); bool units_can_do_action(const struct unit_list *punits, action_id act_id, bool can_do); +bool units_can_do_action_with_result(const struct unit_list *punits, + enum action_result result, + bool can_do); bool units_are_occupied(const struct unit_list *punits); bool units_can_load(const struct unit_list *punits); bool units_can_unload(const struct unit_list *punits); -- 2.20.1