]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/paths.c
Fix pathrange() for paths spanning whole world (with border)
[empserver] / src / lib / subs / paths.c
index e94cadc8157e05ebed9639495a8972743234deed..92ab8d171301e49446bba484fb625996b0ba1113 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 "player.h"
-#include "xy.h"
-#include "path.h"
-#include "nat.h"
-#include "sect.h"
 #include "file.h"
+#include "optlist.h"
+#include "path.h"
+#include "player.h"
 #include "prototypes.h"
+#include "sect.h"
 
 int
 chkdir(char dir_char, int min_dir, int max_dir)
@@ -154,7 +152,7 @@ getpath(char *buf, char *arg, coord x, coord y, int onlyown,
               xyas(nx, ny, player->cnum));
            break;
        }
-       if (dir == DIR_STOP || dir == DIR_MAP) {
+       if (dir == DIR_STOP) {
            p[1] = 0;
            return buf;
        }
@@ -172,13 +170,13 @@ getpath(char *buf, char *arg, coord x, coord y, int onlyown,
                xyas(x, y, player->cnum));
     }
     bp = getstring(prompt, buf2);
-    if (bp && p + strlen(bp) + 1 >= buf + MAX_PATH_LEN) {
+    if (!bp)
+       return NULL;
+    if (p + strlen(bp) + 1 >= buf + MAX_PATH_LEN) {
        pr("Path length may not exceed %d.\n", MAX_PATH_LEN);
        pr("Aborting...\n");
        bp = NULL;
     }
-    if (!bp)
-       return NULL;
     strcpy(p, bp);
     if (*bp)
        goto more;
@@ -240,32 +238,34 @@ pathtoxy(char *path, coord *xp, coord *yp,
 void
 pathrange(coord cx, coord cy, char *pp, int border, struct range *range)
 {
-    int dir;
+    int dir, lx, ly, hx, hy;
 
-    range->lx = cx;
-    range->hx = cx;
-    range->ly = cy;
-    range->hy = cy;
-    range->width = 0;
-    range->height = 0;
+    lx = hx = cx;
+    ly = hy = cy;
     for (; *pp; pp++) {
        dir = diridx(*pp);
        if (dir == DIR_STOP)
            break;
        cx += diroff[dir][0];
        cy += diroff[dir][1];
-       if (cx < range->lx)
-           range->lx = cx;
-       if (cx > range->hx)
-           range->hx = cx;
-       if (cy < range->ly)
-           range->ly = cy;
-       if (cy > range->hy)
-           range->hy = cy;
+       if (cx < lx)
+           lx = cx;
+       if (cx > hx)
+           hx = cx;
+       if (cy < ly)
+           ly = cy;
+       if (cy > hy)
+           hy = cy;
     }
-    range->lx = xnorm(range->lx - border * 2);
-    range->ly = ynorm(range->ly - border);
-    range->hx = xnorm(range->hx + border * 2 + 1);
-    range->hy = ynorm(range->hy + border + 1);
+
+    lx -= border * 2;
+    hx += border * 2;
+    ly -= border;
+    hy += border;
+
+    range->lx = xnorm(lx);
+    range->hx = ynorm(hx - lx < WORLD_X ? hx : lx - 1);
+    range->ly = ynorm(ly);
+    range->hy = ynorm(hy - ly < WORLD_Y ? hy : ly - 1);
     xysize_range(range);
 }