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:
44 #include "prototypes.h"
47 static int isok(int x, int y);
48 static void ok(signed char *map, int x, int y);
49 static void init_sanct(struct natstr *, coord, coord);
51 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
60 struct realmstr newrealm;
61 struct range absrealm;
67 time_t current_time = time(NULL);
69 natp = getnatp(player->cnum);
70 if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
71 pr("Must be at 0,0 to add a new country\n");
74 if (!(natp = natargp(player->argp[1], "Country? ")))
77 if (natp->nat_stat != STAT_NEW) {
78 pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
81 if (player->argp[2] != 0) {
82 if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
84 if (!sarg_xy(p, &x, &y) || !getsect(x, y, §))
86 if (sect.sct_type != SCT_RURAL) {
87 pr("%s is a %s; try again...\n",
88 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
91 getsect(x + 2, y, §);
92 if (sect.sct_type != SCT_RURAL) {
93 pr("%s is a %s; try again...\n",
94 xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
98 for (i = 0; i < 300 && !player->aborted; i++) {
99 /* Both x and y should be either odd or even */
100 x = (random() % WORLD_X) - (WORLD_X / 2);
101 y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
103 * If either of the two potential
104 * sanctuary sectors are already
105 * owned by someone else, pick
106 * another place on the map.
108 getsect(x, y, §);
109 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
111 getsect(x + 2, y, §);
112 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
118 pr("couldn't find an empty slot!\n");
125 pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
126 natp->nat_btu = max_btus;
127 natp->nat_stat = STAT_SANCT;
132 xyabsrange(natp, &defrealm, &absrealm);
133 for (i = 0; i < MAXNOR; i++) {
134 getrealm(i, num, &newrealm);
135 newrealm.r_xl = absrealm.lx;
136 newrealm.r_xh = absrealm.hx;
137 newrealm.r_yl = absrealm.ly;
138 newrealm.r_yh = absrealm.hy;
139 newrealm.r_timestamp = current_time;
146 natp->nat_money = start_cash;
147 natp->nat_level[NAT_HLEV] = start_happiness;
148 natp->nat_level[NAT_RLEV] = start_research;
149 natp->nat_level[NAT_TLEV] = start_technology;
150 natp->nat_level[NAT_ELEV] = start_education;
152 (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
153 init_sanct(natp, x, y);
154 init_sanct(natp, x + 2, y);
160 init_sanct(struct natstr *natp, coord x, coord y)
164 getsect(x, y, §);
165 sect.sct_own = natp->nat_cnum;
166 sect.sct_type = SCT_SANCT;
167 sect.sct_newtype = SCT_SANCT;
168 sect.sct_effic = 100;
171 sect.sct_defense = 0;
172 sect.sct_mobil = startmob;
174 sect.sct_oldown = natp->nat_cnum;
175 if (at_least_one_100) {
177 sect.sct_fertil = 100;
182 sect.sct_item[I_CIVIL] = max_pop(start_research, §);
183 sect.sct_item[I_MILIT] = 55;
184 sect.sct_item[I_FOOD] = opt_NOFOOD ? 0 : 550;
185 sect.sct_item[I_UW] = 75;
189 static int nmin, ngold, noil, nur;
190 static int nfree, navail, nowned;
199 nmin = ngold = noil = nur = 0;
200 navail = nfree = nowned = 0;
201 if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
202 logerror("malloc failed in isok\n");
203 pr("Memory error. Tell the deity.\n");
206 memset(map, 0, (WORLD_X * WORLD_Y) / 2);
211 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
212 xyas(x, y, player->cnum), nowned, nfree, navail);
213 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
214 nmin, noil, ngold, nur);
215 p = getstring("This setup ok? ", buf);
216 if (p == 0 || *p != 'y')
222 ok(signed char *map, int x, int y)
228 if (navail > MAXAVAIL)
233 if (!ef_read(EF_SECTOR, id, §))
235 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
238 if (navail >= MAXAVAIL) {
239 pr("At least %d...\n", MAXAVAIL);
242 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
243 if (sect.sct_own == 0)
247 if (sect.sct_min > 9)
249 if (sect.sct_gmin > 9)
251 if (sect.sct_uran > 9)
253 if (sect.sct_oil > 9)
257 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
258 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);