From 365053fcfe011802aeaa1aa9ef487b169837a073 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 11 Feb 2024 15:41:07 +0200
Subject: [PATCH 39/39] Move action_result_legal_target_kind() to actres.c

Rename as actres_legal_target_kind()

See RM #253

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/actions.c          | 111 --------------------------------------
 common/actions.h          |   2 -
 common/actres.c           | 111 ++++++++++++++++++++++++++++++++++++++
 common/actres.h           |   2 +
 server/ruleset/rssanity.c |   3 +-
 5 files changed, 114 insertions(+), 115 deletions(-)

diff --git a/common/actions.c b/common/actions.c
index 703dca8323..c03913dd16 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -6848,117 +6848,6 @@ const char *action_target_kind_ruleset_var_name(int act)
   return NULL;
 }
 
-/**********************************************************************//**
-  Returns TRUE iff the specified action result works with the specified
-  action target kind.
-**************************************************************************/
-bool action_result_legal_target_kind(enum action_result result,
-                                     enum action_target_kind tgt_kind)
-{
-  fc_assert_ret_val(action_result_is_valid(result) || result == ACTRES_NONE,
-                    FALSE);
-  fc_assert_ret_val(action_target_kind_is_valid(tgt_kind),
-                    FALSE);
-
-  switch (result) {
-  case ACTRES_ESTABLISH_EMBASSY:
-  case ACTRES_SPY_INVESTIGATE_CITY:
-  case ACTRES_SPY_POISON:
-  case ACTRES_SPY_STEAL_GOLD:
-  case ACTRES_SPY_SABOTAGE_CITY:
-  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
-  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
-  case ACTRES_SPY_STEAL_TECH:
-  case ACTRES_SPY_TARGETED_STEAL_TECH:
-  case ACTRES_SPY_INCITE_CITY:
-  case ACTRES_TRADE_ROUTE:
-  case ACTRES_MARKETPLACE:
-  case ACTRES_HELP_WONDER:
-  case ACTRES_JOIN_CITY:
-  case ACTRES_STEAL_MAPS:
-  case ACTRES_SPY_NUKE:
-  case ACTRES_DESTROY_CITY:
-  case ACTRES_DISBAND_UNIT_RECOVER:
-  case ACTRES_HOME_CITY:
-  case ACTRES_UPGRADE_UNIT:
-  case ACTRES_AIRLIFT:
-  case ACTRES_STRIKE_BUILDING:
-  case ACTRES_STRIKE_PRODUCTION:
-  case ACTRES_CONQUER_CITY:
-  case ACTRES_SPY_SPREAD_PLAGUE:
-  case ACTRES_SPY_ESCAPE:
-    return tgt_kind == ATK_CITY;
-  case ACTRES_SPY_BRIBE_UNIT:
-  case ACTRES_SPY_SABOTAGE_UNIT:
-  case ACTRES_EXPEL_UNIT:
-  case ACTRES_HEAL_UNIT:
-  case ACTRES_TRANSPORT_DEBOARD:
-  case ACTRES_TRANSPORT_UNLOAD:
-  case ACTRES_TRANSPORT_LOAD:
-  case ACTRES_TRANSPORT_BOARD:
-  case ACTRES_TRANSPORT_EMBARK:
-    return tgt_kind == ATK_UNIT;
-  case ACTRES_CAPTURE_UNITS:
-  case ACTRES_BOMBARD:
-  case ACTRES_NUKE_UNITS:
-  case ACTRES_ATTACK:
-  case ACTRES_WIPE_UNITS:
-  case ACTRES_SPY_ATTACK:
-  case ACTRES_COLLECT_RANSOM:
-    return tgt_kind == ATK_UNITS;
-  case ACTRES_FOUND_CITY:
-  case ACTRES_PARADROP:
-  case ACTRES_PARADROP_CONQUER:
-  case ACTRES_TRANSFORM_TERRAIN:
-  case ACTRES_CULTIVATE:
-  case ACTRES_PLANT:
-  case ACTRES_CLEAN:
-  case ACTRES_ROAD:
-  case ACTRES_BASE:
-  case ACTRES_MINE:
-  case ACTRES_IRRIGATE:
-  case ACTRES_TRANSPORT_DISEMBARK:
-  case ACTRES_HUT_ENTER:
-  case ACTRES_HUT_FRIGHTEN:
-  case ACTRES_UNIT_MOVE:
-  case ACTRES_TELEPORT:
-  case ACTRES_TELEPORT_CONQUER:
-    return tgt_kind == ATK_TILE;
-  case ACTRES_CONQUER_EXTRAS:
-    return tgt_kind == ATK_EXTRAS;
-  case ACTRES_DISBAND_UNIT:
-  case ACTRES_CONVERT:
-  case ACTRES_FORTIFY:
-  case ACTRES_HOMELESS:
-  case ACTRES_ENABLER_CHECK:
-    return tgt_kind == ATK_SELF;
-  case ACTRES_PILLAGE:
-    return (tgt_kind == ATK_TILE || tgt_kind == ATK_EXTRAS);
-  case ACTRES_NUKE:
-    return (tgt_kind == ATK_TILE || tgt_kind == ATK_CITY);
-  case ACTRES_NONE:
-    switch (tgt_kind) {
-    case ATK_CITY:
-    case ATK_UNIT:
-    case ATK_UNITS:
-    case ATK_TILE:
-    case ATK_EXTRAS:
-    case ATK_SELF:
-      /* Works with all existing target kinds. */
-      return TRUE;
-    case ATK_COUNT:
-      fc_assert_ret_val(tgt_kind != ATK_COUNT, FALSE);
-      break;
-    }
-    break;
-
-  ASSERT_UNUSED_ACTRES_CASES;
-  }
-
-  /* Should never be reached. */
-  return FALSE;
-}
-
 /**********************************************************************//**
   Return actor consuming always ruleset variable name for the action or
   NULL if actor consuming always can't be set in the ruleset.
diff --git a/common/actions.h b/common/actions.h
index a10c53098a..45de38f3b3 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -474,8 +474,6 @@ const char *action_min_range_ruleset_var_name(int act);
 const char *action_max_range_ruleset_var_name(int act);
 
 const char *action_target_kind_ruleset_var_name(int act);
-bool action_result_legal_target_kind(enum action_result result,
-                                     enum action_target_kind tgt_kind);
 const char *action_target_kind_help(enum action_target_kind kind);
 
 const char *action_actor_consuming_always_ruleset_var_name(action_id act);
diff --git a/common/actres.c b/common/actres.c
index d7f777b48d..00d644510a 100644
--- a/common/actres.c
+++ b/common/actres.c
@@ -551,6 +551,117 @@ int actres_max_range_default(enum action_result result)
   return 0;
 }
 
+/**********************************************************************//**
+  Returns TRUE iff the specified action result works with the specified
+  action target kind.
+**************************************************************************/
+bool actres_legal_target_kind(enum action_result result,
+                              enum action_target_kind tgt_kind)
+{
+  fc_assert_ret_val(action_result_is_valid(result) || result == ACTRES_NONE,
+                    FALSE);
+  fc_assert_ret_val(action_target_kind_is_valid(tgt_kind),
+                    FALSE);
+
+  switch (result) {
+  case ACTRES_ESTABLISH_EMBASSY:
+  case ACTRES_SPY_INVESTIGATE_CITY:
+  case ACTRES_SPY_POISON:
+  case ACTRES_SPY_STEAL_GOLD:
+  case ACTRES_SPY_SABOTAGE_CITY:
+  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
+  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
+  case ACTRES_SPY_STEAL_TECH:
+  case ACTRES_SPY_TARGETED_STEAL_TECH:
+  case ACTRES_SPY_INCITE_CITY:
+  case ACTRES_TRADE_ROUTE:
+  case ACTRES_MARKETPLACE:
+  case ACTRES_HELP_WONDER:
+  case ACTRES_JOIN_CITY:
+  case ACTRES_STEAL_MAPS:
+  case ACTRES_SPY_NUKE:
+  case ACTRES_DESTROY_CITY:
+  case ACTRES_DISBAND_UNIT_RECOVER:
+  case ACTRES_HOME_CITY:
+  case ACTRES_UPGRADE_UNIT:
+  case ACTRES_AIRLIFT:
+  case ACTRES_STRIKE_BUILDING:
+  case ACTRES_STRIKE_PRODUCTION:
+  case ACTRES_CONQUER_CITY:
+  case ACTRES_SPY_SPREAD_PLAGUE:
+  case ACTRES_SPY_ESCAPE:
+    return tgt_kind == ATK_CITY;
+  case ACTRES_SPY_BRIBE_UNIT:
+  case ACTRES_SPY_SABOTAGE_UNIT:
+  case ACTRES_EXPEL_UNIT:
+  case ACTRES_HEAL_UNIT:
+  case ACTRES_TRANSPORT_DEBOARD:
+  case ACTRES_TRANSPORT_UNLOAD:
+  case ACTRES_TRANSPORT_LOAD:
+  case ACTRES_TRANSPORT_BOARD:
+  case ACTRES_TRANSPORT_EMBARK:
+    return tgt_kind == ATK_UNIT;
+  case ACTRES_CAPTURE_UNITS:
+  case ACTRES_BOMBARD:
+  case ACTRES_NUKE_UNITS:
+  case ACTRES_ATTACK:
+  case ACTRES_WIPE_UNITS:
+  case ACTRES_SPY_ATTACK:
+  case ACTRES_COLLECT_RANSOM:
+    return tgt_kind == ATK_UNITS;
+  case ACTRES_FOUND_CITY:
+  case ACTRES_PARADROP:
+  case ACTRES_PARADROP_CONQUER:
+  case ACTRES_TRANSFORM_TERRAIN:
+  case ACTRES_CULTIVATE:
+  case ACTRES_PLANT:
+  case ACTRES_CLEAN:
+  case ACTRES_ROAD:
+  case ACTRES_BASE:
+  case ACTRES_MINE:
+  case ACTRES_IRRIGATE:
+  case ACTRES_TRANSPORT_DISEMBARK:
+  case ACTRES_HUT_ENTER:
+  case ACTRES_HUT_FRIGHTEN:
+  case ACTRES_UNIT_MOVE:
+  case ACTRES_TELEPORT:
+  case ACTRES_TELEPORT_CONQUER:
+    return tgt_kind == ATK_TILE;
+  case ACTRES_CONQUER_EXTRAS:
+    return tgt_kind == ATK_EXTRAS;
+  case ACTRES_DISBAND_UNIT:
+  case ACTRES_CONVERT:
+  case ACTRES_FORTIFY:
+  case ACTRES_HOMELESS:
+  case ACTRES_ENABLER_CHECK:
+    return tgt_kind == ATK_SELF;
+  case ACTRES_PILLAGE:
+    return (tgt_kind == ATK_TILE || tgt_kind == ATK_EXTRAS);
+  case ACTRES_NUKE:
+    return (tgt_kind == ATK_TILE || tgt_kind == ATK_CITY);
+  case ACTRES_NONE:
+    switch (tgt_kind) {
+    case ATK_CITY:
+    case ATK_UNIT:
+    case ATK_UNITS:
+    case ATK_TILE:
+    case ATK_EXTRAS:
+    case ATK_SELF:
+      /* Works with all existing target kinds. */
+      return TRUE;
+    case ATK_COUNT:
+      fc_assert_ret_val(tgt_kind != ATK_COUNT, FALSE);
+      break;
+    }
+    break;
+
+  ASSERT_UNUSED_ACTRES_CASES;
+  }
+
+  /* Should never be reached. */
+  return FALSE;
+}
+
 /**********************************************************************//**
   Return default sub target kind for the action with the specified result.
 **************************************************************************/
diff --git a/common/actres.h b/common/actres.h
index 98841a9e30..5e9a7bb0b4 100644
--- a/common/actres.h
+++ b/common/actres.h
@@ -149,6 +149,8 @@ enum fc_tristate actres_possible(const struct civ_map *nmap,
 
 int actres_min_range_default(enum action_result result);
 int actres_max_range_default(enum action_result result);
+bool actres_legal_target_kind(enum action_result result,
+                              enum action_target_kind tgt_kind);
 enum action_target_kind
 actres_target_kind_default(enum action_result result);
 enum action_sub_target_kind
diff --git a/server/ruleset/rssanity.c b/server/ruleset/rssanity.c
index 2aeafb565f..cf9fc2c5cb 100644
--- a/server/ruleset/rssanity.c
+++ b/server/ruleset/rssanity.c
@@ -1240,8 +1240,7 @@ bool sanity_check_ruleset_data(struct rscompat_info *compat)
   action_iterate(act) {
     struct action *paction = action_by_number(act);
 
-    if (!action_result_legal_target_kind(paction->result,
-                                         paction->target_kind)) {
+    if (!actres_legal_target_kind(paction->result, paction->target_kind)) {
       ruleset_error(logger, LOG_ERROR, "Action \"%s\": unsupported target kind %s.",
                     action_id_rule_name(act),
                     action_target_kind_name(paction->target_kind));
-- 
2.43.0

