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 static 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,
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), dchr[des].d_name);
141 if (des == SCT_WASTE) {
142 pr("Only a nuclear device (or %s) can make a %s!\n",
143 cname(0), dchr[des].d_name);
147 if (sect.sct_type == des && sect.sct_newtype == des)
149 if (sect.sct_type == SCT_SANCT)
151 if (des == SCT_HARBR) {
152 for (n = 1; n <= 6; n++) {
153 getsect(nstr.x + diroff[n][0],
154 nstr.y + diroff[n][1], &check);
155 if (check.sct_type == SCT_WATER)
157 if (check.sct_type == SCT_BSPAN)
159 if (check.sct_type == SCT_BTOWER)
164 pr("%s does not border on water.\n",
165 xyas(nstr.x, nstr.y, player->cnum));
168 pr("But if it's what you want ...\n");
173 if (des == SCT_BHEAD) {
174 for (n = 1; n <= 6; n++) {
175 getsect(nstr.x + diroff[n][0],
176 nstr.y + diroff[n][1], &check);
177 if (check.sct_type == SCT_WATER)
179 if (check.sct_type == SCT_BSPAN)
181 if (check.sct_type == SCT_BTOWER)
186 pr("%s does not border on water.\n",
187 xyas(nstr.x, nstr.y, player->cnum));
190 pr("But if it's what you want...\n");
195 if (sect.sct_type == SCT_SANCT && !player->god)
198 if ((sect.sct_newtype != des) && (sect.sct_type != des)
199 && dchr[des].d_cost) {
201 if (check_cost(!deschar, dchr[des].d_cost, cash, &warned,
205 cost += dchr[des].d_cost;
209 if (sect.sct_effic < 5 || player->god) {
212 changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
213 dchr[des].d_mnem, 0);
215 sect.sct_newtype = des;
217 if (sect.sct_x == cap_x && sect.sct_y == cap_y
218 && des != SCT_CAPIT && des != SCT_SANCT && des != SCT_MOUNT
220 pr("You have redesignated your capital!\n");
221 if (opt_EASY_BRIDGES == 0) { /* may cause a bridge fall */
224 bridgefall(§, 0);
229 writemap(player->cnum);