From 1bae13d8bcfbc3acdbb4044c574e22fbfadc8d14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C5=82awomir=20Lach?= <slawek@lach.art.pl>
Date: Fri, 2 Dec 2022 16:17:06 +0100
Subject: [PATCH] =?UTF-8?q?!OSDN:=20Ticket:=2046172=20-=20=C5=82awomir=20L?=
 =?UTF-8?q?ach=20<slawek@lach.art.pl>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It made possible to mark counters as ruledit_disabled/ruledit_enabled
by adding initialize code to counters.c. It also allow to reintialize
give counter.

diff --git a/common/counters.c b/common/counters.c
index 8b30d88314..e578f6e193 100644
--- a/common/counters.c
+++ b/common/counters.c
@@ -33,16 +33,34 @@ static struct counter counters[MAX_COUNTERS];
 /* City counters array + related data */
 static struct counter *counters_city[MAX_COUNTERS];
 static int number_city_counters;
+static void counter_init(struct counter *pcounter);
 
 /************************************************************************//**
   Initialize counters system
 ****************************************************************************/
 void counters_init(void)
 {
-  game.control.num_counters = 0;
-  number_city_counters = 0;
+  int i;
+
+  for (i = 0; i < game.control.num_counters; i++) {
+
+    counter_init(counter_by_id(i));
+  }
 }
 
+/************************************************************************//**
+  Initialize signle system
+****************************************************************************/
+static void counter_init(struct counter *pcounter)
+{
+  pcounter->checkpoint = 0;
+  pcounter->def = 0;
+  pcounter->index = pcounter - counters;
+  name_init(&pcounter->name);
+  pcounter->ruledit_disabled = false;
+  pcounter->target = CTGT_CITY;
+  pcounter->type = CB_CITY_OWNED_TURNS;
+}
 
 /************************************************************************//**
   Free resources allocated by counters system
@@ -52,7 +70,6 @@ void counters_free(void)
   /* TODO: Is freeing translated name needed? If is, write the right
    * code here
    */
-
   game.control.num_counters = 0;
   number_city_counters = 0;
 }
diff --git a/common/counters.h b/common/counters.h
index 29f8e0f40e..ef29b4ff34 100644
--- a/common/counters.h
+++ b/common/counters.h
@@ -13,6 +13,8 @@
 #ifndef FC__COUNTERS_H
 #define FC__COUNTERS_H
 
+#include <stdbool.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -32,6 +34,8 @@ struct counter
                * for this counter */
 
   int index;  /* index in specific (city/player/world) array */
+
+  bool ruledit_disabled; /* used only in ruledit utility */
 };
 
 void counters_init(void);
diff --git a/server/ruleset.c b/server/ruleset.c
index e19b3ce84d..89d724ddac 100644
--- a/server/ruleset.c
+++ b/server/ruleset.c
@@ -7789,6 +7789,7 @@ static bool load_ruleset_game(struct section_file *file, bool act,
   }
 
   if (ok) {
+    counters_init();
     sec = secfile_sections_by_name_prefix(file, COUNTER_SECTION_PREFIX);
 
     if (sec != NULL) {
-- 
2.38.1

