]> git.pond.sub.org Git - empserver/blob - src/lib/commands/desi.c
Update copyright notice
[empserver] / src / lib / commands / desi.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2009, 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 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.
25  *
26  *  ---
27  *
28  *  desi.c: Redesignate sectors
29  *
30  *  Known contributors to this file:
31  *     Steve McClure, 1998-2000
32  *     Markus Armbruster, 2004-2008
33  */
34
35 #include <config.h>
36
37 #include "commands.h"
38 #include "map.h"
39 #include "optlist.h"
40 #include "path.h"
41
42 int
43 desi(void)
44 {
45     int n;
46     char *p;
47     int des;
48     struct nstr_sect nstr;
49     struct sctstr sect;
50     struct natstr *natp;
51     char prompt[128];
52     char buf[1024];
53     int changed = 0;
54     int rc = RET_OK;
55
56     if (!snxtsct(&nstr, player->argp[1]))
57         return RET_SYN;
58     natp = getnatp(player->cnum);
59     while (nxtsct(&nstr, &sect)) {
60         if (!player->owner)
61             continue;
62         if (!player->god && dchr[sect.sct_type].d_cost < 0)
63             continue;
64         sprintf(prompt, "%s %d%% %s  desig? ",
65                 xyas(sect.sct_x, sect.sct_y, player->cnum),
66                 sect.sct_effic, dchr[sect.sct_type].d_name);
67         if ((p = getstarg(player->argp[2], prompt, buf)) == 0) {
68             rc = RET_FAIL;
69             break;
70         }
71
72         if (!check_sect_ok(&sect))
73             continue;
74
75         des = sct_typematch(p);
76         if (des < 0) {
77             pr("No such designation\n"
78                "See \"info Sector-types\" for possible designations\n");
79             rc = RET_FAIL;
80             break;
81         }
82         if (!player->god) {
83             if (des == SCT_WASTE) {
84                 pr("Only a nuclear device (or %s) can make a %s!\n",
85                    cname(0), dchr[des].d_name);
86                 rc = RET_FAIL;
87                 break;
88             }
89             if (dchr[des].d_cost < 0) {
90                 pr("Only %s can designate a %s!\n",
91                    cname(0), dchr[des].d_name);
92                 rc = RET_FAIL;
93                 break;
94             }
95             if (dchr[des].d_terrain != dchr[sect.sct_type].d_terrain) {
96                 pr("You can't change a %s into a %s\n",
97                    dchr[sect.sct_type].d_name, dchr[des].d_name);
98                 continue;
99             }
100         }
101         if (sect.sct_type == des && sect.sct_newtype == des)
102             continue;
103         if ((des == SCT_HARBR || des == SCT_BHEAD) && !sect.sct_coastal) {
104             pr("%s does not border on water.\n",
105                xyas(nstr.x, nstr.y, player->cnum));
106             if (player->god)
107                 pr("But if it's what you want ...\n");
108             else
109                 continue;
110         }
111         if (sect.sct_type == SCT_SANCT && !player->god)
112             continue;
113         n = sect.sct_type;
114         if ((sect.sct_newtype != des) && (sect.sct_type != des)
115             && dchr[des].d_cost > 0) {
116             if (natp->nat_money < player->dolcost + dchr[des].d_cost) {
117                 pr("You can't afford a %s!\n", dchr[des].d_name);
118                 rc = RET_FAIL;
119                 break;
120             }
121             player->dolcost += dchr[des].d_cost;
122         }
123         if (sect.sct_type != des && (sect.sct_effic < 5 || player->god)) {
124             if (player->god)
125                 set_coastal(&sect, sect.sct_type, des);
126             sect.sct_type = des;
127             sect.sct_effic = 0;
128             changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
129                                dchr[des].d_mnem, 0);
130         }
131         sect.sct_newtype = des;
132         putsect(&sect);
133         if (!player->god
134             && sect.sct_x == natp->nat_xcap && sect.sct_y == natp->nat_ycap
135             && des != SCT_CAPIT && des != SCT_SANCT && des != SCT_MOUNT)
136             pr("You have redesignated your capital!\n");
137         if (opt_EASY_BRIDGES == 0) {    /* may cause a bridge fall */
138             if (n != SCT_BHEAD)
139                 continue;
140             bridgefall(&sect);
141         }
142     }
143     if (changed)
144         writemap(player->cnum);
145     return rc;
146 }