From dfb35e55c59e1def94c066204e2b39202c959540 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 9 Nov 2024 07:08:52 +0200
Subject: [PATCH 76/76] Turn production_class_type to genenum

See RM #1086

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-3.22/cityrep.c    | 4 ++--
 client/gui-gtk-4.0/cityrep.c     | 4 ++--
 client/gui-gtk-5.0/cityrep.c     | 4 ++--
 common/city.c                    | 4 ++--
 common/city.h                    | 9 +++------
 gen_headers/enums/Makefile.am    | 2 ++
 gen_headers/enums/city_enums.def | 9 +++++++++
 meson.build                      | 1 +
 8 files changed, 23 insertions(+), 14 deletions(-)
 create mode 100644 gen_headers/enums/city_enums.def

diff --git a/client/gui-gtk-3.22/cityrep.c b/client/gui-gtk-3.22/cityrep.c
index b7e8e78807..a33588ff44 100644
--- a/client/gui-gtk-3.22/cityrep.c
+++ b/client/gui-gtk-3.22/cityrep.c
@@ -1342,7 +1342,7 @@ static void city_select_building_callback(GtkMenuItem *item, gpointer data)
 
     if (NULL != pcity
         && ((which == PCT_UNIT && VUT_UTYPE == pcity->production.kind)
-            || (which == PCT_NORMAL_IMPROVEMENT
+            || (which == PCT_IMPROVEMENT
                 && VUT_IMPROVEMENT == pcity->production.kind
                 && !is_wonder(pcity->production.value.building))
             || (which == PCT_WONDER
@@ -1809,7 +1809,7 @@ static void create_select_menu(GtkWidget *item)
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   g_signal_connect(item, "activate",
   		   G_CALLBACK(city_select_building_callback),
-		   GINT_TO_POINTER(PCT_NORMAL_IMPROVEMENT));
+		   GINT_TO_POINTER(PCT_IMPROVEMENT));
 
   item = gtk_menu_item_new_with_label(_("Building Wonders"));
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
diff --git a/client/gui-gtk-4.0/cityrep.c b/client/gui-gtk-4.0/cityrep.c
index 326968a3de..fdf96e3e59 100644
--- a/client/gui-gtk-4.0/cityrep.c
+++ b/client/gui-gtk-4.0/cityrep.c
@@ -1385,7 +1385,7 @@ static void city_select_building_callback(GSimpleAction *action,
 
     if (NULL != pcity
         && ((which == PCT_UNIT && VUT_UTYPE == pcity->production.kind)
-            || (which == PCT_NORMAL_IMPROVEMENT
+            || (which == PCT_IMPROVEMENT
                 && VUT_IMPROVEMENT == pcity->production.kind
                 && !is_wonder(pcity->production.value.building))
             || (which == PCT_WONDER
@@ -1751,7 +1751,7 @@ static GMenu *create_select_menu(GActionGroup *group)
   act = g_simple_action_new("select_build_impr", NULL);
   g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
   g_signal_connect(act, "activate", G_CALLBACK(city_select_building_callback),
-                   GINT_TO_POINTER(PCT_NORMAL_IMPROVEMENT));
+                   GINT_TO_POINTER(PCT_IMPROVEMENT));
   menu_item_append_unref(select_menu, g_menu_item_new(_("Building Improvements"),
                                                       "win.select_build_impr"));
 
diff --git a/client/gui-gtk-5.0/cityrep.c b/client/gui-gtk-5.0/cityrep.c
index 1feb89a3a4..885875ff1e 100644
--- a/client/gui-gtk-5.0/cityrep.c
+++ b/client/gui-gtk-5.0/cityrep.c
@@ -1575,7 +1575,7 @@ static void city_select_building_callback(GSimpleAction *action,
 
     if (NULL != pcity
         && ((which == PCT_UNIT && VUT_UTYPE == pcity->production.kind)
-            || (which == PCT_NORMAL_IMPROVEMENT
+            || (which == PCT_IMPROVEMENT
                 && VUT_IMPROVEMENT == pcity->production.kind
                 && !is_wonder(pcity->production.value.building))
             || (which == PCT_WONDER
@@ -1944,7 +1944,7 @@ static GMenu *create_select_menu(GActionGroup *group)
   act = g_simple_action_new("select_build_impr", NULL);
   g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
   g_signal_connect(act, "activate", G_CALLBACK(city_select_building_callback),
-                   GINT_TO_POINTER(PCT_NORMAL_IMPROVEMENT));
+                   GINT_TO_POINTER(PCT_IMPROVEMENT));
   menu_item_append_unref(select_menu, g_menu_item_new(_("Building Improvements"),
                                                       "win.select_build_impr"));
 
diff --git a/common/city.c b/common/city.c
index 2289afe67e..a1e28cb6d2 100644
--- a/common/city.c
+++ b/common/city.c
@@ -1896,7 +1896,7 @@ int city_change_production_penalty(const struct city *pcity,
     if (is_wonder(pcity->changed_from.value.building)) {
       orig_class = PCT_WONDER;
     } else {
-      orig_class = PCT_NORMAL_IMPROVEMENT;
+      orig_class = PCT_IMPROVEMENT;
     }
     break;
   case VUT_UTYPE:
@@ -1912,7 +1912,7 @@ int city_change_production_penalty(const struct city *pcity,
     if (is_wonder(target->value.building)) {
       new_class = PCT_WONDER;
     } else {
-      new_class = PCT_NORMAL_IMPROVEMENT;
+      new_class = PCT_IMPROVEMENT;
     }
     break;
   case VUT_UTYPE:
diff --git a/common/city.h b/common/city.h
index d9aa631979..8e7a0f0d7a 100644
--- a/common/city.h
+++ b/common/city.h
@@ -35,12 +35,9 @@ struct unit_list;
 struct vision;
 struct packet_city_rally_point;
 
-enum production_class_type {
-  PCT_UNIT,
-  PCT_NORMAL_IMPROVEMENT,
-  PCT_WONDER,
-  PCT_LAST
-};
+#include "city_enums_gen.h"
+
+#define PCT_LAST PCT_COUNT
 
 /* Various city options. These are stored by the server and can be
  * toggled by the user. Each one defaults to off. Adding new ones
diff --git a/gen_headers/enums/Makefile.am b/gen_headers/enums/Makefile.am
index 27e8b0f9c7..0a93471c8e 100644
--- a/gen_headers/enums/Makefile.am
+++ b/gen_headers/enums/Makefile.am
@@ -2,6 +2,7 @@
 
 ENUMS_GEN = \
 		actions_enums_gen.h	\
+		city_enums_gen.h	\
 		effects_enums_gen.h	\
 		fc_types_enums_gen.h	\
 		manual_enums_gen.h	\
@@ -9,6 +10,7 @@ ENUMS_GEN = \
 
 EXTRA_DIST = \
 		actions_enums.def	\
+		city_enums.def		\
 		effects_enums.def	\
 		fc_types_enums.def	\
 		manual_enums.def	\
diff --git a/gen_headers/enums/city_enums.def b/gen_headers/enums/city_enums.def
new file mode 100644
index 0000000000..be1c65fc07
--- /dev/null
+++ b/gen_headers/enums/city_enums.def
@@ -0,0 +1,9 @@
+
+enum production_class_type
+  prefix PCT_
+  count
+values
+  UNIT        "Unit"
+  IMPROVEMENT "Improvement"
+  WONDER      "Wonder"
+end
diff --git a/meson.build b/meson.build
index bb333ac973..c7f339acb4 100644
--- a/meson.build
+++ b/meson.build
@@ -1140,6 +1140,7 @@ specenum = custom_target('specenum_gen.h', output: 'specenum_gen.h',
 enum_defs = {
   'common': {
     'actions_enums': ['actions_enums.def', 'actions_enums_gen.h'],
+    'city_enums': ['city_enums.def', 'city_enums_gen.h'],
     'effects_enums': ['effects_enums.def', 'effects_enums_gen.h'],
     'fc_types_enums': ['fc_types_enums.def', 'fc_types_enums_gen.h'],
     'terrain_enums': ['terrain_enums.def', 'terrain_enums_gen.h'],
-- 
2.45.2

