Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12285) client_xxx_sprite doesn't work in pre-game
Home

[Freeciv-Dev] (PR#12285) client_xxx_sprite doesn't work in pre-game

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12285) client_xxx_sprite doesn't work in pre-game
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Feb 2005 14:23:25 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Until the client connects and the rulesets are sent, calling these 
functions will cause a crash.

With this patch they should instead return a placeholder sprite.

-jason

? freeciv-2.0.99-devel.tar.gz
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.153
diff -u -r1.153 climisc.c
--- client/climisc.c    17 Feb 2005 03:12:53 -0000      1.153
+++ client/climisc.c    17 Feb 2005 22:22:49 -0000
@@ -303,14 +303,18 @@
 **************************************************************************/
 struct Sprite *client_research_sprite(void)
 {
-  int index = (NUM_TILES_PROGRESS
-              * game.player_ptr->research.bulbs_researched)
-    / (total_bulbs_required(game.player_ptr) + 1);
-
-  /* This clipping can be necessary since we can end up with excess
-   * research. */
-  index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
-  return sprites.bulb[index];
+  if (can_client_change_view() && game.player_ptr) {
+    int index = (NUM_TILES_PROGRESS
+                * game.player_ptr->research.bulbs_researched)
+      / (total_bulbs_required(game.player_ptr) + 1);
+
+    /* This clipping can be necessary since we can end up with excess
+     * research. */
+    index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
+    return sprites.bulb[index];
+  } else {
+    return sprites.bulb[0];
+  }
 }
 
 /**************************************************************************
@@ -318,19 +322,24 @@
 **************************************************************************/
 struct Sprite *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));
-  }
+  if (can_client_change_view() && game.player_ptr) {
+    int index;
 
-  /* The clipping is needed because the above math is a little fuzzy. */
-  index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
-  return sprites.warming[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));
+    }
+
+    /* The clipping is needed because the above math is a little fuzzy. */
+    index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
+    return sprites.warming[index];
+  } else {
+    return sprites.warming[0];
+  }
 }
 
 /**************************************************************************
@@ -338,19 +347,24 @@
 **************************************************************************/
 struct Sprite *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));
-  }
+  if (can_client_change_view()) {
+    int index;
 
-  /* The clipping is needed because the above math is a little fuzzy. */
-  index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
-  return sprites.cooling[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));
+    }
+
+    /* The clipping is needed because the above math is a little fuzzy. */
+    index = CLIP(0, index, NUM_TILES_PROGRESS - 1);
+    return sprites.cooling[index];
+  } else {
+    return sprites.cooling[0];
+  }
 }
 
 /**************************************************************************
@@ -358,14 +372,14 @@
 **************************************************************************/
 struct Sprite *client_government_sprite(void)
 {
-  if (game.government_count == 0) {
+  if (can_client_change_view() && game.government_count > 0) {
+    return get_government(game.player_ptr->government)->sprite;
+  } else {
     /* HACK: the UNHAPPY citizen is used for the government
      * when we don't know any better. */
     struct citizen_type c = {.type = CITIZEN_UNHAPPY};
 
     return get_citizen_sprite(c, 0, NULL);
-  } else {
-    return get_government(game.player_ptr->government)->sprite;
   }
 }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12285) client_xxx_sprite doesn't work in pre-game, Jason Short <=