Inline BestShipPath(), BestAirPath() glue
Following commits will simplify the resulting code.
This commit is contained in:
parent
92e64d7638
commit
e450c31ddb
7 changed files with 70 additions and 89 deletions
|
@ -29,7 +29,7 @@
|
|||
* Known contributors to this file:
|
||||
* Ken Stevens, 1995
|
||||
* Steve McClure, 1996-2000
|
||||
* Markus Armbruster, 2003-2009
|
||||
* Markus Armbruster, 2003-2011
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -615,6 +615,7 @@ perform_mission_bomb(int dam, struct emp_qelem *bombers, coord x, coord y,
|
|||
struct airport *air;
|
||||
char buf[512];
|
||||
char *pp;
|
||||
size_t len;
|
||||
|
||||
air = (struct airport *)qp;
|
||||
md = mapdist(x, y, air->x, air->y);
|
||||
|
@ -635,7 +636,18 @@ perform_mission_bomb(int dam, struct emp_qelem *bombers, coord x, coord y,
|
|||
|
||||
mission_pln_arm(&e, air->x, air->y, 2 * md, 'e', NULL);
|
||||
|
||||
pp = BestAirPath(buf, air->x, air->y, x, y);
|
||||
if (path_find(air->x, air->y, x, y, 0, MOB_FLY) < 0)
|
||||
pp = NULL;
|
||||
else {
|
||||
len = path_find_route(buf, 100, air->x, air->y, x, y);
|
||||
if (len >= 100)
|
||||
pp = NULL;
|
||||
else {
|
||||
if (len == 0)
|
||||
strcpy(buf, "h");
|
||||
pp = buf;
|
||||
}
|
||||
}
|
||||
if (CANT_HAPPEN(!pp))
|
||||
continue;
|
||||
performed = 1;
|
||||
|
|
|
@ -94,6 +94,7 @@ getpath(char *buf, char *arg, coord x, coord y, int onlyown,
|
|||
char buf2[1024];
|
||||
char *p = buf;
|
||||
char *bp;
|
||||
size_t len;
|
||||
char prompt[128];
|
||||
coord dx, dy;
|
||||
struct sctstr sect;
|
||||
|
@ -118,10 +119,32 @@ more:
|
|||
pr("Destination sectors not allowed here!\n");
|
||||
break;
|
||||
case P_FLYING:
|
||||
bp = BestAirPath(buf2, x, y, dx, dy);
|
||||
if (path_find(x, y, dx, dy, 0, MOB_FLY) < 0)
|
||||
bp = NULL;
|
||||
else {
|
||||
len = path_find_route(buf2, 100, x, y, dx, dy);
|
||||
if (len >= 100)
|
||||
bp = NULL;
|
||||
else {
|
||||
if (len == 0)
|
||||
strcpy(buf2, "h");
|
||||
bp = buf2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case P_SAILING:
|
||||
bp = BestShipPath(buf2, x, y, dx, dy, player->cnum);
|
||||
if (path_find(x, y, dx, dy, player->cnum, MOB_SAIL) < 0)
|
||||
bp = NULL;
|
||||
else {
|
||||
len = path_find_route(buf2, 100, x, y, dx, dy);
|
||||
if (len >= 100)
|
||||
bp = NULL;
|
||||
else {
|
||||
if (len == 0)
|
||||
strcpy(buf2, "h");
|
||||
bp = buf2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (bp && p + strlen(bp) + 1 < buf + MAX_PATH_LEN) {
|
||||
|
|
|
@ -157,8 +157,20 @@ unit_path(int together, struct empobj *unit, char *buf)
|
|||
return NULL;
|
||||
}
|
||||
if (unit->ef_type == EF_SHIP) {
|
||||
cp = BestShipPath(buf, unit->x, unit->y,
|
||||
d_sect.sct_x, d_sect.sct_y, player->cnum);
|
||||
if (path_find(unit->x, unit->y, d_sect.sct_x, d_sect.sct_y,
|
||||
player->cnum, MOB_SAIL) < 0)
|
||||
cp = NULL;
|
||||
else {
|
||||
len = path_find_route(buf, 100, unit->x, unit->y,
|
||||
d_sect.sct_x, d_sect.sct_y);
|
||||
if (len >= 100)
|
||||
cp = NULL;
|
||||
else {
|
||||
if (len == 0)
|
||||
strcpy(buf, "h");
|
||||
cp = buf;
|
||||
}
|
||||
}
|
||||
if (!cp || unit->mobil <= 0) {
|
||||
pr("Can't get to '%s' right now.\n",
|
||||
xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue