]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/bestpath.c
Update copyright notice
[empserver] / src / lib / common / bestpath.c
index fe2501923c7e562a2322afe924bed18f9aa56dcf..5003082aa589ae1a45f6df290742022f47fda804 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 
 #include <config.h>
 
-#include "misc.h"
-#include "xy.h"
-#include "sect.h"
 #include "file.h"
+#include "misc.h"
 #include "nat.h"
-#include "path.h"
-#include "common.h"
 #include "optlist.h"
+#include "path.h"
+#include "prototypes.h"
+#include "sect.h"
+#include "xy.h"
 
 static int owned_and_navigable(char *, int, int, int);
 
@@ -79,7 +79,9 @@ static unsigned short **mapindex;
  * the usual rules.
  * Other sectors are assumed to be passable when BIGMAP shows '.' or
  * nothing.
- * Return path or a null pointer.
+ * Return a path if found, else a null pointer.
+ * Wart: the path isn't terminated with 'h', except when if X,Y equals
+ * EX,EY.
  */
 char *
 bestownedpath(char *bpath, char *bigmap,
@@ -130,7 +132,7 @@ bestownedpath(char *bpath, char *bigmap,
     maxy = y + 1;
 
     do {
-       if (++routelen == MAXROUTE - 1)
+       if (++routelen == MAXROUTE)
            return NULL;
        markedsectors = 0;
        for (scanx = minx; scanx <= maxx; scanx++) {
@@ -140,7 +142,7 @@ bestownedpath(char *bpath, char *bigmap,
                if (!valid(x, y))
                    continue;
                if (((mapindex[x][y] & 0x1FFF) == routelen - 1)) {
-                   for (i = DIR_FIRST; i < DIR_LAST; i++) {
+                   for (i = DIR_FIRST; i <= DIR_LAST; i++) {
                        tx = x + diroff[i][0];
                        ty = y + diroff[i][1];
                        tx = XNORM(tx);
@@ -155,8 +157,7 @@ bestownedpath(char *bpath, char *bigmap,
                            }
                        }
                        if (tx == ex && ty == ey) {
-                           bpath[routelen] = 'h';
-                           bpath[routelen + 1] = 0;
+                           bpath[routelen] = 0;
                            while (routelen--) {
                                i = (mapindex[tx][ty] >> 13)
                                    - 1 + DIR_FIRST;