2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * path.c: Show empire distribution paths
30 * Known contributors to this file:
31 * David Muir Sharnoff, 1986
32 * (unknown rewrite), 1989
54 struct range absrange;
55 struct range relrange;
56 struct sctstr sect, dsect;
61 /* Note this is not re-entrant anyway, so we keep the buffers
63 static s_char *mapbuf = (s_char *)0;
64 static s_char **map = (s_char **)0;
68 if (!(p = getstarg(player->argp[1], "from sector : ", buf)) ||
69 !sarg_xy(p, &cx, &cy) || !getsect(cx, cy, §))
71 if ((sect.sct_own != player->cnum) && !player->god) {
75 getsect(sect.sct_dist_x, sect.sct_dist_y, &dsect);
76 pp = BestDistPath(buf, §, &dsect, &move_cost, MOB_ROAD);
77 if (pp == (s_char *)0) {
78 pr("No path possible from %s to distribution sector %s\n",
79 xyas(sect.sct_x, sect.sct_y, player->cnum),
80 xyas(dsect.sct_x, dsect.sct_y, player->cnum));
85 (s_char *)malloc((WORLD_Y * MAPWIDTH(3)) * sizeof(s_char));
87 map = (s_char **)malloc(WORLD_Y * sizeof(s_char *));
89 for (i = 0; i < WORLD_Y; i++)
90 map[i] = &mapbuf[MAPWIDTH(3) * i];
96 if (!mapbuf || !map) {
97 pr("Memory error, tell the deity.\n");
98 logerror("malloc failed in path\n");
101 pathrange(cx, cy, pp, 1, &absrange);
102 snxtsct_area(&ns, &absrange);
103 natp = getnatp(player->cnum);
104 xyrelrange(natp, &absrange, &relrange);
105 blankfill((s_char *)mapbuf, &ns.range, 3);
106 while (*pp && (i = chkdir(*pp, DIR_STOP, DIR_LAST)) >= 0) {
107 memcpy(&map[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx) * 2],
114 border(&relrange, " ", " ");
115 while (nxtsct(&ns, §)) {
118 map[ns.dy][ns.dx * 2 + 1] = dchr[sect.sct_type].d_mnem;
120 for (y = ns.range.ly, i = 0; i < ns.range.height; y++, i++) {
122 pr("%4d %s %-4d\n", cy, map[i], cy);
126 border(&relrange, " ", " ");