]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/path.c
commands: Rename the command functions
[empserver] / src / lib / commands / path.c
index 018502ec3b720f0e4da6ada366532271f729d0c1..bbcc26e9d2409f6dbc8f691e79e8ad4b13a38597 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -29,6 +29,7 @@
  *  Known contributors to this file:
  *     David Muir Sharnoff, 1986
  *     (unknown rewrite), 1989
+ *     Markus Armbruster, 2005-2011
  */
 
 #include <config.h>
 #include "path.h"
 
 int
-path(void)
+c_path(void)
 {
 
     struct nstr_sect ns;
     struct natstr *natp;
     struct range absrange;
     struct range relrange;
-    struct sctstr sect, dsect;
+    struct sctstr sect;
     coord cx, cy;
     int i;
     int y;
     char *pp, *p;
+    size_t len;
     /* Note this is not re-entrant anyway, so we keep the buffers
        around */
     static char *mapbuf = NULL;
     static char **map = NULL;
-    double move_cost;
     char buf[1024];
 
     if (!(p = getstarg(player->argp[1], "from sector : ", buf)) ||
@@ -65,12 +66,19 @@ path(void)
        pr("Not yours\n");
        return RET_FAIL;
     }
-    getsect(sect.sct_dist_x, sect.sct_dist_y, &dsect);
-    pp = BestDistPath(buf, &sect, &dsect, &move_cost);
-    if (!pp) {
+    if (path_find(sect.sct_x, sect.sct_y, sect.sct_dist_x, sect.sct_dist_y,
+                 player->cnum, MOB_MOVE) < 0) {
        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));
+          xyas(sect.sct_dist_x, sect.sct_dist_y, player->cnum));
+       return RET_FAIL;
+    }
+    len = path_find_route(buf, sizeof(buf), sect.sct_x, sect.sct_y,
+                         sect.sct_dist_x, sect.sct_dist_y);
+    if (len >= sizeof(buf)) {
+       pr("Can't handle path from %s to distribution sector %s, it's too long, sorry.\n",
+          xyas(sect.sct_x, sect.sct_y, player->cnum),
+          xyas(sect.sct_dist_x, sect.sct_dist_y, player->cnum));
        return RET_FAIL;
     }
     if (!mapbuf)
@@ -90,14 +98,14 @@ path(void)
        logerror("malloc failed in path\n");
        return RET_FAIL;
     }
-    pathrange(cx, cy, pp, 1, &absrange);
+    pathrange(cx, cy, buf, 1, &absrange);
     snxtsct_area(&ns, &absrange);
     natp = getnatp(player->cnum);
     xyrelrange(natp, &absrange, &relrange);
     blankfill(mapbuf, &ns.range, 3);
-    for (; *pp; ++pp) {
+    for (pp = buf; *pp; ++pp) {
        i = diridx(*pp);
-       if (i == DIR_STOP)
+       if (CANT_HAPPEN(i == DIR_STOP))
            break;
        memcpy(&map[delty(&ns.range, cy)][deltx(&ns.range, cx) * 2],
               routech[i], 3);