From ce04facbc0e3f0ba5cf2b946221310b4b8966c61 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 2 Jan 2024 23:47:27 +0200
Subject: [PATCH 22/22] Move action_(min|max)_range_default() to actres.c as
 actres_...()

See RM #115

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/actions.c          | 181 --------------------------------------
 common/actions.h          |   2 -
 common/actres.c           | 181 ++++++++++++++++++++++++++++++++++++++
 common/actres.h           |   3 +
 server/ruleset/ruleload.c |   6 +-
 tools/ruleutil/rulesave.c |   4 +-
 6 files changed, 189 insertions(+), 188 deletions(-)

diff --git a/common/actions.c b/common/actions.c
index 5ac728f370..75e281f17d 100644
--- a/common/actions.c
+++ b/common/actions.c
@@ -6401,95 +6401,6 @@ const char *action_min_range_ruleset_var_name(int act)
   return NULL;
 }
 
-/**********************************************************************//**
-  Return default min range for the action if it is ruleset settable.
-**************************************************************************/
-int action_min_range_default(enum action_result result)
-{
-  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_SPY_BRIBE_UNIT:
-  case ACTRES_SPY_SABOTAGE_UNIT:
-  case ACTRES_CAPTURE_UNITS:
-  case ACTRES_FOUND_CITY:
-  case ACTRES_JOIN_CITY:
-  case ACTRES_STEAL_MAPS:
-  case ACTRES_BOMBARD:
-  case ACTRES_SPY_NUKE:
-  case ACTRES_DESTROY_CITY:
-  case ACTRES_EXPEL_UNIT:
-  case ACTRES_DISBAND_UNIT_RECOVER:
-  case ACTRES_DISBAND_UNIT:
-  case ACTRES_HOME_CITY:
-  case ACTRES_HOMELESS:
-  case ACTRES_UPGRADE_UNIT:
-  case ACTRES_PARADROP:
-  case ACTRES_PARADROP_CONQUER:
-  case ACTRES_AIRLIFT:
-  case ACTRES_STRIKE_BUILDING:
-  case ACTRES_STRIKE_PRODUCTION:
-  case ACTRES_ATTACK:
-  case ACTRES_WIPE_UNITS:
-  case ACTRES_COLLECT_RANSOM:
-  case ACTRES_CONQUER_CITY:
-  case ACTRES_HEAL_UNIT:
-  case ACTRES_TRANSFORM_TERRAIN:
-  case ACTRES_CULTIVATE:
-  case ACTRES_PLANT:
-  case ACTRES_PILLAGE:
-  case ACTRES_CLEAN:
-  case ACTRES_FORTIFY:
-  case ACTRES_ROAD:
-  case ACTRES_CONVERT:
-  case ACTRES_BASE:
-  case ACTRES_MINE:
-  case ACTRES_IRRIGATE:
-  case ACTRES_TRANSPORT_DEBOARD:
-  case ACTRES_TRANSPORT_UNLOAD:
-  case ACTRES_TRANSPORT_LOAD:
-  case ACTRES_TRANSPORT_DISEMBARK:
-  case ACTRES_TRANSPORT_BOARD:
-  case ACTRES_TRANSPORT_EMBARK:
-  case ACTRES_SPY_ATTACK:
-  case ACTRES_SPY_SPREAD_PLAGUE:
-  case ACTRES_CONQUER_EXTRAS:
-  case ACTRES_HUT_ENTER:
-  case ACTRES_HUT_FRIGHTEN:
-  case ACTRES_UNIT_MOVE:
-  case ACTRES_SPY_ESCAPE:
-  case ACTRES_ENABLER_CHECK:
-    /* Non ruleset defined action min range not supported here */
-    fc_assert_msg(FALSE, "Probably wrong value.");
-    return RS_DEFAULT_ACTION_MIN_RANGE;
-  case ACTRES_NUKE:
-  case ACTRES_NUKE_UNITS:
-    return RS_DEFAULT_ACTION_MIN_RANGE;
-  case ACTRES_TELEPORT:
-  case ACTRES_TELEPORT_CONQUER:
-    return RS_DEFAULT_MOVE_MIN_RANGE;
-  case ACTRES_NONE:
-    return RS_DEFAULT_ACTION_MIN_RANGE;
-
-  ASSERT_UNUSED_ACTRES_CASES;
-  }
-
-  fc_assert(action_result_is_valid(result) || result == ACTRES_NONE);
-
-  return 0;
-}
-
 /**********************************************************************//**
   Return max range ruleset variable name for the action or NULL if max
   range can't be set in the ruleset.
@@ -6658,98 +6569,6 @@ const char *action_max_range_ruleset_var_name(int act)
   return NULL;
 }
 
-/**********************************************************************//**
-  Return default max range for the action if it is ruleset settable.
-**************************************************************************/
-int action_max_range_default(enum action_result result)
-{
-  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_SPY_BRIBE_UNIT:
-  case ACTRES_SPY_SABOTAGE_UNIT:
-  case ACTRES_CAPTURE_UNITS:
-  case ACTRES_FOUND_CITY:
-  case ACTRES_JOIN_CITY:
-  case ACTRES_STEAL_MAPS:
-  case ACTRES_SPY_NUKE:
-  case ACTRES_DESTROY_CITY:
-  case ACTRES_EXPEL_UNIT:
-  case ACTRES_DISBAND_UNIT:
-  case ACTRES_HOME_CITY:
-  case ACTRES_HOMELESS:
-  case ACTRES_UPGRADE_UNIT:
-  case ACTRES_PARADROP:
-  case ACTRES_PARADROP_CONQUER:
-  case ACTRES_STRIKE_BUILDING:
-  case ACTRES_STRIKE_PRODUCTION:
-  case ACTRES_ATTACK:
-  case ACTRES_WIPE_UNITS:
-  case ACTRES_COLLECT_RANSOM:
-  case ACTRES_CONQUER_CITY:
-  case ACTRES_HEAL_UNIT:
-  case ACTRES_TRANSFORM_TERRAIN:
-  case ACTRES_CULTIVATE:
-  case ACTRES_PLANT:
-  case ACTRES_PILLAGE:
-  case ACTRES_CLEAN:
-  case ACTRES_FORTIFY:
-  case ACTRES_ROAD:
-  case ACTRES_CONVERT:
-  case ACTRES_BASE:
-  case ACTRES_MINE:
-  case ACTRES_IRRIGATE:
-  case ACTRES_TRANSPORT_DEBOARD:
-  case ACTRES_TRANSPORT_UNLOAD:
-  case ACTRES_TRANSPORT_LOAD:
-  case ACTRES_TRANSPORT_DISEMBARK:
-  case ACTRES_TRANSPORT_BOARD:
-  case ACTRES_TRANSPORT_EMBARK:
-  case ACTRES_SPY_ATTACK:
-  case ACTRES_SPY_SPREAD_PLAGUE:
-  case ACTRES_CONQUER_EXTRAS:
-  case ACTRES_HUT_ENTER:
-  case ACTRES_HUT_FRIGHTEN:
-  case ACTRES_UNIT_MOVE:
-  case ACTRES_SPY_ESCAPE:
-  case ACTRES_ENABLER_CHECK:
-    /* Non ruleset defined action max range not supported here */
-    fc_assert_msg(FALSE, "Probably wrong value.");
-    return RS_DEFAULT_ACTION_MAX_RANGE;
-  case ACTRES_HELP_WONDER:
-  case ACTRES_DISBAND_UNIT_RECOVER:
-    return RS_DEFAULT_ACTION_MAX_RANGE;
-  case ACTRES_BOMBARD:
-    return RS_DEFAULT_ACTION_MAX_RANGE;
-  case ACTRES_NUKE:
-    return RS_DEFAULT_EXPLODE_NUCLEAR_MAX_RANGE;
-  case ACTRES_NUKE_UNITS:
-    return RS_DEFAULT_ACTION_MAX_RANGE;
-  case ACTRES_AIRLIFT:
-  case ACTRES_TELEPORT:
-  case ACTRES_TELEPORT_CONQUER:
-    return ACTION_DISTANCE_UNLIMITED;
-  case ACTRES_NONE:
-    return RS_DEFAULT_ACTION_MAX_RANGE;
-
-  ASSERT_UNUSED_ACTRES_CASES;
-  }
-
-  fc_assert(action_result_is_valid(result) || result == ACTRES_NONE);
-
-  return 0;
-}
-
 /**********************************************************************//**
   Return target kind ruleset variable name for the action or NULL if
   target kind can't be set in the ruleset.
diff --git a/common/actions.h b/common/actions.h
index 89668cbbd7..f7d3a41630 100644
--- a/common/actions.h
+++ b/common/actions.h
@@ -734,9 +734,7 @@ const char *action_ui_name_ruleset_var_name(int act);
 const char *action_ui_name_default(int act);
 
 const char *action_min_range_ruleset_var_name(int act);
-int action_min_range_default(enum action_result result);
 const char *action_max_range_ruleset_var_name(int act);
-int action_max_range_default(enum action_result result);
 
 const char *action_target_kind_ruleset_var_name(int act);
 enum action_target_kind
diff --git a/common/actres.c b/common/actres.c
index 442e19dfa5..edb68408cb 100644
--- a/common/actres.c
+++ b/common/actres.c
@@ -370,6 +370,187 @@ enum dice_roll_type actres_dice_type(enum action_result result)
   return act_results[result].dice;
 }
 
+/**********************************************************************//**
+  Return default min range for the action if it is ruleset settable.
+**************************************************************************/
+int actres_min_range_default(enum action_result result)
+{
+  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_SPY_BRIBE_UNIT:
+  case ACTRES_SPY_SABOTAGE_UNIT:
+  case ACTRES_CAPTURE_UNITS:
+  case ACTRES_FOUND_CITY:
+  case ACTRES_JOIN_CITY:
+  case ACTRES_STEAL_MAPS:
+  case ACTRES_BOMBARD:
+  case ACTRES_SPY_NUKE:
+  case ACTRES_DESTROY_CITY:
+  case ACTRES_EXPEL_UNIT:
+  case ACTRES_DISBAND_UNIT_RECOVER:
+  case ACTRES_DISBAND_UNIT:
+  case ACTRES_HOME_CITY:
+  case ACTRES_HOMELESS:
+  case ACTRES_UPGRADE_UNIT:
+  case ACTRES_PARADROP:
+  case ACTRES_PARADROP_CONQUER:
+  case ACTRES_AIRLIFT:
+  case ACTRES_STRIKE_BUILDING:
+  case ACTRES_STRIKE_PRODUCTION:
+  case ACTRES_ATTACK:
+  case ACTRES_WIPE_UNITS:
+  case ACTRES_COLLECT_RANSOM:
+  case ACTRES_CONQUER_CITY:
+  case ACTRES_HEAL_UNIT:
+  case ACTRES_TRANSFORM_TERRAIN:
+  case ACTRES_CULTIVATE:
+  case ACTRES_PLANT:
+  case ACTRES_PILLAGE:
+  case ACTRES_CLEAN:
+  case ACTRES_FORTIFY:
+  case ACTRES_ROAD:
+  case ACTRES_CONVERT:
+  case ACTRES_BASE:
+  case ACTRES_MINE:
+  case ACTRES_IRRIGATE:
+  case ACTRES_TRANSPORT_DEBOARD:
+  case ACTRES_TRANSPORT_UNLOAD:
+  case ACTRES_TRANSPORT_LOAD:
+  case ACTRES_TRANSPORT_DISEMBARK:
+  case ACTRES_TRANSPORT_BOARD:
+  case ACTRES_TRANSPORT_EMBARK:
+  case ACTRES_SPY_ATTACK:
+  case ACTRES_SPY_SPREAD_PLAGUE:
+  case ACTRES_CONQUER_EXTRAS:
+  case ACTRES_HUT_ENTER:
+  case ACTRES_HUT_FRIGHTEN:
+  case ACTRES_UNIT_MOVE:
+  case ACTRES_SPY_ESCAPE:
+  case ACTRES_ENABLER_CHECK:
+    /* Non ruleset defined action min range not supported here */
+    fc_assert_msg(FALSE, "Probably wrong value.");
+    return RS_DEFAULT_ACTION_MIN_RANGE;
+  case ACTRES_NUKE:
+  case ACTRES_NUKE_UNITS:
+    return RS_DEFAULT_ACTION_MIN_RANGE;
+  case ACTRES_TELEPORT:
+  case ACTRES_TELEPORT_CONQUER:
+    return RS_DEFAULT_MOVE_MIN_RANGE;
+  case ACTRES_NONE:
+    return RS_DEFAULT_ACTION_MIN_RANGE;
+
+  ASSERT_UNUSED_ACTRES_CASES;
+  }
+
+  fc_assert(action_result_is_valid(result) || result == ACTRES_NONE);
+
+  return 0;
+}
+
+/**********************************************************************//**
+  Return default max range for the action if it is ruleset settable.
+**************************************************************************/
+int actres_max_range_default(enum action_result result)
+{
+  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_SPY_BRIBE_UNIT:
+  case ACTRES_SPY_SABOTAGE_UNIT:
+  case ACTRES_CAPTURE_UNITS:
+  case ACTRES_FOUND_CITY:
+  case ACTRES_JOIN_CITY:
+  case ACTRES_STEAL_MAPS:
+  case ACTRES_SPY_NUKE:
+  case ACTRES_DESTROY_CITY:
+  case ACTRES_EXPEL_UNIT:
+  case ACTRES_DISBAND_UNIT:
+  case ACTRES_HOME_CITY:
+  case ACTRES_HOMELESS:
+  case ACTRES_UPGRADE_UNIT:
+  case ACTRES_PARADROP:
+  case ACTRES_PARADROP_CONQUER:
+  case ACTRES_STRIKE_BUILDING:
+  case ACTRES_STRIKE_PRODUCTION:
+  case ACTRES_ATTACK:
+  case ACTRES_WIPE_UNITS:
+  case ACTRES_COLLECT_RANSOM:
+  case ACTRES_CONQUER_CITY:
+  case ACTRES_HEAL_UNIT:
+  case ACTRES_TRANSFORM_TERRAIN:
+  case ACTRES_CULTIVATE:
+  case ACTRES_PLANT:
+  case ACTRES_PILLAGE:
+  case ACTRES_CLEAN:
+  case ACTRES_FORTIFY:
+  case ACTRES_ROAD:
+  case ACTRES_CONVERT:
+  case ACTRES_BASE:
+  case ACTRES_MINE:
+  case ACTRES_IRRIGATE:
+  case ACTRES_TRANSPORT_DEBOARD:
+  case ACTRES_TRANSPORT_UNLOAD:
+  case ACTRES_TRANSPORT_LOAD:
+  case ACTRES_TRANSPORT_DISEMBARK:
+  case ACTRES_TRANSPORT_BOARD:
+  case ACTRES_TRANSPORT_EMBARK:
+  case ACTRES_SPY_ATTACK:
+  case ACTRES_SPY_SPREAD_PLAGUE:
+  case ACTRES_CONQUER_EXTRAS:
+  case ACTRES_HUT_ENTER:
+  case ACTRES_HUT_FRIGHTEN:
+  case ACTRES_UNIT_MOVE:
+  case ACTRES_SPY_ESCAPE:
+  case ACTRES_ENABLER_CHECK:
+    /* Non ruleset defined action max range not supported here */
+    fc_assert_msg(FALSE, "Probably wrong value.");
+    return RS_DEFAULT_ACTION_MAX_RANGE;
+  case ACTRES_HELP_WONDER:
+  case ACTRES_DISBAND_UNIT_RECOVER:
+    return RS_DEFAULT_ACTION_MAX_RANGE;
+  case ACTRES_BOMBARD:
+    return RS_DEFAULT_ACTION_MAX_RANGE;
+  case ACTRES_NUKE:
+    return RS_DEFAULT_EXPLODE_NUCLEAR_MAX_RANGE;
+  case ACTRES_NUKE_UNITS:
+    return RS_DEFAULT_ACTION_MAX_RANGE;
+  case ACTRES_AIRLIFT:
+  case ACTRES_TELEPORT:
+  case ACTRES_TELEPORT_CONQUER:
+    return ACTION_DISTANCE_UNLIMITED;
+  case ACTRES_NONE:
+    return RS_DEFAULT_ACTION_MAX_RANGE;
+
+  ASSERT_UNUSED_ACTRES_CASES;
+  }
+
+  fc_assert(action_result_is_valid(result) || result == ACTRES_NONE);
+
+  return 0;
+}
+
 /**********************************************************************//**
   Does action with the result create the extra
 
diff --git a/common/actres.h b/common/actres.h
index f506cc9329..7d95b62212 100644
--- a/common/actres.h
+++ b/common/actres.h
@@ -144,6 +144,9 @@ enum fc_tristate actres_possible(enum action_result result,
                                  bool omniscient,
                                  const struct city *homecity);
 
+int actres_min_range_default(enum action_result result);
+int actres_max_range_default(enum action_result result);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/server/ruleset/ruleload.c b/server/ruleset/ruleload.c
index be1b573e71..83c3a9c4f7 100644
--- a/server/ruleset/ruleload.c
+++ b/server/ruleset/ruleload.c
@@ -6300,7 +6300,7 @@ static bool load_action_range_max(struct section_file *file, action_id act)
     pentry = secfile_entry_lookup(file, "actions.%s", vname);
 
     if (pentry == NULL) {
-      max_range = action_max_range_default(paction->result);
+      max_range = actres_max_range_default(paction->result);
     } else {
       const char *custom;
 
@@ -6314,7 +6314,7 @@ static bool load_action_range_max(struct section_file *file, action_id act)
       } else {
         ruleset_error(NULL, LOG_ERROR, "Bad actions.%s",
                       action_max_range_ruleset_var_name(act));
-        action_by_number(act)->max_distance = action_max_range_default(paction->result);
+        action_by_number(act)->max_distance = actres_max_range_default(paction->result);
 
         return FALSE;
       }
@@ -6343,7 +6343,7 @@ static bool load_action_range(struct section_file *file, action_id act)
     /* Min range can be loaded from the ruleset. */
     action_by_number(act)->min_distance
       = secfile_lookup_int_default(file,
-                                   action_min_range_default(paction->result),
+                                   actres_min_range_default(paction->result),
                                    "actions.%s",
                                    vname);
   }
diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c
index 81fbb2230f..c2e382ac1d 100644
--- a/tools/ruleutil/rulesave.c
+++ b/tools/ruleutil/rulesave.c
@@ -909,7 +909,7 @@ static bool save_action_max_range(struct section_file *sfile,
                               action_max_range_ruleset_var_name(act)) != NULL;
   } else {
     return save_default_int(sfile, action_by_number(act)->max_distance,
-                            action_max_range_default(paction->result),
+                            actres_max_range_default(paction->result),
                             "actions",
                             action_max_range_ruleset_var_name(act));
   }
@@ -926,7 +926,7 @@ static bool save_action_range(struct section_file *sfile, action_id act)
     /* Min range can be loaded from the ruleset. */
     save_default_int(sfile,
                      paction->min_distance,
-                     action_min_range_default(paction->result),
+                     actres_min_range_default(paction->result),
                      "actions",
                      action_min_range_ruleset_var_name(act));
   }
-- 
2.43.0

