Clean up path finding in getpath()

Don't claim the destination sector is unreachable when the best path
is longer than 99 characters or the complete path is longer than 1023
characters.  Instead, report that the path is too long when the total
path is longer than 1023 characters.
This commit is contained in:
Markus Armbruster 2011-03-27 08:44:30 +02:00
parent 182d62deed
commit 404a76f79e

View file

@ -24,10 +24,10 @@
* *
* --- * ---
* *
* path.c: Routines associated with paths, directions, etc. * paths.c: Routines associated with paths, directions, etc.
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2005-2009 * Markus Armbruster, 2005-2011
*/ */
#include <config.h> #include <config.h>
@ -113,51 +113,20 @@ getpath(char *buf, char *arg, coord x, coord y, int onlyown, int showdes,
more: more:
while (*p) { while (*p) {
if (sarg_xy(p, &dx, &dy)) { if (sarg_xy(p, &dx, &dy)) {
bp = NULL; if (path_find(x, y, dx, dy, player->cnum, mobtype) < 0) {
switch (mobtype) { pr("Can't get to %s from here!\n",
default: xyas(dx, dy, player->cnum));
CANT_REACH(); break;
pr("Destination sectors not allowed here!\n"); }
break; len = path_find_route(p, buf + MAX_PATH_LEN - p, x, y, dx, dy);
case MOB_FLY: if (p + len >= buf + MAX_PATH_LEN) {
if (path_find(x, y, dx, dy, 0, MOB_FLY) < 0) pr("Can't handle path to %s, it's too long, sorry.\n",
bp = NULL; xyas(dx, dy, player->cnum));
else {
len = path_find_route(buf2, 100, x, y, dx, dy);
if (len >= 100)
bp = NULL;
else {
if (len == 0)
strcpy(buf2, "h");
bp = buf2;
}
}
break;
case MOB_SAIL:
if (path_find(x, y, dx, dy, player->cnum, MOB_SAIL) < 0)
bp = NULL;
else {
len = path_find_route(buf2, 100, x, y, dx, dy);
if (len >= 100)
bp = NULL;
else {
if (len == 0)
strcpy(buf2, "h");
bp = buf2;
}
}
break; break;
} }
if (bp && p + strlen(bp) + 1 < buf + MAX_PATH_LEN) {
strcpy(p, bp);
pr("Using best path '%s'\n", p); pr("Using best path '%s'\n", p);
pr("Using total path '%s'\n", buf); pr("Using total path '%s'\n", buf);
return buf; return buf;
} else {
pr("Can't get to %s from here!\n",
xyas(dx, dy, player->cnum));
}
break;
} }
dir = chkdir(*p, DIR_STOP, DIR_LAST); dir = chkdir(*p, DIR_STOP, DIR_LAST);
if (dir < 0) { if (dir < 0) {