Inline BestLandPath(), BestDistPath() glue
Following commits will simplify the resulting code.
This commit is contained in:
parent
957a6a74df
commit
92e64d7638
6 changed files with 99 additions and 54 deletions
|
@ -27,7 +27,7 @@
|
|||
* best.c: Show the best path between two sectors
|
||||
*
|
||||
* Known contributors to this file:
|
||||
*
|
||||
* Markus Armbruster, 2011
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -43,6 +43,7 @@ best(void)
|
|||
struct sctstr s1, s2;
|
||||
struct nstr_sect nstr, nstr2;
|
||||
char buf[1024];
|
||||
size_t len;
|
||||
|
||||
if (!snxtsct(&nstr, player->argp[1]))
|
||||
return RET_SYN;
|
||||
|
@ -57,7 +58,23 @@ best(void)
|
|||
while (!player->aborted && nxtsct(&nstr2, &s2)) {
|
||||
if (!player->owner)
|
||||
continue;
|
||||
path = BestLandPath(buf, &s1, &s2, &cost, MOB_MOVE);
|
||||
buf[0] = 0;
|
||||
cost = path_find(s1.sct_x, s1.sct_y, s2.sct_x, s2.sct_y,
|
||||
s1.sct_own, MOB_MOVE);
|
||||
if (cost < 0) {
|
||||
cost = 0;
|
||||
path = NULL;
|
||||
} else {
|
||||
len = path_find_route(buf, 1024,
|
||||
s1.sct_x, s1.sct_y,
|
||||
s2.sct_x, s2.sct_y);
|
||||
if (len + 1 >= 1024)
|
||||
path = NULL;
|
||||
else {
|
||||
strcpy(buf + len, "h");
|
||||
path = buf;
|
||||
}
|
||||
}
|
||||
if (path)
|
||||
pr("Best path from %s to %s is %s (cost %1.3f)\n",
|
||||
xyas(s1.sct_x, s1.sct_y, player->cnum),
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
* Known contributors to this file:
|
||||
* David Muir Sharnoff, 1986
|
||||
* (unknown rewrite), 1989
|
||||
* Markus Armbruster, 2005-2011
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -51,6 +52,7 @@ path(void)
|
|||
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;
|
||||
|
@ -66,7 +68,23 @@ path(void)
|
|||
return RET_FAIL;
|
||||
}
|
||||
getsect(sect.sct_dist_x, sect.sct_dist_y, &dsect);
|
||||
pp = BestDistPath(buf, §, &dsect, &move_cost);
|
||||
buf[0] = 0;
|
||||
move_cost = path_find(sect.sct_x, sect.sct_y, dsect.sct_x, dsect.sct_y,
|
||||
sect.sct_own, MOB_MOVE);
|
||||
if (move_cost < 0) {
|
||||
move_cost = 0;
|
||||
pp = NULL;
|
||||
} else {
|
||||
len = path_find_route(buf, 1024,
|
||||
sect.sct_x, sect.sct_y,
|
||||
dsect.sct_x, dsect.sct_y);
|
||||
if (len + 1 >= 1024)
|
||||
pp = NULL;
|
||||
else {
|
||||
strcpy(buf + len, "h");
|
||||
pp = buf;
|
||||
}
|
||||
}
|
||||
if (!pp) {
|
||||
pr("No path possible from %s to distribution sector %s\n",
|
||||
xyas(sect.sct_x, sect.sct_y, player->cnum),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue