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

[Freeciv-Dev] (PR#12822) move some specials code into terrain.h

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12822) move some specials code into terrain.h
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 17 Apr 2005 22:40:42 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch moves a few pieces of terrain-special code into terrain.h.
Most of the specials code (including the special enumeration) is already
there.  However if anyone thinks I should create a new file
specials.[ch] I'd be glad to move it there instead.

-jason

Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.215
diff -u -r1.215 map.c
--- common/map.c        13 Apr 2005 18:41:11 -0000      1.215
+++ common/map.c        13 Apr 2005 20:03:49 -0000
@@ -55,26 +55,6 @@
 const int DIR_DX[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 const int DIR_DY[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
 
-/* Names of specials.
- * (These must correspond to enum tile_special_type in terrain.h.)
- */
-static const char *tile_special_type_names[] =
-{
-  N_("Special1"),
-  N_("Road"),
-  N_("Irrigation"),
-  N_("Railroad"),
-  N_("Mine"),
-  N_("Pollution"),
-  N_("Hut"),
-  N_("Fortress"),
-  N_("Special2"),
-  N_("River"),
-  N_("Farmland"),
-  N_("Airbase"),
-  N_("Fallout")
-};
-
 /****************************************************************************
   Return a bitfield of the specials on the tile that are infrastructure.
 ****************************************************************************/
@@ -540,41 +520,6 @@
   }
 }
 
-/***************************************************************
-...
-***************************************************************/
-enum tile_special_type get_special_by_name(const char * name)
-{
-  int i;
-  enum tile_special_type st = 1;
-
-  for (i = 0; i < ARRAY_SIZE(tile_special_type_names); i++) {
-    if (0 == strcmp(name, tile_special_type_names[i]))
-      return st;
-      
-    st <<= 1;
-  }
-
-  return S_NO_SPECIAL;
-}
-
-/***************************************************************
-...
-***************************************************************/
-const char *get_special_name(enum tile_special_type type)
-{
-  int i;
-
-  for (i = 0; i < ARRAY_SIZE(tile_special_type_names); i++) {
-    if ((type & 0x1) == 1) {
-      return _(tile_special_type_names[i]);
-    }
-    type >>= 1;
-  }
-
-  return NULL;
-}
-
 /****************************************************************************
   Return the "distance" (which is really the Manhattan distance, and should
   rarely be used) for a given vector.
@@ -1233,25 +1178,6 @@
 {
   return contains_special(ptile->special, special);
 }
-  
-/***************************************************************
- Returns TRUE iff the given special is found in the given set.
-***************************************************************/
-bool contains_special(enum tile_special_type set,
-                     enum tile_special_type to_test_for)
-{
-  enum tile_special_type masked = set & to_test_for;
-
-  assert(0 == (int) S_NO_SPECIAL);
-
-  /*
-   * contains_special should only be called with one S_* in
-   * to_test_for.
-   */
-  assert(masked == S_NO_SPECIAL || masked == to_test_for);
-
-  return masked == to_test_for;
-}
 
 /***************************************************************
 ...
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.237
diff -u -r1.237 map.h
--- common/map.h        13 Apr 2005 18:41:11 -0000      1.237
+++ common/map.h        13 Apr 2005 20:03:50 -0000
@@ -304,9 +304,6 @@
 /* special testing */
 bool tile_has_special(const struct tile *ptile,
                      enum tile_special_type to_test_for);
-bool contains_special(enum tile_special_type all,
-                     enum tile_special_type to_test_for);
-
 
 bool is_singular_tile(const struct tile *ptile, int dist);
 bool normalize_map_pos(int *x, int *y);
@@ -329,8 +326,6 @@
                      const struct tile *dst_tile);
 int map_move_cost(struct unit *punit, const struct tile *ptile);
 int map_move_cost_ai(const struct tile *tile0, const struct tile *tile1);
-enum tile_special_type get_special_by_name(const char * name);
-const char *get_special_name(enum tile_special_type type);
 bool is_safe_ocean(const struct tile *ptile);
 bool is_cardinally_adj_to_ocean(const struct tile *ptile);
 int get_tile_output_base(const struct tile *ptile, Output_type_id output);
Index: common/terrain.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.c,v
retrieving revision 1.17
diff -u -r1.17 terrain.c
--- common/terrain.c    13 Apr 2005 18:19:12 -0000      1.17
+++ common/terrain.c    13 Apr 2005 20:03:50 -0000
@@ -17,6 +17,8 @@
 
 #include <assert.h>
 
+#include "fcintl.h"
+
 #include "map.h"
 #include "mem.h"               /* free */
 #include "rand.h"
@@ -190,6 +192,83 @@
   return count;
 }
 
+/* Names of specials.
+ * (These must correspond to enum tile_special_type.)
+ */
+static const char *tile_special_type_names[] =
+{
+  N_("Special1"),
+  N_("Road"),
+  N_("Irrigation"),
+  N_("Railroad"),
+  N_("Mine"),
+  N_("Pollution"),
+  N_("Hut"),
+  N_("Fortress"),
+  N_("Special2"),
+  N_("River"),
+  N_("Farmland"),
+  N_("Airbase"),
+  N_("Fallout")
+};
+
+/****************************************************************************
+  Return the special with the given name, or S_NO_SPECIAL.
+
+  FIXME: should be find_special_by_name().
+****************************************************************************/
+enum tile_special_type get_special_by_name(const char *name)
+{
+  int i;
+  enum tile_special_type st = 1;
+
+  for (i = 0; i < ARRAY_SIZE(tile_special_type_names); i++) {
+    if (0 == strcmp(name, tile_special_type_names[i])) {
+      return st;
+    }
+      
+    st <<= 1;
+  }
+
+  return S_NO_SPECIAL;
+}
+
+/****************************************************************************
+  Return the name of the given special.
+****************************************************************************/
+const char *get_special_name(enum tile_special_type type)
+{
+  int i;
+
+  for (i = 0; i < ARRAY_SIZE(tile_special_type_names); i++) {
+    if ((type & 0x1) == 1) {
+      return _(tile_special_type_names[i]);
+    }
+    type >>= 1;
+  }
+
+  return NULL;
+}
+
+/***************************************************************
+ Returns TRUE iff the given special is found in the given set.
+***************************************************************/
+bool contains_special(enum tile_special_type set,
+                     enum tile_special_type to_test_for)
+{
+  enum tile_special_type masked = set & to_test_for;
+
+  assert(0 == (int) S_NO_SPECIAL);
+
+  /*
+   * contains_special should only be called with one S_* in
+   * to_test_for.
+   */
+  assert(masked == S_NO_SPECIAL || masked == to_test_for);
+
+  return masked == to_test_for;
+}
+
 /****************************************************************************
   Returns TRUE iff any tile adjacent to (map_x,map_y) has the given special.
 ****************************************************************************/
Index: common/terrain.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.h,v
retrieving revision 1.30
diff -u -r1.30 terrain.h
--- common/terrain.h    13 Mar 2005 17:50:54 -0000      1.30
+++ common/terrain.h    13 Apr 2005 20:03:50 -0000
@@ -153,7 +153,7 @@
 
 extern struct tile_type tile_types[MAX_NUM_TERRAINS];
 
-/* General accessor functions. */
+/* General terrain accessor functions. */
 struct tile_type *get_tile_type(Terrain_type_id type);
 Terrain_type_id get_terrain_by_name(const char * name);
 const char *get_terrain_name(Terrain_type_id type);
@@ -168,6 +168,12 @@
                            bool cardinal_only, bool percentage,
                            Terrain_type_id t);
 
+/* General special-accessor functions. */
+enum tile_special_type get_special_by_name(const char * name);
+const char *get_special_name(enum tile_special_type type);
+bool contains_special(enum tile_special_type all,
+                     enum tile_special_type to_test_for);
+
 /* Functions to operate on a terrain special. */
 bool is_special_near_tile(const struct tile *ptile,
                          enum tile_special_type spe);

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