]> git.pond.sub.org Git - empserver/blob - src/lib/commands/new.c
commands: Rename the command functions
[empserver] / src / lib / commands / new.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2021, 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  *     Markus Armbruster, 2004-2011
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 "game.h"
41 #include "optlist.h"
42
43 static void init_sanct(struct natstr *, coord, coord);
44
45 int
46 c_newcap(void)
47 {
48     static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
49     struct sctstr sect;
50     struct natstr *natp;
51     struct realmstr newrealm;
52     struct range absrealm;
53     natid num;
54     coord x, y;
55     int i;
56     char *p;
57     char buf[1024];
58
59     natp = getnatp(player->cnum);
60     if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
61         pr("Origin must be reset to add a new country.\n");
62         pr("Use `origin ~' to reset it.\n");
63         return RET_FAIL;
64     }
65     if (!(natp = natargp(player->argp[1], "Country? ")))
66         return RET_SYN;
67     num = natp->nat_cnum;
68     if (natp->nat_stat != STAT_NEW) {
69         pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
70         return RET_SYN;
71     }
72     if (!(p = getstarg(player->argp[2], "sanctuary pair : ", buf)))
73         return RET_SYN;
74     if (!sarg_xy(p, &x, &y) || !getsect(x, y, &sect))
75         return RET_SYN;
76     if (sect.sct_type != SCT_RURAL) {
77         pr("%s is a %s; try again...\n",
78            xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
79         return RET_SYN;
80     }
81     getsect(x + 2, y, &sect);
82     if (sect.sct_type != SCT_RURAL) {
83         pr("%s is a %s; try again...\n",
84            xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
85         return RET_SYN;
86     }
87
88     pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
89     natp->nat_btu = max_btus;
90     game_tick_to_now(&natp->nat_access);
91     natp->nat_stat = STAT_SANCT;
92     natp->nat_xcap = natp->nat_xorg = x;
93     natp->nat_ycap = natp->nat_yorg = y;
94     xyabsrange(natp, &defrealm, &absrealm);
95     for (i = 0; i < MAXNOR; i++) {
96         ef_blank(EF_REALM, i + natp->nat_cnum * MAXNOR, &newrealm);
97         newrealm.r_xl = absrealm.lx;
98         newrealm.r_xh = absrealm.hx;
99         newrealm.r_yl = absrealm.ly;
100         newrealm.r_yh = absrealm.hy;
101         putrealm(&newrealm);
102     }
103     if (players_at_00) {
104         natp->nat_xorg = 0;
105         natp->nat_yorg = 0;
106     }
107     natp->nat_money = start_cash;
108     putnat(natp);
109     init_sanct(natp, x, y);
110     init_sanct(natp, x + 2, y);
111     return RET_OK;
112 }
113
114 static void
115 init_sanct(struct natstr *natp, coord x, coord y)
116 {
117     struct sctstr sect;
118
119     getsect(x, y, &sect);
120     sect.sct_own = natp->nat_cnum;
121     sect.sct_type = SCT_SANCT;
122     sect.sct_newtype = SCT_SANCT;
123     sect.sct_effic = 100;
124     sect.sct_road = 0;
125     sect.sct_rail = 0;
126     sect.sct_defense = 0;
127     sect.sct_mobil = startmob;
128     sect.sct_work = 100;
129     sect.sct_oldown = natp->nat_cnum;
130     if (at_least_one_100) {
131         sect.sct_oil = 100;
132         sect.sct_fertil = 100;
133         sect.sct_uran = 100;
134         sect.sct_min = 100;
135         sect.sct_gmin = 100;
136     }
137     sect.sct_item[I_CIVIL] = max_pop(start_research, &sect);
138     sect.sct_item[I_MILIT] = 55;
139     sect.sct_item[I_FOOD] = opt_NOFOOD ? 0 : 550;
140     sect.sct_item[I_UW] = 75;
141     putsect(&sect);
142 }