2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * dist.c: Name distribution sector for a given range of sectors
29 * Known contributors to this file:
31 * Thomas Ruschak, 1993 (rewritten)
41 * distribute <SECT> <DISTSECT|.|h>
46 struct sctstr sect, dsect, tsect;
47 struct nstr_sect nstr;
49 double move_cost = 0.0;
53 if (!snxtsct(&nstr, player->argp[1]))
55 while (nxtsct(&nstr, §)) {
58 pr("%s at %s ", dchr[sect.sct_type].d_name,
59 xyas(nstr.x, nstr.y, player->cnum));
60 if ((sect.sct_dist_x != sect.sct_x) ||
61 (sect.sct_dist_y != sect.sct_y)) {
62 getsect(sect.sct_dist_x, sect.sct_dist_y, &tsect);
63 if (tsect.sct_own != player->cnum)
64 pr("distributes to %s, not owned by you.\n",
65 xyas(tsect.sct_x, tsect.sct_y, player->cnum));
67 pr("distributes to %s. \n",
68 xyas(tsect.sct_x, tsect.sct_y, player->cnum));
70 pr("has no dist sector. \n");
71 p = getstarg(player->argp[2], "Distribution sector? ", buf);
76 if (!check_sect_ok(§))
79 if (*p == '.' || *p == 'h') {
82 } else if (!sarg_xy(p, &dstx, &dsty))
84 if (!getsect(dstx, dsty, &dsect)) {
89 if (dsect.sct_own != player->cnum)
90 pr("Warning: you don't own %s!\n",
91 xyas(dsect.sct_x, dsect.sct_y, player->cnum));
93 if (!BestDistPath(buf, §, &dsect, &move_cost)) {
94 pr("No owned path from %s to %s.\n",
95 xyas(dsect.sct_x, dsect.sct_y, player->cnum),
96 xyas(sect.sct_x, sect.sct_y, player->cnum));
100 if ((dsect.sct_x == sect.sct_x) && (dsect.sct_y == sect.sct_y)) {
101 pr("Distribution from and to %s %s terminated\n",
102 dchr[sect.sct_type].d_name,
103 xyas(sect.sct_x, sect.sct_y, player->cnum));
105 pr("%s %s now distributes to %s (cost %1.3f)\n",
106 dchr[sect.sct_type].d_name,
107 xyas(sect.sct_x, sect.sct_y, player->cnum),
108 xyas(dsect.sct_x, dsect.sct_y, player->cnum), move_cost);
111 /* Only change and write out if we are really changing where it
112 distributes to. Otherwise, it's a waste of time (since nothing
114 if ((sect.sct_dist_x != dsect.sct_x) ||
115 (sect.sct_dist_y != dsect.sct_y)) {
116 sect.sct_dist_x = dsect.sct_x;
117 sect.sct_dist_y = dsect.sct_y;