]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/path.c
Update copyright notice.
[empserver] / src / lib / commands / path.c
index 7980dc17f8d8d11dfd0e9b3af990212a6d6943be..442c168b1f4fb4bdfc4466eb0db46753fffc46cd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *     (unknown rewrite), 1989
  */
 
-#include "misc.h"
-#include "player.h"
-#include "var.h"
-#include "xy.h"
-#include "nsc.h"
-#include "nat.h"
-#include "file.h"
-#include "sect.h"
-#include "path.h"
-#include "map.h"
-#include "deity.h"
+#include <config.h>
+
 #include "commands.h"
+#include "map.h"
 #include "optlist.h"
+#include "path.h"
 
 int
 path(void)
@@ -58,13 +51,13 @@ path(void)
     coord cx, cy;
     int i;
     int y;
-    s_char *pp, *p;
+    char *pp, *p;
     /* Note this is not re-entrant anyway, so we keep the buffers
        around */
-    static s_char *mapbuf = (s_char *)0;
-    static s_char **map = (s_char **)0;
+    static char *mapbuf = NULL;
+    static char **map = NULL;
     double move_cost;
-    s_char buf[1024];
+    char buf[1024];
 
     if (!(p = getstarg(player->argp[1], "from sector : ", buf)) ||
        !sarg_xy(p, &cx, &cy) || !getsect(cx, cy, &sect))
@@ -74,24 +67,23 @@ path(void)
        return RET_FAIL;
     }
     getsect(sect.sct_dist_x, sect.sct_dist_y, &dsect);
-    pp = BestDistPath(buf, &sect, &dsect, &move_cost, MOB_ROAD);
-    if (pp == (s_char *)0) {
+    pp = BestDistPath(buf, &sect, &dsect, &move_cost);
+    if (!pp) {
        pr("No path possible from %s to distribution sector %s\n",
           xyas(sect.sct_x, sect.sct_y, player->cnum),
           xyas(dsect.sct_x, dsect.sct_y, player->cnum));
        return RET_FAIL;
     }
     if (!mapbuf)
-       mapbuf =
-           (s_char *)malloc((WORLD_Y * MAPWIDTH(3)) * sizeof(s_char));
+       mapbuf = malloc(WORLD_Y * MAPWIDTH(3));
     if (!map) {
-       map = (s_char **)malloc(WORLD_Y * sizeof(s_char *));
+       map = malloc(WORLD_Y * sizeof(char *));
        if (map && mapbuf) {
            for (i = 0; i < WORLD_Y; i++)
                map[i] = &mapbuf[MAPWIDTH(3) * i];
        } else if (map) {
-           free((s_char *)map);
-           map = (s_char **)0;
+           free(map);
+           map = NULL;
        }
     }
     if (!mapbuf || !map) {
@@ -103,8 +95,11 @@ path(void)
     snxtsct_area(&ns, &absrange);
     natp = getnatp(player->cnum);
     xyrelrange(natp, &absrange, &relrange);
-    blankfill((s_char *)mapbuf, &ns.range, 3);
-    while (*pp && (i = chkdir(*pp, DIR_STOP, DIR_LAST)) >= 0) {
+    blankfill(mapbuf, &ns.range, 3);
+    for (; *pp; ++pp) {
+       i = diridx(*pp);
+       if (i == DIR_STOP)
+           break;
        memcpy(&map[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx) * 2],
               routech[i][0],
               3);