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 * dist.c: Name distribution sector for a given range of sectors
30 * Known contributors to this file:
32 * Thomas Ruschak, 1993 (rewritten)
48 * distribute <SECT> <DISTSECT|.|h>
53 struct sctstr sect, dsect, tsect;
54 struct nstr_sect nstr;
56 double move_cost = 0.0;
60 if (!snxtsct(&nstr, player->argp[1]))
62 while (!player->aborted && nxtsct(&nstr, §)) {
65 pr("%s at %s ", dchr[sect.sct_type].d_name,
66 xyas(nstr.x, nstr.y, player->cnum));
67 if ((sect.sct_dist_x != sect.sct_x) ||
68 (sect.sct_dist_y != sect.sct_y)) {
69 getsect(sect.sct_dist_x, sect.sct_dist_y, &tsect);
70 if (tsect.sct_own != player->cnum)
71 pr("distributes to %s, not owned by you.\n",
72 xyas(tsect.sct_x, tsect.sct_y, player->cnum));
74 pr("distributes to %s. \n",
75 xyas(tsect.sct_x, tsect.sct_y, player->cnum));
77 pr("has no dist sector. \n");
78 p = getstarg(player->argp[2], "Distribution sector? ", buf);
82 if (!check_sect_ok(§))
85 if (p && (*p != '.') && (*p != 'h') && (!sarg_xy(p, &dstx, &dsty)))
88 if (p && ((*p == '.') || (*p == 'h'))) {
93 if (!getsect(dstx, dsty, &dsect)) {
98 if (dsect.sct_own != player->cnum)
99 pr("Warning: you don't own %s!\n",
100 xyas(dsect.sct_x, dsect.sct_y, player->cnum));
102 path = BestDistPath(buf, §, &dsect, &move_cost, MOB_ROAD);
104 if (path == (s_char *)0) {
105 pr("No owned path from %s to %s.\n",
106 xyas(dsect.sct_x, dsect.sct_y, player->cnum),
107 xyas(sect.sct_x, sect.sct_y, player->cnum));
111 if ((dsect.sct_x == sect.sct_x) && (dsect.sct_y == sect.sct_y)) {
112 pr("Distribution from and to %s %s terminated\n",
113 dchr[sect.sct_type].d_name,
114 xyas(sect.sct_x, sect.sct_y, player->cnum));
116 pr("%s %s now distributes to %s (cost %1.3f)\n",
117 dchr[sect.sct_type].d_name,
118 xyas(sect.sct_x, sect.sct_y, player->cnum),
119 xyas(dsect.sct_x, dsect.sct_y, player->cnum), move_cost);
122 /* Only change and write out if we are really changing where it
123 distributes to. Otherwise, it's a waste of time (since nothing
125 if ((sect.sct_dist_x != dsect.sct_x) ||
126 (sect.sct_dist_y != dsect.sct_y)) {
127 sect.sct_dist_x = dsect.sct_x;
128 sect.sct_dist_y = dsect.sct_y;