From bc071174a609c4fdd72d4d75a929dbd5e00b71f1 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Wed, 20 May 2026 06:24:08 +0300
Subject: [PATCH 39/39] Add select_actres_action_unit_on_city()

See RM #2032

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 d0d98a09cd..9a8c85f525 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -7602,3 +7602,28 @@ enum gen_action select_actres_action_unit_on_tile(struct civ_map *nmap,
 
   return ACTION_NONE;
 }
+
+/************************************************************************//**
+  Can unit do any action with the given action result to city?
+  Returns one of the possible actions, or ACTION_NONE.
+****************************************************************************/
+enum gen_action select_actres_action_unit_on_city(struct civ_map *nmap,
+                                                  enum action_result actres,
+                                                  struct unit *punit,
+                                                  struct city *pcity)
+{
+  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_CITY
+        && is_action_enabled_unit_on_city(nmap, act, punit, pcity)) {
+      return act;
+    }
+  } action_list_iterate_end;
+
+  return ACTION_NONE;
+}
diff --git a/common/actions.h b/common/actions.h
index de954cb2c3..05a7ca76b4 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -779,6 +779,10 @@ enum gen_action select_actres_action_unit_on_tile(struct civ_map *nmap,
                                                   enum action_result actres,
                                                   struct unit *punit,
                                                   struct tile *ptile);
+enum gen_action select_actres_action_unit_on_city(struct civ_map *nmap,
+                                                  enum action_result actres,
+                                                  struct unit *punit,
+                                                  struct city *pcity);
 
 #ifdef __cplusplus
 }
-- 
2.53.0

