Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] (PR#7336) A better solution (?) to smallpox
Home

[Freeciv-Dev] (PR#7336) A better solution (?) to smallpox

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7336) A better solution (?) to smallpox
From: "Gregory Richards" <akaquinn@xxxxxxxxxxx>
Date: Tue, 27 Jan 2004 20:47:36 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7336 >

Even with the cityfactor patch, it's still been proven possible to smallpox.  
However, this should fix that.  It adds some extra server options which allow 
you to severely hamper smallpox players.  They are: 
 
cfcivilwar 
        Go into civil war if number of cities has exceeded city factor 
cfbarbarian 
        Some cities are overtaken by barbarians if number of cities has 
exceeded city factor 
cfchance 
        Chance of civil war or barbarian takeover per turn 
cfwhich 
        If both civilwar and barbarian are set, chance of which will happen per 
city factor event 
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/common/game.c 
freeciv-1.14.1-nosmallpox/common/game.c
--- freeciv-1.14.1/common/game.c        2003-12-02 10:56:58.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/common/game.c     2004-01-27 20:27:11.000000000 
-0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -715,6 +715,11 @@
   game.watchtower_extra_vision=GAME_DEFAULT_WATCHTOWER_EXTRA_VISION,
   game.allowed_city_names = GAME_DEFAULT_ALLOWED_CITY_NAMES;
 
+  game.spcivilwar = GAME_DEFAULT_SMALLPOX_CIVILWAR;
+  game.spbarbarian = GAME_DEFAULT_SMALLPOX_BARBARIANISM;
+  game.spchance = GAME_DEFAULT_SMALLPOX_CHANCE;
+  game.spwhich = GAME_DEFAULT_SMALLPOX_WHICH;
+
   sz_strlcpy(game.rulesetdir, GAME_DEFAULT_RULESETDIR);
 
   game.firepower_factor = 1;
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/common/game.h 
freeciv-1.14.1-nosmallpox/common/game.h
--- freeciv-1.14.1/common/game.h        2003-12-02 10:56:58.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/common/game.h     2004-01-27 20:28:09.000000000 
-0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -217,6 +217,11 @@
     bool load_private_map; /* Only makes sense if the players are loaded. */
     bool load_settings;
   } load_options;
+
+  bool spcivilwar;
+  bool spbarbarian;
+  int spchance;
+  int spwhich;
 };
 
 /* Unused? */
@@ -455,4 +460,9 @@
 
 #define GAME_START_YEAR -4000
 
+#define GAME_DEFAULT_SMALLPOX_CIVILWAR 0
+#define GAME_DEFAULT_SMALLPOX_BARBARIANISM 0
+#define GAME_DEFAULT_SMALLPOX_CHANCE 25
+#define GAME_DEFAULT_SMALLPOX_WHICH 100
+
 #endif  /* FC__GAME_H */
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/common/player.c 
freeciv-1.14.1-nosmallpox/common/player.c
--- freeciv-1.14.1/common/player.c      2003-12-02 10:56:58.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/common/player.c   2004-01-27 20:28:30.000000000 
-0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -116,6 +116,7 @@
 
   plr->attribute_block.data = NULL;
   plr->attribute_block.length = 0;
+  plr->cityfactor_turns = 0;
 }
 
 /***************************************************************
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/common/player.h 
freeciv-1.14.1-nosmallpox/common/player.h
--- freeciv-1.14.1/common/player.h      2003-12-02 10:56:58.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/common/player.h   2004-01-27 20:29:00.000000000 
-0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -201,6 +201,7 @@
     int length;
     void *data;
   } attribute_block;
+  int cityfactor_turns;
 };
 
 void player_init(struct player *plr);
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/server/barbarian.c 
freeciv-1.14.1-nosmallpox/server/barbarian.c
--- freeciv-1.14.1/server/barbarian.c   2003-11-30 11:22:43.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/server/barbarian.c        2004-01-27 
20:27:11.000000000 -0800
@@ -76,7 +76,7 @@
 If barbarians are dead, revive them with a new leader :-)
 Dead barbarians forget the map and lose the money.
 **************************************************************************/
-static struct player *create_barbarian_player(bool land)
+struct player *create_barbarian_player(bool land)
 {
   int newplayer = game.nplayers;
   struct player *barbarians;
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/server/barbarian.h 
freeciv-1.14.1-nosmallpox/server/barbarian.h
--- freeciv-1.14.1/server/barbarian.h   2003-11-30 11:22:43.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/server/barbarian.h        2004-01-27 
20:29:25.000000000 -0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -29,6 +29,7 @@
 
 #define MAP_FACTOR     2000  /* adjust this to get a good uprising frequency */
 
+struct player *create_barbarian_player(bool land);
 bool unleash_barbarians(struct player *victim, int x, int y);
 void summon_barbarians(void);
 bool is_land_barbarian(struct player *pplayer);
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/server/savegame.c 
freeciv-1.14.1-nosmallpox/server/savegame.c
--- freeciv-1.14.1/server/savegame.c    2003-11-30 11:22:48.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/server/savegame.c 2004-01-27 20:27:11.000000000 
-0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -181,7 +181,7 @@
   char *pch;
 
   if (ch == ' ') {
-    /* 
+    /*
      * Sane value. It is unknow if there are savegames out there which
      * need this fix. Savegame.c doesn't write such savegames
      * (anymore) since the inclusion into CVS (2000-08-25).
@@ -643,6 +643,8 @@
   plr->capital=secfile_lookup_bool(file, "player%d.capital", plrno);
   plr->revolution=secfile_lookup_int_default(file, 0, "player%d.revolution",
                                              plrno);
+  plr->cityfactor_turns=secfile_lookup_int_default(file, 0, 
"player%d.cityfactor_turns",
+                                             plrno);
 
   for(i=0; i<game.num_tech_types; i++)
     set_invention(plr, i, (p[i]=='1') ? TECH_KNOWN : TECH_UNKNOWN);
@@ -1284,6 +1286,7 @@
 
   secfile_insert_bool(file, plr->capital, "player%d.capital", plrno);
   secfile_insert_int(file, plr->revolution, "player%d.revolution", plrno);
+  secfile_insert_int(file, plr->cityfactor_turns, "player%d.cityfactor_turns", 
plrno);
 
   for(i=0; i<game.num_tech_types; i++)
     invs[i]=(get_invention(plr, i)==TECH_KNOWN) ? '1' : '0';
@@ -1875,7 +1878,16 @@
                                               "game.randseed");
     game.allowed_city_names =
        secfile_lookup_int_default(file, game.allowed_city_names,
-                                  "game.allowed_city_names"); 
+                                  "game.allowed_city_names");
+
+    game.spcivilwar = secfile_lookup_int_default(file, game.spcivilwar,
+                                  "game.spcivilwar");
+    game.spbarbarian = secfile_lookup_int_default(file, game.spbarbarian,
+                                  "game.spbarbarian");
+    game.spchance = secfile_lookup_int_default(file, game.spchance,
+                                  "game.spchance");
+    game.spwhich = secfile_lookup_int_default(file, game.spwhich,
+                                  "game.spwhich");
 
     if(game.civstyle == 1) {
       string = "civ1";
@@ -2199,6 +2211,10 @@
   secfile_insert_int(file, game.watchtower_vision, "game.watchtower_vision");
   secfile_insert_int(file, game.watchtower_extra_vision, 
"game.watchtower_extra_vision");
   secfile_insert_int(file, game.allowed_city_names, "game.allowed_city_names");
+  secfile_insert_int(file, game.spcivilwar, "game.spcivilwar");
+  secfile_insert_int(file, game.spbarbarian, "game.spbarbarian");
+  secfile_insert_int(file, game.spchance, "game.spchance");
+  secfile_insert_int(file, game.spwhich, "game.spwhich");
 
   if (TRUE) {
     /* Now always save these, so the server options reflect the
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/server/srv_main.c 
freeciv-1.14.1-nosmallpox/server/srv_main.c
--- freeciv-1.14.1/server/srv_main.c    2003-11-30 11:22:48.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/server/srv_main.c 2004-01-27 20:41:30.000000000 
-0800
@@ -49,6 +49,7 @@
 #include "events.h"
 #include "fcintl.h"
 #include "game.h"
+#include "government.h"
 #include "log.h"
 #include "map.h"
 #include "mem.h"
@@ -336,6 +337,106 @@
 }
 
 /**************************************************************************
+Main function to prevent people from smallpoxing
+**************************************************************************/
+static void smallpox_handler(void)
+{
+  /* Only handle it if the settings are set to */
+  if ((game.spcivilwar || game.spbarbarian) && game.spchance > 0) {
+    struct player *pplayer, *barb;
+    struct city *pcity, *ccity;
+    int cities, basis, tocivwar, tobarb;
+    int civwars[MAX_NUM_PLAYERS];
+    int barbs[MAX_NUM_PLAYERS];
+    int i, j, k;
+    barb = NULL;
+    tocivwar = 0;
+    tobarb = 0;
+    ccity = NULL;
+    pcity = NULL;
+
+    players_iterate(pplayer) {
+      basis = game.cityfactor + get_gov_pplayer(pplayer)->empire_size_mod;
+      cities = city_list_size(&pplayer->cities);
+      if (cities > basis) {
+        /* Too many cities, time to take rash measures */
+        pplayer->cityfactor_turns++;
+        if (pplayer->cityfactor_turns > 5) { // too late!
+          pplayer->cityfactor_turns = 0;
+          if (myrand(101) <= game.spchance) { // We get to do some killin'
+            if (game.spcivilwar && game.spbarbarian) { // Both are set, take a 
chance
+              if (myrand(101) <= game.spwhich) { // Barbarians
+                barbs[tobarb] = pplayer->player_no;
+                tobarb++;
+              } else { // Civil war
+                civwars[tocivwar] = pplayer->player_no;
+                tocivwar++;
+              }
+            } else if (game.spcivilwar) {
+              civwars[tocivwar] = pplayer->player_no;
+              tocivwar++;
+            } else if (game.spbarbarian) {
+              barbs[tobarb] = pplayer->player_no;
+              tobarb++;
+            }
+          }
+        } else { // Warn them
+          notify_player_ex(pplayer, -1, -1, E_CIVIL_WAR,
+                  _("Game: Your civilization has become too large for you to 
control!  "
+                         "Either disband cities, or change your government to 
a more "
+                         "suitable one."));
+        }
+      } else {
+        if (pplayer->cityfactor_turns > 0) { // They fixed it in time
+          pplayer->cityfactor_turns = 0;
+        }
+      }
+    } players_iterate_end;
+
+    if (tobarb > 0) { // we've got somebody to have cities given to barbarians!
+      for (i = 0; i < tobarb; i++) {
+        players_iterate(pplayer) { // Find a barbarian
+          if (is_barbarian(pplayer)) {
+            barb = pplayer;
+          }
+        } players_iterate_end;
+        if (barb == NULL) { // No available barbarians!
+          barb = create_barbarian_player(TRUE);
+        }
+
+        pplayer = get_player(barbs[tobarb]);
+
+        basis = game.cityfactor + get_gov_pplayer(pplayer)->empire_size_mod;
+        while (city_list_size(&pplayer->cities) > basis) {
+          /* OK, we've got a barbarian, now let's give 'em the city */
+          /* FIXME: this is the only way I know how to get a random city.
+          There's probably a better way */
+          j = myrand(city_list_size(&pplayer->cities));
+          k = 0;
+          city_list_iterate(pplayer->cities, pcity) {
+            if (k == j || k == 0) {
+             ccity = pcity;
+            }
+            k++;
+          } city_list_iterate_end;
+
+          /* What we've all been waiting for */
+          transfer_city(barb, ccity, 1, FALSE, FALSE, FALSE);
+        }
+      }
+    }
+
+    if (tocivwar > 0) { // we've got somebody to incite a civil war!
+      for (i = 0; i < tocivwar; i++) {
+        pplayer = get_player(civwars[i]);
+        civil_war(pplayer);
+      }
+    }
+  }
+}
+
+
+/**************************************************************************
 ...
 **************************************************************************/
 static void update_environmental_upset(enum tile_special_type cause,
@@ -524,6 +625,7 @@
   update_diplomatics();
   do_apollo_program();
   marco_polo_make_contact();
+  smallpox_handler();
   make_history_report();
   send_player_turn_notifications(NULL);
   freelog(LOG_DEBUG, "Turn ended.");
diff -ruN -X freeciv-1.14.1/diff_ignore freeciv-1.14.1/server/stdinhand.c 
freeciv-1.14.1-nosmallpox/server/stdinhand.c
--- freeciv-1.14.1/server/stdinhand.c   2003-11-30 11:22:48.000000000 -0800
+++ freeciv-1.14.1-nosmallpox/server/stdinhand.c        2004-01-27 
20:27:11.000000000 -0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -466,7 +466,7 @@
             "cityfactor, one extra citizen is unhappy before other "
             "adjustments; see also unhappysize.  This assumes a "
             "Democracy; for other governments the effect occurs at "
-            "smaller numbers of cities."), NULL, 
+            "smaller numbers of cities."), NULL,
          GAME_MIN_CITYFACTOR, GAME_MAX_CITYFACTOR, GAME_DEFAULT_CITYFACTOR)
 
   GEN_INT("citymindist", game.citymindist, SSET_RULES, SSET_TO_CLIENT,
@@ -820,6 +820,37 @@
             "40=debuging logging."), NULL, 
          0, 40, 20)
 
+  GEN_BOOL("cfcivilwar", game.spcivilwar, SSET_RULES, SSET_TO_CLIENT,
+         N_("Civil war due to number of cities"),
+         N_("When the number of cities a player owns is greater than "
+            "cityfactor, if this is set, there is also a chance that your "
+            "civilization will erupt into civil war.  "
+            "See cfbarbarian, cfchance and cfwhich"), NULL,
+         GAME_DEFAULT_SMALLPOX_CIVILWAR)
+
+  GEN_BOOL("cfbarbarian", game.spbarbarian, SSET_RULES, SSET_TO_CLIENT,
+         N_("Barbarians due to number of cities"),
+         N_("When the number of cities a player owns is greater than "
+            "cityfactor, if this is set, there is also a chance that random "
+            "cities will be overtaken by barbarians.  "
+            "See cfcivilwar, cfchance and cfwhich"), NULL,
+         GAME_DEFAULT_SMALLPOX_BARBARIANISM)
+
+  GEN_INT("cfchance", game.spchance, SSET_RULES, SSET_TO_CLIENT,
+         N_("Chance of civil war or barbarians"),
+         N_("If cfcivilwar or cfbarbarian is set, this is the chance that "
+              "one of the actions will be taken.  "
+              "See cfcivilwar, cfbarbarian and cfwhich"), NULL,
+         0, 100, GAME_DEFAULT_SMALLPOX_CHANCE)
+
+  GEN_INT("cfwhich", game.spchance, SSET_RULES, SSET_TO_CLIENT,
+         N_("Chance of civil war VS chance of barbarians"),
+         N_("If both cfcivilwar and cfbarbarian is set, this is the 
comparative "
+              "chance of the actions.  A lower number will increase the chance 
"
+              "of a civil war, a higher number will increase the chance of 
barbarians.  "
+              "See cfcivilwar, cfbarbarian and cfchance"), NULL,
+         0, 100, GAME_DEFAULT_CITYFACTOR)
+
   GEN_END
 };
 
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore freeciv-cvs-Jan-26/common/game.c 
freeciv-cvs-Jan-26-nosmallpox/common/game.c
--- freeciv-cvs-Jan-26/common/game.c    2003-11-28 22:05:26.000000000 -0800
+++ freeciv-cvs-Jan-26-nosmallpox/common/game.c 2004-01-27 18:42:21.000000000 
-0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -266,6 +266,11 @@
   game.watchtower_extra_vision=GAME_DEFAULT_WATCHTOWER_EXTRA_VISION,
   game.allowed_city_names = GAME_DEFAULT_ALLOWED_CITY_NAMES;
 
+  game.spcivilwar = GAME_DEFAULT_SMALLPOX_CIVILWAR;
+  game.spbarbarian = GAME_DEFAULT_SMALLPOX_BARBARIANISM;
+  game.spchance = GAME_DEFAULT_SMALLPOX_CHANCE;
+  game.spwhich = GAME_DEFAULT_SMALLPOX_WHICH;
+
   sz_strlcpy(game.rulesetdir, GAME_DEFAULT_RULESETDIR);
 
   game.num_unit_types = 0;
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore freeciv-cvs-Jan-26/common/game.h 
freeciv-cvs-Jan-26-nosmallpox/common/game.h
--- freeciv-cvs-Jan-26/common/game.h    2004-01-11 22:16:19.000000000 -0800
+++ freeciv-cvs-Jan-26-nosmallpox/common/game.h 2004-01-27 19:25:44.000000000 
-0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -227,6 +227,11 @@
   int trireme_loss_chance[MAX_VET_LEVELS];
   int work_veteran_chance[MAX_VET_LEVELS];
   int veteran_chance[MAX_VET_LEVELS];
+
+  bool spcivilwar;
+  bool spbarbarian;
+  int spchance;
+  int spwhich;
 };
 
 /* Unused? */
@@ -479,4 +484,9 @@
 
 #define GAME_START_YEAR -4000
 
+#define GAME_DEFAULT_SMALLPOX_CIVILWAR 0
+#define GAME_DEFAULT_SMALLPOX_BARBARIANISM 0
+#define GAME_DEFAULT_SMALLPOX_CHANCE 25
+#define GAME_DEFAULT_SMALLPOX_WHICH 100
+
 #endif  /* FC__GAME_H */
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore freeciv-cvs-Jan-26/common/player.c 
freeciv-cvs-Jan-26-nosmallpox/common/player.c
--- freeciv-cvs-Jan-26/common/player.c  2003-11-28 22:05:26.000000000 -0800
+++ freeciv-cvs-Jan-26-nosmallpox/common/player.c       2004-01-27 
18:51:56.000000000 -0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -149,6 +149,7 @@
   plr->attribute_block.data = NULL;
   plr->attribute_block.length = 0;
   plr->debug = FALSE;
+  plr->cityfactor_turns = 0;
 }
 
 /***************************************************************
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore freeciv-cvs-Jan-26/common/player.h 
freeciv-cvs-Jan-26-nosmallpox/common/player.h
--- freeciv-cvs-Jan-26/common/player.h  2003-11-28 22:05:26.000000000 -0800
+++ freeciv-cvs-Jan-26-nosmallpox/common/player.h       2004-01-27 
18:51:34.000000000 -0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -213,6 +213,8 @@
     void *data;
   } attribute_block;
   bool debug;
+
+  int cityfactor_turns;
 };
 
 void player_init(struct player *plr);
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore 
freeciv-cvs-Jan-26/server/barbarian.c 
freeciv-cvs-Jan-26-nosmallpox/server/barbarian.c
--- freeciv-cvs-Jan-26/server/barbarian.c       2004-01-11 22:16:29.000000000 
-0800
+++ freeciv-cvs-Jan-26-nosmallpox/server/barbarian.c    2004-01-27 
19:42:42.000000000 -0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 2003 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -81,7 +81,7 @@
 
   Dead barbarians forget the map and lose the money.
 **************************************************************************/
-static struct player *create_barbarian_player(bool land)
+struct player *create_barbarian_player(bool land)
 {
   int newplayer = game.nplayers;
   struct player *barbarians;
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore 
freeciv-cvs-Jan-26/server/barbarian.h 
freeciv-cvs-Jan-26-nosmallpox/server/barbarian.h
--- freeciv-cvs-Jan-26/server/barbarian.h       2003-05-05 05:41:39.000000000 
-0700
+++ freeciv-cvs-Jan-26-nosmallpox/server/barbarian.h    2004-01-27 
19:42:42.000000000 -0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@
 
 #define MAP_FACTOR     2000  /* adjust this to get a good uprising frequency */
 
+struct player *create_barbarian_player(bool land);
 bool unleash_barbarians(int x, int y);
 void summon_barbarians(void);
 bool is_land_barbarian(struct player *pplayer);
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore 
freeciv-cvs-Jan-26/server/savegame.c 
freeciv-cvs-Jan-26-nosmallpox/server/savegame.c
--- freeciv-cvs-Jan-26/server/savegame.c        2004-01-20 22:16:42.000000000 
-0800
+++ freeciv-cvs-Jan-26-nosmallpox/server/savegame.c     2004-01-27 
18:56:08.000000000 -0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -200,7 +200,7 @@
   char *pch;
 
   if (ch == ' ') {
-    /* 
+    /*
      * Sane value. It is unknow if there are savegames out there which
      * need this fix. Savegame.c doesn't write such savegames
      * (anymore) since the inclusion into CVS (2000-08-25).
@@ -739,6 +739,8 @@
   plr->capital=secfile_lookup_bool(file, "player%d.capital", plrno);
   plr->revolution=secfile_lookup_int_default(file, 0, "player%d.revolution",
                                              plrno);
+  plr->cityfactor_turns=secfile_lookup_int_default(file, 0, 
"player%d.cityfactor_turns",
+                                             plrno);
 
   tech_type_iterate(i) {
     if (p[i] == '1') {
@@ -1425,6 +1427,7 @@
 
   secfile_insert_bool(file, plr->capital, "player%d.capital", plrno);
   secfile_insert_int(file, plr->revolution, "player%d.revolution", plrno);
+  secfile_insert_int(file, plr->cityfactor_turns, "player%d.cityfactor_turns", 
plrno);
 
   tech_type_iterate(tech_id) {
     invs[tech_id] = (get_invention(plr, tech_id) == TECH_KNOWN) ? '1' : '0';
@@ -2033,7 +2036,16 @@
                                               "game.randseed");
     game.allowed_city_names =
        secfile_lookup_int_default(file, game.allowed_city_names,
-                                  "game.allowed_city_names"); 
+                                  "game.allowed_city_names");
+
+    game.spcivilwar = secfile_lookup_int_default(file, game.spcivilwar,
+                                  "game.spcivilwar");
+    game.spbarbarian = secfile_lookup_int_default(file, game.spbarbarian,
+                                  "game.spbarbarian");
+    game.spchance = secfile_lookup_int_default(file, game.spchance,
+                                  "game.spchance");
+    game.spwhich = secfile_lookup_int_default(file, game.spwhich,
+                                  "game.spwhich");
 
     if(game.civstyle == 1) {
       string = "civ1";
@@ -2387,6 +2399,10 @@
   secfile_insert_int(file, game.watchtower_vision, "game.watchtower_vision");
   secfile_insert_int(file, game.watchtower_extra_vision, 
"game.watchtower_extra_vision");
   secfile_insert_int(file, game.allowed_city_names, "game.allowed_city_names");
+  secfile_insert_int(file, game.spcivilwar, "game.spcivilwar");
+  secfile_insert_int(file, game.spbarbarian, "game.spbarbarian");
+  secfile_insert_int(file, game.spchance, "game.spchance");
+  secfile_insert_int(file, game.spwhich, "game.spwhich");
 
   if (TRUE) {
     /* Now always save these, so the server options reflect the
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore 
freeciv-cvs-Jan-26/server/srv_main.c 
freeciv-cvs-Jan-26-nosmallpox/server/srv_main.c
--- freeciv-cvs-Jan-26/server/srv_main.c        2004-01-22 22:15:31.000000000 
-0800
+++ freeciv-cvs-Jan-26-nosmallpox/server/srv_main.c     2004-01-27 
20:42:50.000000000 -0800
@@ -51,6 +51,7 @@
 #include "events.h"
 #include "fcintl.h"
 #include "game.h"
+#include "government.h"
 #include "log.h"
 #include "map.h"
 #include "mem.h"
@@ -337,6 +338,106 @@
 }
 
 /**************************************************************************
+Main function to prevent people from smallpoxing
+**************************************************************************/
+static void smallpox_handler(void)
+{
+  /* Only handle it if the settings are set to */
+  if ((game.spcivilwar || game.spbarbarian) && game.spchance > 0) {
+    struct player *pplayer, *barb;
+    struct city *pcity, *ccity;
+    int cities, basis, tocivwar, tobarb;
+    int civwars[MAX_NUM_PLAYERS];
+    int barbs[MAX_NUM_PLAYERS];
+    int i, j, k;
+    barb = NULL;
+    tocivwar = 0;
+    tobarb = 0;
+    ccity = NULL;
+    pcity = NULL;
+
+    players_iterate(pplayer) {
+      basis = game.cityfactor + get_gov_pplayer(pplayer)->empire_size_mod;
+      cities = city_list_size(&pplayer->cities);
+      if (cities > basis) {
+        /* Too many cities, time to take rash measures */
+        pplayer->cityfactor_turns++;
+        if (pplayer->cityfactor_turns > 5) { // too late!
+          pplayer->cityfactor_turns = 0;
+          if (myrand(101) <= game.spchance) { // We get to do some killin'
+            if (game.spcivilwar && game.spbarbarian) { // Both are set, take a 
chance
+              if (myrand(101) <= game.spwhich) { // Barbarians
+                barbs[tobarb] = pplayer->player_no;
+                tobarb++;
+              } else { // Civil war
+                civwars[tocivwar] = pplayer->player_no;
+                tocivwar++;
+              }
+            } else if (game.spcivilwar) {
+              civwars[tocivwar] = pplayer->player_no;
+              tocivwar++;
+            } else if (game.spbarbarian) {
+              barbs[tobarb] = pplayer->player_no;
+              tobarb++;
+            }
+          }
+        } else { // Warn them
+          notify_player_ex(pplayer, -1, -1, E_CIVIL_WAR,
+                  _("Game: Your civilization has become too large for you to 
control!  "
+                         "Either disband cities, or change your government to 
a more "
+                         "suitable one."));
+        }
+      } else {
+        if (pplayer->cityfactor_turns > 0) { // They fixed it in time
+          pplayer->cityfactor_turns = 0;
+        }
+      }
+    } players_iterate_end;
+
+    if (tobarb > 0) { // we've got somebody to have cities given to barbarians!
+      for (i = 0; i < tobarb; i++) {
+        players_iterate(pplayer) { // Find a barbarian
+          if (is_barbarian(pplayer)) {
+            barb = pplayer;
+          }
+        } players_iterate_end;
+        if (barb == NULL) { // No available barbarians!
+          barb = create_barbarian_player(TRUE);
+        }
+
+        pplayer = get_player(barbs[tobarb]);
+
+        basis = game.cityfactor + get_gov_pplayer(pplayer)->empire_size_mod;
+        while (city_list_size(&pplayer->cities) > basis) {
+          /* OK, we've got a barbarian, now let's give 'em the city */
+          /* FIXME: this is the only way I know how to get a random city.
+          There's probably a better way */
+          j = myrand(city_list_size(&pplayer->cities));
+          k = 0;
+          city_list_iterate(pplayer->cities, pcity) {
+            if (k == j || k == 0) {
+             ccity = pcity;
+            }
+            k++;
+          } city_list_iterate_end;
+
+          /* What we've all been waiting for */
+          transfer_city(barb, ccity, 1, FALSE, FALSE, FALSE);
+        }
+      }
+    }
+
+    if (tocivwar > 0) { // we've got somebody to incite a civil war!
+      for (i = 0; i < tocivwar; i++) {
+        pplayer = get_player(civwars[i]);
+        civil_war(pplayer);
+      }
+    }
+  }
+}
+
+
+/**************************************************************************
 ...
 **************************************************************************/
 static void update_environmental_upset(enum tile_special_type cause,
@@ -529,6 +630,7 @@
   update_diplomatics();
   do_apollo_program();
   marco_polo_make_contact();
+  smallpox_handler();
   make_history_report();
   send_player_turn_notifications(NULL);
 
diff -ruN -X freeciv-cvs-Jan-26/diff_ignore 
freeciv-cvs-Jan-26/server/stdinhand.c 
freeciv-cvs-Jan-26-nosmallpox/server/stdinhand.c
--- freeciv-cvs-Jan-26/server/stdinhand.c       2004-01-08 22:16:07.000000000 
-0800
+++ freeciv-cvs-Jan-26-nosmallpox/server/stdinhand.c    2004-01-27 
20:26:14.000000000 -0800
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -488,7 +488,7 @@
             "cityfactor, one extra citizen is unhappy before other "
             "adjustments; see also unhappysize.  This assumes a "
             "Democracy; for other governments the effect occurs at "
-            "smaller numbers of cities."), NULL, 
+            "smaller numbers of cities."), NULL,
          GAME_MIN_CITYFACTOR, GAME_MAX_CITYFACTOR, GAME_DEFAULT_CITYFACTOR)
 
   GEN_INT("citymindist", game.citymindist, SSET_RULES, SSET_TO_CLIENT,
@@ -873,6 +873,37 @@
             "40=debuging logging."), NULL, 
          0, 40, 20)
 
+  GEN_BOOL("cfcivilwar", game.spcivilwar, SSET_RULES, SSET_TO_CLIENT,
+         N_("Civil war due to number of cities"),
+         N_("When the number of cities a player owns is greater than "
+            "cityfactor, if this is set, there is also a chance that your "
+            "civilization will erupt into civil war.  "
+            "See cfbarbarian, cfchance and cfwhich"), NULL,
+         GAME_DEFAULT_SMALLPOX_CIVILWAR)
+
+  GEN_BOOL("cfbarbarian", game.spbarbarian, SSET_RULES, SSET_TO_CLIENT,
+         N_("Barbarians due to number of cities"),
+         N_("When the number of cities a player owns is greater than "
+            "cityfactor, if this is set, there is also a chance that random "
+            "cities will be overtaken by barbarians.  "
+            "See cfcivilwar, cfchance and cfwhich"), NULL,
+         GAME_DEFAULT_SMALLPOX_BARBARIANISM)
+
+  GEN_INT("cfchance", game.spchance, SSET_RULES, SSET_TO_CLIENT,
+         N_("Chance of civil war or barbarians"),
+         N_("If cfcivilwar or cfbarbarian is set, this is the chance that "
+              "one of the actions will be taken.  "
+              "See cfcivilwar, cfbarbarian and cfwhich"), NULL,
+         0, 100, GAME_DEFAULT_SMALLPOX_CHANCE)
+
+  GEN_INT("cfwhich", game.spchance, SSET_RULES, SSET_TO_CLIENT,
+         N_("Chance of civil war VS chance of barbarians"),
+         N_("If both cfcivilwar and cfbarbarian is set, this is the 
comparative "
+              "chance of the actions.  A lower number will increase the chance 
"
+              "of a civil war, a higher number will increase the chance of 
barbarians.  "
+              "See cfcivilwar, cfbarbarian and cfchance"), NULL,
+         0, 100, GAME_DEFAULT_CITYFACTOR)
+
   GEN_END
 };
 

[Prev in Thread] Current Thread [Next in Thread]