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

[Freeciv-Dev] 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] don't show "999" as the city turns to build (PR#1283)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Mon, 25 Feb 2002 10:50:10 -0800 (PST)

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.

jason
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 18:47:38
@@ -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, int 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 < 999) {
+      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 < 999) {
+      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 18:47:38
@@ -62,4 +62,7 @@
                                
 struct city *find_city_near_tile(int x, int y);
 
+void get_city_mapview_production(struct city *pcity,
+                                 char *buf, int 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 18:47:40
@@ -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 18:47:43
@@ -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 18:47:44
@@ -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 18:47:45
@@ -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,

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