]> git.pond.sub.org Git - empserver/blob - src/lib/commands/add.c
Import of Empire 4.2.12
[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
48 extern float start_education, start_happiness;
49 extern float start_technology, start_research;
50
51 int
52 add(void)
53 {
54         struct  natstr *natp;
55         struct  sctstr sect;
56         struct  nstr_sect nstr;
57         register int i;
58         s_char  cntryname[21];
59         s_char  pname[21];
60         natid   coun;
61         natid   freecn;
62         s_char  prompt[128];
63         s_char  buf[1024];
64         s_char  *p;
65         s_char  loopflag;
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_INUSE) == 0)
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         while ((p = getstarg(player->argp[1], prompt, buf)) && *p) {
79                 coun = atoi(p);
80                 if (coun < MAXNOC)
81                         break;
82                 pr("Max # countries is %d\n", MAXNOC);
83                 player->argp[1] = 0;
84         }
85         if (p == 0 || *p == 0)
86                 return RET_FAIL;
87         if (coun == 0) {
88                 pr("Not allowed to add country #0\n");
89                 return RET_FAIL;
90         }
91         natp = getnatp(coun);
92         while ((p = getstarg(player->argp[2], "Country Name? ", buf)) && *p) {
93                 if (strlen(p) < 20) {
94                         (void) strcpy(cntryname, p);
95                         break;
96                 }
97                 pr("Too long.\n");
98                 player->argp[2] = 0;
99         }
100         if (p == 0 || *p == 0)
101                 return RET_OK;
102         while ((p = getstarg(player->argp[3], "Representative? ", buf)) && *p) {
103                 if (strlen(p) < 20) {
104                         (void) strcpy(pname, p);
105                         break;
106                 }
107                 pr("Too long.\n");
108                 player->argp[3] = 0;
109         }
110         if (p == 0 || *p == 0)
111                 return RET_OK;
112         loopflag = 1;
113         stat = natp->nat_stat;
114         strcpy(prompt, "Status? (visitor, new, active, god, delete) ");
115         while (loopflag && (p = getstarg(player->argp[4], prompt, buf))) {
116                 loopflag = 0;
117                 switch (*p) {
118                 case 'v':
119                         stat = STAT_INUSE;
120                         break;
121                 case 'n':
122                         stat = STAT_NEW|STAT_INUSE;  
123                         break;
124                 case 'a':
125                         stat = STAT_NORM|STAT_INUSE;
126                         break;
127                 case 'g':
128                         stat = STAT_GOD|STAT_NORM|STAT_INUSE;
129                         break;
130                 case 'd':
131                         stat = 0;
132                         break;
133                 default:
134                         pr("Illegal selection\n");
135                         loopflag = 1;
136                         break;
137                 }
138                 player->argp[4] = 0;
139         }
140         if (p == 0)
141                 return RET_OK;
142         p = getstarg(player->argp[5],
143                 "Check, wipe, or ignore existing sectors (c|w|i) ", buf);
144         if (p == 0)
145                 return RET_OK;
146         snxtitem_all(&ni,EF_LAND);
147         while(nxtitem(&ni, (s_char *)&land)) {
148                 if (land.lnd_own == coun){
149                         makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y);
150                         land.lnd_own = 0;
151                         pr("Land unit %d wiped\n",land.lnd_uid);
152                         putland(land.lnd_uid,&land);
153                 }
154         }
155         natp->nat_stat = stat;
156         strcpy(natp->nat_cnam, cntryname);
157         strcpy(natp->nat_pnam, pname);
158         if (*p != 'w' && *p != 'c') {
159                 pr("Any existing sectors ignored\n");
160         } else {
161                 pr("Checking sectors...\n");
162                 snxtsct_all(&nstr);
163                 while (nxtsct(&nstr, &sect)) {
164                         if (sect.sct_own != coun)
165                                 continue;
166                         pr("%s ", xyas(nstr.x, nstr.y, player->cnum));
167                         if (*p == 'w') {
168                                 sect.sct_mobil = 0;
169                                 sect.sct_effic = 0;
170                                 sect.sct_road = 0;
171                                 sect.sct_rail = 0;
172                                 sect.sct_defense = 0;
173                                 sect.sct_own = 0;
174                                 sect.sct_oldown = 0;
175                                 if (sect.sct_type != SCT_MOUNT &&
176                                     sect.sct_type != SCT_PLAINS) {
177                                         sect.sct_type = SCT_RURAL;
178                                         sect.sct_newtype = SCT_RURAL;
179                                 }
180                                 /* No dist path */
181                                 sect.sct_dist_x = sect.sct_x;
182                                 sect.sct_dist_y = sect.sct_y;
183                                 sect.sct_nv = 0;
184                                 putsect(&sect);
185                                 pr("wiped\n");
186                         } else {
187                                 pr("\n");
188                         }
189                 }
190         }
191
192         if ((natp->nat_stat & (STAT_INUSE|STAT_NORM|STAT_GOD)) == 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                 bzero((s_char *)natp->nat_b, 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 = NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;
227         for (i=0; i<MAXNOC; i++)
228                 natp->nat_relate[i] = NEUTRAL;
229         putnat(natp);
230         return 0;
231 }