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
|
* Dave Pare, 1986
|
||||||
* Thomas Ruschak, 1993 (rewritten)
|
* Thomas Ruschak, 1993 (rewritten)
|
||||||
* Steve McClure, 1998
|
* Steve McClure, 1998
|
||||||
|
* Markus Armbruster, 2008-2011
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -46,7 +47,7 @@ dist(void)
|
||||||
struct sctstr sect, dsect, tsect;
|
struct sctstr sect, dsect, tsect;
|
||||||
struct nstr_sect nstr;
|
struct nstr_sect nstr;
|
||||||
char *p;
|
char *p;
|
||||||
double move_cost = 0.0;
|
double move_cost;
|
||||||
coord dstx, dsty;
|
coord dstx, dsty;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
|
@ -90,7 +91,9 @@ dist(void)
|
||||||
pr("Warning: you don't own %s!\n",
|
pr("Warning: you don't own %s!\n",
|
||||||
xyas(dsect.sct_x, dsect.sct_y, player->cnum));
|
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",
|
pr("No owned path from %s to %s.\n",
|
||||||
xyas(dsect.sct_x, dsect.sct_y, player->cnum),
|
xyas(dsect.sct_x, dsect.sct_y, player->cnum),
|
||||||
xyas(sect.sct_x, sect.sct_y, player->cnum));
|
xyas(sect.sct_x, sect.sct_y, player->cnum));
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ken Stevens, 1995
|
* Ken Stevens, 1995
|
||||||
* Steve McClure, 1996-2000
|
* Steve McClure, 1996-2000
|
||||||
* Markus Armbruster, 2006-2009
|
* Markus Armbruster, 2006-2011
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#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 nstr_item ni;
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
struct sctstr sect, dsect;
|
|
||||||
struct ulist *llp;
|
struct ulist *llp;
|
||||||
int dtotal;
|
int dtotal;
|
||||||
double new_land = 0;
|
double new_land = 0;
|
||||||
|
@ -1465,7 +1464,6 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
double pathcost;
|
double pathcost;
|
||||||
int origx, origy;
|
int origx, origy;
|
||||||
double eff = att_combat_eff(def);
|
double eff = att_combat_eff(def);
|
||||||
char buf[1024];
|
|
||||||
|
|
||||||
if (list)
|
if (list)
|
||||||
dtotal = get_dtotal(def, list, 1.0, 1);
|
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))
|
if (!in_oparea((struct empobj *)&land, def->x, def->y))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
getsect(land.lnd_x, land.lnd_y, §);
|
pathcost = path_find(land.lnd_x, land.lnd_y, def->x, def->y,
|
||||||
getsect(def->x, def->y, &dsect);
|
def->own, lnd_mobtype(&land));
|
||||||
if (!BestLandPath(buf, §, &dsect, &pathcost,
|
if (pathcost < 0)
|
||||||
lnd_mobtype(&land)))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mobcost = lnd_pathcost(&land, pathcost);
|
mobcost = lnd_pathcost(&land, pathcost);
|
||||||
if (land.lnd_mobil < mobcost)
|
if (land.lnd_mobil < mobcost)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* supply.c: Supply subroutines
|
* supply.c: Supply subroutines
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Markus Armbruster, 2004-2009
|
* Markus Armbruster, 2004-2011
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -109,7 +109,7 @@ s_commod(struct empobj *sink, short *vec,
|
||||||
coord x = sink->x;
|
coord x = sink->x;
|
||||||
coord y = sink->y;
|
coord y = sink->y;
|
||||||
int lookrange;
|
int lookrange;
|
||||||
struct sctstr sect, dest;
|
struct sctstr sect;
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
struct lchrstr *lcp;
|
struct lchrstr *lcp;
|
||||||
|
@ -122,7 +122,6 @@ s_commod(struct empobj *sink, short *vec,
|
||||||
int packing;
|
int packing;
|
||||||
struct dchrstr *dp;
|
struct dchrstr *dp;
|
||||||
struct ichrstr *ip;
|
struct ichrstr *ip;
|
||||||
char buf[1024];
|
|
||||||
|
|
||||||
if (wanted > limit)
|
if (wanted > limit)
|
||||||
wanted = limit;
|
wanted = limit;
|
||||||
|
@ -130,8 +129,6 @@ s_commod(struct empobj *sink, short *vec,
|
||||||
return 1;
|
return 1;
|
||||||
wanted -= vec[type];
|
wanted -= vec[type];
|
||||||
|
|
||||||
getsect(x, y, &dest);
|
|
||||||
|
|
||||||
/* try to get it from sector we're in */
|
/* try to get it from sector we're in */
|
||||||
if (sink->ef_type != EF_SECTOR) {
|
if (sink->ef_type != EF_SECTOR) {
|
||||||
getsect(x, y, §);
|
getsect(x, y, §);
|
||||||
|
@ -175,7 +172,8 @@ s_commod(struct empobj *sink, short *vec,
|
||||||
continue;
|
continue;
|
||||||
if (sect.sct_effic < 60)
|
if (sect.sct_effic < 60)
|
||||||
continue;
|
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;
|
continue;
|
||||||
if (!opt_NOFOOD && type == I_FOOD)
|
if (!opt_NOFOOD && type == I_FOOD)
|
||||||
minimum = 1 + (int)ceil(food_needed(sect.sct_item,
|
minimum = 1 + (int)ceil(food_needed(sect.sct_item,
|
||||||
|
@ -247,7 +245,8 @@ s_commod(struct empobj *sink, short *vec,
|
||||||
continue;
|
continue;
|
||||||
if (sect.sct_effic < 2)
|
if (sect.sct_effic < 2)
|
||||||
continue;
|
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;
|
continue;
|
||||||
if (!opt_NOFOOD && type == I_FOOD)
|
if (!opt_NOFOOD && type == I_FOOD)
|
||||||
minimum = 1 + (int)ceil(food_needed(ship.shp_item,
|
minimum = 1 + (int)ceil(food_needed(ship.shp_item,
|
||||||
|
@ -321,7 +320,8 @@ s_commod(struct empobj *sink, short *vec,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
getsect(land.lnd_x, land.lnd_y, §);
|
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;
|
continue;
|
||||||
|
|
||||||
if ((land.lnd_ship >= 0) && (sect.sct_type != SCT_HARBR))
|
if ((land.lnd_ship >= 0) && (sect.sct_type != SCT_HARBR))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue