From 3e9159ee45ee63e176a630339f47a9f6e8a1e58d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C5=82awomir=20Lach?= <slawek@lach.art.pl>
Date: Sat, 9 Apr 2022 18:36:35 +0200
Subject: [PATCH 2/4] =?UTF-8?q?OSDN!41121=20S=C5=82awomir=20Lach=20<slawek?=
 =?UTF-8?q?@lach.art.pl>=20-=20Change=20hardcode=20types=20into=20auto-gen?=
 =?UTF-8?q?erated=20one=20Change=20enum=20related=20C-code=20types=20into?=
 =?UTF-8?q?=20freeciv=20specenum=20-=20Added=20comments=20for=20introduced?=
 =?UTF-8?q?=20new=20functions.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 common/counters.c  | 27 ++++++++++++---------------
 common/counters.h  | 18 +++++++++++-------
 server/citytools.c |  2 +-
 server/srv_main.c  |  2 +-
 4 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/common/counters.c b/common/counters.c
index 728a113d23..e09fc849de 100644
--- a/common/counters.c
+++ b/common/counters.c
@@ -25,7 +25,6 @@
 
 static struct counter counters[MAX_COUNTERS] =
 {
-  { (struct name_translation) NAME_INIT, COUNTER_OWNED, CTGT_CITY, 5, 0 }
 };
 
 static struct counter *counters_city[MAX_COUNTERS];
@@ -36,24 +35,20 @@ static int number_city_counters;
 ****************************************************************************/
 void counters_init(void)
 {
-  int i;
-
-  number_city_counters = 0;
 
-  name_set(&counters[0].name, NULL, N_("?counter:Owned"));
-
-  for (i = 0; i < MAX_COUNTERS; i++) {
+}
 
-    if (counters[i].type == COUNTER_OWNED) {
-      /* City counter type */
-      counters_city[number_city_counters] = &counters[i];
-      counters[i].index = number_city_counters;
-      counters[i].target = CTGT_CITY;
-      number_city_counters++;
-    }
-  }
+/************************************************************************//**
+  Part of counters system initialization - it is used to add counter
+  to related counter-type array
+****************************************************************************/
+void attach_city_counter(struct counter *counter)
+{
+  counters_city[number_city_counters] = counter;
+  ++number_city_counters;
 }
 
+
 /************************************************************************//**
   Free resources allocated by counters system
 ****************************************************************************/
@@ -167,6 +162,8 @@ struct counter *counter_by_index(int index, enum counter_target target)
   {
     case CTGT_CITY:
       return counters_city[index];
+    case CTGT_LAST:
+      break;
   }
 
   return NULL;
diff --git a/common/counters.h b/common/counters.h
index c5399e91aa..f9c86a49d8 100644
--- a/common/counters.h
+++ b/common/counters.h
@@ -23,22 +23,25 @@ extern "C" {
 #define SPECENUM_NAME counter_behaviour
 /* Not performing any activity right now */
 #define SPECENUM_VALUE0 CB_CITY_OWNED_TURNS
-#define SPECENUM_VALUE0NAME N_("OWNED")
+#define SPECENUM_VALUE0NAME "OWNED"
 /* Number of activities */
 #define SPECENUM_COUNT COUNTER_BEHAVIOUR_LAST
 #include "specenum_gen.h"
 
-enum counter_type { COUNTER_OWNED = 0, COUNTER_COUNT };
-
-enum counter_target { CTGT_CITY };
+#define SPECENUM_NAME counter_target
+/* Not performing any activity right now */
+#define SPECENUM_VALUE0 CTGT_CITY
+#define SPECENUM_VALUE0NAME "City"
+/* Number of activities */
+#define SPECENUM_COUNT CTGT_LAST
+#include "specenum_gen.h"
 
-/* Space for one counter of each type */
-#define MAX_COUNTERS COUNTER_COUNT
+#define MAX_COUNTERS 20
 
 struct counter
 {
   struct name_translation name;
-  enum counter_type type;
+  enum counter_behaviour type;
   enum counter_target target;
   int checkpoint;
   int def;    /* default value for each entity of given type
@@ -62,6 +65,7 @@ struct counter *counter_by_translated_name(const char *name);
 int counter_index(struct counter *pcount);
 struct counter *counter_by_index(int index, enum counter_target target);
 int counters_get_city_counters_count(void);
+void attach_city_counter(struct counter *counter);
 
 
 #define city_counters_iterate(pcount) { \
diff --git a/server/citytools.c b/server/citytools.c
index ada6227b22..3349f4f250 100644
--- a/server/citytools.c
+++ b/server/citytools.c
@@ -1219,7 +1219,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity,
   /* Reset turns owner counters */
   if (city_remains) {
     city_counters_iterate(pcount) {
-      if (pcount->type == COUNTER_OWNED) {
+      if (pcount->type == CB_CITY_OWNED_TURNS) {
         pcity->counter_values[pcount->index] = 0;
       }
     } city_counters_iterate_end;
diff --git a/server/srv_main.c b/server/srv_main.c
index 3c79188239..0366aec7af 100644
--- a/server/srv_main.c
+++ b/server/srv_main.c
@@ -1520,7 +1520,7 @@ static void end_turn(void)
   players_iterate(pplayer) {
     city_list_iterate(pplayer->cities, pcity) {
       city_counters_iterate(pcount) {
-        if (pcount->type == COUNTER_OWNED) {
+        if (pcount->type == CB_CITY_OWNED_TURNS) {
           pcity->counter_values[pcount->index]++;
         }
       } city_counters_iterate_end;
-- 
2.35.1

