]> git.pond.sub.org Git - empserver/blob - src/lib/commands/new.c
Improve newcap's origin error message
[empserver] / src / lib / commands / new.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  new.c: Create a new capital for a player
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1986
31  */
32
33 #include <config.h>
34
35 #include <fcntl.h>
36 #include <sys/stat.h>
37 #include <unistd.h>
38 #include "commands.h"
39 #include "land.h"
40 #include "optlist.h"
41 #include "path.h"
42 #include "prototypes.h"
43
44 static void init_sanct(struct natstr *, coord, coord);
45
46 int
47 new(void)
48 {
49     struct sctstr sect;
50     struct natstr *natp;
51     natid num;
52     coord x, y;
53     char *p;
54     char buf[1024];
55
56     natp = getnatp(player->cnum);
57     if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
58         pr("Origin must be reset to add a new country.\n");
59         pr("Use `origin ~' to reset it.\n");
60         return RET_FAIL;
61     }
62     if (!(natp = natargp(player->argp[1], "Country? ")))
63         return RET_SYN;
64     num = natp->nat_cnum;
65     if (natp->nat_stat != STAT_NEW) {
66         pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
67         return RET_SYN;
68     }
69     if (!(p = getstarg(player->argp[2], "sanctuary pair : ", buf)))
70         return RET_SYN;
71     if (!sarg_xy(p, &x, &y) || !getsect(x, y, &sect))
72         return RET_SYN;
73     if (sect.sct_type != SCT_RURAL) {
74         pr("%s is a %s; try again...\n",
75            xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
76         return RET_SYN;
77     }
78     getsect(x + 2, y, &sect);
79     if (sect.sct_type != SCT_RURAL) {
80         pr("%s is a %s; try again...\n",
81            xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
82         return RET_SYN;
83     }
84
85     pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
86     nat_reset(natp, STAT_SANCT, x, y);
87     init_sanct(natp, x, y);
88     init_sanct(natp, x + 2, y);
89     putnat(natp);
90     return RET_OK;
91 }
92
93 static void
94 init_sanct(struct natstr *natp, coord x, coord y)
95 {
96     struct sctstr sect;
97
98     getsect(x, y, &sect);
99     sect.sct_own = natp->nat_cnum;
100     sect.sct_type = SCT_SANCT;
101     sect.sct_newtype = SCT_SANCT;
102     sect.sct_effic = 100;
103     sect.sct_road = 0;
104     sect.sct_rail = 0;
105     sect.sct_defense = 0;
106     sect.sct_mobil = startmob;
107     sect.sct_work = 100;
108     sect.sct_oldown = natp->nat_cnum;
109     if (at_least_one_100) {
110         sect.sct_oil = 100;
111         sect.sct_fertil = 100;
112         sect.sct_uran = 100;
113         sect.sct_min = 100;
114         sect.sct_gmin = 100;
115     }
116     sect.sct_item[I_CIVIL] = max_pop(start_research, &sect);
117     sect.sct_item[I_MILIT] = 55;
118     sect.sct_item[I_FOOD] = opt_NOFOOD ? 0 : 550;
119     sect.sct_item[I_UW] = 75;
120     putsect(&sect);
121 }