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.
This commit is contained in:
parent
74b08563af
commit
d6cf175b0b
2 changed files with 5 additions and 6 deletions
|
@ -29,6 +29,7 @@
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ken Stevens, 1995 (rewritten)
|
* Ken Stevens, 1995 (rewritten)
|
||||||
* Ron Koenderink, 2006-2007
|
* Ron Koenderink, 2006-2007
|
||||||
|
* Markus Armbruster, 2006-2011
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -92,8 +93,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
|
||||||
|
|
||||||
if (player->argp[2]) {
|
if (player->argp[2]) {
|
||||||
strcpy(buf, player->argp[2]);
|
strcpy(buf, player->argp[2]);
|
||||||
if (!(cp = unit_path(*together, leader, buf)))
|
cp = unit_path(*together, leader, buf);
|
||||||
cp = player->argp[2];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*pt = '\0';
|
*pt = '\0';
|
||||||
|
@ -152,8 +152,8 @@ do_unit_move(struct emp_qelem *ulist, int *together,
|
||||||
stopping = 1;
|
stopping = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(cp = unit_path(*together, leader, buf)))
|
if (cp)
|
||||||
cp = buf;
|
cp = unit_path(*together, leader, cp);
|
||||||
}
|
}
|
||||||
if (type == EF_SHIP) {
|
if (type == EF_SHIP) {
|
||||||
rad_map_set(player->cnum, leader->x, leader->y, leader->effic,
|
rad_map_set(player->cnum, leader->x, leader->y, leader->effic,
|
||||||
|
|
|
@ -147,7 +147,7 @@ unit_path(int together, struct empobj *unit, char *buf)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!sarg_xy(buf, &destx, &desty))
|
if (!sarg_xy(buf, &destx, &desty))
|
||||||
return NULL;
|
return buf;
|
||||||
if (!together) {
|
if (!together) {
|
||||||
pr("Cannot go to a destination sector if not all starting in the same sector\n");
|
pr("Cannot go to a destination sector if not all starting in the same sector\n");
|
||||||
return NULL;
|
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);
|
c = path_find(unit->x, unit->y, destx, desty, sect.sct_own, mtype);
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
buf[0] = 0;
|
|
||||||
pr("No owned %s from %s to %s!\n",
|
pr("No owned %s from %s to %s!\n",
|
||||||
mtype == MOB_RAIL ? "railway" : "path",
|
mtype == MOB_RAIL ? "railway" : "path",
|
||||||
xyas(unit->x, unit->y, player->cnum),
|
xyas(unit->x, unit->y, player->cnum),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue