Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] cleanup to id_to_info_row (PR#1292)
Home

[Freeciv-Dev] cleanup to id_to_info_row (PR#1292)

[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] cleanup to id_to_info_row (PR#1292)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Sat, 2 Mar 2002 02:00:27 -0800 (PST)

The primary purpose of this patch is to add special-case handling for "999" turns to build for the id_to_info_row function (which is used to assemble worklist and production selection list entries in the city dialog for both GTK and Win32).

But in the process, I've done some other cleanups as well.  The changes are:

- I moved id_to_info_row out of common/city.[ch] and into client/citydlg_common.[ch], where it (more) rightfully belongs. AFAICT this function has no potential use on the server.

- I renamed it from id_to_info_row to get_city_dialog_production_row. Although much longer, this is somewhat more informative and is also consistent with the adjacent function get_city_dialog_production. I did _not_ change the order of the arguments, although this is inconsistent between the two functions: one has pcity listed first, the other lists it last.

- I slightly changed handling of the capitalization case. Now instead of being getting "---" for the turns to build it shows up as "N/turn", where N is the amount of gold produced per turn (note, this assumes a 1-1 shield-gold conversion).

- I slightly changed handling of the pcity=NULL case. I'm don't think this actually ever happens in practice, but when it does we set the turns to "---" now. Note, the turns-to-build was previously set to "---" for capitalization or "" for everything else in this (pcity==NULL) case.


Issues: the only issue I can see is that the "N/turn" or "never" entries could be too long for some languages. In English, they fit into the GTK Clist areas with about 33% of the room to spare. A workaround would be to translate both to "---" (although this might necessitate context-dependent strings for translating).

Xaw and Mui do not use this function; both assemble their text entries individually. Mui I can't quite figure out - I could change the code to use "never" when appropriate, but I doubt I could make any good structural changes. Xaw is pretty simple, but it shouldn't use this function in any case because it doesn't use a table-based layout; the entry is just one long string. However, I think this string should be assembled in client-common code also, perhaps in get_city_dialog_production_text() or some such (this would allow future guis to use the same assembly). Either way, it will be pretty easy to make the s/999/never/ change - which is preferred?

After these issues are taken care of, and the city report is dealt with (see other patch), all of the code should special-case the 999 handling. Then a simple patch can be introduced to s/999/FC_INFINITY/.

jason
? crash
? diff
? jason-game.gz
? t
? test-alt.pl
? test.pl
? topology
? client/annotate
? 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/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.4
diff -u -r1.4 citydlg_common.c
--- client/citydlg_common.c     2002/03/01 10:22:54     1.4
+++ client/citydlg_common.c     2002/03/02 09:53:41
@@ -144,3 +144,78 @@
     }
   }
 }
+
+
+/**************************************************************************
+ Pretty sprints the info about a production in 4 columns (name, info,
+ cost, turns to build). The columns must each have a size of
+ column_size bytes.
+**************************************************************************/
+void get_city_dialog_production_row(char *buf[], int column_size, int id,
+                                    bool is_unit, struct city *pcity)
+{
+  if (is_unit) {
+    struct unit_type *ptype;
+
+    my_snprintf(buf[0], column_size, unit_name(id));
+
+    /* from unit.h get_unit_name() */
+    ptype = get_unit_type(id);
+    if (ptype->fuel > 0) {
+      my_snprintf(buf[1], column_size, "%d/%d/%d(%d)",
+                 ptype->attack_strength, ptype->defense_strength,
+                 ptype->move_rate / 3,
+                 (ptype->move_rate / 3) * ptype->fuel);
+    } else {
+      my_snprintf(buf[1], column_size, "%d/%d/%d",
+                 ptype->attack_strength, ptype->defense_strength,
+                 ptype->move_rate / 3);
+    }
+    my_snprintf(buf[2], column_size, "%d", ptype->build_cost);
+  } else {
+    /* Total & turns left meaningless on capitalization */
+    if (id == B_CAPITAL) {
+      my_snprintf(buf[0], column_size, get_improvement_type(id)->name);
+      buf[1][0] = '\0';
+      my_snprintf(buf[2], column_size, "---");
+    } else {
+
+      my_snprintf(buf[0], column_size, get_improvement_type(id)->name);
+
+      /* from city.c get_impr_name_ex() */
+      if (pcity && wonder_replacement(pcity, id)) {
+       my_snprintf(buf[1], column_size, "*");
+      } else {
+       char *state = "";
+
+       if (is_wonder(id)) {
+         state = _("Wonder");
+         if (game.global_wonders[id] != 0)
+           state = _("Built");
+         if (wonder_obsolete(id))
+           state = _("Obsolete");
+       }
+       my_snprintf(buf[1], column_size, state);
+      }
+
+      my_snprintf(buf[2], column_size, "%d",
+                 get_improvement_type(id)->build_cost);
+    }
+  }
+
+  /* Add the turns-to-build entry in the 4th position */
+  if (pcity) {
+    if (!is_unit && id == B_CAPITAL) {
+      my_snprintf(buf[3], column_size, "%d/turn", pcity->shield_surplus);      
+    } else {
+      int turns = city_turns_to_build(pcity, id, is_unit, FALSE);
+      if (turns < 999) {
+        my_snprintf(buf[3], column_size, "%d", turns);
+      } else {
+        my_snprintf(buf[3], column_size, _("never"));
+      }
+    }
+  } else {
+    my_snprintf(buf[3], column_size, "---");
+  }
+}
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.2
diff -u -r1.2 citydlg_common.h
--- client/citydlg_common.h     2002/03/01 10:22:54     1.2
+++ client/citydlg_common.h     2002/03/02 09:53:41
@@ -21,5 +21,7 @@
 
 void get_city_dialog_production(struct city *pcity,
                                 char *buffer, size_t buffer_len);
+void get_city_dialog_production_row(char *buf[], int column_size, int id,
+                                    bool is_unit,  struct city *pcity);
 
 #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.127
diff -u -r1.127 citydlg.c
--- client/gui-gtk/citydlg.c    2002/03/01 10:22:55     1.127
+++ client/gui-gtk/citydlg.c    2002/03/02 09:53:42
@@ -3085,8 +3085,9 @@
     cid cid = items[item].cid;
     int row_no;
 
-    id_to_info_row(row, sizeof(buf[0]), cid_id(cid), cid_is_unit(cid),
-                  pdialog->pcity);
+    get_city_dialog_production_row(row, sizeof(buf[0]),
+                                  cid_id(cid), cid_is_unit(cid),
+                                  pdialog->pcity);
     row_no = gtk_clist_append(GTK_CLIST(pdialog->change_list), row);
     gtk_clist_set_row_data(GTK_CLIST(pdialog->change_list),
                           row_no, (gpointer) cid);
Index: client/gui-gtk/wldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/wldlg.c,v
retrieving revision 1.24
diff -u -r1.24 wldlg.c
--- client/gui-gtk/wldlg.c      2002/02/27 11:46:16     1.24
+++ client/gui-gtk/wldlg.c      2002/03/02 09:53:43
@@ -1316,8 +1316,9 @@
     }
     assert(!wid_is_worklist(wid));
 
-    id_to_info_row(row, BUFFER_SIZE, wid_id(wid), wid_is_unit(wid),
-                  peditor->pcity);
+    get_city_dialog_production_row(row, BUFFER_SIZE,
+                                   wid_id(wid), wid_is_unit(wid),
+                                   peditor->pcity);
     gtk_clist_append(GTK_CLIST(peditor->worklist), row);
   }
 
@@ -1372,8 +1373,9 @@
       my_snprintf(buf[2], BUFFER_SIZE, "---");
       my_snprintf(buf[3], BUFFER_SIZE, "---");
     } else {
-      id_to_info_row(row, BUFFER_SIZE, wid_id(wid), wid_is_unit(wid),
-                    peditor->pcity);
+      get_city_dialog_production_row(row, BUFFER_SIZE,
+                                     wid_id(wid), wid_is_unit(wid),
+                                     peditor->pcity);
     }
     gtk_clist_append(GTK_CLIST(peditor->avail), row);
   }
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.17
diff -u -r1.17 citydlg.c
--- client/gui-win32/citydlg.c  2002/03/01 10:22:56     1.17
+++ client/gui-win32/citydlg.c  2002/03/02 09:53:44
@@ -1138,7 +1138,8 @@
        
       for(i=0, n=0; i<game.num_impr_types; i++)
        if(can_build_improvement(pdialog->pcity, i)) {
-         id_to_info_row(row, sizeof(buf[0]), i, FALSE, pdialog->pcity);
+         get_city_dialog_production_row(row, sizeof(buf[0]), i,
+                                        FALSE, pdialog->pcity);
          fcwin_listview_add_row(lv,n,4,row);
          pdialog->change_list_ids[n++]=i;
        }
@@ -1147,7 +1148,8 @@
       
       for(i=0; i<game.num_unit_types; i++)
        if(can_build_unit(pdialog->pcity, i)) {
-         id_to_info_row(row, sizeof(buf[0]), i, TRUE, pdialog->pcity);
+         get_city_dialog_production_row(row, sizeof(buf[0]), i,
+                                        TRUE, pdialog->pcity);
          fcwin_listview_add_row(lv,n,4,row);
          pdialog->change_list_ids[n++]=i;
        }
Index: client/gui-win32/wldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/wldlg.c,v
retrieving revision 1.6
diff -u -r1.6 wldlg.c
--- client/gui-win32/wldlg.c    2002/02/27 11:46:18     1.6
+++ client/gui-win32/wldlg.c    2002/03/02 09:53:44
@@ -862,8 +862,9 @@
     }
     assert(!wid_is_worklist(wid));
 
-    id_to_info_row(row, BUFFER_SIZE, wid_id(wid), wid_is_unit(wid),
-                   peditor->pcity);
+    get_city_dialog_production_row(row, BUFFER_SIZE,
+                                   wid_id(wid), wid_is_unit(wid),
+                                   peditor->pcity);
     fcwin_listview_add_row(peditor->worklist,i,COLUMNS,row);
   }
   
@@ -917,8 +918,9 @@
       my_snprintf(buf[2], BUFFER_SIZE, "---");
       my_snprintf(buf[3], BUFFER_SIZE, "---");
     } else {
-      id_to_info_row(row, BUFFER_SIZE, wid_id(wid), wid_is_unit(wid),
-                     peditor->pcity);
+      get_city_dialog_production_row(row, BUFFER_SIZE,
+                                     wid_id(wid), wid_is_unit(wid),
+                                     peditor->pcity);
     }
     fcwin_listview_add_row(peditor->avail,i,COLUMNS,row);
   }
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.152
diff -u -r1.152 city.c
--- common/city.c       2002/02/26 17:13:34     1.152
+++ common/city.c       2002/03/02 09:53:45
@@ -1371,78 +1371,6 @@
     (game.rgame.granary_food_inc * city_size * game.foodbox) / 100;
 }
 
-/****************************************************************
- Pretty sprints the info about a production in 4 columns (name, info,
- cost, turns to build). The columns must each have a size of
- column_size bytes.
-*****************************************************************/
-void id_to_info_row(char *buf[], int column_size, int id, bool is_unit,
-                   struct city *pcity)
-{
-  if (is_unit) {
-    struct unit_type *ptype;
-
-    my_snprintf(buf[0], column_size, unit_name(id));
-
-    /* from unit.h get_unit_name() */
-    ptype = get_unit_type(id);
-    if (ptype->fuel > 0) {
-      my_snprintf(buf[1], column_size, "%d/%d/%d(%d)",
-                 ptype->attack_strength, ptype->defense_strength,
-                 ptype->move_rate / 3,
-                 (ptype->move_rate / 3) * ptype->fuel);
-    } else {
-      my_snprintf(buf[1], column_size, "%d/%d/%d",
-                 ptype->attack_strength, ptype->defense_strength,
-                 ptype->move_rate / 3);
-    }
-    my_snprintf(buf[2], column_size, "%d", ptype->build_cost);
-
-    if (pcity) {
-      my_snprintf(buf[3], column_size, "%d",
-                 city_turns_to_build(pcity, id, TRUE, FALSE));
-    } else {
-      buf[3][0] = 0;
-    }
-  } else {
-    /* Total & turns left meaningless on capitalization */
-    if (id == B_CAPITAL) {
-      my_snprintf(buf[0], column_size, get_improvement_type(id)->name);
-      buf[1][0] = '\0';
-      my_snprintf(buf[2], column_size, "---");
-      my_snprintf(buf[3], column_size, "---");
-    } else {
-
-      my_snprintf(buf[0], column_size, get_improvement_type(id)->name);
-
-      /* from city.c get_impr_name_ex() */
-      if (pcity && wonder_replacement(pcity, id)) {
-       my_snprintf(buf[1], column_size, "*");
-      } else {
-       char *state = "";
-
-       if (is_wonder(id)) {
-         state = _("Wonder");
-         if (game.global_wonders[id] != 0)
-           state = _("Built");
-         if (wonder_obsolete(id))
-           state = _("Obsolete");
-       }
-       my_snprintf(buf[1], column_size, state);
-      }
-
-      my_snprintf(buf[2], column_size, "%d",
-                 get_improvement_type(id)->build_cost);
-      if (pcity) {
-       my_snprintf(buf[3], column_size, "%d",
-                   city_turns_to_build(pcity, id, FALSE, FALSE));
-      } else {
-       buf[3][0] = 0;
-      }
-    }
-  }
-}
-
 /**************************************************************************
 v 1.0j code was too rash, only first penalty now!
 **************************************************************************/
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.103
diff -u -r1.103 city.h
--- common/city.h       2002/02/27 11:46:19     1.103
+++ common/city.h       2002/03/02 09:53:46
@@ -435,9 +435,6 @@
 /* granary size as a function of city size */
 int city_granary_size(int city_size);
 
-void id_to_info_row(char *buf[], int column_size, int id, bool is_unit,
-                   struct city *pcity);
-
 void city_add_improvement(struct city *pcity,Impr_Type_id impr);
 void city_remove_improvement(struct city *pcity,Impr_Type_id impr);
 

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