Use path_find() directly where only cost is needed
dist(), att_reacting_units() and s_commod() are only interested in cost, not the actual path. BestLandPath() and BestDistPath() compute both cost and path. Use path_find() directly instead. Destinations are no longer treated as unreachable when the best path is longer than 1023 characters.
This commit is contained in:
parent
04363a92db
commit
aef27e3521
3 changed files with 17 additions and 18 deletions
|
@ -30,6 +30,7 @@
|
|||
* Dave Pare, 1986
|
||||
* Thomas Ruschak, 1993 (rewritten)
|
||||
* Steve McClure, 1998
|
||||
* Markus Armbruster, 2008-2011
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -46,7 +47,7 @@ dist(void)
|
|||
struct sctstr sect, dsect, tsect;
|
||||
struct nstr_sect nstr;
|
||||
char *p;
|
||||
double move_cost = 0.0;
|
||||
double move_cost;
|
||||
coord dstx, dsty;
|
||||
char buf[1024];
|
||||
|
||||
|
@ -90,7 +91,9 @@ dist(void)
|
|||
pr("Warning: you don't own %s!\n",
|
||||
xyas(dsect.sct_x, dsect.sct_y, player->cnum));
|
||||
|
||||
if (!BestDistPath(buf, §, &dsect, &move_cost)) {
|
||||
move_cost = path_find(sect.sct_x, sect.sct_y, dstx, dsty,
|
||||
player->cnum, MOB_MOVE);
|
||||
if (move_cost < 0) {
|
||||
pr("No owned path from %s to %s.\n",
|
||||
xyas(dsect.sct_x, dsect.sct_y, player->cnum),
|
||||
xyas(sect.sct_x, sect.sct_y, player->cnum));
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
* Known contributors to this file:
|
||||
* Ken Stevens, 1995
|
||||
* Steve McClure, 1996-2000
|
||||
* Markus Armbruster, 2006-2009
|
||||
* Markus Armbruster, 2006-2011
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -1457,7 +1457,6 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
|||
{
|
||||
struct nstr_item ni;
|
||||
struct lndstr land;
|
||||
struct sctstr sect, dsect;
|
||||
struct ulist *llp;
|
||||
int dtotal;
|
||||
double new_land = 0;
|
||||
|
@ -1465,7 +1464,6 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
|||
double pathcost;
|
||||
int origx, origy;
|
||||
double eff = att_combat_eff(def);
|
||||
char buf[1024];
|
||||
|
||||
if (list)
|
||||
dtotal = get_dtotal(def, list, 1.0, 1);
|
||||
|
@ -1497,12 +1495,10 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
|||
if (!in_oparea((struct empobj *)&land, def->x, def->y))
|
||||
continue;
|
||||
|
||||
getsect(land.lnd_x, land.lnd_y, §);
|
||||
getsect(def->x, def->y, &dsect);
|
||||
if (!BestLandPath(buf, §, &dsect, &pathcost,
|
||||
lnd_mobtype(&land)))
|
||||
pathcost = path_find(land.lnd_x, land.lnd_y, def->x, def->y,
|
||||
def->own, lnd_mobtype(&land));
|
||||
if (pathcost < 0)
|
||||
continue;
|
||||
|
||||
mobcost = lnd_pathcost(&land, pathcost);
|
||||
if (land.lnd_mobil < mobcost)
|
||||
continue;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* supply.c: Supply subroutines
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Markus Armbruster, 2004-2009
|
||||
* Markus Armbruster, 2004-2011
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -109,7 +109,7 @@ s_commod(struct empobj *sink, short *vec,
|
|||
coord x = sink->x;
|
||||
coord y = sink->y;
|
||||
int lookrange;
|
||||
struct sctstr sect, dest;
|
||||
struct sctstr sect;
|
||||
struct nstr_sect ns;
|
||||
struct nstr_item ni;
|
||||
struct lchrstr *lcp;
|
||||
|
@ -122,7 +122,6 @@ s_commod(struct empobj *sink, short *vec,
|
|||
int packing;
|
||||
struct dchrstr *dp;
|
||||
struct ichrstr *ip;
|
||||
char buf[1024];
|
||||
|
||||
if (wanted > limit)
|
||||
wanted = limit;
|
||||
|
@ -130,8 +129,6 @@ s_commod(struct empobj *sink, short *vec,
|
|||
return 1;
|
||||
wanted -= vec[type];
|
||||
|
||||
getsect(x, y, &dest);
|
||||
|
||||
/* try to get it from sector we're in */
|
||||
if (sink->ef_type != EF_SECTOR) {
|
||||
getsect(x, y, §);
|
||||
|
@ -175,7 +172,8 @@ s_commod(struct empobj *sink, short *vec,
|
|||
continue;
|
||||
if (sect.sct_effic < 60)
|
||||
continue;
|
||||
if (!BestLandPath(buf, §, &dest, &move_cost, MOB_MOVE))
|
||||
move_cost = path_find(sect.sct_x, sect.sct_y, x, y, own, MOB_MOVE);
|
||||
if (move_cost < 0)
|
||||
continue;
|
||||
if (!opt_NOFOOD && type == I_FOOD)
|
||||
minimum = 1 + (int)ceil(food_needed(sect.sct_item,
|
||||
|
@ -247,7 +245,8 @@ s_commod(struct empobj *sink, short *vec,
|
|||
continue;
|
||||
if (sect.sct_effic < 2)
|
||||
continue;
|
||||
if (!BestLandPath(buf, §, &dest, &move_cost, MOB_MOVE))
|
||||
move_cost = path_find(sect.sct_x, sect.sct_y, x, y, own, MOB_MOVE);
|
||||
if (move_cost < 0)
|
||||
continue;
|
||||
if (!opt_NOFOOD && type == I_FOOD)
|
||||
minimum = 1 + (int)ceil(food_needed(ship.shp_item,
|
||||
|
@ -321,7 +320,8 @@ s_commod(struct empobj *sink, short *vec,
|
|||
continue;
|
||||
|
||||
getsect(land.lnd_x, land.lnd_y, §);
|
||||
if (!BestLandPath(buf, §, &dest, &move_cost, MOB_MOVE))
|
||||
move_cost = path_find(land.lnd_x, land.lnd_y, x, y, own, MOB_MOVE);
|
||||
if (move_cost < 0)
|
||||
continue;
|
||||
|
||||
if ((land.lnd_ship >= 0) && (sect.sct_type != SCT_HARBR))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue