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