<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40607 >

> [cazf...@gmail.com - Mo 04. Mai. 2009, 09:53:10]:
> 
> 2009/1/7 Marko Lindqvist <cazf...@gmail.com>:
> > 2008/12/21 Yoav Luft:
> >>
> >> Hi, I think it's pretty much finished, at least the basic 
functionality.
> >> The attached .diff file adds the functionality of cities losing
> >> population when they grow too large due to diseases.
> >
> >  I found additional comments in RT ticket that were not sent to
> > mailing list. I looked latest version of the patch,
> > 40607-freeciv-svn15395-health.patch.diff.
> 
>  Is anybody working on this?
> 

I did try to adapt the patch, especially the AI effect evaluation. But 
I did not understand how and why it is calculated ... After some time 
I moved on to the gold upkeep patch. I still observe this patch but at 
the moment my time to work on this is very limited and if I find some 
time it is the upkeep patch.

I attached my last version. Changes:

* reduced formula for the AI effect evaluation
* change calculation of trade illness
* save plague status for each city (never or turn x)
* ruleset updates

Matthias

PS: If it is possible I would like to get an email if a comment to 
this patch is added (matthias.pfaffer...@mapfa.de)

> 
>  - ML
> 
> 
> 

diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/ai/aicity.c freeciv-2.1.99svn15584.health/ai/aicity.c
--- freeciv-2.1.99svn15584/ai/aicity.c	2009-01-05 11:54:27.000000000 +0100
+++ freeciv-2.1.99svn15584.health/ai/aicity.c	2009-03-23 20:48:22.937206187 +0100
@@ -520,6 +520,11 @@
   case EFT_GROWTH_FOOD:
     v += c * 4 + (amount / 7) * pcity->surplus[O_FOOD];
     break;
+  case EFT_ILLNESS:
+    /* old formula:
+     * v += c * 5 + (amount / 5) * pcity->illness + pcity->had_plague * 20; */
+    v += c * 5 + (amount / 5) * pcity->illness;
+    break;
   case EFT_AIRLIFT:
     /* FIXME: We need some smart algorithm here. The below is 
      * totally braindead. */
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/client/citydlg_common.c freeciv-2.1.99svn15584.health/client/citydlg_common.c
--- freeciv-2.1.99svn15584/client/citydlg_common.c	2009-01-10 20:17:51.000000000 +0100
+++ freeciv-2.1.99svn15584.health/client/citydlg_common.c	2009-03-23 20:48:22.941206067 +0100
@@ -490,6 +490,28 @@
 }
 
 /**************************************************************************
+  Return text describing the chance for a plague.
+**************************************************************************/
+void get_city_dialog_illness_text(const struct city *pcity,
+                                  char *buf, size_t bufsz)
+{
+  int illness, trade, effects, from_size;
+
+  illness = city_illness(pcity, &trade, &effects, &from_size);
+  buf[0] = '\0';
+
+  cat_snprintf(buf, bufsz, "%+2.1f : Risk from trade\n",
+               ((float)(trade) / 10.0));
+  cat_snprintf(buf, bufsz, "%+2.1f : Risk from over crowdness\n",
+               ((float)(from_size) / 10.0));
+  cat_snprintf(buf, bufsz, "%+2.1f : Effect of buildings\n",
+               ((float)(effects) / 10.0));
+  cat_snprintf(buf, bufsz, "==== : Adds up to\n");
+  cat_snprintf(buf, bufsz, "%2.1f : Total chance for a plgue",
+               ((float)(illness) / 10.0));
+}
+
+/**************************************************************************
   Return text describing the pollution output.
 **************************************************************************/
 void get_city_dialog_pollution_text(const struct city *pcity,
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/client/citydlg_common.h freeciv-2.1.99svn15584.health/client/citydlg_common.h
--- freeciv-2.1.99svn15584/client/citydlg_common.h	2009-01-05 11:56:00.000000000 +0100
+++ freeciv-2.1.99svn15584.health/client/citydlg_common.h	2009-03-23 20:48:22.941206067 +0100
@@ -49,6 +49,8 @@
 				 char *buffer, size_t bufsz);
 void get_city_dialog_pollution_text(const struct city *pcity,
 				    char *buffer, size_t bufsz);
+void get_city_dialog_illness_text(const struct city *pcity,
+                                  char *buf, size_t bufsz);
 
 int get_city_citizen_types(struct city *pcity, enum citizen_feeling index,
 			   enum citizen_category *citizens);
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/client/gui-gtk-2.0/citydlg.c freeciv-2.1.99svn15584.health/client/gui-gtk-2.0/citydlg.c
--- freeciv-2.1.99svn15584/client/gui-gtk-2.0/citydlg.c	2009-02-01 19:26:51.000000000 +0100
+++ freeciv-2.1.99svn15584.health/client/gui-gtk-2.0/citydlg.c	2009-03-23 20:48:22.945205388 +0100
@@ -95,7 +95,7 @@
 enum info_style { NORMAL, ORANGE, RED, NUM_INFO_STYLES };
 
 #define NUM_CITIZENS_SHOWN 23
-#define NUM_INFO_FIELDS 11      /* number of fields in city_info */
+#define NUM_INFO_FIELDS 12      /* number of fields in city_info */
 #define NUM_PAGES 6             /* the number of pages in city dialog notebook 
                                  * (+1) if you change this, you must add an
                                  * entry to misc_whichtab_label[] */
@@ -501,7 +501,7 @@
 
 enum { FIELD_FOOD, FIELD_SHIELD, FIELD_TRADE, FIELD_GOLD, FIELD_LUXURY,
        FIELD_SCIENCE, FIELD_GRANARY, FIELD_GROWTH, FIELD_CORRUPTION,
-       FIELD_WASTE, FIELD_POLLUTION 
+       FIELD_WASTE, FIELD_POLLUTION, FIELD_ILLNESS
 };
 
 /****************************************************************
@@ -541,6 +541,9 @@
     case FIELD_POLLUTION:
       get_city_dialog_pollution_text(pdialog->pcity, buf, sizeof(buf));
       break;
+    case FIELD_ILLNESS:
+      get_city_dialog_illness_text(pdialog->pcity, buf, sizeof(buf));
+      break;
     default:
       return TRUE;
     }
@@ -589,7 +592,8 @@
     N_("Change in:"),
     N_("Corruption:"),
     N_("Waste:"),
-    N_("Pollution:")
+    N_("Pollution:"),
+    N_("Plague Risk:")
   };
   static bool output_label_done;
 
@@ -1401,8 +1405,9 @@
   char buf[NUM_INFO_FIELDS][512];
   struct city *pcity = pdialog->pcity;
   int granaryturns;
+
   enum { FOOD, SHIELD, TRADE, GOLD, LUXURY, SCIENCE, 
-	 GRANARY, GROWTH, CORRUPTION, WASTE, POLLUTION 
+	 GRANARY, GROWTH, CORRUPTION, WASTE, POLLUTION, ILLNESS
   };
 
   /* fill the buffers with the necessary info */
@@ -1444,6 +1449,8 @@
           pcity->waste[O_SHIELD]);
   my_snprintf(buf[POLLUTION], sizeof(buf[POLLUTION]), "%2d",
 	      pcity->pollution);
+  my_snprintf(buf[ILLNESS], sizeof(buf[ILLNESS]), "%2.1f",
+	      ((float)(city_illness(pcity, NULL, NULL, NULL)) / 10.0));
 
   /* stick 'em in the labels */
 
@@ -1466,6 +1473,9 @@
 
   style = (pcity->pollution >= 10) ? RED : NORMAL;
   gtk_widget_modify_style(info_label[POLLUTION], info_label_style[style]);
+
+  style = (pcity->illness >= 20) ? RED : NORMAL;
+  gtk_widget_modify_style(info_label[ILLNESS], info_label_style[style]);
 }
 
 /****************************************************************
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/common/city.c freeciv-2.1.99svn15584.health/common/city.c
--- freeciv-2.1.99svn15584/common/city.c	2009-01-05 11:54:25.000000000 +0100
+++ freeciv-2.1.99svn15584.health/common/city.c	2009-03-23 20:48:22.949205268 +0100
@@ -2063,6 +2063,71 @@
 }
 
 /**************************************************************************
+ Get's whether cities that pcity trade's with had the plague. If so, it 
+ returns the health penality.
+ *************************************************************************/
+static int get_trade_illness (const struct city *pcity)
+{
+  int i;
+  int total_penalty = 0;
+
+  for (i = 0 ; i < NUM_TRADEROUTES ; i++) {
+    struct city *trade_city = game_find_city_by_number(pcity->trade[i]);
+    if (trade_city == NULL) {
+      continue;
+    } else if (trade_city->turn_plague != -1
+               && trade_city->turn_plague - game.info.turn < 5) {
+      /* ... */
+      total_penalty += game.info.health_trade_penalty;
+    }
+  }
+
+  return total_penalty;
+}
+
+/**************************************************************************
+ Get's any effects ragarding health the city might have from buildings or
+ sabotage. Negetive value are good effects, positive value are bad.
+ *************************************************************************/
+static int get_city_health (const struct city *pcity)
+{
+  int effects_total = 0;
+  /* Get effects. Don't know how. */
+  effects_total = get_city_bonus(pcity, EFT_ILLNESS);
+  return -(effects_total);
+}
+
+/**************************************************************************
+ Set city's illness. illness cannot exceed 999, or be less then 0
+ City illness is:  (city_size - min_ilness_size) + 10 * trade
+                   routes to plagued cities - effect of buildings
+ *************************************************************************/
+int city_illness(const struct city *pcity, int *trade_ill, int *effects,
+                 int *from_size)
+{
+  int size_mod = game.info.illness_safe_mod;
+  int trade_penalty = get_trade_illness(pcity);
+  int city_health_effects = get_city_health(pcity);
+  int illness = (pcity->size * pcity->size) - size_mod + trade_penalty
+               + pcity->pollution + city_health_effects;
+
+  /* returning other data */
+  if (trade_ill) {
+    *trade_ill = trade_penalty;
+  }
+
+  if (effects) {
+    *effects = city_health_effects;
+  }
+
+  if (from_size) {
+    *from_size = (pcity->size * pcity->size) - size_mod;
+  }
+
+  return CLIP(0, illness , 999);
+}
+
+/**************************************************************************
    Set food, trade and shields production in a city.
 
    This initializes the prod[] and waste[] arrays.  It assumes that
@@ -2502,6 +2567,7 @@
   pcity->did_sell = FALSE;
   pcity->is_updated = FALSE;
   pcity->was_happy = FALSE;
+  pcity->had_plague = -1; /* -1 = never */
 
   pcity->anarchy = 0;
   pcity->rapture = 0;
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/common/city.h freeciv-2.1.99svn15584.health/common/city.h
--- freeciv-2.1.99svn15584/common/city.h	2009-03-21 12:19:14.976947179 +0100
+++ freeciv-2.1.99svn15584.health/common/city.h	2009-03-23 20:48:22.949205268 +0100
@@ -316,6 +316,7 @@
   int food_stock;
   int shield_stock;
   int pollution;                /* not saved */
+  int illness;                  /* not saved */
 
   /* turn states */
   int airlift;
@@ -324,6 +325,7 @@
   bool did_sell;
   bool is_updated;              /* not saved */
   bool was_happy;
+  int turn_plague;              /* last turn with plague in the city */
 
   int anarchy;                  /* anarchy rounds count */ 
   int rapture;                  /* rapture rounds count */ 
@@ -642,6 +644,8 @@
 int city_pollution_types(const struct city *pcity, int shield_total,
 			 int *pollu_prod, int *pollu_pop, int *pollu_mod);
 int city_pollution(const struct city *pcity, int shield_total);
+int city_illness(const struct city *pcity, int *trade_ill, int *effects,
+                 int *from_size);
 
 bool city_exist(int id);
 
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/common/effects.c freeciv-2.1.99svn15584.health/common/effects.c
--- freeciv-2.1.99svn15584/common/effects.c	2009-01-05 11:54:25.000000000 +0100
+++ freeciv-2.1.99svn15584.health/common/effects.c	2009-03-23 20:48:22.949205268 +0100
@@ -54,6 +54,7 @@
   /* TODO: "Force_Content_Pct", */
   "Give_Imm_Tech",
   "Growth_Food",
+  "Illness",
   "Have_Embassies",
   "Make_Content",
   "Make_Content_Mil",
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/common/effects.h freeciv-2.1.99svn15584.health/common/effects.h
--- freeciv-2.1.99svn15584/common/effects.h	2009-01-05 11:54:25.000000000 +0100
+++ freeciv-2.1.99svn15584.health/common/effects.h	2009-03-23 20:48:22.953204310 +0100
@@ -40,6 +40,7 @@
   /* TODO: EFT_FORCE_CONTENT_PCT, */
   EFT_GIVE_IMM_TECH,
   EFT_GROWTH_FOOD,
+  EFT_ILLNESS, /* reduced illness due to buildings, ... */
   EFT_HAVE_EMBASSIES,
   EFT_MAKE_CONTENT,
   EFT_MAKE_CONTENT_MIL,
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/common/events.c freeciv-2.1.99svn15584.health/common/events.c
--- freeciv-2.1.99svn15584/common/events.c	2009-01-10 23:21:53.000000000 +0100
+++ freeciv-2.1.99svn15584.health/common/events.c	2009-03-23 20:48:22.953204310 +0100
@@ -98,6 +98,7 @@
   GEN_EV(E_CITY_GRAN_THROTTLE,	E_S_CITY,	N_("Suggest Growth Throttling")),
   GEN_EV(E_CITY_TRANSFER,	E_S_CITY,	N_("Transfer")),
   GEN_EV(E_CITY_BUILD,		E_S_CITY,	N_("Was Built")),
+  GEN_EV(E_CITY_ILL,		E_S_CITY,	N_("Has Plague")),
   GEN_EV(E_WORKLIST,		E_S_CITY,	N_("Worklist Events")),
   GEN_EV(E_CITY_PRODUCTION_CHANGED, E_S_CITY,	N_("Production changed")),
   GEN_EV(E_MY_DIPLOMAT_BRIBE,		E_S_D_ME,	N_("Bribe")),
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/common/events.h freeciv-2.1.99svn15584.health/common/events.h
--- freeciv-2.1.99svn15584/common/events.h	2009-01-10 23:21:43.000000000 +0100
+++ freeciv-2.1.99svn15584.health/common/events.h	2009-03-23 20:48:22.953204310 +0100
@@ -126,6 +126,7 @@
   E_LOG_FATAL,
   E_TECH_GOAL,			/* Changed tech goal */
   E_UNIT_LOST_MISC,             /* Non-battle unit deaths */
+  E_CITY_ILL,			/* Plague within a city */
   /* 
    * Note: If you add a new event, make sure you make a similar change
    * to the events array in common/events.c using GEN_EV,
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/common/packets.def freeciv-2.1.99svn15584.health/common/packets.def
--- freeciv-2.1.99svn15584/common/packets.def	2009-03-21 12:19:14.976947179 +0100
+++ freeciv-2.1.99svn15584.health/common/packets.def	2009-03-23 20:48:22.953204310 +0100
@@ -446,6 +446,9 @@
   UINT8 granary_food_ini[MAX_GRANARY_INIS];
   UINT8 granary_num_inis;
   UINT8 granary_food_inc;
+  BOOL plague_on;
+  UINT8 illness_safe_mod;
+  UINT8 health_trade_penalty;
   UINT8 tech_cost_style;
   UINT8 tech_leakage;
   YEAR tech_cost_double_year;
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/data/civ1/game.ruleset freeciv-2.1.99svn15584.health/data/civ1/game.ruleset
--- freeciv-2.1.99svn15584/data/civ1/game.ruleset	2009-01-23 18:28:24.000000000 +0100
+++ freeciv-2.1.99svn15584.health/data/civ1/game.ruleset	2009-03-23 20:48:22.953204310 +0100
@@ -65,6 +65,14 @@
 granary_food_ini	= 20
 granary_food_inc	= 10
 
+; Whether plagues are possible
+plague_on = 0
+; how much trading with a plagued city increases our city's chance for plague
+; (in tenth of percents)
+health_trade_penalty = 10
+; how much to reduce from the basic chance (in tenth of percents)
+illness_safe_mod = 20
+
 ; Method of calculating technology costs
 ;   0 - Civ (I|II) style. Every new tech add researchcost to cost of next tech.
 ;   1 - Cost of technology is 
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/data/civ2/game.ruleset freeciv-2.1.99svn15584.health/data/civ2/game.ruleset
--- freeciv-2.1.99svn15584/data/civ2/game.ruleset	2009-01-23 18:28:24.000000000 +0100
+++ freeciv-2.1.99svn15584.health/data/civ2/game.ruleset	2009-03-23 20:48:22.957204189 +0100
@@ -59,6 +59,14 @@
 granary_food_ini	= 20
 granary_food_inc	= 10
 
+; Whether plagues are possible
+plague_on = 0
+; how much trading with a plagued city increases our city's chance for plague
+; (in tenth of percents)
+health_trade_penalty = 10
+; how much to reduce from the basic chance (in tenth of percents)
+illness_safe_mod = 20
+
 ; Method of calculating technology costs
 ;   0 - Civ (I|II) style. Every new tech add researchcost to cost of next tech.
 ;   1 - Cost of technology is 
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/data/default/buildings.ruleset freeciv-2.1.99svn15584.health/data/default/buildings.ruleset
--- freeciv-2.1.99svn15584/data/default/buildings.ruleset	2009-01-05 11:55:06.000000000 +0100
+++ freeciv-2.1.99svn15584.health/data/default/buildings.ruleset	2009-03-23 20:48:22.957204189 +0100
@@ -83,8 +83,9 @@
 sound		= "b_aqueduct"
 sound_alt	= "b_generic"
 helptext	= _("\
-Allows a city to grow larger than size 8.  A Sewer System is also\
- required for a city to grow larger than size 12.\
+Allows a city to grow larger than size 8 and reduces the chance of plague\
+ within the city. A Sewer System is required for a city to grow larger\
+ than size 12.\
 ")
 
 [building_bank]
@@ -363,6 +364,26 @@
  to be coastal to build this improvement.\
 ")
 
+[building_hospital]
+name		= _("Hospital")
+genus		= "Improvement"
+reqs	=
+    { "type", "name", "range"
+      "Tech", "Medicine", "Player"
+    }
+graphic	= "-"
+graphic_alt	= "-"
+obsolete_by	= "None"
+build_cost	= 80
+upkeep		= 3
+sabotage	= 100
+sound		= "-"
+sound_alt	= "b_generic"
+helptext	= _("\
+A Hospital is used to treat the ill, and sometimes for medical research.\
+ A city with a Hospital is less like to suffer from plagues.\
+")
+
 [building_hydro_plant]
 name		= _("Hydro Plant")
 genus		= "Improvement"
@@ -750,8 +771,9 @@
 sound		= "b_sewer_system"
 sound_alt	= "b_generic"
 helptext	= _("\
-Allows a city to grow larger than size 12.  An Aqueduct is first\
- required for a city to grow larger than size 8.\
+Allows a city to grow larger than size 12. Pre-requirement is an Aqueduct\
+ for a city to grow larger than size 8. The Sewer System further reduces\
+ the chance of a plague.\
 ")
 
 [building_solar_plant]
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/data/default/effects.ruleset freeciv-2.1.99svn15584.health/data/default/effects.ruleset
--- freeciv-2.1.99svn15584/data/default/effects.ruleset	2009-01-05 11:55:06.000000000 +0100
+++ freeciv-2.1.99svn15584.health/data/default/effects.ruleset	2009-03-23 20:48:22.961204069 +0100
@@ -730,6 +730,14 @@
       "Building", "Aqueduct", "City"
     }
 
+[effect_aqueduct_illness]
+name	= "Illness"
+value	= 20
+reqs	=
+    { "type", "name", "range"
+      "Building", "Aqueduct", "City"
+    }
+
 [effect_bank]
 name	= "Output_Bonus"
 value	= 50
@@ -1000,6 +1008,14 @@
       "OutputType", "Food", "Local"
     }
 
+[effect_hospital]
+name   = "Illness"
+value  = 40
+reqs   =
+    {"type", "name", "range"
+     "Building", "Hospital", "City"
+    }
+
 [effect_hydro_plant]
 name	= "Output_Bonus"
 value	= 25
@@ -1386,6 +1402,15 @@
 reqs	=
     { "type", "name", "range"
       "Building", "Aqueduct", "City"
+      "Building", "Sewer System", "City"
+    }
+
+[effect_sewer_system_illness]
+name	= "Illness"
+value	= 50
+reqs	=
+    { "type", "name", "range"
+      "Building", "Aqueduct", "City"
       "Building", "Sewer System", "City"
     }
 
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/data/default/game.ruleset freeciv-2.1.99svn15584.health/data/default/game.ruleset
--- freeciv-2.1.99svn15584/data/default/game.ruleset	2009-01-23 18:28:25.000000000 +0100
+++ freeciv-2.1.99svn15584.health/data/default/game.ruleset	2009-03-23 20:48:22.961204069 +0100
@@ -77,6 +77,14 @@
 granary_food_ini	= 20
 granary_food_inc	= 10
 
+; Whether plagues are possible
+plague_on = 1
+; how much trading with a plagued city increases our city's chance for plague
+; (in tenth of percents)
+health_trade_penalty = 10
+; how much to reduce from the basic chance (in tenth of percents)
+illness_safe_mod = 20
+
 ; Method of calculating technology costs
 ;   0 - Civ (I|II) style. Every new tech add researchcost to cost of next tech.
 ;   1 - Cost of technology is 
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/data/stdsounds.soundspec freeciv-2.1.99svn15584.health/data/stdsounds.soundspec
--- freeciv-2.1.99svn15584/data/stdsounds.soundspec	2009-01-23 23:05:14.000000000 +0100
+++ freeciv-2.1.99svn15584.health/data/stdsounds.soundspec	2009-03-23 20:48:22.961204069 +0100
@@ -221,6 +221,7 @@
 ;e_city_nuked = ""
 ;e_city_production_changed = ""
 ;e_city_transfer = ""
+;e_city_ill = ""
 ;e_civil_war = ""
 ;e_connection = ""
 ;e_destroyed = ""
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/server/cityturn.c freeciv-2.1.99svn15584.health/server/cityturn.c
--- freeciv-2.1.99svn15584/server/cityturn.c	2009-03-21 12:19:15.621446311 +0100
+++ freeciv-2.1.99svn15584.health/server/cityturn.c	2009-03-23 20:48:22.965204228 +0100
@@ -89,6 +89,7 @@
 static void define_orig_production_values(struct city *pcity);
 static void update_city_activity(struct player *pplayer, struct city *pcity);
 static void nullify_caravan_and_disband_plus(struct city *pcity);
+static bool check_plague(const struct city * pcity);
 
 static float city_migration_score(const struct city *pcity);
 static bool do_city_migration(struct city *pcity_from,
@@ -1764,12 +1765,23 @@
     }
     pcity->was_happy=city_happy(pcity);
 
+    /* Handle the illness. */
+    if (game.info.plague_on && pcity->size > 1) {
+      /* illness only if the city has a size greater than 1 */
+      pcity->illness = city_illness(pcity, NULL, NULL, NULL);
+      if (check_plague(pcity)) {
+        notify_player(pplayer, city_tile(pcity), E_CITY_ILL,
+                      _("%s had been struck by a plague! Population lost!"), 
+                      city_name(pcity));
+        city_reduce_size(pcity, 1, NULL);
+        pcity->turn_plague = game.info.turn;
+      }
+    }
+
     /* City population updated here, after the rapture stuff above. --Jing */
-    {
-      int id=pcity->id;
-      city_populate(pcity);
-      if(!player_find_city_by_id(pplayer, id))
-	return;
+    city_populate(pcity);
+    if (!player_find_city_by_id(pplayer, saved_id)) {
+      return;
     }
 
     pcity->is_updated=TRUE;
@@ -1818,6 +1830,18 @@
   }
 }
 
+/*****************************************************************************
+ check if city suffers from a plague. Return TRUE if it does, FALSE if not.
+ ****************************************************************************/
+static bool check_plague(const struct city * pcity)
+{
+  if (myrand(1000) < pcity->illness) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
 /**************************************************************************
  Disband a city into the built unit, supported by the closest city.
 **************************************************************************/
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/server/ruleset.c freeciv-2.1.99svn15584.health/server/ruleset.c
--- freeciv-2.1.99svn15584/server/ruleset.c	2009-01-23 18:28:24.000000000 +0100
+++ freeciv-2.1.99svn15584.health/server/ruleset.c	2009-03-23 20:48:22.969206343 +0100
@@ -2979,6 +2979,12 @@
     game.control.description[0] = '\0';
   }
 
+  game.info.health_trade_penalty = 
+        secfile_lookup_int_default(&file, 10, "civstyle.health_trade_penalty");
+  game.info.illness_safe_mod = 
+        secfile_lookup_int_default(&file, 20, "civstyle.illness_safe_mod");
+  game.info.plague_on = 
+        secfile_lookup_int_default(&file, 0, "civstyle.plague_on");
   game.info.base_pollution = 
         secfile_lookup_int_default(&file, -20, "civstyle.base_pollution");
   game.info.happy_cost =
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/server/savegame.c freeciv-2.1.99svn15584.health/server/savegame.c
--- freeciv-2.1.99svn15584/server/savegame.c	2009-03-21 12:19:15.677446072 +0100
+++ freeciv-2.1.99svn15584.health/server/savegame.c	2009-03-23 20:48:22.973206502 +0100
@@ -2471,11 +2471,13 @@
       secfile_lookup_int(file, "player%d.c%d.shield_stock", plrno, i);
 
     pcity->airlift =
-      secfile_lookup_int_default(file, 0, "player%d.c%d.airlift",
-                                  plrno,i);
+      secfile_lookup_int_default(file, 0, "player%d.c%d.airlift", plrno,i);
     pcity->was_happy =
       secfile_lookup_bool_default(file, FALSE, "player%d.c%d.was_happy",
                                   plrno,i);
+    pcity->turn_plague =
+      secfile_lookup_int_default(file, 0, "player%d.c%d.turn_plague",
+                                 plrno,i);
 
     pcity->anarchy =
       secfile_lookup_int(file, "player%d.c%d.anarchy", plrno, i);
@@ -3596,9 +3598,11 @@
 		       plrno, i);
 
     secfile_insert_int(file, pcity->airlift, "player%d.c%d.airlift",
-                        plrno, i);
+                       plrno, i);
     secfile_insert_bool(file, pcity->was_happy, "player%d.c%d.was_happy",
                         plrno, i);
+    secfile_insert_int(file, pcity->turn_plague, "player%d.c%d.turn_plague",
+                       plrno, i);
 
     secfile_insert_int(file, pcity->anarchy, "player%d.c%d.anarchy", plrno,i);
     secfile_insert_int(file, pcity->rapture, "player%d.c%d.rapture", plrno,i);
diff -urN -X./freeciv-2.1.99svn15584/diff_ignore freeciv-2.1.99svn15584/server/scripting/api.pkg freeciv-2.1.99svn15584.health/server/scripting/api.pkg
--- freeciv-2.1.99svn15584/server/scripting/api.pkg	2009-01-23 18:28:24.000000000 +0100
+++ freeciv-2.1.99svn15584.health/server/scripting/api.pkg	2009-03-23 20:48:22.977204706 +0100
@@ -406,6 +406,7 @@
     E_CITY_TRANSFER @ CITY_TRANSFER,
     E_CITY_BUILD @ CITY_BUILD,
     E_CITY_PRODUCTION_CHANGED @ CITY_PRODUCTION_CHANGED,
+    E_CITY_ILL @ CITY_ILL,
     E_WORKLIST @ WORKLIST,
     E_UPRISING @ UPRISING,
     E_CIVIL_WAR @ CIVIL_WAR,
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to