]> git.pond.sub.org Git - empserver/commitdiff
Fix march and navigate not to interpret coordinates as path
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 27 Mar 2011 15:55:35 +0000 (17:55 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 12 Apr 2011 19:51:32 +0000 (21:51 +0200)
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
src/lib/subs/unitsub.c

index 8b4ba6bd8014c5073c4b2cd888528197e7ddbf14..0223823bf096743f0ce93cc4405ba7b636cfcd8b 100644 (file)
@@ -29,6 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995 (rewritten)
  *     Ron Koenderink, 2006-2007
+ *     Markus Armbruster, 2006-2011
  */
 
 #include <config.h>
@@ -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,
index ee8376bf40b6e5ccc1f98a76ec75c154402df73f..e2a2f9f71c2f2480bc3641974728eab9c2557b57 100644 (file)
@@ -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),