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:
37 #if defined(_WIN32) && !defined(__GNUC__)
47 #include "prototypes.h"
50 static int isok(int x, int y);
51 static void ok(signed char *map, int x, int y);
52 static void init_sanct(struct natstr *, coord, coord);
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 natp->nat_btu = max_btus;
130 natp->nat_stat = STAT_SANCT;
135 xyabsrange(natp, &defrealm, &absrealm);
136 for (i = 0; i < MAXNOR; i++) {
137 getrealm(i, num, &newrealm);
138 newrealm.r_xl = absrealm.lx;
139 newrealm.r_xh = absrealm.hx;
140 newrealm.r_yl = absrealm.ly;
141 newrealm.r_yh = absrealm.hy;
142 newrealm.r_timestamp = current_time;
149 natp->nat_money = start_cash;
150 natp->nat_level[NAT_HLEV] = start_happiness;
151 natp->nat_level[NAT_RLEV] = start_research;
152 natp->nat_level[NAT_TLEV] = start_technology;
153 natp->nat_level[NAT_ELEV] = start_education;
155 (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
156 init_sanct(natp, x, y);
157 init_sanct(natp, x + 2, y);
163 init_sanct(struct natstr *natp, coord x, coord y)
167 getsect(x, y, §);
168 sect.sct_own = natp->nat_cnum;
169 sect.sct_type = SCT_SANCT;
170 sect.sct_newtype = SCT_SANCT;
171 sect.sct_effic = 100;
174 sect.sct_defense = 0;
175 sect.sct_mobil = startmob;
177 sect.sct_oldown = natp->nat_cnum;
178 if (at_least_one_100) {
180 sect.sct_fertil = 100;
185 sect.sct_item[I_CIVIL] = max_pop(start_research, §);
186 sect.sct_item[I_MILIT] = 55;
187 sect.sct_item[I_FOOD] = opt_NOFOOD ? 0 : 550;
188 sect.sct_item[I_UW] = 75;
192 static int nmin, ngold, noil, nur;
193 static int nfree, navail, nowned;
202 nmin = ngold = noil = nur = 0;
203 navail = nfree = nowned = 0;
204 if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
205 logerror("malloc failed in isok\n");
206 pr("Memory error. Tell the deity.\n");
209 memset(map, 0, (WORLD_X * WORLD_Y) / 2);
214 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
215 xyas(x, y, player->cnum), nowned, nfree, navail);
216 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
217 nmin, noil, ngold, nur);
218 p = getstring("This setup ok? ", buf);
219 if (p == 0 || *p != 'y')
225 ok(signed char *map, int x, int y)
231 if (navail > MAXAVAIL)
236 if (!ef_read(EF_SECTOR, id, §))
238 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
241 if (navail >= MAXAVAIL) {
242 pr("At least %d...\n", MAXAVAIL);
245 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
246 if (sect.sct_own == 0)
250 if (sect.sct_min > 9)
252 if (sect.sct_gmin > 9)
254 if (sect.sct_uran > 9)
256 if (sect.sct_oil > 9)
260 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
261 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);