2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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:
53 static int deity_build_land(int, coord, coord, natid, int);
55 static int isok(int x, int y);
56 static void ok(s_char *map, int x, int y);
58 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
67 struct boundstr newrealms;
68 struct range absrealm;
77 natp = getnatp(player->cnum);
78 if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
79 pr("Must be at 0,0 to add a new country\n");
82 if ((n = natarg(player->argp[1], "Country? ")) < 0) {
83 pr("Bad country number\n");
88 if ((natp->nat_stat & STAT_NEW) == 0) {
89 pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
92 if (player->argp[2] != 0) {
93 if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
95 if (!sarg_xy(p, &x, &y) || !getsect(x, y, §))
97 if (sect.sct_type != SCT_RURAL) {
98 pr("%s is a %s; try again...\n",
99 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
102 getsect(x + 2, y, §);
103 if (sect.sct_type != SCT_RURAL) {
104 pr("%s is a %s; try again...\n",
105 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
115 for (i = 0; i < 300 && !player->aborted; i++) {
116 /* Both x and y should be either odd or even */
117 x = (random() % WORLD_X) - (WORLD_X / 2);
118 y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
120 * If either of the two potential
121 * sanctuary sectors are already
122 * owned by someone else, pick
123 * another place on the map.
125 getsect(x, y, §);
126 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
128 getsect(x + 2, y, §);
129 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
135 pr("couldn't find an empty slot!\n");
142 pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
143 getsect(x, y, §);
145 sect.sct_type = SCT_SANCT;
146 sect.sct_newtype = SCT_SANCT;
147 sect.sct_effic = 100;
150 sect.sct_defense = 0;
151 if (!opt_DEFENSE_INFRA)
152 sect.sct_defense = sect.sct_effic;
153 sect.sct_mobil = startmob;
155 sect.sct_oldown = num;
156 if (at_least_one_100) {
158 sect.sct_fertil = 100;
163 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
164 sect.sct_item[I_MILIT] = 55;
165 sect.sct_item[I_FOOD] = 1000;
166 sect.sct_item[I_UW] = 75;
168 getsect(x + 2, y, §);
170 sect.sct_type = SCT_SANCT;
171 sect.sct_newtype = SCT_SANCT;
172 sect.sct_effic = 100;
175 sect.sct_defense = 0;
176 if (!opt_DEFENSE_INFRA)
177 sect.sct_defense = sect.sct_effic;
179 sect.sct_oldown = num;
180 sect.sct_mobil = startmob;
181 if (at_least_one_100) {
183 sect.sct_fertil = 100;
188 sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
189 sect.sct_item[I_MILIT] = 55;
190 sect.sct_item[I_FOOD] = 100;
191 sect.sct_item[I_UW] = 75;
193 natp->nat_btu = max_btus;
194 natp->nat_stat &= ~STAT_NEW;
195 natp->nat_stat |= STAT_SANCT;
196 natp->nat_xstart = x;
197 natp->nat_ystart = y;
207 xyabsrange(natp, &defrealm, &absrealm);
208 newrealms.b_xl = absrealm.lx;
209 newrealms.b_xh = absrealm.hx;
210 newrealms.b_yl = absrealm.ly;
211 newrealms.b_yh = absrealm.hy;
212 natp->nat_money = START_CASH;
213 natp->nat_level[NAT_HLEV] = start_happiness;
214 natp->nat_level[NAT_RLEV] = start_research;
215 natp->nat_level[NAT_TLEV] = start_technology;
216 natp->nat_level[NAT_ELEV] = start_education;
217 for (i = 0; i < MAXNOR; i++)
218 natp->nat_b[i] = newrealms;
220 (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
222 for (n = 0; n < START_UNITS; n++)
223 deity_build_land(start_unit_type[n], x, y, num, 0);
224 #endif /* START_UNITS */
229 static int nmin, ngold, noil, nur;
230 static int nfree, navail, nowned;
239 nmin = ngold = noil = nur = 0;
240 navail = nfree = nowned = 0;
241 if ((map = (s_char *)malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
242 logerror("malloc failed in isok\n");
243 pr("Memory error. Tell the deity.\n");
246 memset(map, 0, (WORLD_X * WORLD_Y) / 2);
251 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
252 xyas(x, y, player->cnum), nowned, nfree, navail);
253 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
254 nmin, noil, ngold, nur);
255 p = getstring("This setup ok? ", buf);
256 if (p == 0 || *p != 'y')
262 ok(s_char *map, int x, int y)
268 if (navail > MAXAVAIL)
273 if (!ef_read(EF_SECTOR, id, (s_char *)§))
275 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
278 if (navail >= MAXAVAIL) {
279 pr("At least %d...\n", MAXAVAIL);
282 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
283 if (sect.sct_own == 0)
287 if (sect.sct_min > 9)
289 if (sect.sct_gmin > 9)
291 if (sect.sct_uran > 9)
293 if (sect.sct_oil > 9)
297 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
298 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);
303 deity_build_land(int type, coord x, coord y, natid own, int tlev)
307 struct nstr_item nstr;
313 snxtitem_all(&nstr, EF_LAND);
314 while (nxtitem(&nstr, (s_char *)&land)) {
315 if (land.lnd_own == 0) {
321 ef_extend(EF_LAND, 50);
325 land.lnd_mission = 0;
326 land.lnd_type = type;
327 land.lnd_effic = 100;
328 land.lnd_mobil = land_mob_max;
329 land.lnd_tech = tlev;
330 land.lnd_uid = nstr.cur;
337 time(&land.lnd_access);
339 land.lnd_retreat = morale_base;
342 land.lnd_fuel = lp->l_fuelc;
343 land.lnd_nxlight = 0;
345 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
346 land.lnd_rad_max = lp->l_rad;
347 memset(land.lnd_item, 0, sizeof(land.lnd_item));
349 land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
350 land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech);
351 land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech);
352 land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech);
353 land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech);
354 land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech);
355 land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech);
356 land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech);
357 land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech);
358 land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech);
359 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech);
360 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech);
361 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech);
362 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech);
363 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
364 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
365 land.lnd_item[I_FOOD] = lp->l_item[I_FOOD];
367 putland(land.lnd_uid, &land);
368 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
370 pr("%s", prland(&land));
371 pr(" built in sector %s\n", xyas(x, y, player->cnum));
374 #endif /* START_UNITS */