2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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:
43 #include "prototypes.h"
46 static int isok(int x, int y);
47 static void ok(signed char *map, int x, int y);
48 static void init_sanct(struct natstr *, coord, coord);
50 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
59 struct realmstr newrealm;
60 struct range absrealm;
66 time_t current_time = time(NULL);
68 natp = getnatp(player->cnum);
69 if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
70 pr("Must be at 0,0 to add a new country\n");
73 if (!(natp = natargp(player->argp[1], "Country? ")))
76 if (natp->nat_stat != STAT_NEW) {
77 pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
80 if (player->argp[2] != 0) {
81 if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0)
83 if (!sarg_xy(p, &x, &y) || !getsect(x, y, §))
85 if (sect.sct_type != SCT_RURAL) {
86 pr("%s is a %s; try again...\n",
87 xyas(x, y, player->cnum), dchr[sect.sct_type].d_name);
90 getsect(x + 2, y, §);
91 if (sect.sct_type != SCT_RURAL) {
92 pr("%s is a %s; try again...\n",
93 xyas(x + 2, y, player->cnum), dchr[sect.sct_type].d_name);
97 for (i = 0; i < 300 && !player->aborted; i++) {
98 /* Both x and y should be either odd or even */
99 x = (random() % WORLD_X) - (WORLD_X / 2);
100 y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
102 * If either of the two potential
103 * sanctuary sectors are already
104 * owned by someone else, pick
105 * another place on the map.
107 getsect(x, y, §);
108 if (sect.sct_type != SCT_RURAL || sect.sct_own != 0)
110 getsect(x + 2, y, §);
111 if (sect.sct_type != SCT_RURAL || sect.sct_own != 0)
117 pr("couldn't find an empty slot!\n");
124 pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
125 natp->nat_btu = max_btus;
126 natp->nat_stat = STAT_SANCT;
131 xyabsrange(natp, &defrealm, &absrealm);
132 for (i = 0; i < MAXNOR; i++) {
133 getrealm(i, num, &newrealm);
134 newrealm.r_xl = absrealm.lx;
135 newrealm.r_xh = absrealm.hx;
136 newrealm.r_yl = absrealm.ly;
137 newrealm.r_yh = absrealm.hy;
138 newrealm.r_timestamp = current_time;
145 natp->nat_money = start_cash;
146 natp->nat_level[NAT_HLEV] = start_happiness;
147 natp->nat_level[NAT_RLEV] = start_research;
148 natp->nat_level[NAT_TLEV] = start_technology;
149 natp->nat_level[NAT_ELEV] = start_education;
151 close(creat(mailbox(buf, num), S_IRWUG));
152 init_sanct(natp, x, y);
153 init_sanct(natp, x + 2, y);
159 init_sanct(struct natstr *natp, coord x, coord y)
163 getsect(x, y, §);
164 sect.sct_own = natp->nat_cnum;
165 sect.sct_type = SCT_SANCT;
166 sect.sct_newtype = SCT_SANCT;
167 sect.sct_effic = 100;
170 sect.sct_defense = 0;
171 sect.sct_mobil = startmob;
173 sect.sct_oldown = natp->nat_cnum;
174 if (at_least_one_100) {
176 sect.sct_fertil = 100;
181 sect.sct_item[I_CIVIL] = max_pop(start_research, §);
182 sect.sct_item[I_MILIT] = 55;
183 sect.sct_item[I_FOOD] = opt_NOFOOD ? 0 : 550;
184 sect.sct_item[I_UW] = 75;
188 static int nmin, ngold, noil, nur;
189 static int nfree, navail, nowned;
198 nmin = ngold = noil = nur = 0;
199 navail = nfree = nowned = 0;
200 if (!(map = malloc(WORLD_SZ()))) {
201 logerror("malloc failed in isok\n");
202 pr("Memory error. Tell the deity.\n");
205 memset(map, 0, WORLD_SZ());
210 pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n",
211 xyas(x, y, player->cnum), nowned, nfree, navail);
212 pr("min: %d, oil: %d, gold: %d, uranium: %d\n",
213 nmin, noil, ngold, nur);
214 p = getstring("This setup ok? ", buf);
215 if (p == 0 || *p != 'y')
221 ok(signed char *map, int x, int y)
227 if (navail > MAXAVAIL)
232 if (!ef_read(EF_SECTOR, id, §))
234 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN)
237 if (navail >= MAXAVAIL) {
238 pr("At least %d...\n", MAXAVAIL);
241 if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) {
242 if (sect.sct_own == 0)
246 if (sect.sct_min > 9)
248 if (sect.sct_gmin > 9)
250 if (sect.sct_uran > 9)
252 if (sect.sct_oil > 9)
256 for (dir = DIR_FIRST; dir <= DIR_LAST; dir++)
257 ok(map, diroff[dir][0] + x, diroff[dir][1] + y);