[Freeciv-Dev] [patch] "turns-to-grow" on the map overview
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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.
- 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).
- City descriptions aren't updated when citizens are moved around. This
is probably related to the bug whereby the mapview isn't updated when
citizens are moved around (so if you have the city grid shown, it won't
be updated).
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/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.11
diff -u -r1.11 mapview_common.c
--- client/mapview_common.c 2002/02/26 19:57:08 1.11
+++ client/mapview_common.c 2002/03/04 11:56:53
@@ -23,6 +23,7 @@
#include "mapview_g.h"
#include "mapview_common.h"
+#include "options.h" /* for draw_city_productions */
#include "tilespec.h"
/**************************************************************************
@@ -314,6 +315,30 @@
/* rule e */
last_pcity = pcity2;
return pcity2;
+}
+
+/**************************************************************************
+ Find the mapview city name text for the given city, and place it into
+ the buffer. (The "name" may also contain the turns-to-grow as well.)
+**************************************************************************/
+void get_city_mapview_name(struct city *pcity,
+ char *buffer, size_t buffer_len)
+{
+ if (draw_city_productions) {
+ int turns = city_turns_to_grow(pcity);
+
+ if (turns < 0) {
+ my_snprintf(buffer, buffer_len, "%s [%d]", pcity->name, -turns);
+ } else if (turns == 0) {
+ my_snprintf(buffer, buffer_len, "%s X", pcity->name);
+ } else if (turns < FC_INFINITY) {
+ my_snprintf(buffer, buffer_len, "%s %d", pcity->name, turns);
+ } else {
+ my_snprintf(buffer, buffer_len, "%s -", pcity->name);
+ }
+ } else {
+ my_snprintf(buffer, buffer_len, "%s", pcity->name);
+ }
}
/**************************************************************************
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.5
diff -u -r1.5 mapview_common.h
--- client/mapview_common.h 2002/02/26 10:27:37 1.5
+++ client/mapview_common.h 2002/03/04 11:56:53
@@ -62,6 +62,8 @@
struct city *find_city_near_tile(int x, int y);
+void get_city_mapview_name(struct city *pcity,
+ char *buffer, size_t buffer_len);
void get_city_mapview_production(struct city *pcity,
char *buf, size_t buf_len);
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 11:56:54
@@ -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 11:56:55
@@ -1336,7 +1336,7 @@
get_canvas_xy(x, y, &canvas_x, &canvas_y);
if (draw_city_names) {
- my_snprintf(buffer, sizeof(buffer), "%s", pcity->name);
+ get_city_mapview_name(pcity, buffer, sizeof(buffer));
w = gdk_string_width(main_font, buffer);
draw_shadowed_string(map_canvas->window, main_font,
toplevel->style->black_gc,
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.95
diff -u -r1.95 mapview.c
--- client/gui-xaw/mapview.c 2002/02/26 10:27:41 1.95
+++ client/gui-xaw/mapview.c 2002/03/04 11:56:56
@@ -786,10 +786,12 @@
if((pcity=map_get_city(rx, ry))) {
if (draw_city_names) {
+ char buffer[512];
+ get_city_mapview_name(pcity, buffer, sizeof(buffer));
draw_shadowed_string(main_font_struct, font_gc,
x*NORMAL_TILE_WIDTH+NORMAL_TILE_WIDTH/2,
(y+1)*NORMAL_TILE_HEIGHT,
- pcity->name);
+ buffer);
}
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 11:56:57
@@ -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 11:56:57
@@ -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 */
- [Freeciv-Dev] [patch] "turns-to-grow" on the map overview,
Jason Short <=
|
|