From 4c1eeeae703b0b996aa2283ecb9a34f967cb80ca Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 8 Mar 2024 18:14:02 +0200
Subject: [PATCH 27/27] Make WORLD_PEACE_TURNS ruleset controlled

See RM #299

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/game.h                   |  2 --
 common/networking/packets.def   |  1 +
 data/alien/game.ruleset         |  4 ++++
 data/civ1/game.ruleset          |  4 ++++
 data/civ2/game.ruleset          |  4 ++++
 data/civ2civ3/game.ruleset      |  4 ++++
 data/classic/game.ruleset       |  4 ++++
 data/goldkeep/game.ruleset      |  4 ++++
 data/granularity/game.ruleset   |  4 ++++
 data/multiplayer/game.ruleset   |  4 ++++
 data/ruledit/comments-3.3.txt   |  4 ++++
 data/sandbox/game.ruleset       |  4 ++++
 data/stub/game.ruleset          |  4 ++++
 data/webperimental/game.ruleset |  4 ++++
 server/ruleset/ruleload.c       |  5 +++++
 server/ruleset/ruleload.h       |  2 ++
 server/srv_main.c               |  2 +-
 tools/ruleutil/comments.c       | 13 +++++++++++++
 tools/ruleutil/comments.h       |  1 +
 tools/ruleutil/rulesave.c       |  6 ++++++
 20 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/common/game.h b/common/game.h
index 22a2bdd8a1..ab61fbb35e 100644
--- a/common/game.h
+++ b/common/game.h
@@ -754,8 +754,6 @@ static inline bool is_ruleset_compat_mode(void)
 /* Max number of recursive transports. */
 #define GAME_TRANSPORT_MAX_RECURSIVE 5
 
-#define WORLD_PEACE_TURNS 20
-
 /* Ruleset settings */
 
 #define RS_MAX_VALUE                             1000000
diff --git a/common/networking/packets.def b/common/networking/packets.def
index 79b7fe5ae3..79f23c73b5 100644
--- a/common/networking/packets.def
+++ b/common/networking/packets.def
@@ -507,6 +507,7 @@ PACKET_GAME_INFO = 16; sc, is-info
   UINT16 culture_vic_lead;
   UINT16 culture_migration_pml;
   UINT16 history_interest_pml;
+  UINT16 world_peace_turns;
   /* size limit for cities before they can celebrate */
   UINT8 celebratesize;
   BOOL changable_tax;
diff --git a/data/alien/game.ruleset b/data/alien/game.ruleset
index d6ede54b4a..56198079b0 100644
--- a/data/alien/game.ruleset
+++ b/data/alien/game.ruleset
@@ -385,6 +385,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year  = 250
diff --git a/data/civ1/game.ruleset b/data/civ1/game.ruleset
index 5dd7a4c2d3..eefb622eaa 100644
--- a/data/civ1/game.ruleset
+++ b/data/civ1/game.ruleset
@@ -370,6 +370,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year 1 instead of 0.
 skip_year_0 = TRUE
diff --git a/data/civ2/game.ruleset b/data/civ2/game.ruleset
index be93b7f281..e08d49cca1 100644
--- a/data/civ2/game.ruleset
+++ b/data/civ2/game.ruleset
@@ -366,6 +366,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year 1 instead of 0.
 skip_year_0 = TRUE
diff --git a/data/civ2civ3/game.ruleset b/data/civ2civ3/game.ruleset
index 15189f0f40..73975211ef 100644
--- a/data/civ2civ3/game.ruleset
+++ b/data/civ2civ3/game.ruleset
@@ -391,6 +391,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year = -4000
diff --git a/data/classic/game.ruleset b/data/classic/game.ruleset
index 433e372915..61e8d770e0 100644
--- a/data/classic/game.ruleset
+++ b/data/classic/game.ruleset
@@ -386,6 +386,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year = -4000
diff --git a/data/goldkeep/game.ruleset b/data/goldkeep/game.ruleset
index c03232015f..66eb66dea2 100644
--- a/data/goldkeep/game.ruleset
+++ b/data/goldkeep/game.ruleset
@@ -389,6 +389,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year = -4000
diff --git a/data/granularity/game.ruleset b/data/granularity/game.ruleset
index 4917a7f140..70eca325a2 100644
--- a/data/granularity/game.ruleset
+++ b/data/granularity/game.ruleset
@@ -382,6 +382,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year = 0
diff --git a/data/multiplayer/game.ruleset b/data/multiplayer/game.ruleset
index 0b2883dae8..5a5982116d 100644
--- a/data/multiplayer/game.ruleset
+++ b/data/multiplayer/game.ruleset
@@ -389,6 +389,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year = -4000
diff --git a/data/ruledit/comments-3.3.txt b/data/ruledit/comments-3.3.txt
index 4066c19a3c..3588c1cde1 100644
--- a/data/ruledit/comments-3.3.txt
+++ b/data/ruledit/comments-3.3.txt
@@ -1624,6 +1624,10 @@ migration_pml = "\n\
 ; of a migration point.\
 "
 
+world_peace_turns = "\n\
+; How many turns of world peace is required for a World Peace Victory\n\
+"
+
 calendar_fragments = "\n\
 ; How many fragments each year has. In addition to this, \"Turn_Fragments\" effects are\n\
 ; needed to control fragment accumulation.\n\
diff --git a/data/sandbox/game.ruleset b/data/sandbox/game.ruleset
index 807ea60bd2..81997f1660 100644
--- a/data/sandbox/game.ruleset
+++ b/data/sandbox/game.ruleset
@@ -389,6 +389,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year = -4000
diff --git a/data/stub/game.ruleset b/data/stub/game.ruleset
index 5e58df33e0..e1b6d3291c 100644
--- a/data/stub/game.ruleset
+++ b/data/stub/game.ruleset
@@ -373,6 +373,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year = 0
diff --git a/data/webperimental/game.ruleset b/data/webperimental/game.ruleset
index eff3268841..ec22dd0f69 100644
--- a/data/webperimental/game.ruleset
+++ b/data/webperimental/game.ruleset
@@ -390,6 +390,10 @@ history_interest_pml = 0
 ; of a migration point.
 migration_pml = 50
 
+[world_peace]
+; How many turns of world peace is required for a World Peace Victory
+victory_turns = 20;
+
 [calendar]
 ; Year in the beginning of the game
 start_year = -4000
diff --git a/server/ruleset/ruleload.c b/server/ruleset/ruleload.c
index fdf0d4caae..112279c404 100644
--- a/server/ruleset/ruleload.c
+++ b/server/ruleset/ruleload.c
@@ -7099,6 +7099,11 @@ static bool load_ruleset_game(struct section_file *file, bool act,
       = secfile_lookup_int_default(file, RS_DEFAULT_HISTORY_INTEREST_PML,
                                    "culture.history_interest_pml");
 
+    /* section: world_peace */
+    game.info.world_peace_turns
+      = secfile_lookup_int_default(file, RS_DEFAULT_WORLD_PEACE_TURNS,
+                                   "world_peace.victory_turns");
+
     /* section: calendar */
     game.calendar.calendar_skip_0
       = secfile_lookup_bool_default(file, RS_DEFAULT_CALENDAR_SKIP_0,
diff --git a/server/ruleset/ruleload.h b/server/ruleset/ruleload.h
index 2f400f44ea..5aeda4e3b7 100644
--- a/server/ruleset/ruleload.h
+++ b/server/ruleset/ruleload.h
@@ -96,6 +96,8 @@ int ruleset_purge_redundant_reqs(void);
 #define RS_DEFAULT_CULTURE_MIGRATION_PML 50
 #define RS_DEFAULT_HISTORY_INTEREST_PML  0
 
+#define RS_DEFAULT_WORLD_PEACE_TURNS     20
+
 #define RS_DEFAULT_GOODS_SELECTION       GSM_LEAVING
 
 #define RS_DEFAULT_EXTRA_APPEARANCE      15
diff --git a/server/srv_main.c b/server/srv_main.c
index 55fcec3a14..3ddf79172d 100644
--- a/server/srv_main.c
+++ b/server/srv_main.c
@@ -523,7 +523,7 @@ bool check_for_game_over(void)
 
     /* Check for World Peace victory. */
     if (1 < candidates && victory_enabled(VC_WORLDPEACE)) {
-      if (game.info.turn - game.server.world_peace_start >= WORLD_PEACE_TURNS) {
+      if (game.info.turn - game.server.world_peace_start >= game.info.world_peace_turns) {
         bool first = TRUE;
 
         astr_init(&str);
diff --git a/tools/ruleutil/comments.c b/tools/ruleutil/comments.c
index 39038972ae..1f032614ac 100644
--- a/tools/ruleutil/comments.c
+++ b/tools/ruleutil/comments.c
@@ -96,6 +96,7 @@ static struct {
   char *research_free_tech_method;
   char *culture_history_interest;
   char *culture_migration_pml;
+  char *world_peace_turns;
   char *calendar_fragments;
 } comments_storage;
 
@@ -254,6 +255,8 @@ bool comments_load(void)
                "entrydoc.history_interest_pml");
   comment_load(comments_storage.culture_migration_pml, comment_file,
                "entrydoc.migration_pml");
+  comment_load(comments_storage.world_peace_turns, comment_file,
+               "entrydoc.world_peace_turns");
   comment_load(comments_storage.calendar_fragments, comment_file,
                "entrydoc.calendar_fragments");
 
@@ -873,6 +876,7 @@ void comment_culture_history_interest(struct section_file *sfile)
   comment_entry_write(sfile, comments_storage.culture_history_interest,
                       "culture");
 }
+
 /**********************************************************************//**
   Write culture migration_pml settings header.
 **************************************************************************/
@@ -882,6 +886,15 @@ void comment_culture_migration_pml(struct section_file *sfile)
                       "culture");
 }
 
+/**********************************************************************//**
+  Write world peace turns settings header.
+**************************************************************************/
+void comment_world_peace_turns(struct section_file *sfile)
+{
+  comment_entry_write(sfile, comments_storage.world_peace_turns,
+                      "world_peace");
+}
+
 /**********************************************************************//**
   Write calendar fragments settings header.
 **************************************************************************/
diff --git a/tools/ruleutil/comments.h b/tools/ruleutil/comments.h
index 3d60dfc51d..05ae8ff2ad 100644
--- a/tools/ruleutil/comments.h
+++ b/tools/ruleutil/comments.h
@@ -100,6 +100,7 @@ void comment_research_upkeep_style(struct section_file *sfile);
 void comment_research_free_tech_method(struct section_file *sfile);
 void comment_culture_history_interest(struct section_file *sfile);
 void comment_culture_migration_pml(struct section_file *sfile);
+void comment_world_peace_turns(struct section_file *sfile);
 void comment_calendar_fragments(struct section_file *sfile);
 void comment_counters(struct section_file *sfile);
 
diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c
index c030168b4b..7906f036a1 100644
--- a/tools/ruleutil/rulesave.c
+++ b/tools/ruleutil/rulesave.c
@@ -1607,6 +1607,12 @@ static bool save_game_ruleset(const char *filename, const char *name)
   save_default_int(sfile, game.info.history_interest_pml,
                    RS_DEFAULT_HISTORY_INTEREST_PML,
                    "culture.history_interest_pml", NULL);
+  if (game.info.world_peace_turns != RS_DEFAULT_WORLD_PEACE_TURNS) {
+    comment_world_peace_turns(sfile);
+  }
+  save_default_int(sfile, game.info.world_peace_turns,
+                   RS_DEFAULT_WORLD_PEACE_TURNS,
+                   "world_peace.victory_turns", NULL);
 
   save_default_bool(sfile, game.calendar.calendar_skip_0,
                     RS_DEFAULT_CALENDAR_SKIP_0,
-- 
2.43.0

