Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12938) move tile-info functions out of map.h
Home

[Freeciv-Dev] (PR#12938) move tile-info functions out of map.h

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12938) move tile-info functions out of map.h
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 29 Apr 2005 19:35:07 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12938 >

This patch moves two functions out of map.[ch].

map_get_tile_info_text is moved into tile.[ch] and renamed as
tile_get_info_text.

map_get_tile_fpt_text is moved into client/text.[ch], renamed as
get_tile_output_text, and changed to use the text.c INIT/RETURN form.

Both functions are tile-specific.  The second one is rather trivial and
only used by the client.

-jason

Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.35
diff -u -r1.35 text.c
--- client/text.c       29 Apr 2005 18:39:25 -0000      1.35
+++ client/text.c       30 Apr 2005 02:26:45 -0000
@@ -126,6 +126,21 @@
 }
 
 /****************************************************************************
+  Return a (static) string with a tile's food/prod/trade
+****************************************************************************/
+const char *get_tile_output_text(const struct tile *ptile)
+{
+  INIT;
+  
+  add_line("%d/%d/%d",
+          get_output_tile(ptile, O_FOOD),
+          get_output_tile(ptile, O_SHIELD),
+          get_output_tile(ptile, O_TRADE));
+
+  RETURN;
+}
+
+/****************************************************************************
   Text to popup on a middle-click in the mapview.
 ****************************************************************************/
 const char *popup_info_text(struct tile *ptile)
@@ -149,9 +164,9 @@
   add_line(_("Location: (%d, %d) [%d]"), 
           ptile->x, ptile->y, ptile->continent); 
 #endif /*DEBUG*/
-  add_line(_("Terrain: %s"),  map_get_tile_info_text(ptile));
+  add_line(_("Terrain: %s"),  tile_get_info_text(ptile));
   add_line(_("Food/Prod/Trade: %s"),
-          map_get_tile_fpt_text(ptile));
+          get_tile_output_text(ptile));
   if (tile_has_special(ptile, S_HUT)) {
     add_line(_("Minor Tribe Village"));
   }
@@ -562,7 +577,7 @@
       add_line("%s", unit_activity_text(punit));
     }
 
-    add_line("%s", map_get_tile_info_text(punit->tile));
+    add_line("%s", tile_get_info_text(punit->tile));
     if (infrastructure) {
       add_line("%s", get_infrastructure_text(infrastructure));
     } else {
Index: client/text.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.h,v
retrieving revision 1.10
diff -u -r1.10 text.h
--- client/text.h       13 Apr 2005 01:59:20 -0000      1.10
+++ client/text.h       30 Apr 2005 02:26:45 -0000
@@ -21,6 +21,7 @@
 /****************************************************************************
   These functions return static strings with generally useful text.
 ****************************************************************************/
+const char *get_tile_output_text(const struct tile *ptile);
 const char *popup_info_text(struct tile *ptile);
 const char *concat_tile_activity_text(struct tile *ptile);
 const char *get_nearest_city_text(struct city *pcity, int sq_dist);
Index: client/gui-ftwl/gui_text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/gui_text.c,v
retrieving revision 1.8
diff -u -r1.8 gui_text.c
--- client/gui-ftwl/gui_text.c  29 Apr 2005 18:39:25 -0000      1.8
+++ client/gui-ftwl/gui_text.c  30 Apr 2005 02:26:45 -0000
@@ -141,7 +141,7 @@
   add_line(_("Location: (%d, %d) [%d]"),
           ptile->x, ptile->y, ptile->continent);
 #endif
-  add_line("%s", map_get_tile_info_text(ptile));
+  add_line("%s", tile_get_info_text(ptile));
   if (infrastructure) {
     add_line("%s",
             get_infrastructure_text(infrastructure));
@@ -381,9 +381,9 @@
   INIT;
 
   add_line(_("Terrain: %s"),
-          map_get_tile_info_text(ptile));
+          tile_get_info_text(ptile));
   add_line(_("Food/Prod/Trade: %s"),
-          map_get_tile_fpt_text(ptile));
+          get_tile_output_text(ptile));
   if (tile_has_special(ptile, S_HUT)) {
     add_line(_("Minor Tribe Village"));
   }
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.74
diff -u -r1.74 menu.c
--- client/gui-gtk-2.0/menu.c   29 Apr 2005 17:39:28 -0000      1.74
+++ client/gui-gtk-2.0/menu.c   30 Apr 2005 02:26:45 -0000
@@ -1191,7 +1191,7 @@
     return "-";
   }
 
-  text = map_get_tile_info_text(ptile);
+  text = tile_get_info_text(ptile);
 
   /* Restore the original state of the tile. */
   ptile->terrain = old_terrain;
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.110
diff -u -r1.110 mapclass.c
--- client/gui-mui/mapclass.c   29 Apr 2005 18:39:25 -0000      1.110
+++ client/gui-mui/mapclass.c   30 Apr 2005 02:26:46 -0000
@@ -99,7 +99,7 @@
     if (obj)
     {
       Object *text_obj;
-      my_snprintf(s, sizeof(s), _("Terrain: %s"), 
map_get_tile_info_text(xtile, ytile));
+      my_snprintf(s, sizeof(s), _("Terrain: %s"), tile_get_info_text(xtile, 
ytile));
       text_obj = TextObject, MUIA_Text_Contents, s, End;
       DoMethod(group, OM_ADDMEMBER, text_obj);
 
@@ -1634,7 +1634,7 @@
        else if (punit)
          my_snprintf(title, sizeof(title), _("Unit %s"), 
unit_name(punit->type));
        else
-         my_snprintf(title, sizeof(title), _("Tile %s"), 
map_get_tile_info_text(x, y));
+         my_snprintf(title, sizeof(title), _("Tile %s"), tile_get_info_text(x, 
y));
 
        context_menu = MenustripObject,
          Child, menu_title = MenuObjectT(title),
Index: client/gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.72
diff -u -r1.72 mapview.c
--- client/gui-mui/mapview.c    28 Mar 2005 16:59:14 -0000      1.72
+++ client/gui-mui/mapview.c    30 Apr 2005 02:26:46 -0000
@@ -245,7 +245,7 @@
     settextf(main_unitname_text, "%s%s", unit_type(punit)->name,
             (punit->veteran) ? _(" (veteran)") : "");
     settext(main_moves_text, (hover_unit == punit->id) ? _("Select 
destination") : unit_activity_text(punit));
-    settext(main_terrain_text, map_get_tile_info_text(punit->tile));
+    settext(main_terrain_text, tile_get_info_text(punit->tile));
     settext(main_hometown_text, pcity ? pcity->name : "");
 
 
Index: client/gui-sdl/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/dialogs.c,v
retrieving revision 1.58
diff -u -r1.58 dialogs.c
--- client/gui-sdl/dialogs.c    29 Apr 2005 18:39:25 -0000      1.58
+++ client/gui-sdl/dialogs.c    30 Apr 2005 02:26:46 -0000
@@ -907,7 +907,7 @@
   
     my_snprintf(cBuf, sizeof(cBuf), _("Terrain: %s\nFood/Prod/Trade: %s\n%s"),
                sdl_map_get_tile_info_text(pTile),
-               map_get_tile_fpt_text(x, y),
+               get_tile_output_text(x, y),
                sdl_get_tile_defense_info_text(pTile));
         
     if (tile_has_special(pTile, S_HUT))
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.85
diff -u -r1.85 mapview.c
--- client/gui-sdl/mapview.c    29 Apr 2005 18:39:26 -0000      1.85
+++ client/gui-sdl/mapview.c    30 Apr 2005 02:26:47 -0000
@@ -708,7 +708,7 @@
                
        if (pInfo_Window->size.h > 4 * h + DEFAULT_UNITS_H || right) {
           cat_snprintf(buffer, sizeof(buffer), _("\nFood/Prod/Trade: %s"),
-                               map_get_tile_fpt_text(pUnit->x, pUnit->y));
+                               get_tile_output_text(pUnit->x, pUnit->y));
        }
        
        copy_chars_to_string16(pStr, buffer);
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.222
diff -u -r1.222 map.c
--- common/map.c        29 Apr 2005 18:39:26 -0000      1.222
+++ common/map.c        30 Apr 2005 02:26:47 -0000
@@ -66,86 +66,6 @@
 }
 
 /***************************************************************
-  Return a (static) string with terrain name;
-  eg: "Hills"
-  eg: "Hills (Coals)"
-  eg: "Hills (Coals) [Pollution]"
-***************************************************************/
-const char *map_get_tile_info_text(const struct tile *ptile)
-{
-  static char s[64];
-  bool first;
-
-  sz_strlcpy(s, tile_types[ptile->terrain].terrain_name);
-  if (tile_has_special(ptile, S_RIVER)) {
-    sz_strlcat(s, "/");
-    sz_strlcat(s, get_special_name(S_RIVER));
-  }
-
-  first = TRUE;
-  if (tile_has_special(ptile, S_SPECIAL_1)) {
-    if (first) {
-      first = FALSE;
-      sz_strlcat(s, " (");
-    } else {
-      sz_strlcat(s, "/");
-    }
-    sz_strlcat(s, tile_types[ptile->terrain].special[0].name);
-  }
-  if (tile_has_special(ptile, S_SPECIAL_2)) {
-    if (first) {
-      first = FALSE;
-      sz_strlcat(s, " (");
-    } else {
-      sz_strlcat(s, "/");
-    }
-    sz_strlcat(s, tile_types[ptile->terrain].special[1].name);
-  }
-  if (!first) {
-    sz_strlcat(s, ")");
-  }
-
-  first = TRUE;
-  if (tile_has_special(ptile, S_POLLUTION)) {
-    if (first) {
-      first = FALSE;
-      sz_strlcat(s, " [");
-    } else {
-      sz_strlcat(s, "/");
-    }
-    sz_strlcat(s, get_special_name(S_POLLUTION));
-  }
-  if (tile_has_special(ptile, S_FALLOUT)) {
-    if (first) {
-      first = FALSE;
-      sz_strlcat(s, " [");
-    } else {
-      sz_strlcat(s, "/");
-    }
-    sz_strlcat(s, get_special_name(S_FALLOUT));
-  }
-  if (!first) {
-    sz_strlcat(s, "]");
-  }
-
-  return s;
-}
-
-/***************************************************************
-  Return a (static) string with a tile's food/prod/trade
-***************************************************************/
-const char *map_get_tile_fpt_text(const struct tile *ptile)
-{
-  static char s[64];
-  
-  my_snprintf(s, sizeof(s), "%d/%d/%d",
-             get_output_tile(ptile, O_FOOD),
-             get_output_tile(ptile, O_SHIELD),
-             get_output_tile(ptile, O_TRADE));
-  return s;
-}
-
-/***************************************************************
   Returns 1 if we are at a stage of the game where the map
   has not yet been generated/loaded.
   (To be precise, returns 1 if map_allocate() has not yet been
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.244
diff -u -r1.244 map.h
--- common/map.h        29 Apr 2005 18:39:26 -0000      1.244
+++ common/map.h        30 Apr 2005 02:26:47 -0000
@@ -117,9 +117,6 @@
 void map_allocate(void);
 void map_free(void);
 
-const char *map_get_tile_info_text(const struct tile *ptile);
-const char *map_get_tile_fpt_text(const struct tile *ptile);
-
 int map_vector_to_real_distance(int dx, int dy);
 int map_vector_to_sq_distance(int dx, int dy);
 int map_distance(const struct tile *tile0, const struct tile *tile1);
Index: common/tile.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.c,v
retrieving revision 1.3
diff -u -r1.3 tile.c
--- common/tile.c       29 Apr 2005 17:39:29 -0000      1.3
+++ common/tile.c       30 Apr 2005 02:26:48 -0000
@@ -17,6 +17,8 @@
 
 #include <assert.h>
 
+#include "support.h"
+
 #include "tile.h"
 
 /****************************************************************************
@@ -273,3 +275,71 @@
     tile_change_terrain(ptile, result);
   }
 }
+
+/****************************************************************************
+  Return a (static) string with tile name describing terrain and specials.
+
+  Examples:
+    "Hills"
+    "Hills (Coals)"
+    "Hills (Coals) [Pollution]"
+****************************************************************************/
+const char *tile_get_info_text(const struct tile *ptile)
+{
+  static char s[256];
+  bool first;
+
+  sz_strlcpy(s, tile_types[ptile->terrain].terrain_name);
+  if (tile_has_special(ptile, S_RIVER)) {
+    sz_strlcat(s, "/");
+    sz_strlcat(s, get_special_name(S_RIVER));
+  }
+
+  first = TRUE;
+  if (tile_has_special(ptile, S_SPECIAL_1)) {
+    if (first) {
+      first = FALSE;
+      sz_strlcat(s, " (");
+    } else {
+      sz_strlcat(s, "/");
+    }
+    sz_strlcat(s, tile_types[ptile->terrain].special[0].name);
+  }
+  if (tile_has_special(ptile, S_SPECIAL_2)) {
+    if (first) {
+      first = FALSE;
+      sz_strlcat(s, " (");
+    } else {
+      sz_strlcat(s, "/");
+    }
+    sz_strlcat(s, tile_types[ptile->terrain].special[1].name);
+  }
+  if (!first) {
+    sz_strlcat(s, ")");
+  }
+
+  first = TRUE;
+  if (tile_has_special(ptile, S_POLLUTION)) {
+    if (first) {
+      first = FALSE;
+      sz_strlcat(s, " [");
+    } else {
+      sz_strlcat(s, "/");
+    }
+    sz_strlcat(s, get_special_name(S_POLLUTION));
+  }
+  if (tile_has_special(ptile, S_FALLOUT)) {
+    if (first) {
+      first = FALSE;
+      sz_strlcat(s, " [");
+    } else {
+      sz_strlcat(s, "/");
+    }
+    sz_strlcat(s, get_special_name(S_FALLOUT));
+  }
+  if (!first) {
+    sz_strlcat(s, "]");
+  }
+
+  return s;
+}
Index: common/tile.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.h,v
retrieving revision 1.3
diff -u -r1.3 tile.h
--- common/tile.h       29 Apr 2005 17:39:29 -0000      1.3
+++ common/tile.h       30 Apr 2005 02:26:48 -0000
@@ -78,4 +78,6 @@
 void tile_mine(struct tile *ptile);
 void tile_transform(struct tile *ptile);
 
+const char *tile_get_info_text(const struct tile *ptile);
+
 #endif /* FC__TILE_H */
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.61
diff -u -r1.61 sanitycheck.c
--- server/sanitycheck.c        23 Apr 2005 17:40:29 -0000      1.61
+++ server/sanitycheck.c        30 Apr 2005 02:26:48 -0000
@@ -341,7 +341,7 @@
        freelog(LOG_ERROR, "%s at %d,%d (%s) has activity %s, "
                "which it can't continue!",
                unit_type(punit)->name,
-               TILE_XY(ptile), map_get_tile_info_text(ptile),
+               TILE_XY(ptile), tile_get_info_text(ptile),
                get_activity_text(punit->activity));
       }
 
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.230
diff -u -r1.230 settlers.c
--- server/settlers.c   26 Apr 2005 05:23:59 -0000      1.230
+++ server/settlers.c   30 Apr 2005 02:26:48 -0000
@@ -995,7 +995,7 @@
       if (same_pos(punit->tile, ptile)) {
         if (!ai_do_build_city(pplayer, punit)) {
           UNIT_LOG(LOG_ERROR, punit, "could not make city on %s",
-                   map_get_tile_info_text(punit->tile));
+                   tile_get_info_text(punit->tile));
           ai_unit_new_role(punit, AIUNIT_NONE, NULL);
         } else {
           return; /* We came, we saw, we built... */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12938) move tile-info functions out of map.h, Jason Short <=