Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] [PATCH] Cleaned up magic code in gotohand.c (PR#944)
Home

[Freeciv-Dev] [PATCH] Cleaned up magic code in gotohand.c (PR#944)

[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 magic code in gotohand.c (PR#944)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Sat, 8 Sep 2001 21:15:16 -0700 (PDT)

This tiny patch simply replaces the magic numbers for directions in
gotohand.c (dir_ok/straightest_direction) with the enumeration values.

I haven't fixed the bug in straightest_direction, but I made a comment
about it.  Once this goes through I'll provide a patch to fix it (or I
can provide the patch now, but the two issues are separate).

This shouldn't be at all controversial (unless I substituted the numbers
wrong :-).

jason
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.112
diff -u -r1.112 gotohand.c
--- server/gotohand.c   2001/09/08 22:53:27     1.112
+++ server/gotohand.c   2001/09/09 04:10:18
@@ -452,28 +452,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:
@@ -496,6 +496,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 ?
@@ -504,13 +507,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_SOUTHWEST : 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]