]> git.pond.sub.org Git - empserver/blob - src/lib/commands/best.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / best.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  best.c: Show the best path between two sectors
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include <config.h>
35
36 #include "misc.h"
37 #include "player.h"
38 #include "sect.h"
39 #include "xy.h"
40 #include "path.h"
41 #include "nsc.h"
42 #include "nat.h"
43 #include "commands.h"
44
45 int
46 best(void)
47 {
48     double cost;
49     s_char *s;
50     struct sctstr s1, s2;
51     struct nstr_sect nstr, nstr2;
52     s_char buf[1024];
53
54     if (!snxtsct(&nstr, player->argp[1]))
55         return RET_SYN;
56
57     if (!snxtsct(&nstr2, player->argp[2]))
58         return RET_SYN;
59
60     while (!player->aborted && nxtsct(&nstr, &s1)) {
61         if (s1.sct_own != player->cnum)
62             continue;
63         snxtsct(&nstr2, player->argp[2]);
64         while (!player->aborted && nxtsct(&nstr2, &s2)) {
65             if (s2.sct_own != player->cnum)
66                 continue;
67             s = BestLandPath(buf, &s1, &s2, &cost, MOB_ROAD);
68             if (s != (s_char *)0)
69                 pr("Best path from %s to %s is %s (cost %1.3f)\n",
70                    xyas(s1.sct_x, s1.sct_y, player->cnum),
71                    xyas(s2.sct_x, s2.sct_y, player->cnum), s, cost);
72             else
73                 pr("No owned path from %s to %s exists!\n",
74                    xyas(s1.sct_x, s1.sct_y, player->cnum),
75                    xyas(s2.sct_x, s2.sct_y, player->cnum));
76         }
77     }
78     return 0;
79 }