From 8eb4aea1de8294fc8c1fd314579e3bd26338fe53 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 8 Jan 2026 03:42:19 +0200
Subject: [PATCH 62/62] Add select_actres_action_unit_on_stack()

See RM #1888

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/actions.c | 20 ++++++++++++++++++++
 common/actions.h |  5 +++++
 2 files changed, 25 insertions(+)

diff --git a/common/actions.c b/common/actions.c
index 2f1c46ab6d..5b860f595b 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -7553,3 +7553,23 @@ struct action_list *action_list_by_activity(enum unit_activity activity)
 
   return actlist_by_activity[activity];
 }
+
+/************************************************************************//**
+  Can unit do any action with the given action result to stack?
+  Returns one of the possible actions, or ACTION_NONE.
+****************************************************************************/
+enum unit_activity select_actres_action_unit_on_stack(struct civ_map *nmap,
+                                                      enum action_result actres,
+                                                      struct unit *punit,
+                                                      struct tile *ptile)
+{
+  action_list_iterate(action_list_by_result(actres), paction) {
+    enum gen_action act = action_number(paction);
+
+    if (is_action_enabled_unit_on_stack(nmap, act, punit, ptile)) {
+      return act;
+    }
+  } action_list_iterate_end;
+
+  return ACTION_NONE;
+}
diff --git a/common/actions.h b/common/actions.h
index 1304d6ae3f..3fb0091342 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -771,6 +771,11 @@ void action_array_add_all_by_result(action_id *act_array,
 const struct action_auto_perf *action_auto_perf_by_number(const int num);
 struct action_auto_perf *action_auto_perf_slot_number(const int num);
 
+enum unit_activity select_actres_action_unit_on_stack(struct civ_map *nmap,
+                                                      enum action_result actres,
+                                                      struct unit *punit,
+                                                      struct tile *ptile);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
-- 
2.51.0

