2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 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.
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(signed char *map, int x, int y);
54 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
63 struct realmstr newrealm;
64 struct range absrealm;
70 time_t current_time = time(NULL);
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 (!(natp = natargp(player->argp[1], "Country? ")))
80 if (natp->nat_stat != STAT_NEW) {
81 pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
84 if (player->argp[2] != 0) {
85 if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
87 if (!sarg_xy(p, &x, &y) || !getsect(x, y, §))
89 if (sect.sct_type != SCT_RURAL) {
90 pr("%s is a %s; try again...\n",
91 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
94 getsect(x + 2, y, §);
95 if (sect.sct_type != SCT_RURAL) {
96 pr("%s is a %s; try again...\n",
97 xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
101 for (i = 0; i < 300 && !player->aborted; i++) {
102 /* Both x and y should be either odd or even */
103 x = (random() % WORLD_X) - (WORLD_X / 2);
104 y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
106 * If either of the two potential
107 * sanctuary sectors are already
108 * owned by someone else, pick
109 * another place on the map.
111 getsect(x, y, §);
112 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
114 getsect(x + 2, y, §);
115 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
121 pr("couldn't find an empty slot!\n");
128 pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
129 getsect(x, y, §);
131 sect.sct_type = SCT_SANCT;
132 sect.sct_newtype = SCT_SANCT;
133 sect.sct_effic = 100;
136 sect.sct_defense = 0;
137 if (!opt_DEFENSE_INFRA)
138 sect.sct_defense = sect.sct_effic;
139 sect.sct_mobil = startmob;
141 sect.sct_oldown = num;
142 if (at_least_one_100) {
144 sect.sct_fertil = 100;
149 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
150 sect.sct_item[I_MILIT] = 55;
151 sect.sct_item[I_FOOD] = 1000;
152 sect.sct_item[I_UW] = 75;
154 getsect(x + 2, y, §);
156 sect.sct_type = SCT_SANCT;
157 sect.sct_newtype = SCT_SANCT;
158 sect.sct_effic = 100;
161 sect.sct_defense = 0;
162 if (!opt_DEFENSE_INFRA)
163 sect.sct_defense = sect.sct_effic;
165 sect.sct_oldown = num;
166 sect.sct_mobil = startmob;
167 if (at_least_one_100) {
169 sect.sct_fertil = 100;
174 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
175 sect.sct_item[I_MILIT] = 55;
176 sect.sct_item[I_FOOD] = 100;
177 sect.sct_item[I_UW] = 75;
179 natp->nat_btu = max_btus;
180 natp->nat_stat = STAT_SANCT;
185 xyabsrange(natp, &defrealm, &absrealm);
186 for (i = 0; i < MAXNOR; i++) {
187 getrealm(i, num, &newrealm);
188 newrealm.r_xl = absrealm.lx;
189 newrealm.r_xh = absrealm.hx;
190 newrealm.r_yl = absrealm.ly;
191 newrealm.r_yh = absrealm.hy;
192 newrealm.r_timestamp = current_time;
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;
205 (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
210 static int nmin, ngold, noil, nur;
211 static int nfree, navail, nowned;
220 nmin = ngold = noil = nur = 0;
221 navail = nfree = nowned = 0;
222 if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
223 logerror("malloc failed in isok\n");
224 pr("Memory error. Tell the deity.\n");
227 memset(map, 0, (WORLD_X * WORLD_Y) / 2);
232 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
233 xyas(x, y, player->cnum), nowned, nfree, navail);
234 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
235 nmin, noil, ngold, nur);
236 p = getstring("This setup ok? ", buf);
237 if (p == 0 || *p != 'y')
243 ok(signed char *map, int x, int y)
249 if (navail > MAXAVAIL)
254 if (!ef_read(EF_SECTOR, id, §))
256 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
259 if (navail >= MAXAVAIL) {
260 pr("At least %d...\n", MAXAVAIL);
263 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
264 if (sect.sct_own == 0)
268 if (sect.sct_min > 9)
270 if (sect.sct_gmin > 9)
272 if (sect.sct_uran > 9)
274 if (sect.sct_oil > 9)
278 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
279 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);