]> git.pond.sub.org Git - empserver/blob - src/lib/commands/add.c
Change nation status from bits to a simple enum:
[empserver] / src / lib / commands / add.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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  *  add.c: Add a new country to the game
29  * 
30  *  Known contributors to this file:
31  *     Steve McClure, 2000
32  *     
33  */
34
35 #include <config.h>
36
37 #include <stdio.h>
38 #include <string.h>
39 #include "misc.h"
40 #include "player.h"
41 #include "plague.h"
42 #include "sect.h"
43 #include "nat.h"
44 #include "xy.h"
45 #include "nsc.h"
46 #include "file.h"
47 #include "tel.h"
48 #include "land.h"
49 #include "commands.h"
50 #include "optlist.h"
51
52 int
53 add(void)
54 {
55     struct natstr *natp;
56     struct sctstr sect;
57     struct nstr_sect nstr;
58     int i;
59     char cntryname[sizeof(natp->nat_cnam)];
60     char pname[sizeof(natp->nat_pnam)];
61     natid coun;
62     natid freecn;
63     char prompt[128];
64     char buf[1024];
65     char *p;
66     int stat;
67     struct nstr_item ni;
68     struct lndstr land;
69
70     for (freecn = 0; NULL != (natp = getnatp(freecn)); freecn++) {
71         if (natp->nat_stat == STAT_UNUSED)
72             break;
73     }
74     if (freecn < MAXNOC)
75         sprintf(prompt, "New country number? (%d is unused) ", freecn);
76     else
77         strcpy(prompt, "New country number? (they all seem to be used) ");
78     p = getstarg(player->argp[1], prompt, buf);
79     if (p == 0 || *p == 0)
80         return RET_SYN;
81     i = atoi(p);
82     if (i >= MAXNOC) {
83         pr("Max # countries is %d\n", MAXNOC);
84         return RET_FAIL;
85     }
86     coun = i;
87     if (coun == 0) {
88         pr("Not allowed to add country #0\n");
89         return RET_FAIL;
90     }
91     natp = getnatp(coun);
92     p = getstarg(player->argp[2], "Country Name? ", buf);
93     if (p == 0 || *p == 0)
94         return RET_SYN;
95     if (strlen(p) >= sizeof(cntryname)) {
96         pr("Country name too long\n");
97         return RET_FAIL;
98     }
99     strcpy(cntryname, p);
100     p = getstarg(player->argp[3], "Representative? ", buf);
101     if (p == 0 || *p == 0)
102         return RET_SYN;
103     if (strlen(p) >= sizeof(pname)) {
104         pr("Representative too long\n");
105         return RET_FAIL;
106     }
107     strcpy(pname, p);
108     p = getstarg(player->argp[4],
109                  "Status? (visitor, new, active, god, delete) ", buf);
110     if (p == 0 || *p == 0)
111         return RET_SYN;
112     switch (*p) {
113     case 'v':
114         stat = STAT_VIS;
115         break;
116     case 'n':
117         stat = STAT_NEW;
118         break;
119     case 'a':
120         stat = STAT_ACTIVE;
121         break;
122     case 'g':
123         stat = STAT_GOD;
124         break;
125     case 'd':
126         stat = STAT_UNUSED;
127         break;
128     default:
129         pr("Illegal status\n");
130         return RET_SYN;
131     }
132     p = getstarg(player->argp[5],
133                  "Check, wipe, or ignore existing sectors (c|w|i) ", buf);
134     if (p == 0)
135         return RET_SYN;
136     snxtitem_all(&ni, EF_LAND);
137     while (nxtitem(&ni, &land)) {
138         if (land.lnd_own == coun) {
139             makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
140                      land.lnd_y);
141             land.lnd_own = 0;
142             pr("Land unit %d wiped\n", land.lnd_uid);
143             putland(land.lnd_uid, &land);
144         }
145     }
146     natp->nat_stat = stat;
147     strcpy(natp->nat_cnam, cntryname);
148     strcpy(natp->nat_pnam, pname);
149     if (*p != 'w' && *p != 'c') {
150         pr("Any existing sectors ignored\n");
151     } else {
152         pr("Checking sectors...\n");
153         snxtsct_all(&nstr);
154         while (nxtsct(&nstr, &sect)) {
155             if (sect.sct_own != coun)
156                 continue;
157             pr("%s ", xyas(nstr.x, nstr.y, player->cnum));
158             if (*p == 'w') {
159                 sect.sct_mobil = 0;
160                 sect.sct_effic = 0;
161                 sect.sct_road = 0;
162                 sect.sct_rail = 0;
163                 sect.sct_defense = 0;
164                 sect.sct_own = 0;
165                 sect.sct_oldown = 0;
166                 if (sect.sct_type == SCT_BSPAN ||
167                     sect.sct_type == SCT_BTOWER)
168                     sect.sct_newtype = sect.sct_type = SCT_WATER;
169                 else if (sect.sct_type != SCT_MOUNT &&
170                     sect.sct_type != SCT_PLAINS)
171                     sect.sct_newtype = sect.sct_type = SCT_RURAL;
172                 /* No dist path */
173                 sect.sct_dist_x = sect.sct_x;
174                 sect.sct_dist_y = sect.sct_y;
175                 memset(sect.sct_item, 0, sizeof(sect.sct_item));
176                 memset(sect.sct_del, 0, sizeof(sect.sct_del));
177                 memset(sect.sct_dist, 0, sizeof(sect.sct_dist));
178                 sect.sct_mines = 0;
179                 sect.sct_pstage = PLG_HEALTHY;
180                 sect.sct_ptime = 0;
181                 sect.sct_che = 0;
182                 sect.sct_che_target = 0;
183                 sect.sct_fallout = 0;
184                 putsect(&sect);
185                 pr("wiped\n");
186             } else {
187                 pr("\n");
188             }
189         }
190     }
191
192     if (natp->nat_stat == STAT_NEW || natp->nat_stat == STAT_VIS) {
193         *natp->nat_hostaddr = '\0';
194         *natp->nat_hostname = '\0';
195         *natp->nat_userid = '\0';
196         natp->nat_btu = 0;
197         natp->nat_reserve = 0;
198         natp->nat_tgms = 0;
199         natp->nat_ycap = 0;
200         natp->nat_xcap = 0;
201         natp->nat_yorg = 0;
202         natp->nat_xorg = 0;
203         natp->nat_dayno = 0;
204         natp->nat_minused = 0;
205         memset(natp->nat_b, 0, sizeof(natp->nat_b));
206         natp->nat_last_login = natp->nat_last_login = 0;
207         natp->nat_money = 0;
208         natp->nat_level[NAT_TLEV] = start_technology;
209         natp->nat_level[NAT_RLEV] = start_research;
210         natp->nat_level[NAT_ELEV] = start_education;
211         natp->nat_level[NAT_HLEV] = start_happiness;
212         for (i = 0; i < MAXNOC / 4; i++)
213             natp->nat_rejects[i] = 0;
214         natp->nat_newstim = 0;
215         natp->nat_annotim = 0;
216         (void)creat(mailbox(buf, coun), 0660);
217     } else
218         pr("No special initializations done...\n");
219
220     for (i = 0; i <= PRI_MAX; i++)
221         natp->nat_priorities[i] = -1;
222     natp->nat_flags =
223         NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;
224     for (i = 0; i < MAXNOC; i++)
225         natp->nat_relate[i] = NEUTRAL;
226     putnat(natp);
227     return 0;
228 }