From 1f79fd9b6ab61d49db90e50343e7aed349c1d08e Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 29 Oct 2024 23:39:49 +0200
Subject: [PATCH 54/54] Replace civstyle civil war bonus values with
 Civil_War_City_Bonus effects

See RM #1032

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/game.h                      |  3 ---
 common/networking/packets.def      |  2 --
 data/alien/game.ruleset            |  6 -----
 data/civ1/effects.ruleset          | 16 ++++++++++++++
 data/civ1/game.ruleset             |  6 -----
 data/civ2/effects.ruleset          | 16 ++++++++++++++
 data/civ2/game.ruleset             |  6 -----
 data/civ2civ3/effects.ruleset      | 16 ++++++++++++++
 data/civ2civ3/game.ruleset         |  6 -----
 data/classic/effects.ruleset       | 16 ++++++++++++++
 data/classic/game.ruleset          |  6 -----
 data/goldkeep/effects.ruleset      | 16 ++++++++++++++
 data/goldkeep/game.ruleset         |  6 -----
 data/granularity/game.ruleset      |  6 -----
 data/multiplayer/effects.ruleset   | 16 ++++++++++++++
 data/multiplayer/game.ruleset      |  6 -----
 data/sandbox/effects.ruleset       | 16 ++++++++++++++
 data/sandbox/game.ruleset          |  6 -----
 data/stub/game.ruleset             |  6 -----
 data/webperimental/effects.ruleset | 16 ++++++++++++++
 data/webperimental/game.ruleset    |  6 -----
 server/plrhand.c                   |  6 -----
 server/ruleset/rscompat.c          | 35 ++++++++++++++++++++++++++++++
 server/ruleset/rscompat.h          |  2 ++
 server/ruleset/ruleload.c          | 10 +++------
 tools/ruleutil/rulesave.c          |  6 -----
 26 files changed, 168 insertions(+), 90 deletions(-)

diff --git a/common/game.h b/common/game.h
index 569e01b59a..eadd85679c 100644
--- a/common/game.h
+++ b/common/game.h
@@ -856,9 +856,6 @@ static inline bool is_ruleset_compat_mode(void)
 #define RS_MIN_FOOD_COST                         0
 #define RS_MAX_FOOD_COST                         10000
 
-#define RS_DEFAULT_CIVIL_WAR_CELEB               -5
-#define RS_DEFAULT_CIVIL_WAR_UNHAPPY             5
-
 #define RS_DEFAULT_TIRED_ATTACK                  FALSE
 #define RS_DEFAULT_NUKE_POP_LOSS_PCT             49
 #define RS_MIN_NUKE_POP_LOSS_PCT                 0
diff --git a/common/networking/packets.def b/common/networking/packets.def
index 6cdaef7cb4..66d29b25c4 100644
--- a/common/networking/packets.def
+++ b/common/networking/packets.def
@@ -626,8 +626,6 @@ PACKET_GAME_INFO = 16; sc, is-info
   UINT8 top_cities_count;
   UINT16 fragment_count;
   BOOL civil_war_enabled;
-  SINT16 civil_war_bonus_celebrating;
-  SINT16 civil_war_bonus_unhappy;
   UINT16 granularity;
   WONDER_VISIB small_wonder_visibility;
 end
diff --git a/data/alien/game.ruleset b/data/alien/game.ruleset
index 05b22b08b6..9924d62ca2 100644
--- a/data/alien/game.ruleset
+++ b/data/alien/game.ruleset
@@ -145,12 +145,6 @@ tech_loss_allow_holes     = TRUE
 ; Whether civil war is possible at all
 civil_war_enabled        = FALSE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = 0
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 0
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/civ1/effects.ruleset b/data/civ1/effects.ruleset
index 205b415081..ad6b563468 100644
--- a/data/civ1/effects.ruleset
+++ b/data/civ1/effects.ruleset
@@ -1638,3 +1638,19 @@ reqs    =
       "TileRel",        "Only Other Region", "Adjacent"
       "TileRel",        "Same Region",       "Adjacent"
     }
+
+[effect_civil_war_city_celebration]
+type    = "Civil_War_City_Bonus"
+value   = 5
+reqs    =
+    { "type",       "name",        "range"
+      "CityStatus", "Celebration", "City"
+    }
+
+[effect_civil_war_city_disorder]
+type    = "Civil_War_City_Bonus"
+value   = -5
+reqs    =
+    { "type",       "name",     "range"
+      "CityStatus", "Disorder", "City"
+    }
diff --git a/data/civ1/game.ruleset b/data/civ1/game.ruleset
index c8d9158745..5ec581990b 100644
--- a/data/civ1/game.ruleset
+++ b/data/civ1/game.ruleset
@@ -131,12 +131,6 @@ tech_loss_allow_holes       = FALSE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = -5
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 5
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/civ2/effects.ruleset b/data/civ2/effects.ruleset
index bcd187720a..1cbeb3b617 100644
--- a/data/civ2/effects.ruleset
+++ b/data/civ2/effects.ruleset
@@ -2721,3 +2721,19 @@ reqs    =
       "TileRel",        "Only Other Region", "Adjacent"
       "TileRel",        "Same Region",       "Adjacent"
     }
+
+[effect_civil_war_city_celebration]
+type    = "Civil_War_City_Bonus"
+value   = 5
+reqs    =
+    { "type",       "name",        "range"
+      "CityStatus", "Celebration", "City"
+    }
+
+[effect_civil_war_city_disorder]
+type    = "Civil_War_City_Bonus"
+value   = -5
+reqs    =
+    { "type",       "name",     "range"
+      "CityStatus", "Disorder", "City"
+    }
diff --git a/data/civ2/game.ruleset b/data/civ2/game.ruleset
index d9964ed0de..cdf5f22eb7 100644
--- a/data/civ2/game.ruleset
+++ b/data/civ2/game.ruleset
@@ -127,12 +127,6 @@ tech_loss_allow_holes     = TRUE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = -5
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 5
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/civ2civ3/effects.ruleset b/data/civ2civ3/effects.ruleset
index ed9e73a64e..88909972ed 100644
--- a/data/civ2civ3/effects.ruleset
+++ b/data/civ2civ3/effects.ruleset
@@ -4661,3 +4661,19 @@ reqs    =
       "TileRel",        "Only Other Region", "Adjacent"
       "TileRel",        "Same Region",       "Adjacent"
     }
+
+[effect_civil_war_city_celebration]
+type    = "Civil_War_City_Bonus"
+value   = 5
+reqs    =
+    { "type",       "name",        "range"
+      "CityStatus", "Celebration", "City"
+    }
+
+[effect_civil_war_city_disorder]
+type    = "Civil_War_City_Bonus"
+value   = -5
+reqs    =
+    { "type",       "name",     "range"
+      "CityStatus", "Disorder", "City"
+    }
diff --git a/data/civ2civ3/game.ruleset b/data/civ2civ3/game.ruleset
index 899ee9c146..f4f3b980f4 100644
--- a/data/civ2civ3/game.ruleset
+++ b/data/civ2civ3/game.ruleset
@@ -148,12 +148,6 @@ tech_loss_allow_holes     = FALSE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = -5
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 5
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/classic/effects.ruleset b/data/classic/effects.ruleset
index 218f1bdceb..874df2ae50 100644
--- a/data/classic/effects.ruleset
+++ b/data/classic/effects.ruleset
@@ -2786,3 +2786,19 @@ reqs    =
       "TileRel",        "Only Other Region", "Adjacent"
       "TileRel",        "Same Region",       "Adjacent"
     }
+
+[effect_civil_war_city_celebration]
+type    = "Civil_War_City_Bonus"
+value   = 5
+reqs    =
+    { "type",       "name",        "range"
+      "CityStatus", "Celebration", "City"
+    }
+
+[effect_civil_war_city_disorder]
+type    = "Civil_War_City_Bonus"
+value   = -5
+reqs    =
+    { "type",       "name",     "range"
+      "CityStatus", "Disorder", "City"
+    }
diff --git a/data/classic/game.ruleset b/data/classic/game.ruleset
index fbc98c8de5..cadc74e18e 100644
--- a/data/classic/game.ruleset
+++ b/data/classic/game.ruleset
@@ -141,12 +141,6 @@ tech_loss_allow_holes     = TRUE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = -5
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 5
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/goldkeep/effects.ruleset b/data/goldkeep/effects.ruleset
index a866aceb73..b0d6e43073 100644
--- a/data/goldkeep/effects.ruleset
+++ b/data/goldkeep/effects.ruleset
@@ -3117,3 +3117,19 @@ reqs    =
       "TileRel",        "Only Other Region", "Adjacent"
       "TileRel",        "Same Region",       "Adjacent"
     }
+
+[effect_civil_war_city_celebration]
+type    = "Civil_War_City_Bonus"
+value   = 5
+reqs    =
+    { "type",       "name",        "range"
+      "CityStatus", "Celebration", "City"
+    }
+
+[effect_civil_war_city_disorder]
+type    = "Civil_War_City_Bonus"
+value   = -5
+reqs    =
+    { "type",       "name",     "range"
+      "CityStatus", "Disorder", "City"
+    }
diff --git a/data/goldkeep/game.ruleset b/data/goldkeep/game.ruleset
index 390a84d753..6d5d97ec9f 100644
--- a/data/goldkeep/game.ruleset
+++ b/data/goldkeep/game.ruleset
@@ -146,12 +146,6 @@ tech_loss_allow_holes     = TRUE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = -5
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 5
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/granularity/game.ruleset b/data/granularity/game.ruleset
index 62c43b40a2..91b4f69dfb 100644
--- a/data/granularity/game.ruleset
+++ b/data/granularity/game.ruleset
@@ -138,12 +138,6 @@ tech_loss_allow_holes     = TRUE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = 0
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 0
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/multiplayer/effects.ruleset b/data/multiplayer/effects.ruleset
index e892b2df03..2569b003de 100644
--- a/data/multiplayer/effects.ruleset
+++ b/data/multiplayer/effects.ruleset
@@ -2825,3 +2825,19 @@ reqs    =
       "TileRel",        "Only Other Region", "Adjacent"
       "TileRel",        "Same Region",       "Adjacent"
     }
+
+[effect_civil_war_city_celebration]
+type    = "Civil_War_City_Bonus"
+value   = 5
+reqs    =
+    { "type",       "name",        "range"
+      "CityStatus", "Celebration", "City"
+    }
+
+[effect_civil_war_city_disorder]
+type    = "Civil_War_City_Bonus"
+value   = -5
+reqs    =
+    { "type",       "name",     "range"
+      "CityStatus", "Disorder", "City"
+    }
diff --git a/data/multiplayer/game.ruleset b/data/multiplayer/game.ruleset
index 703cce17f2..8fcdd3566f 100644
--- a/data/multiplayer/game.ruleset
+++ b/data/multiplayer/game.ruleset
@@ -144,12 +144,6 @@ tech_loss_allow_holes     = TRUE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = -5
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 5
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/sandbox/effects.ruleset b/data/sandbox/effects.ruleset
index 3ca44c45ea..ac3cc9ba67 100644
--- a/data/sandbox/effects.ruleset
+++ b/data/sandbox/effects.ruleset
@@ -5466,3 +5466,19 @@ reqs    =
       "TileRel",        "Only Other Region", "Adjacent"
       "TileRel",        "Same Region",       "Adjacent"
     }
+
+[effect_civil_war_city_celebration]
+type    = "Civil_War_City_Bonus"
+value   = 5
+reqs    =
+    { "type",       "name",        "range"
+      "CityStatus", "Celebration", "City"
+    }
+
+[effect_civil_war_city_disorder]
+type    = "Civil_War_City_Bonus"
+value   = -5
+reqs    =
+    { "type",       "name",     "range"
+      "CityStatus", "Disorder", "City"
+    }
diff --git a/data/sandbox/game.ruleset b/data/sandbox/game.ruleset
index 2d919d9c0f..290bcaadfd 100644
--- a/data/sandbox/game.ruleset
+++ b/data/sandbox/game.ruleset
@@ -146,12 +146,6 @@ tech_loss_allow_holes     = FALSE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = -5
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 5
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/stub/game.ruleset b/data/stub/game.ruleset
index 5a96bad9a6..632101409c 100644
--- a/data/stub/game.ruleset
+++ b/data/stub/game.ruleset
@@ -129,12 +129,6 @@ tech_loss_allow_holes     = TRUE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = 0
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 0
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/data/webperimental/effects.ruleset b/data/webperimental/effects.ruleset
index 766b39a888..6920a419c9 100644
--- a/data/webperimental/effects.ruleset
+++ b/data/webperimental/effects.ruleset
@@ -3062,3 +3062,19 @@ reqs    =
       "TileRel",        "Only Other Region", "Adjacent"
       "TileRel",        "Same Region",       "Adjacent"
     }
+
+[effect_civil_war_city_celebration]
+type    = "Civil_War_City_Bonus"
+value   = 5
+reqs    =
+    { "type",       "name",        "range"
+      "CityStatus", "Celebration", "City"
+    }
+
+[effect_civil_war_city_disorder]
+type    = "Civil_War_City_Bonus"
+value   = -5
+reqs    =
+    { "type",       "name",     "range"
+      "CityStatus", "Disorder", "City"
+    }
diff --git a/data/webperimental/game.ruleset b/data/webperimental/game.ruleset
index c19e38200a..7e5e79752e 100644
--- a/data/webperimental/game.ruleset
+++ b/data/webperimental/game.ruleset
@@ -145,12 +145,6 @@ tech_loss_allow_holes     = FALSE
 ; Whether civil war is possible at all
 civil_war_enabled        = TRUE
 
-; How many percents each celebrating city affects chance of civil war
-civil_war_bonus_celebrating = -5
-
-; How many percents each unhappy city affects chance of civil war
-civil_war_bonus_unhappy     = 5
-
 ; Comma separated list of things to happen, in addition to death
 ; of owner, when gameloss unit dies
 ; "CivilWar"   - Part of the empire remains, controlled by a new player
diff --git a/server/plrhand.c b/server/plrhand.c
index e1ecc2f7d9..1efcb5a6c8 100644
--- a/server/plrhand.c
+++ b/server/plrhand.c
@@ -2967,12 +2967,6 @@ bool civil_war_triggered(struct player *pplayer)
 
   /* Now compute the contribution of the cities. */
   city_list_iterate(pplayer->cities, pcity) {
-    if (city_unhappy(pcity)) {
-      prob += game.info.civil_war_bonus_unhappy;
-    }
-    if (city_celebrating(pcity)) {
-      prob += game.info.civil_war_bonus_celebrating;
-    }
     prob -= get_city_bonus(pcity, EFT_CIVIL_WAR_CITY_BONUS);
   } city_list_iterate_end;
 
diff --git a/server/ruleset/rscompat.c b/server/ruleset/rscompat.c
index 156e62f070..5f90b7e620 100644
--- a/server/ruleset/rscompat.c
+++ b/server/ruleset/rscompat.c
@@ -700,3 +700,38 @@ const char *ui_name_old_name_3_3(const char *new_name)
   
   return nullptr;
 }
+
+#define RS_DEFAULT_CIVIL_WAR_CELEB               -5
+#define RS_DEFAULT_CIVIL_WAR_UNHAPPY             5
+
+/**********************************************************************//**
+  Add civil war bonus effects matching old civstyle values.
+**************************************************************************/
+void rscompat_civil_war_effects_3_3(struct section_file *game_rs)
+{
+  int bonus = secfile_lookup_int_default(game_rs, RS_DEFAULT_CIVIL_WAR_CELEB,
+                                         "civstyle.civil_war_bonus_celebrating");
+
+  if (bonus != 0) {
+    struct requirement e_req;
+    struct effect *peffect;
+
+    peffect = effect_new(EFT_CIVIL_WAR_CITY_BONUS, -bonus, nullptr);
+    e_req = req_from_str("CityStatus", "City", FALSE, TRUE, FALSE,
+                         "Celebration");
+    effect_req_append(peffect, e_req);
+  }
+
+  bonus = secfile_lookup_int_default(game_rs, RS_DEFAULT_CIVIL_WAR_UNHAPPY,
+                                     "civstyle.civil_war_bonus_unhappy");
+
+  if (bonus != 0) {
+    struct requirement e_req;
+    struct effect *peffect;
+
+    peffect = effect_new(EFT_CIVIL_WAR_CITY_BONUS, -bonus, nullptr);
+    e_req = req_from_str("CityStatus", "City", FALSE, TRUE, FALSE,
+                         "Disorder");
+    effect_req_append(peffect, e_req);
+  }
+}
diff --git a/server/ruleset/rscompat.h b/server/ruleset/rscompat.h
index 2eaf3bd768..e18c6b5640 100644
--- a/server/ruleset/rscompat.h
+++ b/server/ruleset/rscompat.h
@@ -64,6 +64,8 @@ const char *rscompat_effect_name_3_3(const char *old_name);
 const char *blocked_by_old_name_3_3(const char *new_name);
 const char *ui_name_old_name_3_3(const char *new_name);
 
+void rscompat_civil_war_effects_3_3(struct section_file *game_rs);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/server/ruleset/ruleload.c b/server/ruleset/ruleload.c
index ab4943e226..a4cc5d7ff9 100644
--- a/server/ruleset/ruleload.c
+++ b/server/ruleset/ruleload.c
@@ -6723,13 +6723,9 @@ static bool load_ruleset_game(struct section_file *file, bool act,
     game.info.civil_war_enabled
       = secfile_lookup_bool_default(file, TRUE, "civstyle.civil_war_enabled");
 
-    game.info.civil_war_bonus_celebrating
-      = secfile_lookup_int_default(file, RS_DEFAULT_CIVIL_WAR_CELEB,
-                                   "civstyle.civil_war_bonus_celebrating");
-
-    game.info.civil_war_bonus_unhappy
-      = secfile_lookup_int_default(file, RS_DEFAULT_CIVIL_WAR_UNHAPPY,
-                                   "civstyle.civil_war_bonus_unhappy");
+    if (compat->compat_mode && compat->version < RSFORMAT_3_3) {
+      rscompat_civil_war_effects_3_3(file);
+    }
 
     game.info.base_bribe_cost
       = secfile_lookup_int_default_min_max(file,
diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c
index 6dea0341ee..135ba973db 100644
--- a/tools/ruleutil/rulesave.c
+++ b/tools/ruleutil/rulesave.c
@@ -1366,12 +1366,6 @@ static bool save_game_ruleset(const char *filename, const char *name)
   save_default_bool(sfile, game.info.civil_war_enabled,
                     TRUE,
                     "civstyle.civil_war_enabled", nullptr);
-  save_default_int(sfile, game.info.civil_war_bonus_celebrating,
-                   RS_DEFAULT_CIVIL_WAR_CELEB,
-                   "civstyle.civil_war_bonus_celebrating", nullptr);
-  save_default_int(sfile, game.info.civil_war_bonus_unhappy,
-                   RS_DEFAULT_CIVIL_WAR_UNHAPPY,
-                   "civstyle.civil_war_bonus_unhappy", nullptr);
   save_default_bool(sfile,
                     BV_ISSET(action_by_number(ACTION_PARADROP)->sub_results,
                              ACT_SUB_RES_MAY_EMBARK),
-- 
2.45.2

