]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/best.c
Update copyright notice
[empserver] / src / lib / commands / best.c
index 42e41c0c159cc79bb791f0219202859b62c85797..42a3fb3d0cea0c837c8c24978dd8f98b74d9a8be 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -39,7 +39,6 @@ int
 best(void)
 {
     double cost;
-    char *path;
     struct sctstr s1, s2;
     struct nstr_sect nstr, nstr2;
     char buf[1024];
@@ -58,31 +57,22 @@ best(void)
        while (!player->aborted && nxtsct(&nstr2, &s2)) {
            if (!player->owner)
                continue;
-           buf[0] = 0;
            cost = path_find(s1.sct_x, s1.sct_y, s2.sct_x, s2.sct_y,
-                            s1.sct_own, MOB_MOVE);
-           if (cost < 0) {
-               cost = 0;
-               path = NULL;
-           } else {
-               len = path_find_route(buf, 1024,
-                                     s1.sct_x, s1.sct_y,
-                                     s2.sct_x, s2.sct_y);
-               if (len + 1 >= 1024)
-                   path = NULL;
-               else {
-                   strcpy(buf + len, "h");
-                   path = buf;
-               }
-           }
-           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
+                            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;