2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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:
52 extern float start_education, start_happiness;
53 extern float start_technology, start_research;
54 extern int morale_base;
56 static void ok(s_char *map, int x, int y);
57 static int isok(int x, int y);
59 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
67 extern int players_at_00;
68 extern int at_least_one_100;
70 extern int start_unit_type[START_UNITS];
71 #endif /* START_UNITS */
74 struct boundstr newrealms;
75 struct range absrealm;
85 natp = getnatp(player->cnum);
86 if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
87 pr("Must be at 0,0 to add a new country\n");
90 if ((n = natarg(player->argp[1], "Country? ")) < 0) {
91 pr("Bad country number\n");
96 if ((natp->nat_stat & STAT_NEW) == 0) {
97 pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
100 if (player->argp[2] != 0) {
101 if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
103 if (!sarg_xy(p, &x, &y) || !getsect(x, y, §))
105 if (sect.sct_type != SCT_RURAL) {
106 pr("%s is a %s; try again...\n",
107 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
110 getsect(x + 2, y, §);
111 if (sect.sct_type != SCT_RURAL) {
112 pr("%s is a %s; try again...\n",
113 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
123 for (i = 0; i < 300 && !player->aborted; i++) {
124 /* Both x and y should be either odd or even */
125 x = (random() % WORLD_X) - (WORLD_X / 2);
126 y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
128 * If either of the two potential
129 * sanctuary sectors are already
130 * owned by someone else, pick
131 * another place on the map.
133 getsect(x, y, §);
134 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
136 getsect(x + 2, y, §);
137 if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
143 pr("couldn't find an empty slot!\n");
150 pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
151 getsect(x, y, §);
153 sect.sct_type = SCT_SANCT;
154 sect.sct_newtype = SCT_SANCT;
155 sect.sct_effic = 100;
158 sect.sct_defense = 0;
159 if (!opt_DEFENSE_INFRA)
160 sect.sct_defense = sect.sct_effic;
161 sect.sct_mobil = startmob;
163 sect.sct_oldown = num;
164 if (at_least_one_100) {
166 sect.sct_fertil = 100;
172 putvar(V_CIVIL, 550, (s_char *)§, EF_SECTOR);
174 putvar(V_CIVIL, 999, (s_char *)§, EF_SECTOR);
175 putvar(V_MILIT, 55, (s_char *)§, EF_SECTOR);
176 putvar(V_FOOD, 1000, (s_char *)§, EF_SECTOR);
177 putvar(V_UW, 75, (s_char *)§, EF_SECTOR);
179 getsect(x + 2, y, §);
181 sect.sct_type = SCT_SANCT;
182 sect.sct_newtype = SCT_SANCT;
183 sect.sct_effic = 100;
186 sect.sct_defense = 0;
187 if (!opt_DEFENSE_INFRA)
188 sect.sct_defense = sect.sct_effic;
190 sect.sct_oldown = num;
191 sect.sct_mobil = startmob;
192 if (at_least_one_100) {
194 sect.sct_fertil = 100;
200 putvar(V_CIVIL, 550, (s_char *)§, EF_SECTOR);
202 putvar(V_CIVIL, 999, (s_char *)§, EF_SECTOR);
203 putvar(V_FOOD, 100, (s_char *)§, EF_SECTOR);
204 putvar(V_MILIT, 55, (s_char *)§, EF_SECTOR);
205 putvar(V_UW, 75, (s_char *)§, EF_SECTOR);
207 natp->nat_btu = max_btus;
208 natp->nat_stat &= ~STAT_NEW;
209 natp->nat_stat |= STAT_SANCT;
210 natp->nat_xstart = x;
211 natp->nat_ystart = y;
221 xyabsrange(natp, &defrealm, &absrealm);
222 newrealms.b_xl = absrealm.lx;
223 newrealms.b_xh = absrealm.hx;
224 newrealms.b_yl = absrealm.ly;
225 newrealms.b_yh = absrealm.hy;
226 natp->nat_money = START_CASH;
227 natp->nat_level[NAT_HLEV] = start_happiness;
228 natp->nat_level[NAT_RLEV] = start_research;
229 natp->nat_level[NAT_TLEV] = start_technology;
230 natp->nat_level[NAT_ELEV] = start_education;
231 for (i = 0; i < MAXNOR; i++)
232 natp->nat_b[i] = newrealms;
234 (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
236 for (n = 0; n < START_UNITS; n++)
237 deity_build_land(start_unit_type[n], x, y, num, 0);
238 #endif /* START_UNITS */
243 static int nmin, ngold, noil, nur;
244 static int nfree, navail, nowned;
253 nmin = ngold = noil = nur = 0;
254 navail = nfree = nowned = 0;
255 if ((map = (s_char *)malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
256 logerror("malloc failed in isok\n");
257 pr("Memory error. Tell the deity.\n");
260 bzero((s_char *)map, (WORLD_X * WORLD_Y) / 2);
265 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
266 xyas(x, y, player->cnum), nowned, nfree, navail);
267 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
268 nmin, noil, ngold, nur);
269 p = getstring("This setup ok? ", buf);
270 if (p == 0 || *p != 'y')
276 ok(s_char *map, int x, int y)
282 if (navail > MAXAVAIL)
287 if (!ef_read(EF_SECTOR, id, (s_char *)§))
289 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
292 if (navail >= MAXAVAIL) {
293 pr("At least %d...\n", MAXAVAIL);
296 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
297 if (sect.sct_own == 0)
301 if (sect.sct_min > 9)
303 if (sect.sct_gmin > 9)
305 if (sect.sct_uran > 9)
307 if (sect.sct_oil > 9)
311 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
312 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);
316 deity_build_land(int type, coord x, coord y, natid own, int tlev)
318 extern int land_mob_max;
321 struct nstr_item nstr;
323 double techfact(int, double);
329 snxtitem_all(&nstr, EF_LAND);
330 while (nxtitem(&nstr, (s_char *)&land)) {
331 if (land.lnd_own == 0) {
337 ef_extend(EF_LAND, 50);
341 land.lnd_mission = 0;
342 land.lnd_type = type;
343 land.lnd_effic = 100;
344 land.lnd_mobil = land_mob_max;
346 land.lnd_tech = tlev;
347 land.lnd_uid = nstr.cur;
354 time(&land.lnd_access);
356 land.lnd_retreat = morale_base;
359 land.lnd_fuel = lp->l_fuelc;
360 land.lnd_nxlight = 0;
362 bzero((s_char *)land.lnd_rpath, 10);
363 land.lnd_rad_max = lp->l_rad;
366 land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
367 land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech);
368 land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech);
369 land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech);
370 land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech);
371 land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech);
372 land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech);
373 land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech);
374 land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech);
375 land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech);
376 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech);
377 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech);
378 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech);
379 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech);
380 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
381 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
383 bzero((s_char *)lvec, sizeof(lvec));
384 getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
386 vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int)lp->l_nv);
387 lvec[I_MILIT] = lp->l_mil;
388 putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
390 putland(land.lnd_uid, &land);
391 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
393 pr("%s", prland(&land));
394 pr(" built in sector %s\n", xyas(x, y, player->cnum));