Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12221) needed: better algorithm for choosing warming/c
Home

[Freeciv-Dev] (PR#12221) needed: better algorithm for choosing warming/c

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12221) needed: better algorithm for choosing warming/cooling icons
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 11 Feb 2005 14:36:59 -0800
Reply-to: bugs@xxxxxxxxxxx

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

The indicator icons for warming and cooling are rather poor.

This patch is one possible replacement, but not the best one I think. 
We calculate the chance of having warming/cooling over the next 5 turns 
if nothing changes, and convert this % to a simple linear scale.  The 
problem (which seems to be a problem with warming/cooling in general) is 
that in most cases you'll quickly jump to a very high number on this 
scale.  In other words once you cross the pollution threshhold and your 
pollution level passes 0% you have very little time to fix it.

-jason

Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.151
diff -u -r1.151 climisc.c
--- client/climisc.c    4 Feb 2005 23:00:02 -0000       1.151
+++ client/climisc.c    11 Feb 2005 22:34:06 -0000
@@ -308,20 +308,38 @@
 }
 
 /**************************************************************************
+  Calculate the chance of having an ecological disaster in the given
+  number of turns.
+**************************************************************************/
+static double chance_of_catastrophe(int accumulation, int change, int turns)
+{
+  double safety = 100.0, chance_safe_this_turn;
+  int i;
+
+  for (i = 0; i < turns; i++) {
+    accumulation = CLIP(0, accumulation, 200);
+    accumulation += change;
+
+    /* Calculate the chance we'll stay safe this turn. */
+    chance_safe_this_turn = (200.0 - accumulation) / 200.0;
+
+    /* Calculate the cumulate chance of being safe. */
+    safety *= chance_safe_this_turn;
+  }
+
+  return CLIP(0, 100 - (int)safety, 100);
+}
+
+/**************************************************************************
 Return the sprite index for the global-warming indicator.
 **************************************************************************/
 int client_warming_sprite(void)
 {
-  int index;
-  if ((game.globalwarming <= 0) &&
-      (game.heating < (NUM_TILES_PROGRESS / 2))) {
-    index = MAX(0, game.heating);
-  } else {
-    index = MIN(NUM_TILES_PROGRESS,
-               (MAX(0, 4 + game.globalwarming) / 5) +
-               ((NUM_TILES_PROGRESS / 2) - 1));
-  }
-  return index;
+  double chance = chance_of_catastrophe(game.globalwarming,
+                                       game.heating - game.warminglevel,
+                                       5);
+
+  return (chance / 101.0) * NUM_TILES_PROGRESS;
 }
 
 /**************************************************************************
@@ -329,16 +347,11 @@
 **************************************************************************/
 int client_cooling_sprite(void)
 {
-  int index;
-  if ((game.nuclearwinter <= 0) &&
-      (game.cooling < (NUM_TILES_PROGRESS / 2))) {
-    index = MAX(0, game.cooling);
-  } else {
-    index = MIN(NUM_TILES_PROGRESS,
-               (MAX(0, 4 + game.nuclearwinter) / 5) +
-               ((NUM_TILES_PROGRESS / 2) - 1));
-  }
-  return index;
+  double chance = chance_of_catastrophe(game.nuclearwinter,
+                                       game.cooling - game.coolinglevel,
+                                       5);
+
+  return (chance / 101.0) * NUM_TILES_PROGRESS;
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12221) needed: better algorithm for choosing warming/cooling icons, Jason Short <=