From 625536126923d73c5ad51b9c3a8abc90b57b3d80 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 7 May 2026 01:51:39 +0300
Subject: [PATCH 35/35] Add select_actres_action_unit_on_tile()

See RM #2016

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

diff --git a/common/actions.c b/common/actions.c
index 596e5d4d2c..d0d98a09cd 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -7577,3 +7577,28 @@ enum gen_action select_actres_action_unit_on_stack(struct civ_map *nmap,
 
   return ACTION_NONE;
 }
+
+/************************************************************************//**
+  Can unit do any action with the given action result to tile?
+  Returns one of the possible actions, or ACTION_NONE.
+****************************************************************************/
+enum gen_action select_actres_action_unit_on_tile(struct civ_map *nmap,
+                                                  enum action_result actres,
+                                                  struct unit *punit,
+                                                  struct tile *ptile)
+{
+  if (actres >= ACTRES_LAST) {
+    return ACTION_NONE;
+  }
+
+  action_list_iterate(action_list_by_result(actres), paction) {
+    enum gen_action act = action_number(paction);
+
+    if (action_id_get_target_kind(act) == ATK_TILE
+        && is_action_enabled_unit_on_tile(nmap, act, punit, ptile, nullptr)) {
+      return act;
+    }
+  } action_list_iterate_end;
+
+  return ACTION_NONE;
+}
diff --git a/common/actions.h b/common/actions.h
index 65f6eb1eb4..de954cb2c3 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -775,6 +775,10 @@ enum gen_action select_actres_action_unit_on_stack(struct civ_map *nmap,
                                                    enum action_result actres,
                                                    struct unit *punit,
                                                    struct tile *ptile);
+enum gen_action select_actres_action_unit_on_tile(struct civ_map *nmap,
+                                                  enum action_result actres,
+                                                  struct unit *punit,
+                                                  struct tile *ptile);
 
 #ifdef __cplusplus
 }
-- 
2.53.0

