Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] [PATCH] Cleaned up more magic code in the client (PR#945)
Home

[Freeciv-Dev] [PATCH] Cleaned up more magic code in the client (PR#945)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] Cleaned up more magic code in the client (PR#945)
From: Jason Dorje Short <jshort@xxxxxxxxxxxxx>
Date: Sat, 8 Sep 2001 21:26:57 -0700 (PDT)

This patch cleans up all remaining magic directional-system code that I
know of.

- There's an easy fix to get_drawn().  Much cleaner.  (Actually, this
should have been included in the PR#944 patch.)

- To clean up the magic numbers that are used with DIR_D[XY]2, I removed
the use of DIR_D[XY]2 entirely.  This may seem like a step back, but if
the plan is to put all schema-dependent code into map.[ch] and then
convert all at once to the new system, this is the way to go.

I've kept this separate from the PR#944 patch because this is
controversial.

jason
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.20
diff -u -r1.20 goto.c
--- client/goto.c       2001/08/30 10:44:16     1.20
+++ client/goto.c       2001/09/09 04:20:47
@@ -671,8 +671,7 @@
 ***********************************************************************/
 int get_drawn(int x, int y, int dir)
 {
-  if ((y == 0 && dir <= 2)
-      || (y == map.ysize-1 && dir >= 5))
+  if (!is_real_tile(x + DIR_DX[dir], y + DIR_DY[dir]))
     return 0;
 
   return *get_drawn_char(x, y, dir);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.49
diff -u -r1.49 tilespec.c
--- client/tilespec.c   2001/08/24 08:22:01     1.49
+++ client/tilespec.c   2001/09/09 04:20:50
@@ -1097,8 +1097,8 @@
   }
 
   for (dir=0; dir<8; dir++) {
-    int x1 = x + DIR_DX2[dir];
-    int y1 = y + DIR_DY2[dir];
+    int x1 = x + DIR_DX[dir];
+    int y1 = y + DIR_DY[dir];
     if (normalize_map_pos(&x1, &y1)) {
       ttype_near[dir] = map_get_terrain(x1, y1);
       tspecial_near[dir] = map_get_special(x1, y1);
@@ -1113,22 +1113,22 @@
       tspecial_near[dir] = S_NO_SPECIAL;
     }
   }
-  ttype_north      = ttype_near[0];
-  ttype_north_east = ttype_near[1];
-  ttype_east       = ttype_near[2];
-  ttype_south_east = ttype_near[3];
-  ttype_south      = ttype_near[4];
-  ttype_south_west = ttype_near[5];
-  ttype_west       = ttype_near[6];
-  ttype_north_west = ttype_near[7];
-  tspecial_north      = tspecial_near[0];
-  tspecial_north_east = tspecial_near[1];
-  tspecial_east       = tspecial_near[2];
-  tspecial_south_east = tspecial_near[3];
-  tspecial_south      = tspecial_near[4];
-  tspecial_south_west = tspecial_near[5];
-  tspecial_west       = tspecial_near[6];
-  tspecial_north_west = tspecial_near[7];
+  ttype_north      = ttype_near[DIR8_NORTH];
+  ttype_north_east = ttype_near[DIR8_NORTHEAST];
+  ttype_east       = ttype_near[DIR8_EAST];
+  ttype_south_east = ttype_near[DIR8_SOUTHEAST];
+  ttype_south      = ttype_near[DIR8_SOUTH];
+  ttype_south_west = ttype_near[DIR8_SOUTHWEST];
+  ttype_west       = ttype_near[DIR8_WEST];
+  ttype_north_west = ttype_near[DIR8_NORTHWEST];
+  tspecial_north      = tspecial_near[DIR8_NORTH];
+  tspecial_north_east = tspecial_near[DIR8_NORTHEAST];
+  tspecial_east       = tspecial_near[DIR8_EAST];
+  tspecial_south_east = tspecial_near[DIR8_SOUTHEAST];
+  tspecial_south      = tspecial_near[DIR8_SOUTH];
+  tspecial_south_west = tspecial_near[DIR8_SOUTHWEST];
+  tspecial_west       = tspecial_near[DIR8_WEST];
+  tspecial_north_west = tspecial_near[DIR8_NORTHWEST];
   
   if (draw_terrain) {
     if (ttype != T_OCEAN) /* painted via coasts. */
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.84
diff -u -r1.84 map.c
--- common/map.c        2001/09/06 21:23:07     1.84
+++ common/map.c        2001/09/09 04:20:53
@@ -49,10 +49,6 @@
 const int CAR_DIR_DX[4] = {1, 0, -1, 0};
 const int CAR_DIR_DY[4] = {0, 1, 0, -1};
 
-/* used to compute neighboring tiles */
-const int DIR_DX2[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
-const int DIR_DY2[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
-
 /* Names of specials.
  * (These must correspond to enum tile_special_type in terrain.h.)
  */
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.88
diff -u -r1.88 map.h
--- common/map.h        2001/09/06 18:19:09     1.88
+++ common/map.h        2001/09/09 04:20:54
@@ -495,23 +495,6 @@
 }
 
 
-/*
-used to compute neighboring tiles:
-using
-x1 = x + DIR_DX2[dir];
-y1 = y + DIR_DY2[dir];
-will give you the tile as shown below.
--------
-|7|0|1|
-|-+-+-|
-|6| |2|
-|-+-+-|
-|5|4|3|
--------
- */
-extern const int DIR_DX2[8];
-extern const int DIR_DY2[8];
-
 #define MAP_DEFAULT_HUTS         50
 #define MAP_MIN_HUTS             0
 #define MAP_MAX_HUTS             500

[Prev in Thread] Current Thread [Next in Thread]