]> git.pond.sub.org Git - empserver/blob - src/lib/commands/desi.c
Supply prototypes where possible. This uncovered type errors with
[empserver] / src / lib / commands / desi.c
1 /*
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
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  desi.c: Redesignate sectors
29  * 
30  *  Known contributors to this file:
31  *      Steve McClure, 1998-2000
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "var.h"
37 #include "sect.h"
38 #include "item.h"
39 #include "xy.h"
40 #include "path.h"
41 #include "nsc.h"
42 #include "deity.h"
43 #include "file.h"
44 #include "nat.h"
45 #include "optlist.h"
46 #include "commands.h"
47
48 static long do_desi(struct natstr *natp, s_char *sects, s_char *deschar,
49                     long int cash, int for_real);
50
51 int
52 desi(void)
53 {
54     long cash;
55     long cost;
56     struct natstr *natp;
57
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);
62         if (cost < 0)
63             return (int)(-cost);
64         if (chkmoney(cost, cash, player->argp[3]))
65             return RET_SYN;
66     }
67     return (int)do_desi(natp, player->argp[1], player->argp[2], cash, 1);
68 }
69
70 static long
71 do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
72         int for_real)
73 {
74     register int n;
75     s_char *p;
76     int breaksanct;
77     int cap_x;
78     int cap_y;
79     int des;
80     struct nstr_sect nstr;
81     struct sctstr sect;
82     struct sctstr check;
83     s_char prompt[128];
84     s_char buf[1024];
85     long cost = 0;
86     int changed = 0;
87     int warned = 0;
88
89     breaksanct = 0;
90     if (!snxtsct(&nstr, sects)) {
91         if (for_real)
92             return (long)RET_SYN;
93         else
94             return (long)-RET_SYN;
95     }
96     cap_x = natp->nat_xcap;
97     cap_y = natp->nat_ycap;
98     while (!player->aborted && nxtsct(&nstr, &sect)) {
99         if (!player->owner)
100             continue;
101         if (!player->god) {
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))
111                 continue;
112         }
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)
117             continue;
118
119         if (!check_sect_ok(&sect))
120             continue;
121
122         des = typematch(p, EF_SECTOR);
123         if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
124                         !player->god)) {
125             pr("See \"info Sector-types\"\n");
126             if (for_real)
127                 return (long)RET_FAIL;
128             else
129                 return (long)-RET_FAIL;
130         }
131         if (!player->god) {
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);
139                 continue;
140             }
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);
144                 continue;
145             }
146         }
147         if (sect.sct_type == des && sect.sct_newtype == des)
148             continue;
149         if (sect.sct_type == SCT_SANCT)
150             breaksanct++;
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)
156                     break;
157                 if (check.sct_type == SCT_BSPAN)
158                     break;
159                 if (check.sct_type == SCT_BTOWER)
160                     break;
161             }
162             if (n > 6) {
163                 if (for_real)
164                     pr("%s does not border on water.\n",
165                        xyas(nstr.x, nstr.y, player->cnum));
166                 if (player->god) {
167                     if (for_real)
168                         pr("But if it's what you want ...\n");
169                 } else
170                     continue;
171             }
172         }
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)
178                     break;
179                 if (check.sct_type == SCT_BSPAN)
180                     break;
181                 if (check.sct_type == SCT_BTOWER)
182                     break;
183             }
184             if (n > 6) {
185                 if (for_real)
186                     pr("%s does not border on water.\n",
187                        xyas(nstr.x, nstr.y, player->cnum));
188                 if (player->god) {
189                     if (for_real)
190                         pr("But if it's what you want...\n");
191                 } else
192                     continue;
193             }
194         }
195         if (sect.sct_type == SCT_SANCT && !player->god)
196             continue;
197         n = sect.sct_type;
198         if ((sect.sct_newtype != des) && (sect.sct_type != des)
199             && dchr[des].d_cost) {
200             if (for_real) {
201                 if (check_cost(!deschar, dchr[des].d_cost, cash, &warned,
202                                player->argp[3]))
203                     break;
204             } else {
205                 cost += dchr[des].d_cost;
206                 continue;
207             }
208         }
209         if (sect.sct_effic < 5 || player->god) {
210             sect.sct_type = des;
211             sect.sct_effic = 0;
212             changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
213                                dchr[des].d_mnem, 0);
214         }
215         sect.sct_newtype = des;
216         putsect(&sect);
217         if (sect.sct_x == cap_x && sect.sct_y == cap_y
218             && des != SCT_CAPIT && des != SCT_SANCT && des != SCT_MOUNT
219             && for_real)
220             pr("You have redesignated your capital!\n");
221         if (opt_EASY_BRIDGES == 0) {    /* may cause a bridge fall */
222             if (n != SCT_BHEAD)
223                 continue;
224             bridgefall(&sect, 0);
225         }
226     }
227     if (for_real) {
228         if (changed)
229             writemap(player->cnum);
230         if (breaksanct)
231             bsanct();
232         return (long)RET_OK;
233     } else {
234         return cost;
235     }
236 }