Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: directional system: more magic code cleanups
Home

[Freeciv-Dev] Re: directional system: more magic code cleanups

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: directional system: more magic code cleanups
From: Jason Dorje Short <jshort@xxxxxxxxxxxxx>
Date: Mon, 17 Sep 2001 13:03:59 -0400
Reply-to: jdorje@xxxxxxxxxxxxxxxxxxxxx

Raimar Falke wrote:
> 
> On Mon, Sep 17, 2001 at 03:00:43AM -0400, Jason Dorje Short wrote:
> > Just to let you know where we stand, the attached patch fixes all
> > remaining known magic code (unless Ross knows of more).
> >
> > It does *not* fully fix dir_ok and straightest_direction as it should; I
> > think Ross should provide a patch that fixes these guys properly.
> > However it is good as far as it goes.
> >
> > -    best_dir = (go_y > 0) ? 7 : 2;
> > +    best_dir = (go_y > 0) ? DIR8_SOUTHWEST : DIR8_NORTHEAST;
> > -    best_dir = (go_y > 0) ? 5 : 0;
> > +    best_dir = (go_y > 0) ? DIR8_SOUTHWEST : DIR8_NORTHWEST;
> 
> One of the DIR8_SOUTHWESTs is wrong.

Of course you're right.

How about this?

jason
? rc
? civserver-regular
? civserver-macro
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.23
diff -u -r1.23 goto.c
--- client/goto.c       2001/09/15 15:31:19     1.23
+++ client/goto.c       2001/09/17 16:46:06
@@ -672,8 +672,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: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.115
diff -u -r1.115 gotohand.c
--- server/gotohand.c   2001/09/15 15:31:26     1.115
+++ server/gotohand.c   2001/09/17 16:46:12
@@ -451,28 +451,28 @@
     diff_y = 0;
 
   switch(dir) {
-  case 0:
+  case DIR8_NORTHWEST:
     if (diff_x >= 0 && diff_y >= 0) return 0;
     else return 1;
-  case 1:
+  case DIR8_NORTH:
     if (diff_y == 1) return 0;
     else return 1;
-  case 2:
+  case DIR8_NORTHEAST:
     if (diff_x <= 0 && diff_y >= 0) return 0;
     else return 1;
-  case 3:
+  case DIR8_WEST:
     if (diff_x == 1) return 0;
     else return 1;
-  case 4:
+  case DIR8_EAST:
     if (diff_x == -1) return 0;
     else return 1;
-  case 5:
+  case DIR8_SOUTHWEST:
     if (diff_x >= 0 && diff_y <= 0) return 0;
     else return 1;
-  case 6:
+  case DIR8_SOUTH:
     if (diff_y == -1) return 0;
     else return 1;
-  case 7:
+  case DIR8_SOUTHEAST:
     if (diff_x <= 0 && diff_y <= 0) return 0;
     else return 1;
   default:
@@ -495,6 +495,9 @@
   int best_dir;
   int go_x, go_y;
 
+  /* FIXME: This function buggily prefers to travel diagonally rather than
+     in an actual "straight" direction. */
+
   /* Should we go up or down, east or west: go_x/y is the "step" in x/y.
      Will allways be -1 or 1 even if src_x == dest_x or src_y == dest_y. */
   go_x = dest_x > src_x ?
@@ -503,13 +506,13 @@
   go_y = dest_y > src_y ? 1 : -1;
 
   if (src_x == dest_x)
-    best_dir = (go_y > 0) ? 6 : 1;
+    best_dir = (go_y > 0) ? DIR8_SOUTH : DIR8_NORTH;
   else if (src_y == dest_y)
-    best_dir = (go_x > 0) ? 4 : 3;
+    best_dir = (go_x > 0) ? DIR8_EAST : DIR8_WEST;
   else if (go_x > 0)
-    best_dir = (go_y > 0) ? 7 : 2;
+    best_dir = (go_y > 0) ? DIR8_SOUTHEAST : DIR8_NORTHEAST;
   else /* go_x < 0 */
-    best_dir = (go_y > 0) ? 5 : 0;
+    best_dir = (go_y > 0) ? DIR8_SOUTHWEST : DIR8_NORTHWEST;
 
   return (best_dir);
 }

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