2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * new.c: Create a new capital for a player
30 * Known contributors to this file:
50 static int isok(int x, int y);
51 static void ok(s_char *map, int x, int y);
53 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
62 struct boundstr newrealms;
63 struct range absrealm;
71 natp = getnatp(player->cnum);
72 if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
73 pr("Must be at 0,0 to add a new country\n");
76 if ((n = natarg(player->argp[1], "Country? ")) < 0) {
77 pr("Bad country number\n");
82 if ((natp->nat_stat & STAT_NEW) == 0) {
83 pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
86 if (player->argp[2] != 0) {
87 if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
89 if (!sarg_xy(p, &x, &y) || !getsect(x, y, §))
91 if (sect.sct_type != SCT_RURAL) {
92 pr("%s is a %s; try again...\n",
93 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
96 getsect(x + 2, y, §);
97 if (sect.sct_type != SCT_RURAL) {
98 pr("%s is a %s; try again...\n",
99 xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
103 for (i = 0; i < 300 && !player->aborted; i++) {
104 /* Both x and y should be either odd or even */
105 x = (random() % WORLD_X) - (WORLD_X / 2);
106 y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
108 * If either of the two potential
109 * sanctuary sectors are already
110 * owned by someone else, pick
111 * another place on the map.
113 getsect(x, y, §);
114 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
116 getsect(x + 2, y, §);
117 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
123 pr("couldn't find an empty slot!\n");
130 pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
131 getsect(x, y, §);
133 sect.sct_type = SCT_SANCT;
134 sect.sct_newtype = SCT_SANCT;
135 sect.sct_effic = 100;
138 sect.sct_defense = 0;
139 if (!opt_DEFENSE_INFRA)
140 sect.sct_defense = sect.sct_effic;
141 sect.sct_mobil = startmob;
143 sect.sct_oldown = num;
144 if (at_least_one_100) {
146 sect.sct_fertil = 100;
151 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
152 sect.sct_item[I_MILIT] = 55;
153 sect.sct_item[I_FOOD] = 1000;
154 sect.sct_item[I_UW] = 75;
156 getsect(x + 2, y, §);
158 sect.sct_type = SCT_SANCT;
159 sect.sct_newtype = SCT_SANCT;
160 sect.sct_effic = 100;
163 sect.sct_defense = 0;
164 if (!opt_DEFENSE_INFRA)
165 sect.sct_defense = sect.sct_effic;
167 sect.sct_oldown = num;
168 sect.sct_mobil = startmob;
169 if (at_least_one_100) {
171 sect.sct_fertil = 100;
176 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
177 sect.sct_item[I_MILIT] = 55;
178 sect.sct_item[I_FOOD] = 100;
179 sect.sct_item[I_UW] = 75;
181 natp->nat_btu = max_btus;
182 natp->nat_stat &= ~STAT_NEW;
183 natp->nat_stat |= STAT_SANCT;
184 natp->nat_xstart = x;
185 natp->nat_ystart = y;
190 xyabsrange(natp, &defrealm, &absrealm);
191 newrealms.b_xl = absrealm.lx;
192 newrealms.b_xh = absrealm.hx;
193 newrealms.b_yl = absrealm.ly;
194 newrealms.b_yh = absrealm.hy;
199 natp->nat_money = START_CASH;
200 natp->nat_level[NAT_HLEV] = start_happiness;
201 natp->nat_level[NAT_RLEV] = start_research;
202 natp->nat_level[NAT_TLEV] = start_technology;
203 natp->nat_level[NAT_ELEV] = start_education;
204 for (i = 0; i < MAXNOR; i++)
205 natp->nat_b[i] = newrealms;
207 (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
212 static int nmin, ngold, noil, nur;
213 static int nfree, navail, nowned;
222 nmin = ngold = noil = nur = 0;
223 navail = nfree = nowned = 0;
224 if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
225 logerror("malloc failed in isok\n");
226 pr("Memory error. Tell the deity.\n");
229 memset(map, 0, (WORLD_X * WORLD_Y) / 2);
234 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
235 xyas(x, y, player->cnum), nowned, nfree, navail);
236 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
237 nmin, noil, ngold, nur);
238 p = getstring("This setup ok? ", buf);
239 if (p == 0 || *p != 'y')
245 ok(s_char *map, int x, int y)
251 if (navail > MAXAVAIL)
256 if (!ef_read(EF_SECTOR, id, §))
258 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
261 if (navail >= MAXAVAIL) {
262 pr("At least %d...\n", MAXAVAIL);
265 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
266 if (sect.sct_own == 0)
270 if (sect.sct_min > 9)
272 if (sect.sct_gmin > 9)
274 if (sect.sct_uran > 9)
276 if (sect.sct_oil > 9)
280 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
281 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);