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