Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2002:
[Freeciv-Dev] Re: don't show "999" as the city turns to build (PR#1283)
Home

[Freeciv-Dev] Re: don't show "999" as the city turns to build (PR#1283)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: don't show "999" as the city turns to build (PR#1283)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Mon, 25 Feb 2002 15:25:48 -0800 (PST)

Raimar Falke wrote:
On Mon, Feb 25, 2002 at 10:50:10AM -0800, jdorje@xxxxxxxxxxxxxxxxxxxxx wrote:

The attached patch is a rewrite of a patch I submitted about a year ago. It was more-or-less ignored at the time, but recently a friend mentioned to me how much this bugged him as well, so I've brought it back out.

The game shows "999" as the turns to build for production that will never finish. This has always annoyed me. This patch corrects that for the city descriptions in the mapview only. It takes out all of the identical code to assemble the mapview production description, and puts that into a function get_city_mapview_production() in mapview_common.[ch]. (Thus, it consolidates code overall.) It also special-cases the "999" that is returned, and prints a "-" in place of the number. (I had originally put "never" here instead of "-", but CivIII uses "-" so I figure that's just as good.)

I've made changes to all GUI's, but I've only tested GTK and XAW, naturally.

Finally, note this only changes the mapview, not the city dialog. These are pretty much completely separate, and the city dialog will probably be a bit more difficult since it varies between GUIs.


Very nice. However this 999 in city_turns_to_build should really be a
FC_INFINITY. This will also force us to have special handling
everywhere. Can you do that?

It's easy enough to change the 999's to FC_INFINITY, and makes things better (much more readible).

The only problem is that it (kind of) forces us to have special handling everywhere _in this patch_, since otherwise people will use "10...000 turns" everywhere, which just doesn't look good.

But, here's the patch without that. It still just changes the mapview, makes the FC_INIFINITY change, and fixes the typos pointed out for win32 and mui (the same typo).

jason
? crash
? jason-game.gz
? t
? test-alt.pl
? test.pl
? topology
? data/README-isotrident
? data/isoengels
? data/isoengels.tilespec
? data/isotrident
? data/isotrident.tilespec
? data/lexxy
? data/lexxy.tilespec
? data/macroisotrident
? data/macroisotrident.tilespec
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.9
diff -u -r1.9 mapview_common.c
--- client/mapview_common.c     2002/02/19 16:41:17     1.9
+++ client/mapview_common.c     2002/02/25 23:24:26
@@ -18,6 +18,8 @@
 #include <assert.h>
 
 #include "map.h"
+#include "support.h"
+
 #include "mapview_g.h"
 
 #include "mapview_common.h"
@@ -312,4 +314,39 @@
   /* rule e */
   last_pcity = pcity2;
   return pcity2;
+}
+
+/**************************************************************************
+  Find the mapview city production text for the given city, and place it
+  into the buffer.
+**************************************************************************/
+void get_city_mapview_production(struct city *pcity,
+                                 char *buffer, size_t buffer_len)
+{
+  int turns = city_turns_to_build(pcity, pcity->currently_building,
+                                 pcity->is_building_unit, TRUE);
+                               
+  if (pcity->is_building_unit) {
+    struct unit_type *punit_type =
+               get_unit_type(pcity->currently_building);
+    if (turns < FC_INFINITY) {
+      my_snprintf(buffer, buffer_len, "%s %d",
+                  punit_type->name, turns);
+    } else {
+      my_snprintf(buffer, buffer_len, "%s -",
+                  punit_type->name);
+    }
+  } else {
+    struct impr_type *pimprovement_type =
+               get_improvement_type(pcity->currently_building);
+    if (pcity->currently_building == B_CAPITAL) {
+      my_snprintf(buffer, buffer_len, "%s", pimprovement_type->name);
+    } else if (turns < FC_INFINITY) {
+      my_snprintf(buffer, buffer_len, "%s %d",
+                 pimprovement_type->name, turns);
+    } else {
+      my_snprintf(buffer, buffer_len, "%s -",
+                  pimprovement_type->name);
+    }
+  }
 }
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.4
diff -u -r1.4 mapview_common.h
--- client/mapview_common.h     2002/02/19 16:41:17     1.4
+++ client/mapview_common.h     2002/02/25 23:24:26
@@ -62,4 +62,7 @@
                                
 struct city *find_city_near_tile(int x, int y);
 
+void get_city_mapview_production(struct city *pcity,
+                                 char *buf, size_t buf_len);
+
 #endif /* FC__MAPVIEW_COMMON_H */
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.119
diff -u -r1.119 mapview.c
--- client/gui-gtk/mapview.c    2002/02/22 13:14:40     1.119
+++ client/gui-gtk/mapview.c    2002/02/25 23:24:30
@@ -1348,27 +1348,10 @@
     }
 
     if (draw_city_productions && (pcity->owner==game.player_idx)) {
-      int turns, y_offset;
-      struct unit_type *punit_type;
-      struct impr_type *pimprovement_type;
+      int y_offset;
 
-      turns = city_turns_to_build(pcity, pcity->currently_building,
-                                 pcity->is_building_unit, TRUE);
+      get_city_mapview_production(pcity, buffer, sizeof(buffer));
 
-      if (pcity->is_building_unit) {
-       punit_type = get_unit_type(pcity->currently_building);
-       my_snprintf(buffer, sizeof(buffer), "%s %d",
-                   punit_type->name, turns);
-      } else {
-       pimprovement_type =
-         get_improvement_type(pcity->currently_building);
-       if (pcity->currently_building == B_CAPITAL) {
-         sz_strlcpy(buffer, pimprovement_type->name);
-       } else {
-         my_snprintf(buffer, sizeof(buffer), "%s %d",
-                     pimprovement_type->name, turns);
-       }
-      }
       if (draw_city_names)
        y_offset = main_font->ascent + main_font->descent;
       else
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.78
diff -u -r1.78 mapclass.c
--- client/gui-mui/mapclass.c   2002/02/22 13:14:41     1.78
+++ client/gui-mui/mapclass.c   2002/02/25 23:24:35
@@ -459,27 +459,8 @@
     }
 
     if (draw_city_productions && (pcity->owner==game.player_idx)) {
-      int turns;
-      struct unit_type *punit_type;
-      struct impr_type *pimprovement_type;
+      get_city_mapview_production(pcity, buffer, sizeof(buffer));
 
-      turns = city_turns_to_build(pcity, pcity->currently_building,
-                                 pcity->is_building_unit, TRUE);
-
-      if (pcity->is_building_unit) {
-       punit_type = get_unit_type(pcity->currently_building);
-       my_snprintf(buffer, sizeof(buffer), "%s %d",
-                   punit_type->name, turns);
-      } else {
-       pimprovement_type =
-         get_improvement_type(pcity->currently_building);
-       if (pcity->currently_building == B_CAPITAL) {
-         sz_strlcpy(buffer, pimprovement_type->name);
-       } else {
-         my_snprintf(buffer, sizeof(buffer), "%s %d",
-                     pimprovement_type->name, turns);
-       }
-      }
       w = TextLength(rp, buffer, strlen(buffer));
       pix_x = _mleft(o) + canvas_x + NORMAL_TILE_WIDTH/2 - w/2;
 
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.22
diff -u -r1.22 mapview.c
--- client/gui-win32/mapview.c  2002/02/22 13:14:41     1.22
+++ client/gui-win32/mapview.c  2002/02/25 23:24:38
@@ -891,28 +891,9 @@
       y_offset=rc.bottom+2;
     }      
     if (draw_city_productions && (pcity->owner==game.player_idx)) {
-      int turns;
       RECT rc;
-      struct unit_type *punit_type;
-      struct impr_type *pimprovement_type;
-      
-      turns = city_turns_to_build(pcity, pcity->currently_building,
-                                 pcity->is_building_unit,TRUE);
-      
-      if (pcity->is_building_unit) {
-       punit_type = get_unit_type(pcity->currently_building);
-       my_snprintf(buffer, sizeof(buffer), "%s %d",
-                   punit_type->name, turns);
-      } else {
-       pimprovement_type =
-         get_improvement_type(pcity->currently_building);
-       if (pcity->currently_building == B_CAPITAL) {
-         sz_strlcpy(buffer, pimprovement_type->name);
-       } else {
-         my_snprintf(buffer, sizeof(buffer), "%s %d",
-                     pimprovement_type->name, turns);
-       }
-      }
+
+      get_city_mapview_production(pcity, buffer, sizeof(buffer));
       
       DrawText(hdc,buffer,strlen(buffer),&rc,DT_CALCRECT);
       rc.left=canvas_x+NORMAL_TILE_WIDTH/2-10;
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.94
diff -u -r1.94 mapview.c
--- client/gui-xaw/mapview.c    2002/02/19 15:21:03     1.94
+++ client/gui-xaw/mapview.c    2002/02/25 23:24:40
@@ -793,28 +793,9 @@
        }
 
        if (draw_city_productions && (pcity->owner==game.player_idx)) {
-         int turns, show_turns = 1;
-         struct unit_type *punit_type;
-         struct impr_type *pimpr_type;
-         char *name;
          char buffer[512];
-
-         turns = city_turns_to_build(pcity, pcity->currently_building,
-                                     pcity->is_building_unit, TRUE);
-
-         if (pcity->is_building_unit) {
-           punit_type = get_unit_type(pcity->currently_building);
-           name = punit_type->name;
-         } else {
-           pimpr_type = get_improvement_type(pcity->currently_building);
-           name = pimpr_type->name;
-           show_turns = (pcity->currently_building != B_CAPITAL);
-         }
-         if (show_turns) {
-           my_snprintf(buffer, sizeof(buffer), "%s %d", name, turns);
-         } else {
-           sz_strlcpy(buffer, name);
-         }
+       
+          get_city_mapview_production(pcity, buffer, sizeof(buffer));
 
          draw_shadowed_string(prod_font_struct, prod_font_gc,
                               x*NORMAL_TILE_WIDTH+NORMAL_TILE_WIDTH/2,
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.151
diff -u -r1.151 city.c
--- common/city.c       2002/02/22 13:14:43     1.151
+++ common/city.c       2002/02/25 23:24:44
@@ -1261,7 +1261,7 @@
       (improvement_cost - city_shield_stock + city_shield_surplus - 1) /
       city_shield_surplus;
   } else {
-    return 999;
+    return FC_INFINITY;
   }
 }
 

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