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 deity_build_land(int, coord, coord, natid, int);
53 static int isok(int x, int y);
54 static void ok(s_char *map, int x, int y);
56 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
65 struct boundstr newrealms;
66 struct range absrealm;
74 natp = getnatp(player->cnum);
75 if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
76 pr("Must be at 0,0 to add a new country\n");
79 if ((n = natarg(player->argp[1], "Country? ")) < 0) {
80 pr("Bad country number\n");
85 if ((natp->nat_stat & STAT_NEW) == 0) {
86 pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
89 if (player->argp[2] != 0) {
90 if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
92 if (!sarg_xy(p, &x, &y) || !getsect(x, y, §))
94 if (sect.sct_type != SCT_RURAL) {
95 pr("%s is a %s; try again...\n",
96 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
99 getsect(x + 2, y, §);
100 if (sect.sct_type != SCT_RURAL) {
101 pr("%s is a %s; try again...\n",
102 xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
106 for (i = 0; i < 300 && !player->aborted; i++) {
107 /* Both x and y should be either odd or even */
108 x = (random() % WORLD_X) - (WORLD_X / 2);
109 y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
111 * If either of the two potential
112 * sanctuary sectors are already
113 * owned by someone else, pick
114 * another place on the map.
116 getsect(x, y, §);
117 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
119 getsect(x + 2, y, §);
120 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
126 pr("couldn't find an empty slot!\n");
133 pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
134 getsect(x, y, §);
136 sect.sct_type = SCT_SANCT;
137 sect.sct_newtype = SCT_SANCT;
138 sect.sct_effic = 100;
141 sect.sct_defense = 0;
142 if (!opt_DEFENSE_INFRA)
143 sect.sct_defense = sect.sct_effic;
144 sect.sct_mobil = startmob;
146 sect.sct_oldown = num;
147 if (at_least_one_100) {
149 sect.sct_fertil = 100;
154 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
155 sect.sct_item[I_MILIT] = 55;
156 sect.sct_item[I_FOOD] = 1000;
157 sect.sct_item[I_UW] = 75;
159 getsect(x + 2, y, §);
161 sect.sct_type = SCT_SANCT;
162 sect.sct_newtype = SCT_SANCT;
163 sect.sct_effic = 100;
166 sect.sct_defense = 0;
167 if (!opt_DEFENSE_INFRA)
168 sect.sct_defense = sect.sct_effic;
170 sect.sct_oldown = num;
171 sect.sct_mobil = startmob;
172 if (at_least_one_100) {
174 sect.sct_fertil = 100;
179 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
180 sect.sct_item[I_MILIT] = 55;
181 sect.sct_item[I_FOOD] = 100;
182 sect.sct_item[I_UW] = 75;
184 natp->nat_btu = max_btus;
185 natp->nat_stat &= ~STAT_NEW;
186 natp->nat_stat |= STAT_SANCT;
187 natp->nat_xstart = x;
188 natp->nat_ystart = y;
193 xyabsrange(natp, &defrealm, &absrealm);
194 newrealms.b_xl = absrealm.lx;
195 newrealms.b_xh = absrealm.hx;
196 newrealms.b_yl = absrealm.ly;
197 newrealms.b_yh = absrealm.hy;
202 natp->nat_money = START_CASH;
203 natp->nat_level[NAT_HLEV] = start_happiness;
204 natp->nat_level[NAT_RLEV] = start_research;
205 natp->nat_level[NAT_TLEV] = start_technology;
206 natp->nat_level[NAT_ELEV] = start_education;
207 for (i = 0; i < MAXNOR; i++)
208 natp->nat_b[i] = newrealms;
210 (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
212 for (n = 0; n < START_UNITS; n++)
213 deity_build_land(start_unit_type[n], x, y, num, 0);
214 #endif /* START_UNITS */
219 static int nmin, ngold, noil, nur;
220 static int nfree, navail, nowned;
229 nmin = ngold = noil = nur = 0;
230 navail = nfree = nowned = 0;
231 if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
232 logerror("malloc failed in isok\n");
233 pr("Memory error. Tell the deity.\n");
236 memset(map, 0, (WORLD_X * WORLD_Y) / 2);
241 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
242 xyas(x, y, player->cnum), nowned, nfree, navail);
243 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
244 nmin, noil, ngold, nur);
245 p = getstring("This setup ok? ", buf);
246 if (p == 0 || *p != 'y')
252 ok(s_char *map, int x, int y)
258 if (navail > MAXAVAIL)
263 if (!ef_read(EF_SECTOR, id, §))
265 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
268 if (navail >= MAXAVAIL) {
269 pr("At least %d...\n", MAXAVAIL);
272 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
273 if (sect.sct_own == 0)
277 if (sect.sct_min > 9)
279 if (sect.sct_gmin > 9)
281 if (sect.sct_uran > 9)
283 if (sect.sct_oil > 9)
287 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
288 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);
293 deity_build_land(int type, coord x, coord y, natid own, int tlev)
297 struct nstr_item nstr;
303 snxtitem_all(&nstr, EF_LAND);
304 while (nxtitem(&nstr, &land)) {
305 if (land.lnd_own == 0) {
311 ef_extend(EF_LAND, 50);
315 land.lnd_mission = 0;
316 land.lnd_type = type;
317 land.lnd_effic = 100;
318 land.lnd_mobil = land_mob_max;
319 land.lnd_tech = tlev;
320 land.lnd_uid = nstr.cur;
327 time(&land.lnd_access);
329 land.lnd_retreat = morale_base;
332 land.lnd_fuel = lp->l_fuelc;
333 land.lnd_nxlight = 0;
335 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
336 land.lnd_rad_max = lp->l_rad;
337 memset(land.lnd_item, 0, sizeof(land.lnd_item));
339 land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
340 land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech);
341 land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech);
342 land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech);
343 land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech);
344 land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech);
345 land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech);
346 land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech);
347 land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech);
348 land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech);
349 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech);
350 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech);
351 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech);
352 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech);
353 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
354 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
355 land.lnd_item[I_FOOD] = lp->l_item[I_FOOD];
357 putland(land.lnd_uid, &land);
358 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
360 pr("%s", prland(&land));
361 pr(" built in sector %s\n", xyas(x, y, player->cnum));
364 #endif /* START_UNITS */