Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12925) move specials helpers into terrain.h
Home

[Freeciv-Dev] (PR#12925) move specials helpers into terrain.h

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12925) move specials helpers into terrain.h
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 28 Apr 2005 10:57:04 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch moves three specials helper functions from map.[ch] into
terrain.[ch], and renames them to be consistent.

  map_get_infrastructure_text => get_infrastructure_text
  map_get_infrastructure_prerequisite => get_infrastructure_prereq
  get_preferred_pillage

I added comments and fixed style in the functions' code and increased
the size of a static buffer.

-jason

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.170
diff -u -r1.170 control.c
--- client/control.c    26 Apr 2005 19:58:24 -0000      1.170
+++ client/control.c    28 Apr 2005 17:53:46 -0000
@@ -1119,7 +1119,7 @@
   enum tile_special_type what =
       get_preferred_pillage(pspresent & (~psworking));
   enum tile_special_type would =
-      what | map_get_infrastructure_prerequisite(what);
+      what | get_infrastructure_prereq(what);
 
   if ((game.rgame.pillage_select) &&
       ((pspresent & (~(psworking | would))) != S_NO_SPECIAL)) {
Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.34
diff -u -r1.34 text.c
--- client/text.c       27 Apr 2005 02:48:00 -0000      1.34
+++ client/text.c       28 Apr 2005 17:53:46 -0000
@@ -229,7 +229,7 @@
   } 
   if (get_tile_infrastructure_set(ptile)) {
     add_line(_("Infrastructure: %s"),
-            map_get_infrastructure_text(ptile->special));
+            get_infrastructure_text(ptile->special));
   }
   activity_text = concat_tile_activity_text(ptile);
   if (strlen(activity_text) > 0) {
@@ -564,7 +564,7 @@
 
     add_line("%s", map_get_tile_info_text(punit->tile));
     if (infrastructure) {
-      add_line("%s", map_get_infrastructure_text(infrastructure));
+      add_line("%s", get_infrastructure_text(infrastructure));
     } else {
       add_line(" ");
     }
Index: client/gui-ftwl/gui_text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/gui_text.c,v
retrieving revision 1.6
diff -u -r1.6 gui_text.c
--- client/gui-ftwl/gui_text.c  23 Apr 2005 17:40:23 -0000      1.6
+++ client/gui-ftwl/gui_text.c  28 Apr 2005 17:53:47 -0000
@@ -144,7 +144,7 @@
   add_line("%s", map_get_tile_info_text(ptile));
   if (infrastructure) {
     add_line("%s",
-            map_get_infrastructure_text(infrastructure));
+            get_infrastructure_text(infrastructure));
   }
   RETURN;
 }
@@ -412,7 +412,7 @@
   }
   if (get_tile_infrastructure_set(ptile)) {
     add_line(_("Infrastructure: %s"),
-            map_get_infrastructure_text(ptile->special));
+            get_infrastructure_text(ptile->special));
   }
   if (strlen(activity_text)) {
     add_line(_("Activity: %s"), activity_text);
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.c,v
retrieving revision 1.101
diff -u -r1.101 dialogs.c
--- client/gui-gtk-2.0/dialogs.c        23 Apr 2005 17:40:24 -0000      1.101
+++ client/gui-gtk-2.0/dialogs.c        28 Apr 2005 17:53:47 -0000
@@ -1104,10 +1104,10 @@
     while (may_pillage != S_NO_SPECIAL) {
       enum tile_special_type what = get_preferred_pillage(may_pillage);
 
-      message_dialog_add(shl, map_get_infrastructure_text(what),
+      message_dialog_add(shl, get_infrastructure_text(what),
                         G_CALLBACK(pillage_callback), GINT_TO_POINTER(what));
 
-      may_pillage &= (~(what | map_get_infrastructure_prerequisite(what)));
+      may_pillage &= (~(what | get_infrastructure_prereq(what)));
     }
 
     message_dialog_add(shl, GTK_STOCK_CANCEL, 0, 0);
Index: client/gui-mui/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/dialogs.c,v
retrieving revision 1.60
diff -u -r1.60 dialogs.c
--- client/gui-mui/dialogs.c    23 Apr 2005 17:40:24 -0000      1.60
+++ client/gui-mui/dialogs.c    28 Apr 2005 17:53:47 -0000
@@ -1080,7 +1080,7 @@
     {
       enum tile_special_type what = get_preferred_pillage(may_pillage);
 
-      may_pillage &= (~(what | map_get_infrastructure_prerequisite (what)));
+      may_pillage &= (~(what | get_infrastructure_prereq (what)));
       count++;
     }
 
@@ -1100,11 +1100,11 @@
        {
          enum tile_special_type what = get_preferred_pillage (may_pillage);
        
-          msg_dlg[i].label = mystrdup(map_get_infrastructure_text(what));
+          msg_dlg[i].label = mystrdup(get_infrastructure_text(what));
           msg_dlg[i].function = (APTR)pillage_button;
           msg_dlg[i].data = (APTR)what;
        
-          may_pillage &= (~(what | map_get_infrastructure_prerequisite 
(what)));
+          may_pillage &= (~(what | get_infrastructure_prereq (what)));
         }
        
         msg_dlg[i].label = _("_Cancel");
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.109
diff -u -r1.109 mapclass.c
--- client/gui-mui/mapclass.c   23 Apr 2005 17:40:25 -0000      1.109
+++ client/gui-mui/mapclass.c   28 Apr 2005 17:53:48 -0000
@@ -128,7 +128,7 @@
       if (get_tile_infrastructure_set(ptile))
       {
        sz_strlcpy(s, _("Infrastructure: "));
-       sz_strlcat(s, map_get_infrastructure_text(ptile->special));
+       sz_strlcat(s, get_infrastructure_text(ptile->special));
        text_obj = TextObject, MUIA_Text_Contents, s, End;
        DoMethod(group, OM_ADDMEMBER, text_obj);
       }
Index: client/gui-sdl/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/dialogs.c,v
retrieving revision 1.57
diff -u -r1.57 dialogs.c
--- client/gui-sdl/dialogs.c    23 Apr 2005 17:40:25 -0000      1.57
+++ client/gui-sdl/dialogs.c    28 Apr 2005 17:53:48 -0000
@@ -919,7 +919,7 @@
       if (get_tile_infrastructure_set(pTile))
       {
        cat_snprintf(cBuf, sizeof(cBuf), _("\nInfrastructure: %s"),
-                               map_get_infrastructure_text(pTile->special));
+                               get_infrastructure_text(pTile->special));
       }
     }
     
@@ -3426,7 +3426,7 @@
     w = MAX(w, pBuf->size.w);
     h += pBuf->size.h;
         
-    may_pillage &= (~(what | map_get_infrastructure_prerequisite(what)));
+    may_pillage &= (~(what | get_infrastructure_prereq(what)));
   }
   pPillage_Dlg->pBeginWidgetList = pBuf;
   
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.84
diff -u -r1.84 mapview.c
--- client/gui-sdl/mapview.c    23 Apr 2005 17:40:25 -0000      1.84
+++ client/gui-sdl/mapview.c    28 Apr 2005 17:53:49 -0000
@@ -606,7 +606,7 @@
                  unit_activity_text(pUnit),
                  sdl_map_get_tile_info_text(pTile),
                  infrastructure ?
-                 map_get_infrastructure_text(infrastructure) : "",
+                 get_infrastructure_text(infrastructure) : "",
                  infrastructure ? "\n" : "", pCity ? pCity->name : _("NONE"));
 
       copy_chars_to_string16(pStr, buffer);
Index: client/gui-win32/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/dialogs.c,v
retrieving revision 1.67
diff -u -r1.67 dialogs.c
--- client/gui-win32/dialogs.c  23 Apr 2005 17:40:26 -0000      1.67
+++ client/gui-win32/dialogs.c  28 Apr 2005 17:53:49 -0000
@@ -1678,9 +1678,9 @@
     while(may_pillage != S_NO_SPECIAL) {
       enum tile_special_type what = get_preferred_pillage(may_pillage);
 
-      fcwin_box_add_button(vbox,map_get_infrastructure_text(what),
+      fcwin_box_add_button(vbox,get_infrastructure_text(what),
                           ID_PILLAGE_BASE+what,0,TRUE,FALSE,5);
-      may_pillage &= (~(what | map_get_infrastructure_prerequisite (what)));
+      may_pillage &= (~(what | get_infrastructure_prereq (what)));
     }
     fcwin_box_add_button(vbox,_("Cancel"),IDCANCEL,0,TRUE,FALSE,5);
     fcwin_set_box(dlg,vbox);
Index: client/gui-xaw/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v
retrieving revision 1.112
diff -u -r1.112 dialogs.c
--- client/gui-xaw/dialogs.c    23 Apr 2005 17:40:26 -0000      1.112
+++ client/gui-xaw/dialogs.c    28 Apr 2005 17:53:49 -0000
@@ -1311,12 +1311,12 @@
       XtVaCreateManagedWidget ("button", commandWidgetClass, form,
                               XtNfromVert, prev,
                               XtNlabel,
-                                (XtArgVal)(map_get_infrastructure_text (what)),
+                                (XtArgVal)(get_infrastructure_text (what)),
                               NULL);
     XtAddCallback(button, XtNcallback, pillage_callback,
                  INT_TO_XTPOINTER(what));
     prev = button;
-    may_pillage &= (~(what | map_get_infrastructure_prerequisite (what)));
+    may_pillage &= (~(what | get_infrastructure_prereq (what)));
   }
   button =
     I_L(XtVaCreateManagedWidget("closebutton", commandWidgetClass, form,
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.220
diff -u -r1.220 map.c
--- common/map.c        28 Apr 2005 03:47:56 -0000      1.220
+++ common/map.c        28 Apr 2005 17:53:50 -0000
@@ -640,85 +640,6 @@
 }
 
 /***************************************************************
-  Return a (static) string with special(s) name(s);
-  eg: "Mine"
-  eg: "Road/Farmland"
-***************************************************************/
-const char *map_get_infrastructure_text(enum tile_special_type spe)
-{
-  static char s[64];
-  char *p;
-  
-  s[0] = '\0';
-
-  /* Since railroad requires road, Road/Railroad is redundant */
-  if (contains_special(spe, S_RAILROAD))
-    cat_snprintf(s, sizeof(s), "%s/", _("Railroad"));
-  else if (contains_special(spe, S_ROAD))
-    cat_snprintf(s, sizeof(s), "%s/", _("Road"));
-
-  /* Likewise for farmland on irrigation */
-  if (contains_special(spe, S_FARMLAND))
-    cat_snprintf(s, sizeof(s), "%s/", _("Farmland"));
-  else if (contains_special(spe, S_IRRIGATION))
-    cat_snprintf(s, sizeof(s), "%s/", _("Irrigation"));
-
-  if (contains_special(spe, S_MINE))
-    cat_snprintf(s, sizeof(s), "%s/", _("Mine"));
-
-  if (contains_special(spe, S_FORTRESS))
-    cat_snprintf(s, sizeof(s), "%s/", _("Fortress"));
-
-  if (contains_special(spe, S_AIRBASE))
-    cat_snprintf(s, sizeof(s), "%s/", _("Airbase"));
-
-  p = s + strlen(s) - 1;
-  if (*p == '/')
-    *p = '\0';
-
-  return s;
-}
-
-/****************************************************************************
-  Return the prerequesites needed before building the given infrastructure.
-****************************************************************************/
-enum tile_special_type map_get_infrastructure_prerequisite(enum 
tile_special_type spe)
-{
-  enum tile_special_type prereq = S_NO_SPECIAL;
-
-  if (contains_special(spe, S_RAILROAD)) {
-    prereq |= S_ROAD;
-  }
-  if (contains_special(spe, S_FARMLAND)) {
-    prereq |= S_IRRIGATION;
-  }
-
-  return prereq;
-}
-
-/***************************************************************
-...
-***************************************************************/
-enum tile_special_type get_preferred_pillage(enum tile_special_type pset)
-{
-  if (contains_special(pset, S_FARMLAND))
-    return S_FARMLAND;
-  if (contains_special(pset, S_IRRIGATION))
-    return S_IRRIGATION;
-  if (contains_special(pset, S_MINE))
-    return S_MINE;
-  if (contains_special(pset, S_FORTRESS))
-    return S_FORTRESS;
-  if (contains_special(pset, S_AIRBASE))
-    return S_AIRBASE;
-  if (contains_special(pset, S_RAILROAD))
-    return S_RAILROAD;
-  if (contains_special(pset, S_ROAD))
-    return S_ROAD;
-  return S_NO_SPECIAL;
-}
-
-/***************************************************************
 ...
 ***************************************************************/
 bool is_water_adjacent_to_tile(const struct tile *ptile)
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.242
diff -u -r1.242 map.h
--- common/map.h        28 Apr 2005 03:47:56 -0000      1.242
+++ common/map.h        28 Apr 2005 17:53:50 -0000
@@ -280,9 +280,6 @@
 bool is_safe_ocean(const struct tile *ptile);
 bool is_cardinally_adj_to_ocean(const struct tile *ptile);
 enum tile_special_type get_tile_infrastructure_set(const struct tile *ptile);
-const char *map_get_infrastructure_text(enum tile_special_type spe);
-enum tile_special_type map_get_infrastructure_prerequisite(enum 
tile_special_type spe);
-enum tile_special_type get_preferred_pillage(enum tile_special_type pset);
 
 void map_irrigate_tile(struct tile *ptile);
 void map_mine_tile(struct tile *ptile);
Index: common/terrain.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.c,v
retrieving revision 1.20
diff -u -r1.20 terrain.c
--- common/terrain.c    26 Apr 2005 06:57:36 -0000      1.20
+++ common/terrain.c    28 Apr 2005 17:53:50 -0000
@@ -363,3 +363,98 @@
   }
   return count;
 }
+
+/****************************************************************************
+  Return a (static) string with special(s) name(s):
+    eg: "Mine"
+    eg: "Road/Farmland"
+  This only includes "infrastructure", i.e., man-made specials.
+****************************************************************************/
+const char *get_infrastructure_text(enum tile_special_type spe)
+{
+  static char s[256];
+  char *p;
+  
+  s[0] = '\0';
+
+  /* Since railroad requires road, Road/Railroad is redundant */
+  if (contains_special(spe, S_RAILROAD)) {
+    cat_snprintf(s, sizeof(s), "%s/", _("Railroad"));
+  } else if (contains_special(spe, S_ROAD)) {
+    cat_snprintf(s, sizeof(s), "%s/", _("Road"));
+  }
+
+  /* Likewise for farmland on irrigation */
+  if (contains_special(spe, S_FARMLAND)) {
+    cat_snprintf(s, sizeof(s), "%s/", _("Farmland"));
+  } else if (contains_special(spe, S_IRRIGATION)) {
+    cat_snprintf(s, sizeof(s), "%s/", _("Irrigation"));
+  }
+
+  if (contains_special(spe, S_MINE)) {
+    cat_snprintf(s, sizeof(s), "%s/", _("Mine"));
+  }
+
+  if (contains_special(spe, S_FORTRESS)) {
+    cat_snprintf(s, sizeof(s), "%s/", _("Fortress"));
+  }
+
+  if (contains_special(spe, S_AIRBASE)) {
+    cat_snprintf(s, sizeof(s), "%s/", _("Airbase"));
+  }
+
+  p = s + strlen(s) - 1;
+  if (*p == '/') {
+    *p = '\0';
+  }
+
+  return s;
+}
+
+/****************************************************************************
+  Return the prerequesites needed before building the given infrastructure.
+****************************************************************************/
+enum tile_special_type get_infrastructure_prereq(enum tile_special_type spe)
+{
+  enum tile_special_type prereq = S_NO_SPECIAL;
+
+  if (contains_special(spe, S_RAILROAD)) {
+    prereq |= S_ROAD;
+  }
+  if (contains_special(spe, S_FARMLAND)) {
+    prereq |= S_IRRIGATION;
+  }
+
+  return prereq;
+}
+
+/****************************************************************************
+  Returns the highest-priority (best) infrastructure (man-made special) to
+  be pillaged from the terrain set.  May return S_NO_SPECIAL if nothing
+  better is available.
+****************************************************************************/
+enum tile_special_type get_preferred_pillage(enum tile_special_type pset)
+{
+  if (contains_special(pset, S_FARMLAND)) {
+    return S_FARMLAND;
+  }
+  if (contains_special(pset, S_IRRIGATION)) {
+    return S_IRRIGATION;
+  }
+  if (contains_special(pset, S_MINE)) {
+    return S_MINE;
+  }
+  if (contains_special(pset, S_FORTRESS)) {
+    return S_FORTRESS;
+  }
+  if (contains_special(pset, S_AIRBASE)) {
+    return S_AIRBASE;
+  }
+  if (contains_special(pset, S_RAILROAD)) {
+    return S_RAILROAD;
+  }
+  if (contains_special(pset, S_ROAD)) {
+    return S_ROAD;
+  }
+  return S_NO_SPECIAL;
+}
Index: common/terrain.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.h,v
retrieving revision 1.32
diff -u -r1.32 terrain.h
--- common/terrain.h    26 Apr 2005 06:57:36 -0000      1.32
+++ common/terrain.h    28 Apr 2005 17:53:50 -0000
@@ -218,6 +218,11 @@
                                 bool cardinal_only, bool percentage,
                                 enum terrain_flag_id flag);
 
+/* Special helper functions */
+const char *get_infrastructure_text(enum tile_special_type spe);
+enum tile_special_type get_infrastructure_prereq(enum tile_special_type spe);
+enum tile_special_type get_preferred_pillage(enum tile_special_type pset);
+
 /* Terrain-specific functions. */
 #define is_ocean(x) (terrain_has_flag((x), TER_OCEANIC))
 #define is_ocean_near_tile(ptile) \
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.235
diff -u -r1.235 unit.c
--- common/unit.c       27 Apr 2005 02:48:00 -0000      1.235
+++ common/unit.c       28 Apr 2005 17:53:50 -0000
@@ -1029,7 +1029,7 @@
      } else {
        my_snprintf(text, sizeof(text), "%s: %s",
                   get_activity_text (punit->activity),
-                  map_get_infrastructure_text(punit->activity_target));
+                  get_infrastructure_text(punit->activity_target));
        return (text);
      }
    default:
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.330
diff -u -r1.330 unithand.c
--- server/unithand.c   28 Apr 2005 04:15:42 -0000      1.330
+++ server/unithand.c   28 Apr 2005 17:53:52 -0000
@@ -1437,7 +1437,7 @@
     case ACTIVITY_PILLAGE: 
       {
         enum tile_special_type prereq =
-         map_get_infrastructure_prerequisite(old_target);
+         get_infrastructure_prereq(old_target);
         if (prereq != S_NO_SPECIAL) {
           unit_list_iterate (punit->tile->units, punit2)
             if ((punit2->activity == ACTIVITY_PILLAGE) &&

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12925) move specials helpers into terrain.h, Jason Short <=