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