From 48022e7b69d7aa268f265bc4d0915688154c1a29 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

From now, counter-related code will be aware to reinitialize, so code in
ruleset is redutand. This was made to allow ruledit work in future.

diff --git a/common/counters.c b/common/counters.c
index 8b30d88314..730a155e62 100644
--- a/common/counters.c
+++ b/common/counters.c
@@ -33,16 +33,30 @@ 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;
+  counters_free();
 }
 
+/************************************************************************//**
+  Initialize signle system
+****************************************************************************/
+static void counter_init(struct counter *pcounter)
+{
+  pcounter->checkpoint = 0;
+  pcounter->def = 0;
+  pcounter->index = 0;
+  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 +66,12 @@ void counters_free(void)
   /* TODO: Is freeing translated name needed? If is, write the right
    * code here
    */
-
+  int i;
+    
+  for (i = 0; i < game.control.num_counters; i++) {
+      
+      counter_init(counter_by_id(i));
+  }
   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);
-- 
2.38.1

