2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * desi.c: Redesignate sectors
30 * Known contributors to this file:
31 * Steve McClure, 1998-2000
47 static long do_desi(struct natstr *natp, s_char *sects, s_char *deschar,
48 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,
79 struct nstr_sect nstr;
89 if (!snxtsct(&nstr, sects)) {
93 return (long)-RET_SYN;
95 cap_x = natp->nat_xcap;
96 cap_y = natp->nat_ycap;
97 while (!player->aborted && nxtsct(&nstr, §)) {
100 if (!player->god && dchr[sect.sct_type].d_cost < 0)
102 sprintf(prompt, "%s %d%% %s desig? ",
103 xyas(sect.sct_x, sect.sct_y, player->cnum),
104 sect.sct_effic, dchr[sect.sct_type].d_name);
105 if ((p = getstarg(deschar, prompt, buf)) == 0)
108 if (!check_sect_ok(§))
111 des = sct_typematch(p);
112 if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
114 pr("See \"info Sector-types\"\n");
116 return (long)RET_FAIL;
118 return (long)-RET_FAIL;
121 if (des == SCT_WASTE) {
123 pr("Only a nuclear device (or %s) can make a %s!\n",
124 cname(0), dchr[des].d_name);
127 if (dchr[des].d_cost < 0) {
129 pr("Only %s can make a %s!\n", cname(0), dchr[des].d_name);
133 if (sect.sct_type == des && sect.sct_newtype == des)
135 if (sect.sct_type == SCT_SANCT)
137 if ((des == SCT_HARBR) || (des == SCT_BHEAD)) {
138 for (n = 1; n <= 6; n++) {
139 getsect(nstr.x + diroff[n][0],
140 nstr.y + diroff[n][1], &check);
141 if (check.sct_type == SCT_WATER)
143 if (check.sct_type == SCT_BSPAN)
145 if (check.sct_type == SCT_BTOWER)
150 pr("%s does not border on water.\n",
151 xyas(nstr.x, nstr.y, player->cnum));
154 pr("But if it's what you want ...\n");
159 if (sect.sct_type == SCT_SANCT && !player->god)
162 if ((sect.sct_newtype != des) && (sect.sct_type != des)
163 && dchr[des].d_cost > 0) {
165 if (check_cost(!deschar, dchr[des].d_cost, cash, &warned,
169 cost += dchr[des].d_cost;
173 if (sect.sct_type != des && (sect.sct_effic < 5 || player->god)) {
175 set_coastal(§, des);
178 changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
179 dchr[des].d_mnem, 0);
181 sect.sct_newtype = des;
183 if (sect.sct_x == cap_x && sect.sct_y == cap_y
184 && des != SCT_CAPIT && des != SCT_SANCT && des != SCT_MOUNT
186 pr("You have redesignated your capital!\n");
187 if (opt_EASY_BRIDGES == 0) { /* may cause a bridge fall */
190 bridgefall(§, 0);
195 writemap(player->cnum);