From d6cf175b0b972bbfe6a138fc6dc9082da9501f69 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 27 Mar 2011 17:55:35 +0200 Subject: [PATCH] Fix march and navigate not to interpret coordinates as path Destination arguments can be a path or sector coordinates. do_unit_move() passes the argument buffer to unit_path() to convert coordinates to a path. If unit_path() fails, do_unit_move() still interprets the argument as path. This is correct when unit_path() fails because the argument is not coordinates. But it can also fail when it is coordinates, namely when the destination isn't reachable, when the path to it is too long, or when the ships or land units aren't together. Then do_unit_move() interprets coordinates as path, and rejects them with "Legal directions are:". Except when a land unit's destination read from a march prompt isn't reachable, because then unit_path() empties the argument buffer that do_unit_move() uses. Change unit_path() to succeed when the argument is not coordinates. Make do_unit_move() discard the argument when unit_path() fails, i.e. when it is bad coordinates. unit_path() emptying the argument no longer has an effect, drop it. --- src/lib/commands/navi.c | 8 ++++---- src/lib/subs/unitsub.c | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/commands/navi.c b/src/lib/commands/navi.c index 8b4ba6bd..0223823b 100644 --- a/src/lib/commands/navi.c +++ b/src/lib/commands/navi.c @@ -29,6 +29,7 @@ * Known contributors to this file: * Ken Stevens, 1995 (rewritten) * Ron Koenderink, 2006-2007 + * Markus Armbruster, 2006-2011 */ #include @@ -92,8 +93,7 @@ do_unit_move(struct emp_qelem *ulist, int *together, if (player->argp[2]) { strcpy(buf, player->argp[2]); - if (!(cp = unit_path(*together, leader, buf))) - cp = player->argp[2]; + cp = unit_path(*together, leader, buf); } *pt = '\0'; @@ -152,8 +152,8 @@ do_unit_move(struct emp_qelem *ulist, int *together, stopping = 1; continue; } - if (!(cp = unit_path(*together, leader, buf))) - cp = buf; + if (cp) + cp = unit_path(*together, leader, cp); } if (type == EF_SHIP) { rad_map_set(player->cnum, leader->x, leader->y, leader->effic, diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c index ee8376bf..e2a2f9f7 100644 --- a/src/lib/subs/unitsub.c +++ b/src/lib/subs/unitsub.c @@ -147,7 +147,7 @@ unit_path(int together, struct empobj *unit, char *buf) return NULL; if (!sarg_xy(buf, &destx, &desty)) - return NULL; + return buf; if (!together) { pr("Cannot go to a destination sector if not all starting in the same sector\n"); return NULL; @@ -172,7 +172,6 @@ unit_path(int together, struct empobj *unit, char *buf) */ c = path_find(unit->x, unit->y, destx, desty, sect.sct_own, mtype); if (c < 0) { - buf[0] = 0; pr("No owned %s from %s to %s!\n", mtype == MOB_RAIL ? "railway" : "path", xyas(unit->x, unit->y, player->cnum),