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:
51 static int isok(int x, int y);
52 static void ok(s_char *map, int x, int y);
54 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
63 struct boundstr newrealms;
64 struct range absrealm;
72 natp = getnatp(player->cnum);
73 if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
74 pr("Must be at 0,0 to add a new country\n");
77 if ((n = natarg(player->argp[1], "Country? ")) < 0) {
78 pr("Bad country number\n");
83 if ((natp->nat_stat & STAT_NEW) == 0) {
84 pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
87 if (player->argp[2] != 0) {
88 if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
90 if (!sarg_xy(p, &x, &y) || !getsect(x, y, §))
92 if (sect.sct_type != SCT_RURAL) {
93 pr("%s is a %s; try again...\n",
94 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
97 getsect(x + 2, y, §);
98 if (sect.sct_type != SCT_RURAL) {
99 pr("%s is a %s; try again...\n",
100 xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
104 for (i = 0; i < 300 && !player->aborted; i++) {
105 /* Both x and y should be either odd or even */
106 x = (random() % WORLD_X) - (WORLD_X / 2);
107 y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
109 * If either of the two potential
110 * sanctuary sectors are already
111 * owned by someone else, pick
112 * another place on the map.
114 getsect(x, y, §);
115 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
117 getsect(x + 2, y, §);
118 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
124 pr("couldn't find an empty slot!\n");
131 pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
132 getsect(x, y, §);
134 sect.sct_type = SCT_SANCT;
135 sect.sct_newtype = SCT_SANCT;
136 sect.sct_effic = 100;
139 sect.sct_defense = 0;
140 if (!opt_DEFENSE_INFRA)
141 sect.sct_defense = sect.sct_effic;
142 sect.sct_mobil = startmob;
144 sect.sct_oldown = num;
145 if (at_least_one_100) {
147 sect.sct_fertil = 100;
152 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
153 sect.sct_item[I_MILIT] = 55;
154 sect.sct_item[I_FOOD] = 1000;
155 sect.sct_item[I_UW] = 75;
157 getsect(x + 2, y, §);
159 sect.sct_type = SCT_SANCT;
160 sect.sct_newtype = SCT_SANCT;
161 sect.sct_effic = 100;
164 sect.sct_defense = 0;
165 if (!opt_DEFENSE_INFRA)
166 sect.sct_defense = sect.sct_effic;
168 sect.sct_oldown = num;
169 sect.sct_mobil = startmob;
170 if (at_least_one_100) {
172 sect.sct_fertil = 100;
177 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
178 sect.sct_item[I_MILIT] = 55;
179 sect.sct_item[I_FOOD] = 100;
180 sect.sct_item[I_UW] = 75;
182 natp->nat_btu = max_btus;
183 natp->nat_stat &= ~STAT_NEW;
184 natp->nat_stat |= STAT_SANCT;
189 xyabsrange(natp, &defrealm, &absrealm);
190 newrealms.b_xl = absrealm.lx;
191 newrealms.b_xh = absrealm.hx;
192 newrealms.b_yl = absrealm.ly;
193 newrealms.b_yh = absrealm.hy;
198 natp->nat_money = start_cash;
199 natp->nat_level[NAT_HLEV] = start_happiness;
200 natp->nat_level[NAT_RLEV] = start_research;
201 natp->nat_level[NAT_TLEV] = start_technology;
202 natp->nat_level[NAT_ELEV] = start_education;
203 for (i = 0; i < MAXNOR; i++)
204 natp->nat_b[i] = newrealms;
206 (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
211 static int nmin, ngold, noil, nur;
212 static int nfree, navail, nowned;
221 nmin = ngold = noil = nur = 0;
222 navail = nfree = nowned = 0;
223 if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
224 logerror("malloc failed in isok\n");
225 pr("Memory error. Tell the deity.\n");
228 memset(map, 0, (WORLD_X * WORLD_Y) / 2);
233 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
234 xyas(x, y, player->cnum), nowned, nfree, navail);
235 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
236 nmin, noil, ngold, nur);
237 p = getstring("This setup ok? ", buf);
238 if (p == 0 || *p != 'y')
244 ok(s_char *map, int x, int y)
250 if (navail > MAXAVAIL)
255 if (!ef_read(EF_SECTOR, id, §))
257 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
260 if (navail >= MAXAVAIL) {
261 pr("At least %d...\n", MAXAVAIL);
264 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
265 if (sect.sct_own == 0)
269 if (sect.sct_min > 9)
271 if (sect.sct_gmin > 9)
273 if (sect.sct_uran > 9)
275 if (sect.sct_oil > 9)
279 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
280 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);