Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: [patch] "turns-to-grow" on the map overview
Home

[Freeciv-Dev] Re: [patch] "turns-to-grow" on the map overview

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [patch] "turns-to-grow" on the map overview
From: Jason Short <vze2zq63@xxxxxxxxxxx>
Date: Mon, 04 Mar 2002 15:37:48 -0500
Reply-to: jdorje@xxxxxxxxxxxx

Raimar Falke wrote:
On Mon, Mar 04, 2002 at 03:05:08PM -0500, Jason Short wrote:

Raimar Falke wrote:

On Mon, Mar 04, 2002 at 07:21:31AM -0500, Jason Short wrote:


Civ III shows the city's "turns-to-grow" on the map overview, like:

   XXX
   XXX   <-- city
   XXX
 CityName 5
SomeProduction 7

where 5 is the turns-to-grow and 7 the turns-to-build. The only way this really differs from freeciv is that the turns-to-build is shown. I found it very helpful to see.

Here's a patch that adds this feature to freeciv by adding a new function, get_city_mapview_name, to mapview_common, and changing the GUI code to use it.

I also introduce a new function, city_turns_to_grow, in common/city.[ch], and change the GTK city dialog to use it. I've changed the xaw and gtk frontends.


Issues:

- It's controled by the draw_city_productions option (of course, draw_city_names must also be enabled). This is better than nothing IMO, but still not ideal.


An extra option?

Most likely, yes.  But first it should be supported by all GUI's, right?


By default should things be implemented for all GUIs.

Yes, but doing so in one patch is probably a bad idea, since I can only compile half of the GUIs.

- Shrinking cities are a bit tricky. In the GTK citydlg, they're shown in red to symbolize the shrinking. With the mapview as a backdrop, this wouldn't work so well (it would also require lots of gui-specific code). So instead I use [N] for a city that will _shrink_ in N turns.

- Differentiating blocked and never-growing cities is a bit tricky. I use "X" for blocked cities and "-" for never-growing ones. (I believe CivIII just used "-" for both.)

- The city names are drawn in a bigger font than the city productions. This is a bit odd when the growth is included in the city name.

- Since city names can have numbers in them, this could get a bit confusing. For instance we could have "Paris 2" (Paris, 2 turns to grow) and "Paris 2 -" (Paris 2, no growth).


It is possible to use another font for this one. We already do some
width and height calculations. If the grow string is drawn separately
it is also not a problem to use a different color.

Well, I couldn't figure out how to do red with the GTK-client.


   gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_RED]);

Very nice (new patch attached).  Now to do this for the other 3 GUIs...

This change significantly enhances playability IMO.

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/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.128
diff -u -r1.128 citydlg.c
--- client/gui-gtk/citydlg.c    2002/03/04 09:01:15     1.128
+++ client/gui-gtk/citydlg.c    2002/03/04 20:33:34
@@ -1711,27 +1711,23 @@
 
   my_snprintf(buf[SCIENCE], sizeof(buf[SCIENCE]), "%2d",
              pcity->science_total);
+       
 
-  if (pcity->food_surplus > 0) {
-    granaryturns = (city_granary_size(pcity->size) - pcity->food_stock +
-                   pcity->food_surplus - 1) / pcity->food_surplus;
-  } else if (pcity->food_surplus < 0) {
-    granaryturns = 1 - (pcity->food_stock / pcity->food_surplus);
-    /* turns before famine loss */
-  } else {
-    granaryturns = 999;
-  }
-
   my_snprintf(buf[GRANARY], sizeof(buf[GRANARY]), "%d/%-d",
              pcity->food_stock, city_granary_size(pcity->size));
+       
+  granaryturns = city_turns_to_grow(pcity);
   if (granaryturns == 0) {
     my_snprintf(buf[GROWTH], sizeof(buf[GROWTH]), "blocked");
-  } else if (granaryturns == 999) {
+  } else if (granaryturns == FC_INFINITY) {
     my_snprintf(buf[GROWTH], sizeof(buf[GROWTH]), "never");
   } else {
+    /* A negative value means we'll have famine in that many turns.
+       But that's handled down below. */
     my_snprintf(buf[GROWTH], sizeof(buf[GROWTH]),
-               PL_("%d turn", "%d turns", granaryturns), granaryturns);
+               PL_("%d turn", "%d turns", abs(granaryturns)), 
abs(granaryturns));
   }
+
   my_snprintf(buf[CORRUPTION], sizeof(buf[CORRUPTION]), "%2d",
              pcity->corruption);
   my_snprintf(buf[POLLUTION], sizeof(buf[POLLUTION]), "%2d",
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.121
diff -u -r1.121 mapview.c
--- client/gui-gtk/mapview.c    2002/03/02 23:47:54     1.121
+++ client/gui-gtk/mapview.c    2002/03/04 20:33:36
@@ -1328,7 +1328,7 @@
 **************************************************************************/
 static void show_desc_at_tile(int x, int y)
 {
-  static char buffer[512];
+  static char buffer[512], buffer2[32];
   struct city *pcity;
   if ((pcity = map_get_city(x, y))) {
     int canvas_x, canvas_y;
@@ -1336,14 +1336,51 @@
 
     get_canvas_xy(x, y, &canvas_x, &canvas_y);
     if (draw_city_names) {
-      my_snprintf(buffer, sizeof(buffer), "%s", pcity->name);
+      int turns = 0, w2 = 0;
+      int draw_city_growth = draw_city_productions && pcity->owner == 
game.player_idx;
+
+      my_snprintf(buffer, sizeof(buffer),
+                  draw_city_productions ? "%s " : "%s", pcity->name);
       w = gdk_string_width(main_font, buffer);
+
+      if (draw_city_growth) {
+        turns = city_turns_to_grow(pcity);
+        if (turns == 0) {
+          snprintf(buffer2, sizeof(buffer2), "X");
+        } else if (turns == FC_INFINITY) {
+          snprintf(buffer2, sizeof(buffer2), "-");
+        } else {
+          /* Negative turns means we're shrinking, but that's handled
+             down below. */
+          snprintf(buffer2, sizeof(buffer2), "%d", abs(turns));
+        }
+
+        w2 = gdk_string_width(city_productions_font, buffer2);
+      }
+
       draw_shadowed_string(map_canvas->window, main_font,
                           toplevel->style->black_gc,
                           toplevel->style->white_gc,
-                          canvas_x + NORMAL_TILE_WIDTH / 2 - w / 2,
+                          canvas_x + NORMAL_TILE_WIDTH / 2 - (w + w2) / 2,
                           canvas_y + NORMAL_TILE_HEIGHT +
                           main_font->ascent, buffer);
+               
+      if (draw_city_growth) {
+        if (turns <= 0) {
+          /* A blocked or shrinking city has its growth status shown in red. */
+          gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_RED]);
+        } else {
+          gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_WHITE]);
+        }
+
+        draw_shadowed_string(map_canvas->window, city_productions_font,
+                             toplevel->style->black_gc,
+                             civ_gc,
+                             canvas_x + NORMAL_TILE_WIDTH / 2 - (w + w2) / 2 + 
w,
+                             canvas_y + NORMAL_TILE_HEIGHT + main_font->ascent,
+                             buffer2);
+      }
+
     }
 
     if (draw_city_productions && (pcity->owner==game.player_idx)) {
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.153
diff -u -r1.153 city.c
--- common/city.c       2002/03/04 09:01:17     1.153
+++ common/city.c       2002/03/04 20:33:39
@@ -1266,6 +1266,25 @@
 }
 
 /**************************************************************************
+ Calculates the turns which are needed for the city to grow.  A value of
+ FC_INFINITY means the city will never grow.  A value of 0 means city
+ growth is blocked.  A negative value of -x means the city will shrink in
+ x turns.  A positive value of x means the city will grow in x turns.
+**************************************************************************/
+int city_turns_to_grow(struct city *pcity)
+{
+  if (pcity->food_surplus > 0) {
+    return (city_granary_size(pcity->size) - pcity->food_stock +
+                   pcity->food_surplus - 1) / pcity->food_surplus;
+  } else if (pcity->food_surplus < 0) {
+    /* turns before famine loss */
+    return -1 + (pcity->food_stock / pcity->food_surplus);
+  } else {
+    return FC_INFINITY;
+  }
+}
+
+/**************************************************************************
  is there an enemy city on this tile?
 **************************************************************************/
 struct city *is_enemy_city_tile(struct tile *ptile, struct player *pplayer)
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.104
diff -u -r1.104 city.h
--- common/city.h       2002/03/04 09:01:17     1.104
+++ common/city.h       2002/03/04 20:33:39
@@ -347,6 +347,7 @@
                                   int target, bool is_unit, bool apply_it);
 int city_turns_to_build(struct city *pcity, int id, bool id_is_unit,
                         bool include_shield_stock );
+int city_turns_to_grow(struct city *pcity);
 
 /* textual representation of buildings */
 

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