From e151bcb1097ba373fbc67bef99caf8ccab3b1009 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 7 Sep 2024 02:18:33 +0300
Subject: [PATCH 26/26] savecompat: Convert Conquer City action names

Old names like "Conquer City", new names like "Conquer City Shrink"

See RM #833

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 server/savegame/savecompat.c | 83 +++++++++++++++++++++++++++++++++++-
 1 file changed, 82 insertions(+), 1 deletion(-)

diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c
index e38bb6f4fe..6ad02c9a1f 100644
--- a/server/savegame/savecompat.c
+++ b/server/savegame/savecompat.c
@@ -2480,6 +2480,47 @@ static void compat_load_030300(struct loaddata *loading,
     }
   }
 
+  {
+    int action_count;
+
+    action_count = secfile_lookup_int_default(loading->file, 0,
+                                              "savefile.action_size");
+
+    if (action_count > 0) {
+      const char **modname;
+      const char **savemod;
+      int j;
+      const char *cc1_name = "Conquer City Shrink";
+      const char *cc2_name = "Conquer City Shrink 2";
+      const char *cc3_name = "Conquer City Shrink 3";
+      const char *cc4_name = "Conquer City Shrink 4";
+
+      modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
+                                       "savefile.action_vector");
+
+      savemod = fc_calloc(action_count, sizeof(*savemod));
+
+      for (j = 0; j < action_count; j++) {
+        if (!fc_strcasecmp("Conquer City", modname[j])) {
+          savemod[j] = cc1_name;
+        } else if (!fc_strcasecmp("Conquer City 2", modname[j])) {
+          savemod[j] = cc2_name;
+        } else if (!fc_strcasecmp("Conquer City 3", modname[j])) {
+          savemod[j] = cc3_name;
+        } else if (!fc_strcasecmp("Conquer City 4", modname[j])) {
+          savemod[j] = cc4_name;
+        } else {
+          savemod[j] = modname[j];
+        }
+      }
+
+      secfile_replace_str_vec(loading->file, savemod, action_count,
+                              "savefile.action_vector");
+
+      free(savemod);
+    }
+  }
+
   /* Add actions for unit activities */
   if (format_class == SAVEGAME_3) {
     loading->activities.size
@@ -2514,7 +2555,7 @@ static void compat_load_030300(struct loaddata *loading,
       for (j = 0; j < loading->action.size; j++) {
         struct action *real_action = action_by_rule_name(modname[j]);
 
-        if (real_action) {
+        if (real_action != nullptr) {
           loading->action.order[j] = real_action->id;
         } else {
           log_sg("Unknown action \'%s\'", modname[j]);
@@ -2969,6 +3010,46 @@ static void compat_load_dev(struct loaddata *loading)
   if (game_version < 3029300) {
     /* Before version number bump to 3.2.93 */
 
+    {
+      int action_count;
+
+      action_count = secfile_lookup_int_default(loading->file, 0,
+                                                "savefile.action_size");
+
+      if (action_count > 0) {
+        const char **modname;
+        const char **savemod;
+        int j;
+        const char *cc1_name = "Conquer City Shrink";
+        const char *cc2_name = "Conquer City Shrink 2";
+        const char *cc3_name = "Conquer City Shrink 3";
+        const char *cc4_name = "Conquer City Shrink 4";
+
+        modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
+                                         "savefile.action_vector");
+
+        savemod = fc_calloc(action_count, sizeof(*savemod));
+
+        for (j = 0; j < action_count; j++) {
+          if (!fc_strcasecmp("Conquer City", modname[j])) {
+            savemod[j] = cc1_name;
+          } else if (!fc_strcasecmp("Conquer City 2", modname[j])) {
+            savemod[j] = cc2_name;
+          } else if (!fc_strcasecmp("Conquer City 3", modname[j])) {
+            savemod[j] = cc3_name;
+          } else if (!fc_strcasecmp("Conquer City 4", modname[j])) {
+            savemod[j] = cc4_name;
+          } else {
+            savemod[j] = modname[j];
+          }
+        }
+
+        secfile_replace_str_vec(loading->file, savemod, action_count,
+                                "savefile.action_vector");
+
+        free(savemod);
+      }
+    }
   } /* Version < 3.2.93 */
 
 #endif /* FREECIV_DEV_SAVE_COMPAT_3_3 */
-- 
2.45.2

