]> 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-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  desi.c: Redesignate sectors
28  *
29  *  Known contributors to this file:
30  *     Steve McClure, 1998-2000
31  *     Markus Armbruster, 2004-2016
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37 #include "map.h"
38 #include "optlist.h"
39
40 int
41 desi(void)
42 {
43     int n;
44     char *p;
45     int des;
46     struct nstr_sect nstr;
47     struct sctstr sect;
48     struct natstr *natp;
49     char prompt[128];
50     char buf[1024];
51     int changed = 0;
52     int rc = RET_OK;
53
54     if (!snxtsct(&nstr, player->argp[1]))
55         return RET_SYN;
56     natp = getnatp(player->cnum);
57     while (nxtsct(&nstr, &sect)) {
58         if (!player->owner)
59             continue;
60         if ((dchr[sect.sct_type].d_flags & D_DEITY) && !player->god)
61             continue;
62         sprintf(prompt, "%s %d%% %s  desig? ",
63                 xyas(sect.sct_x, sect.sct_y, player->cnum),
64                 sect.sct_effic, dchr[sect.sct_type].d_name);
65         if (!(p = getstarg(player->argp[2], prompt, buf))) {
66             rc = RET_FAIL;
67             break;
68         }
69
70         if (!check_sect_ok(&sect))
71             continue;
72
73         des = sct_typematch(p);
74         if (des < 0) {
75             pr("No such designation\n"
76                "See \"info Sector-types\" for possible designations\n");
77             rc = RET_FAIL;
78             break;
79         }
80         if (!player->god) {
81             if (des == SCT_WASTE) {
82                 pr("Only a nuclear device (or %s) can make a %s!\n",
83                    cname(0), dchr[des].d_name);
84                 rc = RET_FAIL;
85                 break;
86             }
87             if (dchr[des].d_flags & D_DEITY) {
88                 pr("Only %s can designate a %s!\n",
89                    cname(0), dchr[des].d_name);
90                 rc = RET_FAIL;
91                 break;
92             }
93             if (dchr[des].d_terrain != dchr[sect.sct_type].d_terrain) {
94                 pr("You can't change a %s into a %s\n",
95                    dchr[sect.sct_type].d_name, dchr[des].d_name);
96                 continue;
97             }
98         }
99         if (sect.sct_type == des && sect.sct_newtype == des)
100             continue;
101         if ((des == SCT_HARBR || des == SCT_BHEAD) && !sect.sct_coastal) {
102             pr("%s does not border on water.\n",
103                xyas(nstr.x, nstr.y, player->cnum));
104             if (player->god)
105                 pr("But if it's what you want ...\n");
106             else
107                 continue;
108         }
109         if (sect.sct_type == SCT_SANCT && !player->god)
110             continue;
111         n = sect.sct_type;
112         if (sect.sct_type != des && (sect.sct_effic < 5 || player->god)) {
113             if (player->god)
114                 set_coastal(&sect, sect.sct_type, des);
115             sect.sct_type = des;
116             sect.sct_effic = 0;
117             changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
118                                dchr[des].d_mnem, 0);
119         }
120         sect.sct_newtype = des;
121         putsect(&sect);
122         if (!player->god
123             && sect.sct_x == natp->nat_xcap && sect.sct_y == natp->nat_ycap
124             && des != SCT_CAPIT && des != SCT_SANCT && des != SCT_MOUNT)
125             pr("You have redesignated your capital!\n");
126         if (opt_EASY_BRIDGES == 0) {    /* may cause a bridge fall */
127             if (n != SCT_BHEAD)
128                 continue;
129             bridgefall(&sect);
130         }
131     }
132     if (changed)
133         writemap(player->cnum);
134     return rc;
135 }