]> git.pond.sub.org Git - empserver/blob - src/lib/commands/add.c
Drop add's undocumented land unit destruction feature
[empserver] / src / lib / commands / add.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2011, 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  *  add.c: Add a new country to the game
28  *
29  *  Known contributors to this file:
30  *     Steve McClure, 2000
31  *     Markus Armbruster, 2004-2011
32  */
33
34 #include <config.h>
35
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <sys/stat.h>
39
40 #include "commands.h"
41 #include "optlist.h"
42 #include "plague.h"
43
44 int
45 add(void)
46 {
47     struct natstr *natp;
48     struct sctstr sect;
49     struct nstr_sect nstr;
50     int i;
51     char cntryname[sizeof(natp->nat_cnam)];
52     char pname[sizeof(natp->nat_pnam)];
53     natid coun;
54     natid freecn;
55     char prompt[128];
56     char buf[1024];
57     char *p;
58     int stat;
59
60     for (freecn = 0; NULL != (natp = getnatp(freecn)); freecn++) {
61         if (natp->nat_stat == STAT_UNUSED)
62             break;
63     }
64     if (freecn < MAXNOC)
65         sprintf(prompt, "New country number? (%d is unused) ", freecn);
66     else
67         strcpy(prompt, "New country number? (they all seem to be used) ");
68     p = getstarg(player->argp[1], prompt, buf);
69     if (!p || !*p)
70         return RET_SYN;
71     i = atoi(p);
72     if (i >= MAXNOC) {
73         pr("Max # countries is %d\n", MAXNOC);
74         return RET_FAIL;
75     }
76     coun = i;
77     if (coun == 0) {
78         pr("Not allowed to add country #0\n");
79         return RET_FAIL;
80     }
81     natp = getnatp(coun);
82     p = getstarg(player->argp[2], "Country name? ", buf);
83     if (!p)
84         return RET_SYN;
85     if (!check_nat_name(p, coun))
86         return RET_FAIL;
87     strcpy(cntryname, p);
88     p = getstarg(player->argp[3], "Representative? ", buf);
89     if (!p || !*p)
90         return RET_SYN;
91     if (strlen(p) >= sizeof(pname)) {
92         pr("Representative too long\n");
93         return RET_FAIL;
94     }
95     strcpy(pname, p);
96     p = getstarg(player->argp[4],
97                  "Status? (visitor, new, active, god, delete) ", buf);
98     if (!p || !*p)
99         return RET_SYN;
100     switch (*p) {
101     case 'v':
102         stat = STAT_VIS;
103         break;
104     case 'n':
105         stat = STAT_NEW;
106         break;
107     case 'a':
108         stat = STAT_ACTIVE;
109         break;
110     case 'g':
111         stat = STAT_GOD;
112         break;
113     case 'd':
114         stat = STAT_UNUSED;
115         break;
116     default:
117         pr("Illegal status\n");
118         return RET_SYN;
119     }
120     p = getstarg(player->argp[5],
121                  "Check, wipe, or ignore existing sectors (c|w|i) ", buf);
122     if (!p)
123         return RET_SYN;
124     strcpy(natp->nat_cnam, cntryname);
125     strcpy(natp->nat_pnam, pname);
126     if (*p != 'w' && *p != 'c') {
127         pr("Any existing sectors ignored\n");
128     } else {
129         pr("Checking sectors...\n");
130         snxtsct_all(&nstr);
131         while (nxtsct(&nstr, &sect)) {
132             if (sect.sct_own != coun)
133                 continue;
134             pr("%s ", xyas(nstr.x, nstr.y, player->cnum));
135             if (*p == 'w') {
136                 sect.sct_mobil = 0;
137                 sect.sct_effic = 0;
138                 sect.sct_road = 0;
139                 sect.sct_rail = 0;
140                 sect.sct_defense = 0;
141                 sect.sct_own = 0;
142                 sect.sct_oldown = 0;
143                 sect.sct_newtype = sect.sct_type
144                     = dchr[sect.sct_type].d_terrain;
145                 sect.sct_dist_x = sect.sct_x;
146                 sect.sct_dist_y = sect.sct_y;
147                 memset(sect.sct_item, 0, sizeof(sect.sct_item));
148                 memset(sect.sct_del, 0, sizeof(sect.sct_del));
149                 memset(sect.sct_dist, 0, sizeof(sect.sct_dist));
150                 sect.sct_mines = 0;
151                 sect.sct_pstage = PLG_HEALTHY;
152                 sect.sct_ptime = 0;
153                 sect.sct_che = 0;
154                 sect.sct_che_target = 0;
155                 sect.sct_fallout = 0;
156                 putsect(&sect);
157                 pr("wiped\n");
158             } else {
159                 pr("\n");
160             }
161         }
162     }
163
164     if (stat == STAT_NEW || stat == STAT_VIS)
165         nat_reset(natp, stat, 0, 0);
166     else {
167         natp->nat_stat = stat;
168         pr("No special initializations done...\n");
169     }
170     putnat(natp);
171     return 0;
172 }