2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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
41 static long do_desi(struct natstr *natp, char *sects, char *deschar,
42 long cash, int for_real);
51 natp = getnatp(player->cnum);
52 cash = natp->nat_money;
53 if (player->argp[2]) {
54 cost = do_desi(natp, player->argp[1], player->argp[2], cash, 0);
57 if (chkmoney(cost, cash, player->argp[3]))
60 return (int)do_desi(natp, player->argp[1], player->argp[2], cash, 1);
64 do_desi(struct natstr *natp, char *sects, char *deschar, long cash,
73 struct nstr_sect nstr;
83 if (!snxtsct(&nstr, sects)) {
87 return (long)-RET_SYN;
89 cap_x = natp->nat_xcap;
90 cap_y = natp->nat_ycap;
91 while (!player->aborted && nxtsct(&nstr, §)) {
94 if (!player->god && dchr[sect.sct_type].d_cost < 0)
96 sprintf(prompt, "%s %d%% %s desig? ",
97 xyas(sect.sct_x, sect.sct_y, player->cnum),
98 sect.sct_effic, dchr[sect.sct_type].d_name);
99 if ((p = getstarg(deschar, prompt, buf)) == 0)
102 if (!check_sect_ok(§))
105 des = sct_typematch(p);
106 if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
108 pr("No such designation\n"
109 "See \"info Sector-types\" for possible designations\n");
111 return (long)RET_FAIL;
113 return (long)-RET_FAIL;
116 if (des == SCT_WASTE) {
118 pr("Only a nuclear device (or %s) can make a %s!\n",
119 cname(0), dchr[des].d_name);
122 if (dchr[des].d_cost < 0) {
124 pr("Only %s can make a %s!\n",
125 cname(0), dchr[des].d_name);
129 if (sect.sct_type == des && sect.sct_newtype == des)
131 if (sect.sct_type == SCT_SANCT)
133 if ((des == SCT_HARBR) || (des == SCT_BHEAD)) {
134 for (n = 1; n <= 6; n++) {
135 getsect(nstr.x + diroff[n][0],
136 nstr.y + diroff[n][1], &check);
137 if (check.sct_type == SCT_WATER)
139 if (check.sct_type == SCT_BSPAN)
141 if (check.sct_type == SCT_BTOWER)
146 pr("%s does not border on water.\n",
147 xyas(nstr.x, nstr.y, player->cnum));
150 pr("But if it's what you want ...\n");
155 if (sect.sct_type == SCT_SANCT && !player->god)
158 if ((sect.sct_newtype != des) && (sect.sct_type != des)
159 && dchr[des].d_cost > 0) {
161 if (check_cost(!deschar, dchr[des].d_cost, cash, &warned,
165 cost += dchr[des].d_cost;
169 if (sect.sct_type != des && (sect.sct_effic < 5 || player->god)) {
171 set_coastal(§, sect.sct_type, des);
174 changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
175 dchr[des].d_mnem, 0);
177 sect.sct_newtype = des;
179 if (sect.sct_x == cap_x && sect.sct_y == cap_y
180 && des != SCT_CAPIT && des != SCT_SANCT && des != SCT_MOUNT
182 pr("You have redesignated your capital!\n");
183 if (opt_EASY_BRIDGES == 0) { /* may cause a bridge fall */
186 bridgefall(§, 0);
191 writemap(player->cnum);