/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
* best.c: Show the best path between two sectors
*
* Known contributors to this file:
- *
+ * Markus Armbruster, 2011
*/
#include <config.h>
best(void)
{
double cost;
- char *path;
struct sctstr s1, s2;
struct nstr_sect nstr, nstr2;
char buf[1024];
+ size_t len;
if (!snxtsct(&nstr, player->argp[1]))
return RET_SYN;
while (!player->aborted && nxtsct(&nstr2, &s2)) {
if (!player->owner)
continue;
- path = BestLandPath(buf, &s1, &s2, &cost, MOB_MOVE);
- if (path)
- pr("Best path from %s to %s is %s (cost %1.3f)\n",
- xyas(s1.sct_x, s1.sct_y, player->cnum),
- xyas(s2.sct_x, s2.sct_y, player->cnum), path, cost);
- else
+ cost = path_find(s1.sct_x, s1.sct_y, s2.sct_x, s2.sct_y,
+ player->cnum, MOB_MOVE);
+ if (cost < 0)
pr("No owned path from %s to %s exists!\n",
xyas(s1.sct_x, s1.sct_y, player->cnum),
xyas(s2.sct_x, s2.sct_y, player->cnum));
+ else {
+ len = path_find_route(buf, sizeof(buf),
+ s1.sct_x, s1.sct_y,
+ s2.sct_x, s2.sct_y);
+ pr("Best path from %s to %s is %s%s (cost %1.3f)\n",
+ xyas(s1.sct_x, s1.sct_y, player->cnum),
+ xyas(s2.sct_x, s2.sct_y, player->cnum),
+ buf, len < sizeof(buf) ? "h" : "...",
+ cost);
+ }
}
}
return 0;