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, long int cash, int for_real);
57 natp = getnatp(player->cnum);
58 cash = natp->nat_money;
59 if (player->argp[2]) {
60 cost = do_desi(natp, player->argp[1], player->argp[2], cash, 0);
63 if (chkmoney(cost, cash, player->argp[3]))
66 return (int)do_desi(natp, player->argp[1], player->argp[2], cash, 1);
70 do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash, int for_real)
72 extern int opt_NO_LCMS;
73 extern int opt_NO_HCMS;
80 struct nstr_sect nstr;
90 if (!snxtsct(&nstr, sects)) {
94 return (long)-RET_SYN;
96 cap_x = natp->nat_xcap;
97 cap_y = natp->nat_ycap;
98 while (!player->aborted && nxtsct(&nstr, §)) {
102 if (sect.sct_type == SCT_MOUNT ||
103 sect.sct_type == SCT_BTOWER ||
104 sect.sct_type == SCT_BSPAN ||
105 sect.sct_type == SCT_WASTE ||
106 sect.sct_type == SCT_PLAINS ||
107 (opt_NO_LCMS && sect.sct_type == SCT_LIGHT) ||
108 (opt_NO_HCMS && sect.sct_type == SCT_HEAVY) ||
109 (opt_NO_OIL && sect.sct_type == SCT_OIL) ||
110 (opt_NO_OIL && sect.sct_type == SCT_REFINE))
113 sprintf(prompt, "%s %d%% %s desig? ",
114 xyas(sect.sct_x, sect.sct_y, player->cnum),
115 sect.sct_effic, dchr[sect.sct_type].d_name);
116 if ((p = getstarg(deschar, prompt, buf)) == 0)
119 if (!check_sect_ok(§))
122 des = typematch(p, EF_SECTOR);
123 if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
125 pr("See \"info Sector-types\"\n");
127 return (long)RET_FAIL;
129 return (long)-RET_FAIL;
132 if (des == SCT_WATER || des == SCT_MOUNT ||
133 des == SCT_SANCT || des == SCT_PLAINS ||
134 (opt_NO_LCMS && des == SCT_LIGHT) ||
135 (opt_NO_HCMS && des == SCT_HEAVY) ||
136 (opt_NO_OIL && des == SCT_OIL) ||
137 (opt_NO_OIL && des == SCT_REFINE)) {
138 pr("Only %s can make a %s!\n", cname(0),
142 if (des == SCT_WASTE) {
143 pr("Only a nuclear device (or %s) can make a %s!\n",
144 cname(0), dchr[des].d_name);
148 if (sect.sct_type == des && sect.sct_newtype == des)
150 if (sect.sct_type == SCT_SANCT)
152 if (sect.sct_x == cap_x && sect.sct_y == cap_y &&
153 des != SCT_CAPIT && des != SCT_SANCT &&
154 des != SCT_MOUNT && for_real)
155 pr("You have redesignated your capital!\n");
156 if (des == SCT_HARBR) {
157 for (n = 1; n <= 6; n++) {
158 getsect(nstr.x + diroff[n][0],
159 nstr.y + diroff[n][1], &check);
160 if (check.sct_type == SCT_WATER)
162 if (check.sct_type == SCT_BSPAN)
164 if (check.sct_type == SCT_BTOWER)
169 pr("%s does not border on water.\n",
170 xyas(nstr.x, nstr.y, player->cnum));
173 pr("But if it's what you want ...\n");
178 if (des == SCT_BHEAD) {
179 for (n = 1; n <= 6; n++) {
180 getsect(nstr.x + diroff[n][0],
181 nstr.y + diroff[n][1], &check);
182 if (check.sct_type == SCT_WATER)
184 if (check.sct_type == SCT_BSPAN)
186 if (check.sct_type == SCT_BTOWER)
191 pr("%s does not border on water.\n",
192 xyas(nstr.x, nstr.y,player->cnum));
195 pr("But if it's what you want...\n");
200 if (sect.sct_type == SCT_SANCT && !player->god)
203 if ((sect.sct_newtype != des) && (sect.sct_type != des) && dchr[des].d_cost) {
205 if (check_cost(!deschar, dchr[des].d_cost, cash, &warned, player->argp[3]))
208 cost += dchr[des].d_cost;
212 if (sect.sct_effic < 5 || player->god) {
215 /* No longer tear down infrasturcture
217 sect.sct_defense = 0;
219 changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
220 dchr[des].d_mnem, 0);
222 sect.sct_newtype = des;
224 if (opt_EASY_BRIDGES == 0) { /* may cause a bridge fall */
227 bridgefall(§, 0);
232 writemap(player->cnum);