]> git.pond.sub.org Git - empserver/blob - src/lib/commands/desi.c
(dchr): Negative d_cost now means that only deity can designate.
[empserver] / src / lib / commands / desi.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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 "sect.h"
37 #include "item.h"
38 #include "xy.h"
39 #include "path.h"
40 #include "nsc.h"
41 #include "file.h"
42 #include "nat.h"
43 #include "optlist.h"
44 #include "commands.h"
45
46 static long do_desi(struct natstr *natp, s_char *sects, s_char *deschar,
47                     long int cash, int for_real);
48
49 int
50 desi(void)
51 {
52     long cash;
53     long cost;
54     struct natstr *natp;
55
56     natp = getnatp(player->cnum);
57     cash = natp->nat_money;
58     if (player->argp[2]) {
59         cost = do_desi(natp, player->argp[1], player->argp[2], cash, 0);
60         if (cost < 0)
61             return (int)(-cost);
62         if (chkmoney(cost, cash, player->argp[3]))
63             return RET_SYN;
64     }
65     return (int)do_desi(natp, player->argp[1], player->argp[2], cash, 1);
66 }
67
68 static long
69 do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
70         int for_real)
71 {
72     int n;
73     s_char *p;
74     int breaksanct;
75     int cap_x;
76     int cap_y;
77     int des;
78     struct nstr_sect nstr;
79     struct sctstr sect;
80     struct sctstr check;
81     s_char prompt[128];
82     s_char buf[1024];
83     long cost = 0;
84     int changed = 0;
85     int warned = 0;
86
87     breaksanct = 0;
88     if (!snxtsct(&nstr, sects)) {
89         if (for_real)
90             return (long)RET_SYN;
91         else
92             return (long)-RET_SYN;
93     }
94     cap_x = natp->nat_xcap;
95     cap_y = natp->nat_ycap;
96     while (!player->aborted && nxtsct(&nstr, &sect)) {
97         if (!player->owner)
98             continue;
99         if (!player->god && dchr[sect.sct_type].d_cost < 0)
100             continue;
101         sprintf(prompt, "%s %d%% %s  desig? ",
102                 xyas(sect.sct_x, sect.sct_y, player->cnum),
103                 sect.sct_effic, dchr[sect.sct_type].d_name);
104         if ((p = getstarg(deschar, prompt, buf)) == 0)
105             continue;
106
107         if (!check_sect_ok(&sect))
108             continue;
109
110         des = sct_typematch(p);
111         if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
112                         !player->god)) {
113             pr("See \"info Sector-types\"\n");
114             if (for_real)
115                 return (long)RET_FAIL;
116             else
117                 return (long)-RET_FAIL;
118         }
119         if (!player->god) {
120             if (des == SCT_WASTE) {
121                 if (for_real)
122                     pr("Only a nuclear device (or %s) can make a %s!\n",
123                        cname(0), dchr[des].d_name);
124                 continue;
125             }
126             if (dchr[des].d_cost < 0) {
127                 if (for_real)
128                     pr("Only %s can make a %s!\n", cname(0), dchr[des].d_name);
129                 continue;
130             }
131         }
132         if (sect.sct_type == des && sect.sct_newtype == des)
133             continue;
134         if (sect.sct_type == SCT_SANCT)
135             breaksanct++;
136         if ((des == SCT_HARBR) || (des == SCT_BHEAD)) {
137             for (n = 1; n <= 6; n++) {
138                 getsect(nstr.x + diroff[n][0],
139                         nstr.y + diroff[n][1], &check);
140                 if (check.sct_type == SCT_WATER)
141                     break;
142                 if (check.sct_type == SCT_BSPAN)
143                     break;
144                 if (check.sct_type == SCT_BTOWER)
145                     break;
146             }
147             if (n > 6) {
148                 if (for_real)
149                     pr("%s does not border on water.\n",
150                        xyas(nstr.x, nstr.y, player->cnum));
151                 if (player->god) {
152                     if (for_real)
153                         pr("But if it's what you want ...\n");
154                 } else
155                     continue;
156             }
157         }
158         if (sect.sct_type == SCT_SANCT && !player->god)
159             continue;
160         n = sect.sct_type;
161         if ((sect.sct_newtype != des) && (sect.sct_type != des)
162             && dchr[des].d_cost > 0) {
163             if (for_real) {
164                 if (check_cost(!deschar, dchr[des].d_cost, cash, &warned,
165                                player->argp[3]))
166                     break;
167             } else {
168                 cost += dchr[des].d_cost;
169                 continue;
170             }
171         }
172         if (sect.sct_type != des && (sect.sct_effic < 5 || player->god)) {
173             sect.sct_type = des;
174             sect.sct_effic = 0;
175             changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
176                                dchr[des].d_mnem, 0);
177         }
178         sect.sct_newtype = des;
179         putsect(&sect);
180         if (sect.sct_x == cap_x && sect.sct_y == cap_y
181             && des != SCT_CAPIT && des != SCT_SANCT && des != SCT_MOUNT
182             && for_real)
183             pr("You have redesignated your capital!\n");
184         if (opt_EASY_BRIDGES == 0) {    /* may cause a bridge fall */
185             if (n != SCT_BHEAD)
186                 continue;
187             bridgefall(&sect, 0);
188         }
189     }
190     if (for_real) {
191         if (changed)
192             writemap(player->cnum);
193         if (breaksanct)
194             bsanct();
195         return (long)RET_OK;
196     } else {
197         return cost;
198     }
199 }