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: Tue, 26 Feb 2002 18:15:53 -0800 (PST)

Raimar Falke wrote:
On Mon, Feb 25, 2002 at 03:25:48PM -0800, jdorje@xxxxxxxxxxxxxxxxxxxxx wrote:

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.


Yes I tought at all users of city_turns_to_build.

Yes. But there are a number of them, and they're not all trivial to figure out since they're spread through different GUIs.

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).


I will apply this patch without the FC_INIFINITY change. Can you made
a patch which changes all callers of city_turns_to_build? Or do we
need to unify this first a bit?

I think doing it piecemeal is easiest, since much of the code can be grouped by functionality.

Here's a second patch. This changes all of the city dialog code to use get_city_dialog_production. get_city_dialog_production has been changed to use "never" or "-" (depending on concise_city_production) instead of "999".

This has been tested for GTK and XAW, but not MUI or WIN32. It is more complex than the last change, so there is a possibility for errors there.

After this, I think all that is left should be the city report. This one may be the hardest, since it (I think) varies somewhat between GUIs.

jason
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.3
diff -u -r1.3 citydlg_common.c
--- client/citydlg_common.c     2001/12/13 15:30:30     1.3
+++ client/citydlg_common.c     2002/02/27 02:06:39
@@ -14,9 +14,13 @@
 #include <config.h>
 #endif
 
+#include "city.h"
+#include "fcintl.h"
 #include "log.h"
+#include "support.h"
 
 #include "citydlg_common.h"
+#include "options.h"           /* for concise_city_production */
 #include "tilespec.h"          /* for is_isometric */
 
 /**************************************************************************
@@ -79,4 +83,63 @@
     *map_y = canvas_y / NORMAL_TILE_HEIGHT;
   }
   freelog(LOG_DEBUG, "canvas_pos_to_city_pos(pos=(%d,%d))=(%d,%d)", canvas_x, 
canvas_y, *map_x, *map_y);
+}
+
+/**************************************************************************
+  Find the city dialog city production text for the given city, and place
+  it into the buffer.  This will check the concise_city_production option.
+  pcity may be NULL; in this case a filler string is returned.
+**************************************************************************/
+void get_city_dialog_production(struct city *pcity,
+                                char *buffer, size_t buffer_len)
+{
+  int turns, cost, stock;
+
+  if (pcity == NULL) {
+    /* Some GUIs use this to build a "filler string" so that they
+       can properly size the widget to hold the string.  This has some
+       obvious problems; the big one is that we have two forms of
+       time information: "XXX turns" and "never".  Later this may
+       need to be extended to return the longer of the two; in
+       the meantime translators can fudge it by changing this
+       "filler" string. */
+    my_snprintf(buffer, buffer_len, Q_("?filler:XXX/XXX XXX turns"));
+    return;
+  }
+
+  turns = city_turns_to_build(pcity, pcity->currently_building,
+                              pcity->is_building_unit, TRUE);
+  stock = pcity->shield_stock;
+
+  if (pcity->is_building_unit) {
+    cost = get_unit_type(pcity->currently_building)->build_cost;
+  } else {
+    cost = get_improvement_type(pcity->currently_building)->build_cost;
+  }
+
+  if (!pcity->is_building_unit
+      && pcity->currently_building == B_CAPITAL) {
+    my_snprintf(buffer, buffer_len, _("%3d per turn"), stock);
+  } else {
+    char time[25];
+
+    if (turns < 999) {
+      if (concise_city_production) {
+        my_snprintf(time, sizeof(time), "%3d", turns);
+      } else {
+        my_snprintf(time, sizeof(time),
+                    PL_("%3d turn", "%3d turns", turns),
+                    turns);
+      }
+    } else {
+      my_snprintf(time, sizeof(time), "%s",
+                  concise_city_production ? "-" : _("never"));
+    }
+
+    if (concise_city_production) {
+      my_snprintf(buffer, buffer_len, _("%3d/%3d:%s"), stock, cost, time);
+    } else {
+      my_snprintf(buffer, buffer_len, _("%3d/%3d %s"), stock, cost, time);
+    }
+  }
 }
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.1
diff -u -r1.1 citydlg_common.h
--- client/citydlg_common.h     2001/12/05 04:15:50     1.1
+++ client/citydlg_common.h     2002/02/27 02:06:39
@@ -14,7 +14,12 @@
 #ifndef FC__CITYDLG_COMMON_H
 #define FC__CITYDLG_COMMON_H
 
+#include "city.h"
+
 void city_pos_to_canvas_pos(int city_x, int city_y, int *canvas_x, int 
*canvas_y);
 void canvas_pos_to_city_pos(int canvas_x, int canvas_y, int *map_x, int 
*map_y);
+
+void get_city_dialog_production(struct city *pcity,
+                                char *buffer, size_t buffer_len);
 
 #endif /* FC__CITYDLG_COMMON_H */
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.125
diff -u -r1.125 citydlg.c
--- client/gui-gtk/citydlg.c    2002/02/26 01:33:44     1.125
+++ client/gui-gtk/citydlg.c    2002/02/27 02:06:46
@@ -1890,53 +1890,35 @@
 static void city_dialog_update_building(struct city_dialog *pdialog)
 {
   char buf[32], buf2[200], *descr;
-  int turns;
   struct city *pcity = pdialog->pcity;
   gfloat pct;
+  int cost;
 
   gtk_widget_set_sensitive(pdialog->overview.buy_command, !pcity->did_buy);
   gtk_widget_set_sensitive(pdialog->overview.sell_command,
                           !pcity->did_sell);
+                       
+  get_city_dialog_production(pcity, buf, sizeof(buf));
 
   if (pcity->is_building_unit) {
-    turns =
-       city_turns_to_build(pcity, pcity->currently_building, TRUE, TRUE);
-    my_snprintf(buf, sizeof(buf),
-               concise_city_production ? "%3d/%3d:%3d" :
-               PL_("%3d/%3d %3d turn", "%3d/%3d %3d turns", turns),
-               pcity->shield_stock,
-               get_unit_type(pcity->currently_building)->build_cost,
-               turns);
+    cost = get_unit_type(pcity->currently_building)->build_cost;
     descr = get_unit_type(pcity->currently_building)->name;
-    pct =
-       (gfloat) pcity->shield_stock /
-       (get_unit_type(pcity->currently_building)->build_cost + 0.1);
-    pct = CLAMP(pct, 0.0, 1.0);
   } else {
     if (pcity->currently_building == B_CAPITAL) {
-      /* Capitalization is special, you can't buy it or finish making it */
-      my_snprintf(buf, sizeof(buf),
-                 concise_city_production ? "%3d/XXX:XXX" :
-                 _("%3d/XXX XXX turns"), pcity->shield_stock);
+      /* You can't buy capitalization */
       gtk_widget_set_sensitive(pdialog->overview.buy_command, FALSE);
-      pct = 1.0;
+      cost = 0;
     } else {
-      turns =
-         city_turns_to_build(pcity, pcity->currently_building, FALSE,
-                             TRUE);
-      my_snprintf(buf, sizeof(buf),
-                 concise_city_production ? "%3d/%3d:%3d" :
-                 PL_("%3d/%3d %3d turn", "%3d/%3d %3d turns", turns),
-                 pcity->shield_stock,
-                 get_improvement_type(pcity->currently_building)->
-                 build_cost, turns);
-
-      pct = (gfloat) pcity->shield_stock /
-         (get_improvement_type(pcity->currently_building)->build_cost +
-          0.1);
-      pct = CLAMP(pct, 0.0, 1.0);
+      cost = get_improvement_type(pcity->currently_building)->build_cost;;
     }
     descr = get_impr_name_ex(pcity, pcity->currently_building);
+  }
+
+  if (cost > 0) {
+    pct = (gfloat) pcity->shield_stock / (gfloat) cost;
+    pct = CLAMP(pct, 0.0, 1.0);
+  } else {
+    pct = 1.0;
   }
   
   my_snprintf(buf2, sizeof(buf2), "%s%s", descr,
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.45
diff -u -r1.45 citydlg.c
--- client/gui-mui/citydlg.c    2002/02/25 15:24:55     1.45
+++ client/gui-mui/citydlg.c    2002/02/27 02:06:48
@@ -1763,64 +1763,44 @@
 *****************************************************************/
 static void city_dialog_update_building(struct city_dialog *pdialog)
 {
-  char buf[32], buf2[64], buf3[128];
+  char buf[32], buf2[128], *descr;
   struct city *pcity = pdialog->pcity;
-  int turns;
+  int max_shield, shield;
 
-  int max_shield;
-  int shield;
-
   set(pdialog->buy_button, MUIA_Disabled, pcity->did_buy);
   set(pdialog->sell_button, MUIA_Disabled, pcity->did_sell || 
pdialog->sell_wnd);
 
-  if (pcity->is_building_unit)
-  {
-    turns = city_turns_to_build(pcity, pcity->currently_building,
-                               TRUE, TRUE);
+  get_city_dialog_production(pcity, buf, sizeof(buf));
+
+  if (pcity->is_building_unit) {
     shield = pcity->shield_stock;
     max_shield = get_unit_type(pcity->currently_building)->build_cost;
-
-    my_snprintf(buf, sizeof(buf),
-               PL_("%3d/%3d %3d turn", "%3d/%3d %3d turns", turns),
-               shield, max_shield, turns);
-    sz_strlcpy(buf2, get_unit_type(pcity->currently_building)->name);
-  }
-  else
-  {
-    if (pcity->currently_building == B_CAPITAL)
-    {
-      /* Capitalization is special, you can't buy it or finish making it */
-      my_snprintf(buf, sizeof(buf),"%d/XXX", pcity->shield_stock);
+    descr = get_unit_type(pcity->currently_building)->name;
+  } else {
+    if (pcity->currently_building == B_CAPITAL) {
+      /* You can't buy Capitalization */
       set(pdialog->buy_button, MUIA_Disabled, TRUE);
 
       shield = 0;
       max_shield = 1;
-    }
-    else
-    {
-      turns = city_turns_to_build(pcity, pcity->currently_building,
-                                 FALSE, TRUE);
+    } else {
       shield = pcity->shield_stock;
       max_shield = get_improvement_type(pcity->currently_building)->build_cost;
-
-      my_snprintf(buf, sizeof(buf),
-                 PL_("%3d/%3d %3d turn", "%3d/%3d %3d turns", turns),
-                 shield, max_shield, turns);
-
     }
 
-    sz_strlcpy(buf2, get_impr_name_ex(pcity, pcity->currently_building));
+    descr = get_impr_name_ex(pcity, pcity->currently_building);
   }
 
   if (!worklist_is_empty(pcity->worklist))
   {
-    my_snprintf(buf3, sizeof(buf3), _("%s (%s) (worklist)"), buf, buf2);
+    my_snprintf(buf2, sizeof(buf2), _("%s (%s) (worklist)"), buf, descr);
   } else
   {
-    my_snprintf(buf3, sizeof(buf3), "%s (%s)", buf, buf2);
+    my_snprintf(buf2, sizeof(buf2), "%s (%s)", buf, descr);
   }
 
-  DoMethod(pdialog->prod_gauge, MUIM_MyGauge_SetGauge, shield, max_shield, 
buf3);
+  DoMethod(pdialog->prod_gauge, MUIM_MyGauge_SetGauge,
+           shield, max_shield, buf2);
 }
 
 
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.14
diff -u -r1.14 citydlg.c
--- client/gui-win32/citydlg.c  2002/02/25 15:24:56     1.14
+++ client/gui-win32/citydlg.c  2002/02/27 02:06:53
@@ -399,51 +399,27 @@
 
 void city_dialog_update_building(struct city_dialog *pdialog)
 {
-  char buf3[100];
-  char buf[32], buf2[64];
+  char buf2[100], buf[32], *descr;
   int turns;
   struct city *pcity=pdialog->pcity;    
   
   EnableWindow(pdialog->buy_but,!pcity->did_buy);
   EnableWindow(pdialog->sell_but, !pcity->did_sell);
+
+  get_city_dialog_production(pcity, buf, sizeof(buf));
   
-  if (pcity->is_building_unit)
-    {
-      turns = city_turns_to_build (pcity, pcity->currently_building, TRUE, 
TRUE);
-      my_snprintf(buf, sizeof(buf),
-                 concise_city_production ? "%3d/%3d:%3d" :
-                 PL_("%3d/%3d %3d turn", "%3d/%3d %3d turns", turns),
-                 pcity->shield_stock,
-                 get_unit_type(pcity->currently_building)->build_cost,
-                 turns);
-    
-      sz_strlcpy(buf2, get_unit_type(pcity->currently_building)->name);  
+  if (pcity->is_building_unit) {
+    descr = get_unit_type(pcity->currently_building)->name;
+  } else {
+    if(pcity->currently_building==B_CAPITAL)  {
+      /* You can't buy Capitalization. */
+      EnableWindow(pdialog->buy_but,FALSE);
     }
-  else
-    {
-      if(pcity->currently_building==B_CAPITAL)  {
-       /* Capitalization is special, you can't buy it or finish making it */
-       my_snprintf(buf, sizeof(buf),
-                   concise_city_production ? "%3d/XXX:XXX" :
-                    _("%3d/XXX XXX turns"),
-                   pcity->shield_stock);
-       EnableWindow(pdialog->buy_but,FALSE);
-      }
-      else {
-       turns = city_turns_to_build (pcity, pcity->currently_building, FALSE, 
TRUE);
-       my_snprintf(buf, sizeof(buf),
-                   concise_city_production ? "%3d/%3d:%3d" :
-                   PL_("%3d/%3d %3d turn", "%3d/%3d %3d turns", turns),
-                   pcity->shield_stock,
-                   get_improvement_type(pcity->currently_building)->
-                   build_cost, turns);
-      }
-      sz_strlcpy(buf2, get_impr_name_ex(pcity, pcity->currently_building));
-    }
-  sz_strlcpy(buf3,buf2);
-  strcat(buf3,"\r\n");
-  strcat(buf3,buf);
-  SetWindowText(pdialog->build_area,buf3);
+    descr = get_impr_name_ex(pcity, pcity->currently_building);
+  }
+
+  snprintf(buf2, sizeof(buf2), "%s\r\n%s", descr, buf);
+  SetWindowText(pdialog->build_area, buf2);
   resize_city_dialog(pdialog);
   /* FIXME Worklists */
 }
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.67
diff -u -r1.67 citydlg.c
--- client/gui-xaw/citydlg.c    2002/02/26 17:47:57     1.67
+++ client/gui-xaw/citydlg.c    2002/02/27 02:06:59
@@ -285,34 +285,14 @@
                                     char *retbuf, int n)
 {
   struct city *pcity = pdialog ? pdialog->pcity : NULL;
-  int stock=0;
-  int cost=0;
-  int turns=0;
+  int len;
 
-  if (pcity) {
-    stock = pcity->shield_stock;
-    if(pcity->is_building_unit) {
-      cost = get_unit_type(pcity->currently_building)->build_cost;
-      turns = city_turns_to_build(pcity, pcity->currently_building,
-                                 TRUE, TRUE);
-    } else {
-      cost = get_improvement_type(pcity->currently_building)->build_cost;
-      turns = city_turns_to_build(pcity, pcity->currently_building,
-                                 FALSE, TRUE);
-    }
-  }
-
-  if (pcity && (pcity->currently_building==B_CAPITAL)) {
-    /* Capitalization is special, you can't buy it or finish making it */
-    my_snprintf(retbuf, n,
-               concise_city_production ? " %3d/XXX:XXX " :
-                 _(" %3d/XXX XXX turns "),
-               stock);
-  } else {
-    my_snprintf(retbuf, n,
-               concise_city_production ? " %3d/%3d:%3d " :
-               PL_(" %3d/%3d %3d turn ", " %3d/%3d %3d turns ", turns),
-               stock, cost, turns);
+  retbuf[0] = ' ';
+  get_city_dialog_production(pcity, retbuf + 1, n - 1);
+  len = strlen(retbuf);
+  if (len < n - 1) {
+    retbuf[len] = ' ';
+    retbuf[len+1] = '\0';
   }
 }
 

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