Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12260) more global-warming fixes
Home

[Freeciv-Dev] (PR#12260) more global-warming fixes

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12260) more global-warming fixes
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 14 Feb 2005 22:31:18 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch fixes global warming/nuclear winter in a few more ways:

1.  It is proportional to map size.  Originally any polluted tiles after 
the 8th one would cause a chance of global warming.  Under the patch 
this value is size * 2.  With a default size of 4 that's 1/500 tiles 
that are allowed to be polluted.

2.  It fixes nuclear winter handling in autosettlers.  Originally there 
is an ai.warmth value that is used for calculation of the benfits of 
cleaning up pollution and fallout.  This value is based on global 
warming levels but is used to determine fallout cleanup benefits also. 
Under the patch there is a separate ai.frost value used for calculating 
fallout cleanup benefits.

3.  ai.warmth and ai.frost are calculated a little better (I think). 
Until there are warminglevel/2 polluted tiles the benefit for cleanup is 
0.  Once we reach warminglevel/2 polluted tiles the benefit becomes 1 
(the same as it would be now).  Once we pass warminglevel polluted tiles 
the benefit becomes 2 (the same as it would be now).  As the number of 
polluted tiles goes up the benefit continues to rise.  The globalwarming 
value is also added on - although IME once this value becomes > 0 it is 
often too late to avoid warming.  Note that cleaning a polluted/fallout 
tile gives a benefit to the output of the tile which is already 
accounted for.

There is some ugliness because game.warminglevel cannot be set in 
game_init() because the map isn't yet initialized.  It would probably be 
most correct to move these values into the map structure.  However for 
the moment I just made a game_map_init() function.

-jason

Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.195
diff -u -r1.195 game.c
--- common/game.c       22 Jan 2005 19:45:41 -0000      1.195
+++ common/game.c       15 Feb 2005 06:24:33 -0000
@@ -176,9 +176,9 @@
   int i;
   game.is_new_game   = TRUE;
   game.globalwarming = 0;
-  game.warminglevel  = 8;
+  game.warminglevel  = 0; /* set later */
   game.nuclearwinter = 0;
-  game.coolinglevel  = 8;
+  game.coolinglevel  = 0; /* set later */
   game.gold          = GAME_DEFAULT_GOLD;
   game.tech          = GAME_DEFAULT_TECHLEVEL;
   game.skill_level   = GAME_DEFAULT_SKILL_LEVEL;
@@ -294,6 +294,20 @@
   terrain_control.river_help_text[0] = '\0';
 }
 
+/****************************************************************************
+  Initialize map-specific parts of the game structure.  Maybe these should
+  be moved into the map structure?
+****************************************************************************/
+void game_map_init(void)
+{
+  /* FIXME: it's not clear where these values should be initialized.  It
+   * can't be done in game_init because the map isn't created yet.  Maybe it
+   * should be done in the mapgen code or in the maphand code.  It should
+   * surely be called when the map is generated. */
+  game.warminglevel = (map_num_tiles() + 499) / 500;
+  game.coolinglevel = (map_num_tiles() + 499) / 500;
+}
+
 /***************************************************************
   Remove all initialized players. This is all player slots, 
   since we initialize them all on game initialization.
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.171
diff -u -r1.171 game.h
--- common/game.h       29 Jan 2005 17:58:18 -0000      1.171
+++ common/game.h       15 Feb 2005 06:24:33 -0000
@@ -262,6 +262,7 @@
 };
 
 void game_init(void);
+void game_map_init(void);
 void game_free(void);
 void ruleset_data_free(void);
 
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.138
diff -u -r1.138 player.h
--- common/player.h     22 Jan 2005 19:45:43 -0000      1.138
+++ common/player.h     15 Feb 2005 06:24:33 -0000
@@ -140,7 +140,7 @@
   int expand;                  /* percentage factor to value new cities */
   int science_cost;             /* Cost in bulbs to get new tech, relative
                                    to non-AI players (100: Equal cost) */
-  int warmth; /* threat of global warming */
+  int warmth, frost; /* threat of global warming / nuclear winter */
   enum barbarian_type barbarian_type;
 
   int love[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
Index: server/citytools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.h,v
retrieving revision 1.61
diff -u -r1.61 citytools.h
--- server/citytools.h  12 Jan 2005 18:26:55 -0000      1.61
+++ server/citytools.h  15 Feb 2005 06:24:33 -0000
@@ -29,6 +29,7 @@
  */
 #define POLLUTION_WEIGHTING 14 /* tentative */
 #define WARMING_FACTOR 50
+#define COOLING_FACTOR WARMING_FACTOR
 
 int build_points_left(struct city *pcity);
 int do_make_unit_veteran(struct city *pcity, Unit_Type_id id);
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.357
diff -u -r1.357 plrhand.c
--- server/plrhand.c    14 Feb 2005 22:52:41 -0000      1.357
+++ server/plrhand.c    15 Feb 2005 06:24:33 -0000
@@ -1973,6 +1973,7 @@
   cplayer->ai.maxbuycost = pplayer->ai.maxbuycost;
   cplayer->ai.handicap = pplayer->ai.handicap;
   cplayer->ai.warmth = pplayer->ai.warmth;
+  cplayer->ai.frost = pplayer->ai.frost;
   set_ai_level_direct(cplayer, game.skill_level);
 
   tech_type_iterate(i) {
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.220
diff -u -r1.220 settlers.c
--- server/settlers.c   13 Feb 2005 19:17:25 -0000      1.220
+++ server/settlers.c   15 Feb 2005 06:24:34 -0000
@@ -982,7 +982,7 @@
          time = mv_turns
            + get_turns_for_activity_at(punit, ACTIVITY_FALLOUT, ptile);
          consider_settler_action(pplayer, ACTIVITY_FALLOUT,
-                                 pplayer->ai.warmth,
+                                 pplayer->ai.frost,
                                  pcity->ai.derad[i][j], oldv, in_use, time,
                                  &best_newv, &best_oldv,
                                  best_act, best_tile,
@@ -1248,10 +1248,21 @@
   /* Initialize the infrastructure cache, which is used shortly. */
   initialize_infrastructure_cache(pplayer);
 
-  pplayer->ai.warmth = WARMING_FACTOR * (game.heating > game.warminglevel ? 2 
: 1);
+  /* An extra consideration for the benefit of cleaning up pollution/fallout.
+   * This depends heavily on the calculations in update_environmental_upset.
+   * Aside from that it's more or less a WAG that simply grows incredibly
+   * large as an environmental disaster approaches. */
+  pplayer->ai.warmth
+    = (WARMING_FACTOR * game.heating / ((game.warminglevel + 1) / 2)
+       + game.globalwarming);
+  pplayer->ai.frost
+    = (COOLING_FACTOR * game.cooling / ((game.coolinglevel + 1) / 2)
+       + game.nuclearwinter);
 
   freelog(LOG_DEBUG, "Warmth = %d, game.globalwarming=%d",
          pplayer->ai.warmth, game.globalwarming);
+  freelog(LOG_DEBUG, "Frost = %d, game.nuclearwinter=%d",
+         pplayer->ai.warmth, game.nuclearwinter);
 
   /* Auto-settle with a settler unit if it's under AI control (e.g. human
    * player auto-settler mode) or if the player is an AI.  But don't
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.223
diff -u -r1.223 srv_main.c
--- server/srv_main.c   14 Feb 2005 22:52:41 -0000      1.223
+++ server/srv_main.c   15 Feb 2005 06:24:34 -0000
@@ -389,7 +389,7 @@
     if (myrand(200) <= *accum) {
       upset_action_fn((map.xsize / 10) + (map.ysize / 10) + ((*accum) * 5));
       *accum = 0;
-      *level+=4;
+      *level += (map_num_tiles() + 999) / 1000;
     }
   }
 
Index: server/generator/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/generator/mapgen.c,v
retrieving revision 1.20
diff -u -r1.20 mapgen.c
--- server/generator/mapgen.c   3 Dec 2004 09:53:35 -0000       1.20
+++ server/generator/mapgen.c   15 Feb 2005 06:24:35 -0000
@@ -1125,6 +1125,7 @@
   }
 
   assign_continent_numbers(FALSE);
+  game_map_init();
 
   print_mapgen_map();
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12260) more global-warming fixes, Jason Short <=