2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 * desi.c: Redesignate sectors
30 * Known contributors to this file:
31 * Steve McClure, 1998-2000
48 long do_desi(struct natstr *natp, s_char *sects, s_char *deschar,
49 long int cash, int for_real);
58 natp = getnatp(player->cnum);
59 cash = natp->nat_money;
60 if (player->argp[2]) {
61 cost = do_desi(natp, player->argp[1], player->argp[2], cash, 0);
64 if (chkmoney(cost, cash, player->argp[3]))
67 return (int)do_desi(natp, player->argp[1], player->argp[2], cash, 1);
71 do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
74 extern int opt_NO_LCMS;
75 extern int opt_NO_HCMS;
82 struct nstr_sect nstr;
92 if (!snxtsct(&nstr, sects)) {
96 return (long)-RET_SYN;
98 cap_x = natp->nat_xcap;
99 cap_y = natp->nat_ycap;
100 while (!player->aborted && nxtsct(&nstr, §)) {
104 if (sect.sct_type == SCT_MOUNT ||
105 sect.sct_type == SCT_BTOWER ||
106 sect.sct_type == SCT_BSPAN ||
107 sect.sct_type == SCT_WASTE ||
108 sect.sct_type == SCT_PLAINS ||
109 (opt_NO_LCMS && sect.sct_type == SCT_LIGHT) ||
110 (opt_NO_HCMS && sect.sct_type == SCT_HEAVY) ||
111 (opt_NO_OIL && sect.sct_type == SCT_OIL) ||
112 (opt_NO_OIL && sect.sct_type == SCT_REFINE))
115 sprintf(prompt, "%s %d%% %s desig? ",
116 xyas(sect.sct_x, sect.sct_y, player->cnum),
117 sect.sct_effic, dchr[sect.sct_type].d_name);
118 if ((p = getstarg(deschar, prompt, buf)) == 0)
121 if (!check_sect_ok(§))
124 des = typematch(p, EF_SECTOR);
125 if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
127 pr("See \"info Sector-types\"\n");
129 return (long)RET_FAIL;
131 return (long)-RET_FAIL;
134 if (des == SCT_WATER || des == SCT_MOUNT ||
135 des == SCT_SANCT || des == SCT_PLAINS ||
136 (opt_NO_LCMS && des == SCT_LIGHT) ||
137 (opt_NO_HCMS && des == SCT_HEAVY) ||
138 (opt_NO_OIL && des == SCT_OIL) ||
139 (opt_NO_OIL && des == SCT_REFINE)) {
140 pr("Only %s can make a %s!\n", cname(0), dchr[des].d_name);
143 if (des == SCT_WASTE) {
144 pr("Only a nuclear device (or %s) can make a %s!\n",
145 cname(0), dchr[des].d_name);
149 if (sect.sct_type == des && sect.sct_newtype == des)
151 if (sect.sct_type == SCT_SANCT)
153 if (sect.sct_x == cap_x && sect.sct_y == cap_y &&
154 des != SCT_CAPIT && des != SCT_SANCT &&
155 des != SCT_MOUNT && for_real)
156 pr("You have redesignated your capital!\n");
157 if (des == SCT_HARBR) {
158 for (n = 1; n <= 6; n++) {
159 getsect(nstr.x + diroff[n][0],
160 nstr.y + diroff[n][1], &check);
161 if (check.sct_type == SCT_WATER)
163 if (check.sct_type == SCT_BSPAN)
165 if (check.sct_type == SCT_BTOWER)
170 pr("%s does not border on water.\n",
171 xyas(nstr.x, nstr.y, player->cnum));
174 pr("But if it's what you want ...\n");
179 if (des == SCT_BHEAD) {
180 for (n = 1; n <= 6; n++) {
181 getsect(nstr.x + diroff[n][0],
182 nstr.y + diroff[n][1], &check);
183 if (check.sct_type == SCT_WATER)
185 if (check.sct_type == SCT_BSPAN)
187 if (check.sct_type == SCT_BTOWER)
192 pr("%s does not border on water.\n",
193 xyas(nstr.x, nstr.y, player->cnum));
196 pr("But if it's what you want...\n");
201 if (sect.sct_type == SCT_SANCT && !player->god)
204 if ((sect.sct_newtype != des) && (sect.sct_type != des)
205 && dchr[des].d_cost) {
208 (!deschar, dchr[des].d_cost, cash, &warned,
212 cost += dchr[des].d_cost;
216 if (sect.sct_effic < 5 || player->god) {
219 /* No longer tear down infrasturcture
221 sect.sct_defense = 0;
223 changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
224 dchr[des].d_mnem, 0);
226 sect.sct_newtype = des;
228 if (opt_EASY_BRIDGES == 0) { /* may cause a bridge fall */
231 bridgefall(§, 0);
236 writemap(player->cnum);