Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10293) more descriptive menu text when changing terrai
Home

[Freeciv-Dev] (PR#10293) more descriptive menu text when changing terrai

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10293) more descriptive menu text when changing terrains
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 23 Sep 2004 20:04:32 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10293 >

When you change terrain (through irrigate, mining, or transform) the 
menu text says something like "Change to plains (I)".  When there are 
specials involved the special type is preserved, but through the 
bad-but-better-than-the-alternatives method is changed into the special 
for the new type.  However there's no way to know this from the menu 
text.  This patch changes it to give the "full" tile text, so the above 
could instead be "Change to plains (grassland/wheat) (I)".  Much more 
informative.  (Knowing that the river is preserved is unnecessary but 
harmless.)

This patch supports gui-gtk-2.0 only.  If other GUIs want to use it the 
function could be moved into text.c.

jason

? new
? orig
? common/output
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.40
diff -u -r1.40 menu.c
--- client/gui-gtk-2.0/menu.c   18 Sep 2004 17:47:28 -0000      1.40
+++ client/gui-gtk-2.0/menu.c   24 Sep 2004 03:00:16 -0000
@@ -1069,6 +1069,50 @@
   set_government_choice(GPOINTER_TO_INT(data));
 }
 
+/****************************************************************************
+  Return the text for the tile, changed by the activity.
+
+  Should only be called for irrigation, mining, or transformation, and
+  only when the activity changes the base terrain type.
+****************************************************************************/
+static const char *get_tile_change_menu_text(int x, int y,
+                                            enum unit_activity activity)
+{
+  struct tile *ptile = map_get_tile(x, y);
+  Terrain_type_id old_terrain = ptile->terrain;
+  struct tile_type *ptype = get_tile_type(ptile->terrain);
+  const char *text;
+
+  /* Change the terrain manually to avoid any side effects. */
+  switch (activity) {
+  case ACTIVITY_IRRIGATE:
+    assert(ptype->irrigation_result != ptile->terrain
+          && ptype->irrigation_result != T_NONE);
+    ptile->terrain = ptype->irrigation_result;
+    break;
+  case ACTIVITY_MINE:
+    assert(ptype->mining_result != ptile->terrain
+          && ptype->mining_result != T_NONE);
+    ptile->terrain = ptype->mining_result;
+    break;
+
+  case ACTIVITY_TRANSFORM:
+    assert(ptype->transform_result != ptile->terrain
+          && ptype->transform_result != T_NONE);
+    ptile->terrain = ptype->transform_result;
+    break;
+  default:
+    assert(0);
+    return "-";
+  }
+
+  text = map_get_tile_info_text(x, y);
+
+  ptile->terrain = old_terrain;
+
+  return text;
+}
+
 /****************************************************************
 Note: the menu strings should contain underscores as in the
 menu_items struct. The underscores will be removed elsewhere if
@@ -1294,7 +1338,8 @@
       if (tinfo->irrigation_result != T_NONE
          && tinfo->irrigation_result != ttype) {
        my_snprintf(irrtext, sizeof(irrtext), irrfmt,
-                   (get_tile_type(tinfo->irrigation_result))->terrain_name);
+                   get_tile_change_menu_text(punit->x, punit->y,
+                                             ACTIVITY_IRRIGATE));
       } else if (map_has_special(punit->x, punit->y, S_IRRIGATION)
                 && player_knows_techs_with_flag(game.player_ptr,
                                                 TF_FARMLAND)) {
@@ -1303,12 +1348,14 @@
       if (tinfo->mining_result != T_NONE
          && tinfo->mining_result != ttype) {
        my_snprintf(mintext, sizeof(mintext), minfmt,
-                   (get_tile_type(tinfo->mining_result))->terrain_name);
+                   get_tile_change_menu_text(punit->x, punit->y,
+                                             ACTIVITY_MINE));
       }
       if (tinfo->transform_result != T_NONE
          && tinfo->transform_result != ttype) {
        my_snprintf(transtext, sizeof(transtext), transfmt,
-                   (get_tile_type(tinfo->transform_result))->terrain_name);
+                   get_tile_change_menu_text(punit->x, punit->y,
+                                             ACTIVITY_TRANSFORM));
       }
 
       menus_rename("<main>/_Orders/Build _Irrigation", irrtext);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#10293) more descriptive menu text when changing terrains, Jason Short <=