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 @@
|
|||
* move.c: Move something somewhere.
|
||||
*
|
||||
* Known contributors to this file:
|
||||
*
|
||||
* Markus Armbruster, 2004-2011
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -58,6 +58,7 @@ move_ground(struct sctstr *start, struct sctstr *end,
|
|||
double sect_mcost;
|
||||
double total_mcost;
|
||||
double mv_cost;
|
||||
size_t len;
|
||||
double mobility = start->sct_mobil;
|
||||
int dir;
|
||||
int intcost;
|
||||
|
@ -79,8 +80,24 @@ move_ground(struct sctstr *start, struct sctstr *end,
|
|||
return -1;
|
||||
}
|
||||
pr("Looking for best path to %s\n", path);
|
||||
path = BestLandPath(buf2, start, &ending_sect, &total_mcost,
|
||||
MOB_MOVE);
|
||||
buf2[0] = 0;
|
||||
total_mcost = path_find(start->sct_x, start->sct_y,
|
||||
ending_sect.sct_x, ending_sect.sct_y,
|
||||
start->sct_own, MOB_MOVE);
|
||||
if (total_mcost < 0) {
|
||||
total_mcost = 0;
|
||||
path = NULL;
|
||||
} else {
|
||||
len = path_find_route(buf2, 1024,
|
||||
start->sct_x, start->sct_y,
|
||||
ending_sect.sct_x, ending_sect.sct_y);
|
||||
if (len + 1 >= 1024)
|
||||
path = NULL;
|
||||
else {
|
||||
strcpy(buf2 + len, "h");
|
||||
path = buf2;
|
||||
}
|
||||
}
|
||||
if (exploring && path) /* take off the 'h' */
|
||||
path[strlen(path) - 1] = '\0';
|
||||
if (!path)
|
||||
|
@ -120,8 +137,24 @@ move_ground(struct sctstr *start, struct sctstr *end,
|
|||
}
|
||||
if (movstr && sarg_xy(movstr, &dx, &dy)) {
|
||||
if (getsect(dx, dy, &dsect)) {
|
||||
movstr = BestLandPath(buf2, §, &dsect, &mv_cost,
|
||||
MOB_MOVE);
|
||||
buf2[0] = 0;
|
||||
mv_cost = path_find(sect.sct_x, sect.sct_y,
|
||||
dsect.sct_x, dsect.sct_y,
|
||||
sect.sct_own, MOB_MOVE);
|
||||
if (mv_cost < 0) {
|
||||
mv_cost = 0;
|
||||
movstr = NULL;
|
||||
} else {
|
||||
len = path_find_route(buf2, 1024,
|
||||
sect.sct_x, sect.sct_y,
|
||||
dsect.sct_x, dsect.sct_y);
|
||||
if (len + 1 >= 1024)
|
||||
movstr = NULL;
|
||||
else {
|
||||
strcpy(buf2 + len, "h");
|
||||
movstr = buf2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pr("Invalid destination sector!\n");
|
||||
movstr = NULL;
|
||||
|
|
|
@ -139,8 +139,8 @@ unit_path(int together, struct empobj *unit, char *buf)
|
|||
coord destx;
|
||||
coord desty;
|
||||
struct sctstr d_sect, sect;
|
||||
size_t len;
|
||||
char *cp;
|
||||
double dummy;
|
||||
int mtype;
|
||||
|
||||
if (CANT_HAPPEN(unit->ef_type != EF_LAND && unit->ef_type != EF_SHIP))
|
||||
|
@ -167,7 +167,28 @@ unit_path(int together, struct empobj *unit, char *buf)
|
|||
} else {
|
||||
getsect(unit->x, unit->y, §);
|
||||
mtype = lnd_mobtype((struct lndstr *)unit);
|
||||
cp = BestLandPath(buf, §, &d_sect, &dummy, mtype);
|
||||
buf[0] = 0;
|
||||
/*
|
||||
* Note: passing sect.sct_own for actor is funny, but works:
|
||||
* its only effect is to confine the search to that nation's
|
||||
* land. It doesn't affect mobility costs. The real actor is
|
||||
* different for marching in allied land, and passing it would
|
||||
* break path finding there.
|
||||
*/
|
||||
if (path_find(sect.sct_x, sect.sct_y, d_sect.sct_x, d_sect.sct_y,
|
||||
sect.sct_own, mtype) < 0)
|
||||
cp = NULL;
|
||||
else {
|
||||
len = path_find_route(buf, 1024,
|
||||
sect.sct_x, sect.sct_y,
|
||||
d_sect.sct_x, d_sect.sct_y);
|
||||
if (len + 1 >= 1024)
|
||||
cp = NULL;
|
||||
else {
|
||||
strcpy(buf + len, "h");
|
||||
cp = buf;
|
||||
}
|
||||
}
|
||||
if (!cp) {
|
||||
pr("No owned %s from %s to %s!\n",
|
||||
mtype == MOB_RAIL ? "railway" : "path",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue