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 * ore.c: Create a world
30 * Known contributors to this file:
35 * In the oceans, it puts oil = (2d6-4)*10+d10, fert = (2d6-2)*10+d10
36 * (max of 127 in both cases)
38 * For islands smaller than ISLANDSIZE, it puts in normal
39 * resources. (These are assumed to be small non-start islands)
40 * For islands at least ISLANDSIZE big, it makes normal fert,
41 * but it uses the MIN, OIL, GOLD, and URAN arrays to find out
42 * what resources to put there. The intent is to find all start
43 * islands, and give them all a pre-determined spread of stuff.
44 * To change the stuff, just change the MIN, OIL, GOLD, and URAN arrays.
46 * For example, if the GOLD array is 90,80,70,60, it'll try to put 1
47 * sector with 90 gold, 1 with 80 gold, 1 with 70, and 1 with 60 gold
48 * on each island of at least ISLANDSIZE. It will not overrun start
49 * sectors, and should be run AFTER you have placed capitals.
53 #if defined(aix) || defined(linux) || defined(solaris)
55 #endif /* aix or linux */
65 #include "prototypes.h"
66 #define XPLATES WORLD_X/2
67 #define YPLATES WORLD_Y
68 #define YbyX (YPLATES*XPLATES/8)
70 #define ISLANDMAX 1000
71 int MIN[] = { 90, 85, 85, 85, 70, 70, 70, 70, 70 };
72 int OIL[] = { 90, 80, 70, 60, 50 };
73 int GOLD[] = { 90, 80, 70, 60, 50 };
74 int URAN[] = { 90, 80, 70, 60, 50 };
81 struct sctstr sects[YPLATES * XPLATES];
82 u_char s[WORLD_Y][WORLD_X];
83 short c[WORLD_Y][WORLD_X];
84 short e[WORLD_Y][WORLD_X];
91 int ix[ISLANDMAX], iy[ISLANDMAX], ic[ISLANDMAX], in = 0;
104 register struct sctstr *sp;
109 s_char *sectfil = NULL;
113 char *config_file = NULL;
116 while ((opt = getopt(argc, argp, "e:s:")) != EOF) {
119 config_file = optarg;
127 emp_config(config_file);
130 sectfil = empfile[EF_SECTOR].file;
132 srandom((unsigned int)now);
133 sectf = open(sectfil, O_RDWR, 0);
138 read(sectf, sects, sizeof(sects));
140 for (y = 0; y < WORLD_Y; y++) {
141 for (x = 0; x < WORLD_X; x++) {
144 c[sp->sct_y][sp->sct_x] = 0;
145 s[sp->sct_y][sp->sct_x] = sp->sct_type;
146 e[sp->sct_y][sp->sct_x] = sp->sct_elev;
150 for (y = 0; y < WORLD_Y; y++) {
151 for (x = 0; x < WORLD_X; x++) {
156 if (s[y][x] == SCT_WATER)
161 for (y1 = 0; y1 < WORLD_Y; y1++)
162 for (x1 = 0; x1 < WORLD_X; x1++)
169 if (size[cont] >= ISLANDSIZE) {
171 for (y1 = 0; y1 < WORLD_Y; y1++)
172 for (x1 = 0; x1 < WORLD_X; x1++)
173 if (c[y1][x1] == cont) {
181 printf("Found island %d of size %d at %d,%d\n",
182 in, size[cont], ix[in - 1], iy[in - 1]);
184 printf("Found islet %d of size %d\n", cont, size[cont]);
185 for (y1 = 0; y1 < WORLD_Y; y1++)
186 for (x1 = 0; x1 < WORLD_X; x1++)
187 if (c[y1][x1] == cont)
188 c[y1][x1] = ISLANDMAX + 1;
194 for (y = 0; y < WORLD_Y; y++) {
195 for (x = 0; x < WORLD_X; x++) {
201 for (x = 0; x < in; x++) {
202 printf("Making ore for island %d\n", x);
203 place(x, MIN, sizeof(MIN) / sizeof(int), OFFSET(sctstr, sct_min),
205 place(x, URAN, sizeof(URAN) / sizeof(int),
206 OFFSET(sctstr, sct_uran), "URAN");
207 place(x, OIL, sizeof(OIL) / sizeof(int), OFFSET(sctstr, sct_oil),
209 place(x, GOLD, sizeof(GOLD) / sizeof(int),
210 OFFSET(sctstr, sct_gmin), "GOLD");
214 write(sectf, sects, sizeof(sects));
219 #define max(a,b) (a < b ? b : a)
231 if (s[y][x] == SCT_WATER)
242 for (dir = 1; dir <= 6; dir++) {
243 dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X;
244 dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y;
249 #define MINIMUM(x,y) (x > y ? y : x)
250 #define MAXIMUM(x,y) (x > y ? x : y)
254 register struct sctstr *sp;
257 int oil, gmin, iron, fertil, ur;
262 if (sp->sct_type == SCT_SANCT)
269 lev = (elev * 12 + nearelev(x, y)) / 18;
277 if (sp->sct_type == SCT_WATER) {
278 oil = MAXIMUM(((roll(6) + roll(6) - 4) * 10 + roll(10)), 0);
279 sp->sct_oil = MINIMUM(oil, 127);
280 fertil = MAXIMUM(((roll(6) + roll(6) - 2) * 12 + roll(10)), 0);
281 sp->sct_fertil = MINIMUM(fertil, 127);
284 iron = roll(100) + 100 - roll(100);
285 oil = roll(100) + 100 - roll(100);
286 ur = roll(100) + 100 - roll(100);
287 gmin = roll(100) + 100 - roll(100);
288 fertil = 85 + 100 - roll(100);
290 iron = MAXIMUM(iron, 0);
291 oil = MAXIMUM(oil, 0);
293 gmin = MAXIMUM(gmin, 0);
294 fertil = MAXIMUM(fertil, 0);
295 iron = MINIMUM(iron, 127);
296 oil = MINIMUM(oil, 127);
297 ur = MINIMUM(ur, 127);
298 gmin = MINIMUM(gmin, 127);
299 fertil = MINIMUM(fertil, 127);
301 sp->sct_fertil = fertil;
309 fertil = MAXIMUM(fertil, 0);
310 fertil = MINIMUM(fertil, 127);
311 sp->sct_fertil = fertil;
326 for (dir = 1; dir <= 6; dir++) {
327 dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X;
328 dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y;
334 /* Already in libgen.a
353 place(island, res, num, offset, restype)
354 int island, res[], num, offset;
357 int x1, y1, x2, y2, x3, y3, j, k;
358 int tried[WORLD_Y][WORLD_X];
365 for (k = 0; k < num; k++) {
369 bzero((s_char *)tried, sizeof(tried));
371 while ((sects[y2 * XPLATES + x2 / 2].sct_type == SCT_WATER) ||
373 ((u_char *)(((s_char *)§s[y2 * XPLATES + x2 / 2]) +
375 || (sects[y2 * XPLATES + x2 / 2].sct_type == SCT_MOUNT)) {
378 *((u_char *)(((s_char *)§s[y2 * XPLATES + x2 / 2]) +
381 foo = §s[y2 * XPLATES + x2 / 2];
383 if (sects[y2 * XPLATES + x2 / 2].sct_type == SCT_RURAL) {
384 if (!tried[y2][x2]) {
387 if (numtried == ISLANDSIZE) {
389 printf("*** %d) couldn't place %s %d (%d)\n",
390 island, restype, k, res[k]);
391 for (a = 0; a < WORLD_Y; a++)
392 for (b = 0; b < WORLD_X; b++)
394 printf("\tTried %d,%d\n", b, a);
401 x3 = (diroff[j][0] + x2 + WORLD_X) % WORLD_X;
402 y3 = (diroff[j][1] + y2 + WORLD_Y) % WORLD_Y;
403 } while (sects[y3 * XPLATES + x3 / 2].sct_type == SCT_WATER);
408 /* sects[y2*XPLATES+x2/2].sct_min = MIN[k]; */
409 *((u_char *)(((s_char *)§s[y2 * XPLATES + x2 / 2]) + offset)) =