From a59d3a2c7480ee5c89a028d009d75ec4058947d4 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 30 Dec 2023 14:12:32 +0200
Subject: [PATCH 02/27] Add disaster type "Robbery"

See RM #98

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 common/city.h                   |  4 ++--
 common/disaster.h               |  2 ++
 data/alien/game.ruleset         |  1 +
 data/civ1/game.ruleset          |  1 +
 data/civ2/game.ruleset          |  1 +
 data/civ2civ3/game.ruleset      |  1 +
 data/classic/game.ruleset       |  1 +
 data/goldkeep/game.ruleset      |  1 +
 data/granularity/game.ruleset   |  1 +
 data/multiplayer/game.ruleset   |  1 +
 data/ruledit/comments-3.3.txt   |  1 +
 data/sandbox/game.ruleset       |  1 +
 data/stub/game.ruleset          |  1 +
 data/webperimental/game.ruleset |  1 +
 server/cityturn.c               | 14 ++++++++++++++
 15 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/common/city.h b/common/city.h
index aeeea3b7fa..7cd8f2ef7b 100644
--- a/common/city.h
+++ b/common/city.h
@@ -351,7 +351,7 @@ struct city {
    * radius. */
   int tile_cache_radius_sq;
 
-  /* the productions */
+  /* The productions */
   int surplus[O_LAST]; /* Final surplus in each category. */
   int waste[O_LAST]; /* Waste/corruption in each category. */
   int unhappy_penalty[O_LAST]; /* Penalty from unhappy cities. */
@@ -363,7 +363,7 @@ struct city {
   int bonus[O_LAST];
   int abs_bonus[O_LAST];
 
-  /* the physics */
+  /* The physics */
   int food_stock;
   int shield_stock;
   int pollution;                /* not saved */
diff --git a/common/disaster.h b/common/disaster.h
index a02f7efc89..09b14bf79e 100644
--- a/common/disaster.h
+++ b/common/disaster.h
@@ -37,6 +37,8 @@ extern "C" {
 #define SPECENUM_VALUE5NAME "Fallout"
 #define SPECENUM_VALUE6 DE_REDUCE_DESTROY
 #define SPECENUM_VALUE6NAME "ReducePopDestroy"
+#define SPECENUM_VALUE7 DE_ROBBERY
+#define SPECENUM_VALUE7NAME "Robbery"
 #define SPECENUM_COUNT DE_COUNT
 #define SPECENUM_BITVECTOR bv_disaster_effects
 #include "specenum_gen.h"
diff --git a/data/alien/game.ruleset b/data/alien/game.ruleset
index 79f61e76f7..cc41b2318d 100644
--- a/data/alien/game.ruleset
+++ b/data/alien/game.ruleset
@@ -425,6 +425,7 @@ negative_label = _("BGE")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/civ1/game.ruleset b/data/civ1/game.ruleset
index 38db22ef13..7d4f94c509 100644
--- a/data/civ1/game.ruleset
+++ b/data/civ1/game.ruleset
@@ -408,6 +408,7 @@ negative_label = _("BC")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/civ2/game.ruleset b/data/civ2/game.ruleset
index cd1a961e9b..103c4abce5 100644
--- a/data/civ2/game.ruleset
+++ b/data/civ2/game.ruleset
@@ -404,6 +404,7 @@ negative_label = _("BC")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/civ2civ3/game.ruleset b/data/civ2civ3/game.ruleset
index 028646552b..d57b6e67c8 100644
--- a/data/civ2civ3/game.ruleset
+++ b/data/civ2civ3/game.ruleset
@@ -432,6 +432,7 @@ negative_label = _("BCE")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/classic/game.ruleset b/data/classic/game.ruleset
index 070b221467..8627e023ec 100644
--- a/data/classic/game.ruleset
+++ b/data/classic/game.ruleset
@@ -427,6 +427,7 @@ negative_label = _("BCE")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/goldkeep/game.ruleset b/data/goldkeep/game.ruleset
index 9425804c23..6357cf9372 100644
--- a/data/goldkeep/game.ruleset
+++ b/data/goldkeep/game.ruleset
@@ -430,6 +430,7 @@ negative_label = _("BCE")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/granularity/game.ruleset b/data/granularity/game.ruleset
index 43a14f22ba..6dd19a256b 100644
--- a/data/granularity/game.ruleset
+++ b/data/granularity/game.ruleset
@@ -422,6 +422,7 @@ negative_label = _("BCE")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/multiplayer/game.ruleset b/data/multiplayer/game.ruleset
index 519aa7b064..4beb69869f 100644
--- a/data/multiplayer/game.ruleset
+++ b/data/multiplayer/game.ruleset
@@ -430,6 +430,7 @@ negative_label = _("BCE")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/ruledit/comments-3.3.txt b/data/ruledit/comments-3.3.txt
index 28ee9291da..23666c0623 100644
--- a/data/ruledit/comments-3.3.txt
+++ b/data/ruledit/comments-3.3.txt
@@ -1049,6 +1049,7 @@ disasters = "\
 ;   - \"EmptyProdStock\"    = Destroy current production\n\
 ;   - \"Pollution\"         = One tile surrounding city polluted\n\
 ;   - \"Fallout\"           = One tile surrounding city polluted with fallout\n\
+;   - \"Robbery\"           = Player loses city\'s five turn trade worth of gold\n\
 ;\n\
 ; */ <-- avoid gettext warnings\n\
 "
diff --git a/data/sandbox/game.ruleset b/data/sandbox/game.ruleset
index 4e6756dab1..4f659ef237 100644
--- a/data/sandbox/game.ruleset
+++ b/data/sandbox/game.ruleset
@@ -430,6 +430,7 @@ negative_label = _("BCE")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/stub/game.ruleset b/data/stub/game.ruleset
index 31ccdfb9f6..bb49f6c25b 100644
--- a/data/stub/game.ruleset
+++ b/data/stub/game.ruleset
@@ -414,6 +414,7 @@ negative_label = _("BCE")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/data/webperimental/game.ruleset b/data/webperimental/game.ruleset
index d27b397887..42b3592615 100644
--- a/data/webperimental/game.ruleset
+++ b/data/webperimental/game.ruleset
@@ -431,6 +431,7 @@ negative_label = _("BC")
 ;   - "EmptyProdStock"    = Destroy current production
 ;   - "Pollution"         = One tile surrounding city polluted
 ;   - "Fallout"           = One tile surrounding city polluted with fallout
+;   - "Robbery"           = Player loses city's five turn trade worth of gold
 ;
 ; */ <-- avoid gettext warnings
 
diff --git a/server/cityturn.c b/server/cityturn.c
index 363eedd40a..2a75bc6437 100644
--- a/server/cityturn.c
+++ b/server/cityturn.c
@@ -4266,6 +4266,20 @@ static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
                 _("%s was hit by %s."), city_name_get(pcity),
                 disaster_name_translation(pdis));
 
+  if (disaster_has_effect(pdis, DE_ROBBERY)) {
+    if (pplayer->economic.gold > 0 && pcity->prod[O_TRADE] > 0) {
+      int amount = pcity->prod[O_TRADE] * 5;
+
+      amount = MIN(pplayer->economic.gold, amount);
+      pplayer->economic.gold -= amount;
+      notify_player(pplayer, ptile, E_DISASTER, ftc_server,
+                    PL_("Robbery in %s. %d gold stolen.",
+                        "Robbery in %s. %d gold stolen.", amount),
+                    city_link(pcity), amount);
+      had_internal_effect = TRUE;
+    }
+  }
+
   if (disaster_has_effect(pdis, DE_POLLUTION)) {
     if (place_pollution(pcity, EC_POLLUTION)) {
       notify_player(pplayer, ptile, E_DISASTER, ftc_server,
-- 
2.43.0

