]> git.pond.sub.org Git - empserver/blob - src/lib/commands/new.c
556d1e2f8f1dc15ff6cfaee69bb1ecf152020a76
[empserver] / src / lib / commands / new.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, 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  *  new.c: Create a new capital for a player
29  *
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  */
33
34 #include <config.h>
35
36 #include <fcntl.h>
37 #include <sys/stat.h>
38 #include <unistd.h>
39 #include "commands.h"
40 #include "land.h"
41 #include "optlist.h"
42 #include "path.h"
43 #include "prototypes.h"
44 #include "tel.h"
45
46 static void init_sanct(struct natstr *, coord, coord);
47
48 int
49 new(void)
50 {
51     struct sctstr sect;
52     struct natstr *natp;
53     natid num;
54     coord x, y;
55     char *p;
56     char buf[1024];
57
58     natp = getnatp(player->cnum);
59     if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
60         pr("Must be at 0,0 to add a new country\n");
61         return RET_FAIL;
62     }
63     if (!(natp = natargp(player->argp[1], "Country? ")))
64         return RET_SYN;
65     num = natp->nat_cnum;
66     if (natp->nat_stat != STAT_NEW) {
67         pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
68         return RET_SYN;
69     }
70     if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
71         return RET_SYN;
72     if (!sarg_xy(p, &x, &y) || !getsect(x, y, &sect))
73         return RET_SYN;
74     if (sect.sct_type != SCT_RURAL) {
75         pr("%s is a %s; try again...\n",
76            xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
77         return RET_SYN;
78     }
79     getsect(x + 2, y, &sect);
80     if (sect.sct_type != SCT_RURAL) {
81         pr("%s is a %s; try again...\n",
82            xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
83         return RET_SYN;
84     }
85
86     pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
87     nat_reset(natp, STAT_SANCT, x, y);
88     init_sanct(natp, x, y);
89     init_sanct(natp, x + 2, y);
90     putnat(natp);
91     return RET_OK;
92 }
93
94 static void
95 init_sanct(struct natstr *natp, coord x, coord y)
96 {
97     struct sctstr sect;
98
99     getsect(x, y, &sect);
100     sect.sct_own = natp->nat_cnum;
101     sect.sct_type = SCT_SANCT;
102     sect.sct_newtype = SCT_SANCT;
103     sect.sct_effic = 100;
104     sect.sct_road = 0;
105     sect.sct_rail = 0;
106     sect.sct_defense = 0;
107     sect.sct_mobil = startmob;
108     sect.sct_work = 100;
109     sect.sct_oldown = natp->nat_cnum;
110     if (at_least_one_100) {
111         sect.sct_oil = 100;
112         sect.sct_fertil = 100;
113         sect.sct_uran = 100;
114         sect.sct_min = 100;
115         sect.sct_gmin = 100;
116     }
117     sect.sct_item[I_CIVIL] = max_pop(start_research, &sect);
118     sect.sct_item[I_MILIT] = 55;
119     sect.sct_item[I_FOOD] = opt_NOFOOD ? 0 : 550;
120     sect.sct_item[I_UW] = 75;
121     putsect(&sect);
122 }